From 8c0e5213d37f959dd6f08a765cc5ef5582a2696d Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 23 Jan 2023 12:47:16 +1100 Subject: [PATCH] Delegate debug for ScriptBuf to Script Currently the derived implementation of `Debug` for `ScriptBuf` prints the inner vector of u8s as integers, this is ugly and hard to read. The `Script` implementation of `Debug` prints the script opcodes and data as hex, we can just delegate to it. With this applied we get debug output of form: Script(OP_DUP OP_HASH160 OP_PUSHBYTES_20 \ 3bde42dbee7e4dbe6a21b2d50ce2f0167faa8159 OP_EQUALVERIFY OP_CHECKSIG) Fix: #1516 --- bitcoin/src/blockdata/script.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/script.rs b/bitcoin/src/blockdata/script.rs index 6ea51a63..7359c3d1 100644 --- a/bitcoin/src/blockdata/script.rs +++ b/bitcoin/src/blockdata/script.rs @@ -137,7 +137,7 @@ pub struct Script([u8]); /// that all the safety/validity restrictions that apply to [`Script`] apply to `ScriptBuf` as well. /// /// [deref coercions]: https://doc.rust-lang.org/std/ops/trait.Deref.html#more-on-deref-coercion -#[derive(Default, Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] +#[derive(Default, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct ScriptBuf(Vec); impl ToOwned for Script { @@ -1315,6 +1315,12 @@ impl ScriptBuf { } } +impl fmt::Debug for ScriptBuf { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.as_script(), f) + } +} + impl Deref for ScriptBuf { type Target = Script;