Merge rust-bitcoin/rust-bitcoin#1753: Add `ChainHash::from_genesis_block_hash`

ed80df5ebc Add `ChainHash::from_genesis_block_hash` (Martin Habovstiak)

Pull request description:

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

  Closes #1751

ACKs for top commit:
  apoelstra:
    ACK ed80df5ebc
  tcharding:
    ACK ed80df5ebc

Tree-SHA512: b03eb9ca0a1eb38196cc8e43751c2def0d00b463b774003c5319bf56599db598ddd4bb0e2ad0bd3803f21a925135992d421848e7b1ba5e7bab3a405f60fc973c
This commit is contained in:
Andrew Poelstra 2023-03-28 00:45:43 +00:00
commit dc72dfb9f2
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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)]