Merge rust-bitcoin/rust-bitcoin#2126: Implement manual fmt::Debug for BlockHeader to include block hash

b108ffa2ec Implement manual fmt::Debug for BlockHeader to include block hash (Steven Roose)

Pull request description:

  I think it makes sense for a block header to have the block hash shown in the debug print.

ACKs for top commit:
  tcharding:
    ACK b108ffa2ec
  vincenzopalazzo:
    ACK b108ffa2ec
  apoelstra:
    ACK b108ffa2ec

Tree-SHA512: 37b77f8b2d8da3903bc5ff329abd45dcb5f189ba2ac38fc309fa477b0eb569b01dd85c41f160e073bb56b4a599b7c4774fbfbd8da4b82ddb41540d60bfeafea3
This commit is contained in:
Andrew Poelstra 2023-10-17 20:47:06 +00:00
commit 37daf4620c
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 15 additions and 1 deletions

View File

@ -33,7 +33,7 @@ use crate::{io, merkle_tree, VarInt};
/// ### Bitcoin Core References
///
/// * [CBlockHeader definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/block.h#L20)
#[derive(Copy, PartialEq, Eq, Clone, Debug, PartialOrd, Ord, Hash)]
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
pub struct Header {
@ -92,6 +92,20 @@ impl Header {
pub fn work(&self) -> Work { self.target().to_work() }
}
impl fmt::Debug for Header {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Header")
.field("block_hash", &self.block_hash())
.field("version", &self.version)
.field("prev_blockhash", &self.prev_blockhash)
.field("merkle_root", &self.merkle_root)
.field("time", &self.time)
.field("bits", &self.bits)
.field("nonce", &self.nonce)
.finish()
}
}
/// Bitcoin block version number.
///
/// Originally used as a protocol version, but repurposed for soft-fork signaling.