From ed80df5ebc654c7da3f74572b109432430f08450 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sun, 26 Mar 2023 10:40:30 +0200 Subject: [PATCH] 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 --- bitcoin/src/blockdata/constants.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index 01d8238c..7a737d38 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -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)]