New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constants to ChainHash
for each Network
#1283
Add constants to ChainHash
for each Network
#1283
Conversation
`ChainHash::using_genesis_block` can't be made `const` because it uses a `match` expression, which is only valid in Rust 1.46. Add individual constants as a workaround so that `ChainHash` can be used in `const` contexts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK b1d8516
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK b1d8516
Thanks for the contribution man! |
Oh, I didn't see this soon enough
Actually, it can! let hashes = [GENESIS_BLOCK_HASH_BITCOIN, GENESIS_BLOCK_HASH_TESTNET, GENESIS_BLOCK_HASH_SIGNET, GENESIS_BLOCK_HASH_REGTEST];
ChainHash(hashes[network as usize]) I don't mind making them public, it's useful anywas, but having |
Yeah, I could put that together. Is there any concern that adding a new |
We could write a dummy test that matches all variants returning |
No reason, just that |
I'm surprised we missed it before. I guess I will go through all of enums at some point. |
Yeah, we should -- but I think so far we only went through error enums because those were easy targets for non_exhaustie. |
92ef41b Make `ChainHash::using_genesis_block` constant (Jeffrey Czyz) Pull request description: 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. Follow-up suggested in [#1283](#1283 (comment)). ACKs for top commit: apoelstra: ACK 92ef41b Kixunil: ACK 92ef41b Tree-SHA512: 71f95877c8e5335012ad0339e1f8691e3b33344fa02ecc24c3d4d728232cb7b0de62aec20eb1855b23eeccfbc2eeab920b21ee2243d95c6c89fa8ad5bc846975
ChainHash::using_genesis_block
can't be madeconst
because it uses amatch
expression, which is only valid in Rust 1.46. Add individual constants as a workaround so thatChainHash
can be used inconst
contexts.