Skip to main content

BlockHeader

Struct BlockHeader 

Source
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: Hash32

Commitment 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: u32

Compact 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

Source

pub fn equihash_input(&self) -> [u8; 108]

The 108-byte Equihash puzzle input: every header field before the nonce and solution.

Source

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}
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BlockHeader

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for BlockHeader

Source§

impl PartialEq for BlockHeader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for BlockHeader

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for BlockHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.