Manually implement block::Header::block_hash
We want to move the `block_hash` function to `primitives` but it uses `Encodable` which currently lives in `bitcoin`. Just implement it manually. We added a regression test already in a previous commit to check that this is correct.
This commit is contained in:
parent
b02ab25342
commit
65925117a0
|
@ -66,9 +66,16 @@ impl Header {
|
|||
pub const SIZE: usize = 4 + 32 + 32 + 4 + 4 + 4; // 80
|
||||
|
||||
/// Returns the block hash.
|
||||
// This is the same as `Encodable` but done manually because `Encodable` isn't in `primitives`.
|
||||
pub fn block_hash(&self) -> BlockHash {
|
||||
let mut engine = sha256d::Hash::engine();
|
||||
self.consensus_encode(&mut engine).expect("engines don't error");
|
||||
engine.input(&self.version.to_consensus().to_le_bytes());
|
||||
engine.input(self.prev_blockhash.as_byte_array());
|
||||
engine.input(self.merkle_root.as_byte_array());
|
||||
engine.input(&self.time.to_le_bytes());
|
||||
engine.input(&self.bits.to_consensus().to_le_bytes());
|
||||
engine.input(&self.nonce.to_le_bytes());
|
||||
|
||||
BlockHash::from_byte_array(sha256d::Hash::from_engine(engine).to_byte_array())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue