snarkvm_ledger_block/
genesis.rs1use super::*;
17
18impl<N: Network> Block<N> {
19 pub const NUM_GENESIS_TRANSACTIONS: usize = 4;
21
22 pub fn is_genesis(&self) -> Result<bool> {
24 if !self.header.is_genesis()? {
25 return Ok(false);
26 }
27
28 ensure!(self.previous_hash == N::BlockHash::default(), "Invalid previous hash");
29 ensure!(self.authority.is_beacon(), "Invalid block authority");
30 ensure!(self.solutions.is_empty(), "Invalid solutins");
31 ensure!(self.transactions.num_rejected() == 0, "Invalid number of rejected transactions");
32 ensure!(self.aborted_transaction_ids.is_empty(), "Genesis block must not contain aborted transactions");
33
34 #[cfg(not(any(test, feature = "test")))]
36 {
37 ensure!(self.ratifications.len() == 1, "Invalid number of ratifications");
38 ensure!(
39 self.transactions.num_accepted() == Self::NUM_GENESIS_TRANSACTIONS,
40 "Invalid number of accepted transactions"
41 );
42 ensure!(
43 self.transactions.num_finalize() == 2 * Self::NUM_GENESIS_TRANSACTIONS,
44 "Invalid number of finalized transactions"
45 );
46 }
47
48 Ok(true)
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55 use console::network::MainnetV0;
56
57 type CurrentNetwork = MainnetV0;
58
59 #[test]
60 fn test_genesis() {
61 let genesis_block = Block::<CurrentNetwork>::read_le(CurrentNetwork::genesis_bytes()).unwrap();
63 assert!(genesis_block.is_genesis().unwrap());
64 }
65}