Make `ChainHash::using_genesis_block` constant
ChainHash::using_genesis_block can't be `const` if it uses a `match` expression prior to Rust 1.46. Use an array mapping to work around this limitation.
This commit is contained in:
parent
ba642daf54
commit
92ef41b663
|
@ -188,13 +188,9 @@ impl ChainHash {
|
||||||
///
|
///
|
||||||
/// See [BOLT 0](https://github.com/lightning/bolts/blob/ffeece3dab1c52efdb9b53ae476539320fa44938/00-introduction.md#chain_hash)
|
/// See [BOLT 0](https://github.com/lightning/bolts/blob/ffeece3dab1c52efdb9b53ae476539320fa44938/00-introduction.md#chain_hash)
|
||||||
/// for specification.
|
/// for specification.
|
||||||
pub fn using_genesis_block(network: Network) -> Self {
|
pub const fn using_genesis_block(network: Network) -> Self {
|
||||||
match network {
|
let hashes = [Self::BITCOIN, Self::TESTNET, Self::SIGNET, Self::REGTEST];
|
||||||
Network::Bitcoin => Self::BITCOIN,
|
hashes[network as usize]
|
||||||
Network::Testnet => Self::TESTNET,
|
|
||||||
Network::Signet => Self::SIGNET,
|
|
||||||
Network::Regtest => Self::REGTEST,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +277,14 @@ mod test {
|
||||||
|
|
||||||
// Compare strings because the spec specifically states how the chain hash must encode to hex.
|
// Compare strings because the spec specifically states how the chain hash must encode to hex.
|
||||||
assert_eq!(got, want);
|
assert_eq!(got, want);
|
||||||
|
|
||||||
|
match network {
|
||||||
|
Network::Bitcoin => {},
|
||||||
|
Network::Testnet => {},
|
||||||
|
Network::Signet => {},
|
||||||
|
Network::Regtest => {},
|
||||||
|
// Update ChainHash::using_genesis_block and chain_hash_genesis_block with new variants.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! chain_hash_genesis_block {
|
macro_rules! chain_hash_genesis_block {
|
||||||
|
|
Loading…
Reference in New Issue