Implement manual fmt::Debug for BlockHeader to include block hash

This commit is contained in:
Steven Roose 2023-10-17 02:00:42 +01:00
parent e0ddead255
commit b108ffa2ec
No known key found for this signature in database
GPG Key ID: 2F2A88D7F8D68E87
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.