Add `ChainHash::from_genesis_block_hash`

This improves readability of converting `BlockHash` into `ChainHash`.
It's useful in e.g. Electrum protocol which sends `BlockHash`
(serialized backward).

Closes #1751
This commit is contained in:
Martin Habovstiak 2023-03-26 10:40:30 +02:00
parent d8c7cd1e6c
commit ed80df5ebc
1 changed files with 5 additions and 0 deletions

View File

@ -185,6 +185,11 @@ impl ChainHash {
let hashes = [Self::BITCOIN, Self::TESTNET, Self::SIGNET, Self::REGTEST];
hashes[network as usize]
}
/// Converts genesis block hash into `ChainHash`.
pub fn from_genesis_block_hash(block_hash: crate::BlockHash) -> Self {
ChainHash(block_hash.to_byte_array())
}
}
#[cfg(test)]