Remove BlockHash::all_zeros
Recently we removed the `all_zeros` function from `OutPoint` in favour of a more meaningfully named associated const. We can do the same for `BlockHash`, the all zeros has is used for the previous blockhash of the genesis block, add a const named as such. In test code where we use the `all_zeros` function, just use the more explicit form `from_byte_array([0; 32])`.
This commit is contained in:
parent
20d8dbd586
commit
6b9429ac7b
|
@ -497,7 +497,7 @@ mod test {
|
|||
{
|
||||
// test serialization
|
||||
let raw: Vec<u8> = serialize(&BlockTransactionsRequest {
|
||||
block_hash: BlockHash::all_zeros(),
|
||||
block_hash: BlockHash::from_byte_array([0; 32]),
|
||||
indexes: testcase.1,
|
||||
});
|
||||
let mut expected_raw: Vec<u8> = [0u8; 32].to_vec();
|
||||
|
@ -520,7 +520,7 @@ mod test {
|
|||
#[should_panic] // 'attempt to add with overflow' in consensus_encode()
|
||||
fn test_getblocktx_panic_when_encoding_u64_max() {
|
||||
serialize(&BlockTransactionsRequest {
|
||||
block_hash: BlockHash::all_zeros(),
|
||||
block_hash: BlockHash::from_byte_array([0; 32]),
|
||||
indexes: vec![u64::MAX],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -32,11 +32,8 @@ hashes::hash_newtype! {
|
|||
impl_hashencode!(BlockHash);
|
||||
|
||||
impl BlockHash {
|
||||
/// The "all zeros" blockhash.
|
||||
///
|
||||
/// This is not the hash of a real block. It is used as the previous blockhash
|
||||
/// of the genesis block and in other placeholder contexts.
|
||||
pub fn all_zeros() -> Self { Self::from_byte_array([0; 32]) }
|
||||
/// Dummy hash used as the previous blockhash of the genesis block.
|
||||
pub const GENESIS_PREVIOUS_BLOCK_HASH: Self = Self::from_byte_array([0; 32]);
|
||||
}
|
||||
|
||||
/// Bitcoin block header.
|
||||
|
|
|
@ -113,7 +113,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
|
|||
Network::Bitcoin => Block {
|
||||
header: block::Header {
|
||||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: 1231006505,
|
||||
bits: CompactTarget::from_consensus(0x1d00ffff),
|
||||
|
@ -124,7 +124,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
|
|||
Network::Testnet => Block {
|
||||
header: block::Header {
|
||||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: 1296688602,
|
||||
bits: CompactTarget::from_consensus(0x1d00ffff),
|
||||
|
@ -135,7 +135,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
|
|||
Network::Signet => Block {
|
||||
header: block::Header {
|
||||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: 1598918400,
|
||||
bits: CompactTarget::from_consensus(0x1e0377ae),
|
||||
|
@ -146,7 +146,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block {
|
|||
Network::Regtest => Block {
|
||||
header: block::Header {
|
||||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: 1296688602,
|
||||
bits: CompactTarget::from_consensus(0x207fffff),
|
||||
|
@ -261,7 +261,7 @@ mod test {
|
|||
let gen = genesis_block(¶ms::MAINNET);
|
||||
|
||||
assert_eq!(gen.header.version, block::Version::ONE);
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::GENESIS_PREVIOUS_BLOCK_HASH);
|
||||
assert_eq!(
|
||||
gen.header.merkle_root.to_string(),
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
|
@ -280,7 +280,7 @@ mod test {
|
|||
fn testnet_genesis_full_block() {
|
||||
let gen = genesis_block(¶ms::TESTNET);
|
||||
assert_eq!(gen.header.version, block::Version::ONE);
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::GENESIS_PREVIOUS_BLOCK_HASH);
|
||||
assert_eq!(
|
||||
gen.header.merkle_root.to_string(),
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
|
@ -298,7 +298,7 @@ mod test {
|
|||
fn signet_genesis_full_block() {
|
||||
let gen = genesis_block(¶ms::SIGNET);
|
||||
assert_eq!(gen.header.version, block::Version::ONE);
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::all_zeros());
|
||||
assert_eq!(gen.header.prev_blockhash, BlockHash::GENESIS_PREVIOUS_BLOCK_HASH);
|
||||
assert_eq!(
|
||||
gen.header.merkle_root.to_string(),
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
|
|
|
@ -159,7 +159,7 @@ mod tests {
|
|||
assert_eq!(real_decode.version, 70002);
|
||||
assert_eq!(real_decode.locator_hashes.len(), 1);
|
||||
assert_eq!(serialize(&real_decode.locator_hashes[0]), genhash);
|
||||
assert_eq!(real_decode.stop_hash, BlockHash::all_zeros());
|
||||
assert_eq!(real_decode.stop_hash, BlockHash::GENESIS_PREVIOUS_BLOCK_HASH);
|
||||
|
||||
assert_eq!(serialize(&real_decode), from_sat);
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ mod tests {
|
|||
assert_eq!(real_decode.version, 70002);
|
||||
assert_eq!(real_decode.locator_hashes.len(), 1);
|
||||
assert_eq!(serialize(&real_decode.locator_hashes[0]), genhash);
|
||||
assert_eq!(real_decode.stop_hash, BlockHash::all_zeros());
|
||||
assert_eq!(real_decode.stop_hash, BlockHash::GENESIS_PREVIOUS_BLOCK_HASH);
|
||||
|
||||
assert_eq!(serialize(&real_decode), from_sat);
|
||||
}
|
||||
|
|
|
@ -1771,7 +1771,7 @@ mod tests {
|
|||
// Block 2015, the only information used are `bits` and `time`
|
||||
let current = Header {
|
||||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: 1599332177,
|
||||
bits: epoch_start.bits,
|
||||
|
@ -1793,7 +1793,7 @@ mod tests {
|
|||
// Block 2016, the only information used is `time`
|
||||
let epoch_start = Header {
|
||||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: 1599332844,
|
||||
bits: starting_bits,
|
||||
|
@ -1803,7 +1803,7 @@ mod tests {
|
|||
// Block 4031, the only information used are `bits` and `time`
|
||||
let current = Header {
|
||||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::all_zeros(),
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: 1600591200,
|
||||
bits: starting_bits,
|
||||
|
|
Loading…
Reference in New Issue