pub struct Header<N: Network> { /* private fields */ }
Expand description
The header for the block contains metadata that uniquely identifies the block.
Implementations§
Source§impl<N: Network> Header<N>
impl<N: Network> Header<N>
Sourcepub fn genesis(
ratifications: &Ratifications<N>,
transactions: &Transactions<N>,
ratified_finalize_operations: Vec<FinalizeOperation<N>>,
) -> Result<Self>
pub fn genesis( ratifications: &Ratifications<N>, transactions: &Transactions<N>, ratified_finalize_operations: Vec<FinalizeOperation<N>>, ) -> Result<Self>
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: Network> Header<N>
impl<N: Network> Header<N>
Sourcepub fn to_path(&self, leaf: &HeaderLeaf<N>) -> Result<HeaderPath<N>>
pub fn to_path(&self, leaf: &HeaderLeaf<N>) -> Result<HeaderPath<N>>
Returns the Merkle path for the Merkle tree of the block header.
Sourcepub fn to_leaf(&self, id: &Field<N>) -> Result<HeaderLeaf<N>>
pub fn to_leaf(&self, id: &Field<N>) -> Result<HeaderLeaf<N>>
Returns the Merkle leaf for the given ID in the header.
Sourcepub fn to_tree(&self) -> Result<HeaderTree<N>>
pub fn to_tree(&self) -> Result<HeaderTree<N>>
Returns an instance of the Merkle tree for the block header.
Source§impl<N: Network> Header<N>
impl<N: Network> Header<N>
Sourcepub fn verify(
&self,
expected_previous_state_root: N::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<()>
pub fn verify( &self, expected_previous_state_root: N::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<()>
Ensures the block header is correct.
Source§impl<N: Network> Header<N>
impl<N: Network> Header<N>
Sourcepub fn from(
previous_state_root: N::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<Self>
pub fn from( previous_state_root: N::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<Self>
Initializes a new block header with the given inputs.
Sourcepub const fn previous_state_root(&self) -> N::StateRoot
pub const fn previous_state_root(&self) -> N::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: Network> Deserialize<'de> for Header<N>
impl<'de, N: Network> Deserialize<'de> for Header<N>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserializes the header from a JSON-string or buffer.
impl<N: Copy + Network> Copy for Header<N>
impl<N: Eq + Network> Eq for Header<N>
impl<N: Network> StructuralPartialEq for Header<N>
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§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> 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