pub struct Header<N>where
N: Network,{ /* private fields */ }
Expand description
The header for the block contains metadata that uniquely identifies the block.
Implementations§
Source§impl<N> Header<N>where
N: Network,
impl<N> Header<N>where
N: Network,
Sourcepub fn genesis(
ratifications: &Ratifications<N>,
transactions: &Transactions<N>,
ratified_finalize_operations: Vec<FinalizeOperation<N>>,
) -> Result<Header<N>, Error>
pub fn genesis( ratifications: &Ratifications<N>, transactions: &Transactions<N>, ratified_finalize_operations: Vec<FinalizeOperation<N>>, ) -> Result<Header<N>, Error>
Initializes the genesis block header.
Sourcepub fn is_genesis(&self) -> bool
pub fn is_genesis(&self) -> bool
Returns true
if the block header is a genesis block header.
Source§impl<N> Header<N>where
N: Network,
impl<N> Header<N>where
N: Network,
Sourcepub fn to_path(
&self,
leaf: &HeaderLeaf<N>,
) -> Result<MerklePath<N, snarkvm_console_program::::state_path::configuration::HeaderPath::{constant#0}>, Error>
pub fn to_path( &self, leaf: &HeaderLeaf<N>, ) -> Result<MerklePath<N, snarkvm_console_program::::state_path::configuration::HeaderPath::{constant#0}>, Error>
Returns the Merkle path for the Merkle tree of the block header.
Source§impl<N> Header<N>where
N: Network,
impl<N> Header<N>where
N: Network,
Sourcepub fn verify(
&self,
expected_previous_state_root: <N as Network>::StateRoot,
expected_transactions_root: Field<N>,
expected_finalize_root: Field<N>,
expected_ratifications_root: Field<N>,
expected_solutions_root: Field<N>,
expected_subdag_root: Field<N>,
expected_round: u64,
expected_height: u32,
expected_cumulative_weight: u128,
expected_cumulative_proof_target: u128,
expected_coinbase_target: u64,
expected_proof_target: u64,
expected_last_coinbase_target: u64,
expected_last_coinbase_timestamp: i64,
expected_timestamp: i64,
current_timestamp: i64,
) -> Result<(), Error>
pub fn verify( &self, expected_previous_state_root: <N as Network>::StateRoot, expected_transactions_root: Field<N>, expected_finalize_root: Field<N>, expected_ratifications_root: Field<N>, expected_solutions_root: Field<N>, expected_subdag_root: Field<N>, expected_round: u64, expected_height: u32, expected_cumulative_weight: u128, expected_cumulative_proof_target: u128, expected_coinbase_target: u64, expected_proof_target: u64, expected_last_coinbase_target: u64, expected_last_coinbase_timestamp: i64, expected_timestamp: i64, current_timestamp: i64, ) -> Result<(), Error>
Ensures the block header is correct.
Source§impl<N> Header<N>where
N: Network,
impl<N> Header<N>where
N: Network,
Sourcepub fn from(
previous_state_root: <N as Network>::StateRoot,
transactions_root: Field<N>,
finalize_root: Field<N>,
ratifications_root: Field<N>,
solutions_root: Field<N>,
subdag_root: Field<N>,
metadata: Metadata<N>,
) -> Result<Header<N>, Error>
pub fn from( previous_state_root: <N as Network>::StateRoot, transactions_root: Field<N>, finalize_root: Field<N>, ratifications_root: Field<N>, solutions_root: Field<N>, subdag_root: Field<N>, metadata: Metadata<N>, ) -> Result<Header<N>, Error>
Initializes a new block header with the given inputs.
Sourcepub const fn previous_state_root(&self) -> <N as Network>::StateRoot
pub const fn previous_state_root(&self) -> <N as Network>::StateRoot
Returns the previous state root from the block header.
Sourcepub const fn transactions_root(&self) -> Field<N>
pub const fn transactions_root(&self) -> Field<N>
Returns the transactions root in the block header.
Sourcepub const fn finalize_root(&self) -> Field<N>
pub const fn finalize_root(&self) -> Field<N>
Returns the finalize root in the block header.
Sourcepub const fn ratifications_root(&self) -> Field<N>
pub const fn ratifications_root(&self) -> Field<N>
Returns the ratifications root in the block header.
Sourcepub const fn solutions_root(&self) -> Field<N>
pub const fn solutions_root(&self) -> Field<N>
Returns the solutions root in the block header.
Sourcepub const fn subdag_root(&self) -> Field<N>
pub const fn subdag_root(&self) -> Field<N>
Returns the subdag root in the block header.
Sourcepub const fn cumulative_weight(&self) -> u128
pub const fn cumulative_weight(&self) -> u128
Returns the cumulative weight for this block.
Sourcepub const fn cumulative_proof_target(&self) -> u128
pub const fn cumulative_proof_target(&self) -> u128
Returns the cumulative proof target for this block.
Sourcepub const fn coinbase_target(&self) -> u64
pub const fn coinbase_target(&self) -> u64
Returns the coinbase target for this block.
Sourcepub const fn proof_target(&self) -> u64
pub const fn proof_target(&self) -> u64
Returns the proof target for this block.
Sourcepub const fn last_coinbase_target(&self) -> u64
pub const fn last_coinbase_target(&self) -> u64
Returns the coinbase target of the last coinbase.
Sourcepub const fn last_coinbase_timestamp(&self) -> i64
pub const fn last_coinbase_timestamp(&self) -> i64
Returns the Unix timestamp (UTC) of the last coinbase.
Trait Implementations§
Source§impl<'de, N> Deserialize<'de> for Header<N>where
N: Network,
impl<'de, N> Deserialize<'de> for Header<N>where
N: Network,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Header<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Header<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserializes the header from a JSON-string or buffer.
Source§impl<N> Serialize for Header<N>where
N: Network,
impl<N> Serialize for Header<N>where
N: Network,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serializes the header to a JSON-string or buffer.
impl<N> Copy for Header<N>
impl<N> Eq for Header<N>
impl<N> StructuralPartialEq for Header<N>where
N: Network,
Auto Trait Implementations§
impl<N> Freeze for Header<N>
impl<N> RefUnwindSafe for Header<N>where
<N as Network>::StateRoot: RefUnwindSafe,
<N as Environment>::Field: RefUnwindSafe,
N: RefUnwindSafe,
impl<N> Send for Header<N>
impl<N> Sync for Header<N>
impl<N> Unpin for Header<N>
impl<N> UnwindSafe for Header<N>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
impl<'de, T> DeserializeExt<'de> for Twhere
T: DeserializeOwned,
fn take_from_value<D>(
value: &mut Value,
field: &str,
) -> Result<T, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more