Merge rust-bitcoin/rust-bitcoin#1580: Delegate debug for ScriptBuf to Script

8c0e5213d3 Delegate debug for ScriptBuf to Script (Tobin C. Harding)

Pull request description:

  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

ACKs for top commit:
  Kixunil:
    ACK 8c0e5213d3
  apoelstra:
    ACK 8c0e5213d3

Tree-SHA512: ca07d9fb191f4e0379cbd96b2944e6881094a8334d39b97209b6bf452a3c15d4aede53b9c88176b9b7667b7a539d47897940bc561dc9f8cd83ce1990a08047e1
This commit is contained in:
Andrew Poelstra 2023-01-24 15:11:56 +00:00
commit 96865e3b23
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 7 additions and 1 deletions

View File

@ -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<u8>);
impl ToOwned for Script {
@ -1334,6 +1334,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;