diff --git a/src/miniscript/astelem.rs b/src/miniscript/astelem.rs index 4c806a23e..49bd2a84b 100644 --- a/src/miniscript/astelem.rs +++ b/src/miniscript/astelem.rs @@ -89,7 +89,7 @@ impl Terminal { if ch == 'c' { if let Terminal::PkK(ref pk) = sub.node { // alias: pk(K) = c:pk_k(K) - return write!(f, "pk({})", pk); + return fmt_1(f, "pk(", pk, is_debug); } else if let Terminal::RawPkH(ref pkh) = sub.node { // `RawPkH` is currently unsupported in the descriptor spec // alias: pkh(K) = c:pk_h(K) @@ -97,10 +97,10 @@ impl Terminal { // are not defined in the spec yet. These are prefixed with `expr` // in the descriptor string. // We do not support parsing these descriptors yet. - return write!(f, "expr_raw_pkh({})", pkh); + return fmt_1(f, "expr_raw_pkh(", pkh, is_debug); } else if let Terminal::PkH(ref pk) = sub.node { // alias: pkh(K) = c:pk_h(K) - return write!(f, "pkh({})", pk); + return fmt_1(f, "pkh(", pk, is_debug); } } @@ -119,7 +119,11 @@ impl Terminal { }, _ => {} }; - write!(f, "{}", sub) + if is_debug { + write!(f, "{:?}", sub) + } else { + write!(f, "{}", sub) + } } else { unreachable!(); } @@ -180,7 +184,6 @@ fn conditional_fmt( impl fmt::Debug for Terminal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fn fmt_type_map(f: &mut fmt::Formatter<'_>, type_map: types::Type) -> fmt::Result { f.write_str(match type_map.corr.base { types::Base::B => "B", @@ -223,15 +226,8 @@ impl fmt::Debug for Terminal { f.write_str("TYPECHECK FAILED")?; } f.write_str("]")?; - if let Some((ch, sub)) = self.wrap_char() { - fmt::Write::write_char(f, ch)?; - if sub.node.wrap_char().is_none() { - f.write_str(":")?; - } - write!(f, "{:?}", sub) - } else { - self.conditional_fmt(f, true) - } + + self.conditional_fmt(f, true) } } diff --git a/src/miniscript/mod.rs b/src/miniscript/mod.rs index 053fc6da1..03f41fc39 100644 --- a/src/miniscript/mod.rs +++ b/src/miniscript/mod.rs @@ -898,7 +898,7 @@ mod tests { phantom: PhantomData, })); let pkk_ms: Miniscript = Miniscript::from_ast(pk_node).unwrap(); - dummy_string_rtt(pkk_ms, "[B/onduesm]c:[K/onduesm]pk_k(\"\")", "pk()"); + dummy_string_rtt(pkk_ms, "[B/onduesm]pk(\"\")", "pk()"); let pkh_node = Terminal::Check(Arc::new(Miniscript { node: Terminal::PkH(String::from("")), @@ -908,7 +908,7 @@ mod tests { })); let pkh_ms: Miniscript = Miniscript::from_ast(pkh_node).unwrap(); - let expected_debug = "[B/nduesm]c:[K/nduesm]pk_h(\"\")"; + let expected_debug = "[B/nduesm]pkh(\"\")"; let expected_display = "pkh()"; assert_eq!(pkh_ms.ty.corr.base, types::Base::B); @@ -988,7 +988,7 @@ mod tests { string_rtt( script, - "[B/onduesm]c:[K/onduesm]pk_k(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/onduesm]pk(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "pk(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)" ); @@ -996,7 +996,7 @@ mod tests { string_rtt( script, - "[B/onduesm]c:[K/onduesm]pk_k(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/onduesm]pk(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "pk(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)" ); @@ -1004,7 +1004,7 @@ mod tests { string_rtt( script, - "[B/onufsm]t[V/onfsm]v[B/onduesm]c:[K/onduesm]pk_k(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/onufsm]t[V/onfsm]v:[B/onduesm]pk(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "tv:pk(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)" ); @@ -1012,7 +1012,7 @@ mod tests { string_display_debug_test( script, - "[B/nduesm]c:[K/nduesm]pk_h(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/nduesm]pkh(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "pkh(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)", ); @@ -1020,7 +1020,7 @@ mod tests { string_display_debug_test( script, - "[B/nduesm]c:[K/nduesm]pk_h(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/nduesm]pkh(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "pkh(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)", ); @@ -1028,7 +1028,7 @@ mod tests { string_display_debug_test( script, - "[B/nufsm]t[V/nfsm]v[B/nduesm]c:[K/nduesm]pk_h(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", + "[B/nufsm]t[V/nfsm]v:[B/nduesm]pkh(PublicKey { compressed: true, inner: PublicKey(aa4c32e50fb34a95a372940ae3654b692ea35294748c3dd2c08b29f87ba9288c8294efcb73dc719e45b91c45f084e77aebc07c1ff3ed8f37935130a36304a340) })", "tv:pkh(028c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa)", ); }