MCPcopy Create free account
hub / github.com/BitVM/BitVM / compute_block_hash

Method compute_block_hash

header-chain/src/header_chain.rs:119–135  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

117
118impl CircuitBlockHeader {
119 pub fn compute_block_hash(&self) -> [u8; 32] {
120 let mut hasher = Sha256::new();
121 hasher.update(&self.version.to_le_bytes());
122 hasher.update(&self.prev_block_hash);
123 hasher.update(&self.merkle_root);
124 hasher.update(&self.time.to_le_bytes());
125 hasher.update(&self.bits.to_le_bytes());
126 hasher.update(&self.nonce.to_le_bytes());
127 let first_hash_result = hasher.finalize_reset();
128
129 hasher.update(first_hash_result);
130 let result: [u8; 32] = hasher
131 .finalize()
132 .try_into()
133 .expect("SHA256 should produce a 32-byte output");
134 result
135 }
136}
137
138impl From<Header> for CircuitBlockHeader {

Callers 7

apply_blocksMethod · 0.80
test_hash_check_failFunction · 0.80
test_hash_check_passFunction · 0.80
verifyMethod · 0.80
test_spvFunction · 0.80

Calls 1

finalizeMethod · 0.45

Tested by 5

test_hash_check_failFunction · 0.64
test_hash_check_passFunction · 0.64
test_spvFunction · 0.64