Struct snarkvm_ledger_block::Block
source · pub struct Block<N: Network> { /* private fields */ }
Implementations§
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub const NUM_GENESIS_TRANSACTIONS: usize = 4usize
pub const NUM_GENESIS_TRANSACTIONS: usize = 4usize
Specifies the number of genesis transactions.
sourcepub fn is_genesis(&self) -> bool
pub fn is_genesis(&self) -> bool
Returns true
if the block is a genesis block.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn verify(
&self,
previous_block: &Block<N>,
current_state_root: N::StateRoot,
current_committee: &Committee<N>,
current_puzzle: &CoinbasePuzzle<N>,
current_epoch_challenge: &EpochChallenge<N>,
current_timestamp: i64,
ratified_finalize_operations: Vec<FinalizeOperation<N>>
) -> Result<()>
pub fn verify( &self, previous_block: &Block<N>, current_state_root: N::StateRoot, current_committee: &Committee<N>, current_puzzle: &CoinbasePuzzle<N>, current_epoch_challenge: &EpochChallenge<N>, current_timestamp: i64, ratified_finalize_operations: Vec<FinalizeOperation<N>> ) -> Result<()>
Ensures the block is correct.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn new_beacon<R: Rng + CryptoRng>(
private_key: &PrivateKey<N>,
previous_hash: N::BlockHash,
header: Header<N>,
ratifications: Ratifications<N>,
solutions: Option<CoinbaseSolution<N>>,
transactions: Transactions<N>,
aborted_transaction_ids: Vec<N::TransactionID>,
rng: &mut R
) -> Result<Self>
pub fn new_beacon<R: Rng + CryptoRng>( private_key: &PrivateKey<N>, previous_hash: N::BlockHash, header: Header<N>, ratifications: Ratifications<N>, solutions: Option<CoinbaseSolution<N>>, transactions: Transactions<N>, aborted_transaction_ids: Vec<N::TransactionID>, rng: &mut R ) -> Result<Self>
Initializes a new beacon block from the given previous block hash, block header, ratifications, solutions, transactions, and aborted transaction IDs.
sourcepub fn new_quorum(
previous_hash: N::BlockHash,
header: Header<N>,
subdag: Subdag<N>,
ratifications: Ratifications<N>,
solutions: Option<CoinbaseSolution<N>>,
transactions: Transactions<N>,
aborted_transaction_ids: Vec<N::TransactionID>
) -> Result<Self>
pub fn new_quorum( previous_hash: N::BlockHash, header: Header<N>, subdag: Subdag<N>, ratifications: Ratifications<N>, solutions: Option<CoinbaseSolution<N>>, transactions: Transactions<N>, aborted_transaction_ids: Vec<N::TransactionID> ) -> Result<Self>
Initializes a new quorum block from the given previous block hash, block header, subdag, ratifications, solutions, transactions, and aborted transaction IDs.
sourcepub fn from(
previous_hash: N::BlockHash,
header: Header<N>,
authority: Authority<N>,
ratifications: Ratifications<N>,
solutions: Option<CoinbaseSolution<N>>,
transactions: Transactions<N>,
aborted_transaction_ids: Vec<N::TransactionID>
) -> Result<Self>
pub fn from( previous_hash: N::BlockHash, header: Header<N>, authority: Authority<N>, ratifications: Ratifications<N>, solutions: Option<CoinbaseSolution<N>>, transactions: Transactions<N>, aborted_transaction_ids: Vec<N::TransactionID> ) -> Result<Self>
Initializes a new block from the given previous block hash, block header, authority, ratifications, solutions, transactions, and aborted transaction IDs.
sourcepub fn from_unchecked(
block_hash: N::BlockHash,
previous_hash: N::BlockHash,
header: Header<N>,
authority: Authority<N>,
ratifications: Ratifications<N>,
solutions: Option<CoinbaseSolution<N>>,
transactions: Transactions<N>,
aborted_transaction_ids: Vec<N::TransactionID>
) -> Result<Self>
pub fn from_unchecked( block_hash: N::BlockHash, previous_hash: N::BlockHash, header: Header<N>, authority: Authority<N>, ratifications: Ratifications<N>, solutions: Option<CoinbaseSolution<N>>, transactions: Transactions<N>, aborted_transaction_ids: Vec<N::TransactionID> ) -> Result<Self>
Initializes a new block from the given block hash, previous block hash, block header, authority, ratifications, solutions, transactions, and aborted transaction IDs.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub const fn previous_hash(&self) -> N::BlockHash
pub const fn previous_hash(&self) -> N::BlockHash
Returns the previous block hash.
Returns the authority.
sourcepub const fn ratifications(&self) -> &Ratifications<N>
pub const fn ratifications(&self) -> &Ratifications<N>
Returns the ratifications in this block.
sourcepub const fn solutions(&self) -> Option<&CoinbaseSolution<N>>
pub const fn solutions(&self) -> Option<&CoinbaseSolution<N>>
Returns the solutions in the block.
sourcepub const fn transactions(&self) -> &Transactions<N>
pub const fn transactions(&self) -> &Transactions<N>
Returns the transactions in this block.
sourcepub const fn aborted_transaction_ids(&self) -> &Vec<N::TransactionID>
pub const fn aborted_transaction_ids(&self) -> &Vec<N::TransactionID>
Returns the aborted transaction IDs in this block.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
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 epoch_number(&self) -> u32
pub const fn epoch_number(&self) -> u32
Returns the epoch number of this block.
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 block timestamp of the last coinbase.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn contains_transition(&self, transition_id: &N::TransitionID) -> bool
pub fn contains_transition(&self, transition_id: &N::TransitionID) -> bool
Returns true
if the block contains the given transition ID.
sourcepub fn contains_serial_number(&self, serial_number: &Field<N>) -> bool
pub fn contains_serial_number(&self, serial_number: &Field<N>) -> bool
Returns true
if the block contains the given serial number.
sourcepub fn contains_commitment(&self, commitment: &Field<N>) -> bool
pub fn contains_commitment(&self, commitment: &Field<N>) -> bool
Returns true
if the block contains the given commitment.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn get_solution(
&self,
puzzle_commitment: &PuzzleCommitment<N>
) -> Option<&ProverSolution<N>>
pub fn get_solution( &self, puzzle_commitment: &PuzzleCommitment<N> ) -> Option<&ProverSolution<N>>
Returns the solution with the given solution ID, if it exists.
sourcepub fn get_transaction(
&self,
transaction_id: &N::TransactionID
) -> Option<&Transaction<N>>
pub fn get_transaction( &self, transaction_id: &N::TransactionID ) -> Option<&Transaction<N>>
Returns the transaction with the given transaction ID, if it exists.
sourcepub fn get_confirmed_transaction(
&self,
transaction_id: &N::TransactionID
) -> Option<&ConfirmedTransaction<N>>
pub fn get_confirmed_transaction( &self, transaction_id: &N::TransactionID ) -> Option<&ConfirmedTransaction<N>>
Returns the confirmed transaction with the given transaction ID, if it exists.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn find_transaction_for_transition_id(
&self,
transition_id: &N::TransitionID
) -> Option<&Transaction<N>>
pub fn find_transaction_for_transition_id( &self, transition_id: &N::TransitionID ) -> Option<&Transaction<N>>
Returns the transaction with the given transition ID, if it exists.
sourcepub fn find_transaction_for_serial_number(
&self,
serial_number: &Field<N>
) -> Option<&Transaction<N>>
pub fn find_transaction_for_serial_number( &self, serial_number: &Field<N> ) -> Option<&Transaction<N>>
Returns the transaction with the given serial number, if it exists.
sourcepub fn find_transaction_for_commitment(
&self,
commitment: &Field<N>
) -> Option<&Transaction<N>>
pub fn find_transaction_for_commitment( &self, commitment: &Field<N> ) -> Option<&Transaction<N>>
Returns the transaction with the given commitment, if it exists.
sourcepub fn find_transition(
&self,
transition_id: &N::TransitionID
) -> Option<&Transition<N>>
pub fn find_transition( &self, transition_id: &N::TransitionID ) -> Option<&Transition<N>>
Returns the transition with the corresponding transition ID, if it exists.
sourcepub fn find_transition_for_serial_number(
&self,
serial_number: &Field<N>
) -> Option<&Transition<N>>
pub fn find_transition_for_serial_number( &self, serial_number: &Field<N> ) -> Option<&Transition<N>>
Returns the transition for the given serial number, if it exists.
sourcepub fn find_transition_for_commitment(
&self,
commitment: &Field<N>
) -> Option<&Transition<N>>
pub fn find_transition_for_commitment( &self, commitment: &Field<N> ) -> Option<&Transition<N>>
Returns the transition for the given commitment, if it exists.
sourcepub fn find_record(
&self,
commitment: &Field<N>
) -> Option<&Record<N, Ciphertext<N>>>
pub fn find_record( &self, commitment: &Field<N> ) -> Option<&Record<N, Ciphertext<N>>>
Returns the record with the corresponding commitment, if it exists.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn puzzle_commitments(
&self
) -> Option<impl '_ + Iterator<Item = &PuzzleCommitment<N>>>
pub fn puzzle_commitments( &self ) -> Option<impl '_ + Iterator<Item = &PuzzleCommitment<N>>>
Returns the puzzle commitments in this block.
sourcepub fn transaction_ids(&self) -> impl '_ + Iterator<Item = &N::TransactionID>
pub fn transaction_ids(&self) -> impl '_ + Iterator<Item = &N::TransactionID>
Returns an iterator over the transaction IDs, for all transactions in self
.
sourcepub fn deployments(&self) -> impl '_ + Iterator<Item = &ConfirmedTransaction<N>>
pub fn deployments(&self) -> impl '_ + Iterator<Item = &ConfirmedTransaction<N>>
Returns an iterator over all transactions in self
that are accepted deploy transactions.
sourcepub fn executions(&self) -> impl '_ + Iterator<Item = &ConfirmedTransaction<N>>
pub fn executions(&self) -> impl '_ + Iterator<Item = &ConfirmedTransaction<N>>
Returns an iterator over all transactions in self
that are accepted execute transactions.
sourcepub fn transitions(&self) -> impl '_ + Iterator<Item = &Transition<N>>
pub fn transitions(&self) -> impl '_ + Iterator<Item = &Transition<N>>
Returns an iterator over all transitions.
sourcepub fn transition_ids(&self) -> impl '_ + Iterator<Item = &N::TransitionID>
pub fn transition_ids(&self) -> impl '_ + Iterator<Item = &N::TransitionID>
Returns an iterator over the transition IDs, for all transitions.
sourcepub fn transition_public_keys(&self) -> impl '_ + Iterator<Item = &Group<N>>
pub fn transition_public_keys(&self) -> impl '_ + Iterator<Item = &Group<N>>
Returns an iterator over the transition public keys, for all transactions.
sourcepub fn transition_commitments(&self) -> impl '_ + Iterator<Item = &Field<N>>
pub fn transition_commitments(&self) -> impl '_ + Iterator<Item = &Field<N>>
Returns an iterator over the transition commitments, for all transactions.
Returns an iterator over the tags, for all transition inputs that are records.
sourcepub fn input_ids(&self) -> impl '_ + Iterator<Item = &Field<N>>
pub fn input_ids(&self) -> impl '_ + Iterator<Item = &Field<N>>
Returns an iterator over the input IDs, for all transition inputs that are records.
sourcepub fn serial_numbers(&self) -> impl '_ + Iterator<Item = &Field<N>>
pub fn serial_numbers(&self) -> impl '_ + Iterator<Item = &Field<N>>
Returns an iterator over the serial numbers, for all transition inputs that are records.
sourcepub fn output_ids(&self) -> impl '_ + Iterator<Item = &Field<N>>
pub fn output_ids(&self) -> impl '_ + Iterator<Item = &Field<N>>
Returns an iterator over the output IDs, for all transition inputs that are records.
sourcepub fn commitments(&self) -> impl '_ + Iterator<Item = &Field<N>>
pub fn commitments(&self) -> impl '_ + Iterator<Item = &Field<N>>
Returns an iterator over the commitments, for all transition outputs that are records.
sourcepub fn records(
&self
) -> impl '_ + Iterator<Item = (&Field<N>, &Record<N, Ciphertext<N>>)>
pub fn records( &self ) -> impl '_ + Iterator<Item = (&Field<N>, &Record<N, Ciphertext<N>>)>
Returns an iterator over the records, for all transition outputs that are records.
sourcepub fn nonces(&self) -> impl '_ + Iterator<Item = &Group<N>>
pub fn nonces(&self) -> impl '_ + Iterator<Item = &Group<N>>
Returns an iterator over the nonces, for all transition outputs that are records.
sourcepub fn transaction_fee_amounts(
&self
) -> impl '_ + Iterator<Item = Result<U64<N>>>
pub fn transaction_fee_amounts( &self ) -> impl '_ + Iterator<Item = Result<U64<N>>>
Returns an iterator over the transaction fee amounts, for all transactions.
source§impl<N: Network> Block<N>
impl<N: Network> Block<N>
sourcepub fn into_transaction_ids(self) -> impl Iterator<Item = N::TransactionID>
pub fn into_transaction_ids(self) -> impl Iterator<Item = N::TransactionID>
Returns a consuming iterator over the transaction IDs, for all transactions in self
.
sourcepub fn into_deployments(self) -> impl Iterator<Item = ConfirmedTransaction<N>>
pub fn into_deployments(self) -> impl Iterator<Item = ConfirmedTransaction<N>>
Returns a consuming iterator over all transactions in self
that are accepted deploy transactions.
sourcepub fn into_executions(self) -> impl Iterator<Item = ConfirmedTransaction<N>>
pub fn into_executions(self) -> impl Iterator<Item = ConfirmedTransaction<N>>
Returns a consuming iterator over all transactions in self
that are accepted execute transactions.
sourcepub fn into_transitions(self) -> impl Iterator<Item = Transition<N>>
pub fn into_transitions(self) -> impl Iterator<Item = Transition<N>>
Returns a consuming iterator over all transitions.
sourcepub fn into_transition_ids(self) -> impl Iterator<Item = N::TransitionID>
pub fn into_transition_ids(self) -> impl Iterator<Item = N::TransitionID>
Returns a consuming iterator over the transition IDs, for all transitions.
sourcepub fn into_transition_public_keys(self) -> impl Iterator<Item = Group<N>>
pub fn into_transition_public_keys(self) -> impl Iterator<Item = Group<N>>
Returns a consuming iterator over the transition public keys, for all transactions.
Returns a consuming iterator over the tags, for all transition inputs that are records.
sourcepub fn into_serial_numbers(self) -> impl Iterator<Item = Field<N>>
pub fn into_serial_numbers(self) -> impl Iterator<Item = Field<N>>
Returns a consuming iterator over the serial numbers, for all transition inputs that are records.
sourcepub fn into_commitments(self) -> impl Iterator<Item = Field<N>>
pub fn into_commitments(self) -> impl Iterator<Item = Field<N>>
Returns a consuming iterator over the commitments, for all transition outputs that are records.
sourcepub fn into_records(
self
) -> impl Iterator<Item = (Field<N>, Record<N, Ciphertext<N>>)>
pub fn into_records( self ) -> impl Iterator<Item = (Field<N>, Record<N, Ciphertext<N>>)>
Returns a consuming iterator over the records, for all transition outputs that are records.
sourcepub fn into_nonces(self) -> impl Iterator<Item = Group<N>>
pub fn into_nonces(self) -> impl Iterator<Item = Group<N>>
Returns a consuming iterator over the nonces, for all transition outputs that are records.
Trait Implementations§
source§impl<N: Clone + Network> Clone for Block<N>where
N::BlockHash: Clone,
N::TransactionID: Clone,
impl<N: Clone + Network> Clone for Block<N>where N::BlockHash: Clone, N::TransactionID: Clone,
source§impl<'de, N: Network> Deserialize<'de> for Block<N>
impl<'de, N: Network> Deserialize<'de> for Block<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 block from a JSON-string or buffer.
source§impl<N: PartialEq + Network> PartialEq for Block<N>where
N::BlockHash: PartialEq,
N::TransactionID: PartialEq,
impl<N: PartialEq + Network> PartialEq for Block<N>where N::BlockHash: PartialEq, N::TransactionID: PartialEq,
impl<N: Eq + Network> Eq for Block<N>where N::BlockHash: Eq, N::TransactionID: Eq,
impl<N: Network> StructuralEq for Block<N>
impl<N: Network> StructuralPartialEq for Block<N>
Auto Trait Implementations§
impl<N> RefUnwindSafe for Block<N>where N: RefUnwindSafe, <N as Network>::BlockHash: RefUnwindSafe, <N as Environment>::Field: RefUnwindSafe, <<N as Environment>::PairingCurve as PairingEngine>::G1Affine: RefUnwindSafe, <N as Environment>::Projective: RefUnwindSafe, <N as Network>::RatificationID: RefUnwindSafe, <N as Environment>::Scalar: RefUnwindSafe, <N as Network>::StateRoot: RefUnwindSafe, <N as Network>::TransactionID: RefUnwindSafe, <N as Network>::TransitionID: RefUnwindSafe,
impl<N> Send for Block<N>
impl<N> Sync for Block<N>
impl<N> Unpin for Block<N>where N: Unpin, <N as Network>::BlockHash: Unpin, <N as Environment>::Field: Unpin, <<N as Environment>::PairingCurve as PairingEngine>::G1Affine: Unpin, <N as Environment>::Projective: Unpin, <N as Network>::RatificationID: Unpin, <N as Environment>::Scalar: Unpin, <N as Network>::StateRoot: Unpin, <N as Network>::TransactionID: Unpin, <N as Network>::TransitionID: Unpin,
impl<N> UnwindSafe for Block<N>where N: UnwindSafe, <N as Network>::BlockHash: UnwindSafe, <N as Environment>::Field: UnwindSafe + RefUnwindSafe, <<N as Environment>::PairingCurve as PairingEngine>::G1Affine: UnwindSafe + RefUnwindSafe, <N as Environment>::Projective: UnwindSafe + RefUnwindSafe, <N as Network>::RatificationID: UnwindSafe, <N as Environment>::Scalar: UnwindSafe + RefUnwindSafe, <N as Network>::StateRoot: UnwindSafe, <N as Network>::TransactionID: UnwindSafe + RefUnwindSafe, <N as Network>::TransitionID: UnwindSafe,
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
§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>,
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.