diff --git a/zebra-consensus/src/lib.rs b/zebra-consensus/src/lib.rs index 8c105941b..aa1486c67 100644 --- a/zebra-consensus/src/lib.rs +++ b/zebra-consensus/src/lib.rs @@ -17,6 +17,7 @@ pub mod block; pub mod checkpoint; pub mod mempool; +pub mod parameters; pub mod redjubjub; mod script; mod transaction; diff --git a/zebra-consensus/src/parameters.rs b/zebra-consensus/src/parameters.rs new file mode 100644 index 000000000..488cfdcb7 --- /dev/null +++ b/zebra-consensus/src/parameters.rs @@ -0,0 +1,36 @@ +//! The consensus parameters for each Zcash network. +//! +//! Some consensus parameters change based on network upgrades. Each network +//! upgrade happens at a particular block height. Some parameters have a value +//! (or function) before the upgrade height, at the upgrade height, and after +//! the upgrade height. (For example, the value of the reserved field in the +//! block header during the Heartwood upgrade.) +//! +//! Typically, consensus parameters are accessed via a function that takes a +//! `Network` and `BlockHeight`. + +use zebra_chain::block::BlockHeaderHash; +use zebra_chain::{Network, Network::*}; + +/// Returns the previous block hash for the genesis block in `network`. +pub fn genesis_previous_block_hash(network: Network) -> BlockHeaderHash { + // All current networks use all-zeroes for the parent of the genesis block. + // (In Bitcoin, `null` is `[0; 32]`.) + // + // TODO: make this function const when feature(const_if_match) stabilises. + match network { + Mainnet | Testnet => BlockHeaderHash([0; 32]), + } +} + +/// Returns the hash for the genesis block in `network`. +pub fn genesis_hash(network: Network) -> BlockHeaderHash { + match network { + // zcash-cli getblockhash 0 | zebrad revhex + Mainnet => "08ce3d9731b000c08338455c8a4a6bd05da16e26b11daa1b917184ece80f0400", + // zcash-cli -testnet getblockhash 0 | zebrad revhex + Testnet => "382c4a332661c7ed0671f32a34d724619f086c61873bce7c99859dd9920aa605", + } + .parse() + .expect("hard-coded hash parses") +}