pub struct BlockHeader {
pub version: u32,
pub prev_hash: Hash32,
pub merkle_root: Hash32,
pub state_root: Hash32,
pub time: u32,
pub bits: u32,
pub nonce: [u8; 32],
pub solution: Vec<u8>,
}Fields§
§version: u32§prev_hash: Hash32§merkle_root: Hash32§state_root: Hash32Commitment to chain state (UTXO/note/contract roots). Zero until the state-commitment milestone; consensus requires zero for now. Occupies the reserved-hash slot of the Zcash header layout.
time: u32§bits: u32Compact difficulty target (Bitcoin nBits encoding).
nonce: [u8; 32]§solution: Vec<u8>Equihash solution: big-endian bitstream of (c+1)-bit indices (1344 bytes on mainnet, like Zcash).
Implementations§
Source§impl BlockHeader
impl BlockHeader
Sourcepub fn equihash_input(&self) -> [u8; 108]
pub fn equihash_input(&self) -> [u8; 108]
The 108-byte Equihash puzzle input: every header field before the nonce and solution.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
pub fn serialize(&self) -> Vec<u8> ⓘ
Full wire serialization: 140-byte fixed region + solution.
Examples found in repository?
examples/golden_gen.rs (line 53)
4fn main() {
5 let tx = Transaction {
6 version: 1,
7 inputs: vec![TxInput {
8 prev: OutPoint { txid: [0x11; 32], vout: 3 },
9 pubkey: vec![0x22; 8],
10 signature: vec![0x33; 4],
11 }],
12 outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13 coinbase_data: vec![],
14 shielded: Some(ShieldedBundle {
15 spends: vec![ShieldedSpend {
16 anchor: [0x55; 32],
17 nullifier: [0x66; 32],
18 value: 42,
19 proof: vec![0x77; 5],
20 }],
21 outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22 transfers: vec![ShieldedTransfer {
23 anchor: [0x99; 32],
24 nullifier: [0xaa; 32],
25 commitment1: [0xbb; 32],
26 commitment2: [0xcc; 32],
27 fee: 9,
28 memo: vec![0xdd; 3],
29 proof: vec![0xee; 6],
30 }],
31 }),
32 contract: Some(ContractAction::Call {
33 contract: [0xff; 32],
34 input: vec![1, 2, 3],
35 value: 55,
36 gas_limit: 1000,
37 }),
38 };
39 println!("txid: {}", hex::encode(tx.txid()));
40 println!("sighash: {}", hex::encode(tx.sighash()));
41 println!("size: {}", tx.serialized_size());
42
43 let header = BlockHeader {
44 version: 1,
45 prev_hash: [0x01; 32],
46 merkle_root: [0x02; 32],
47 state_root: [0x00; 32],
48 time: 1_790_000_000,
49 bits: 0x207fffff,
50 nonce: [0x03; 32],
51 solution: vec![0x04; 36],
52 };
53 println!("header_ser_len: {}", header.serialize().len());
54 println!("header_hash: {}", hex::encode(header.hash()));
55 let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56 println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}Sourcepub fn hash(&self) -> Hash32
pub fn hash(&self) -> Hash32
Block id: double-SHA256 of the serialized header, compared to the difficulty target as a little-endian integer.
Examples found in repository?
examples/golden_gen.rs (line 54)
4fn main() {
5 let tx = Transaction {
6 version: 1,
7 inputs: vec![TxInput {
8 prev: OutPoint { txid: [0x11; 32], vout: 3 },
9 pubkey: vec![0x22; 8],
10 signature: vec![0x33; 4],
11 }],
12 outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13 coinbase_data: vec![],
14 shielded: Some(ShieldedBundle {
15 spends: vec![ShieldedSpend {
16 anchor: [0x55; 32],
17 nullifier: [0x66; 32],
18 value: 42,
19 proof: vec![0x77; 5],
20 }],
21 outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22 transfers: vec![ShieldedTransfer {
23 anchor: [0x99; 32],
24 nullifier: [0xaa; 32],
25 commitment1: [0xbb; 32],
26 commitment2: [0xcc; 32],
27 fee: 9,
28 memo: vec![0xdd; 3],
29 proof: vec![0xee; 6],
30 }],
31 }),
32 contract: Some(ContractAction::Call {
33 contract: [0xff; 32],
34 input: vec![1, 2, 3],
35 value: 55,
36 gas_limit: 1000,
37 }),
38 };
39 println!("txid: {}", hex::encode(tx.txid()));
40 println!("sighash: {}", hex::encode(tx.sighash()));
41 println!("size: {}", tx.serialized_size());
42
43 let header = BlockHeader {
44 version: 1,
45 prev_hash: [0x01; 32],
46 merkle_root: [0x02; 32],
47 state_root: [0x00; 32],
48 time: 1_790_000_000,
49 bits: 0x207fffff,
50 nonce: [0x03; 32],
51 solution: vec![0x04; 36],
52 };
53 println!("header_ser_len: {}", header.serialize().len());
54 println!("header_hash: {}", hex::encode(header.hash()));
55 let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56 println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}Trait Implementations§
Source§impl Clone for BlockHeader
impl Clone for BlockHeader
Source§impl Debug for BlockHeader
impl Debug for BlockHeader
Source§impl<'de> Deserialize<'de> for BlockHeader
impl<'de> Deserialize<'de> for BlockHeader
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for BlockHeader
Source§impl PartialEq for BlockHeader
impl PartialEq for BlockHeader
Source§impl Serialize for BlockHeader
impl Serialize for BlockHeader
impl StructuralPartialEq for BlockHeader
Auto Trait Implementations§
impl Freeze for BlockHeader
impl RefUnwindSafe for BlockHeader
impl Send for BlockHeader
impl Sync for BlockHeader
impl Unpin for BlockHeader
impl UnsafeUnpin for BlockHeader
impl UnwindSafe for BlockHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more