pub struct Chain<N: NodePrimitives = EthPrimitives> { /* private fields */ }Expand description
A chain of blocks and their final state.
The chain contains the state of accounts after execution of its blocks, changesets for those blocks (and their transactions), as well as the blocks themselves.
Used inside the BlockchainTree.
§Warning
A chain of blocks should not be empty.
Implementations§
Source§impl<N: NodePrimitives> Chain<N>
impl<N: NodePrimitives> Chain<N>
Sourcepub fn new(
blocks: impl IntoIterator<Item: Into<Arc<RecoveredBlock<N::Block>>>>,
execution_outcome: ExecutionOutcome<N::Receipt>,
trie_data: BTreeMap<BlockNumber, LazyTrieData>,
) -> Self
pub fn new( blocks: impl IntoIterator<Item: Into<Arc<RecoveredBlock<N::Block>>>>, execution_outcome: ExecutionOutcome<N::Receipt>, trie_data: BTreeMap<BlockNumber, LazyTrieData>, ) -> Self
Sourcepub fn from_block(
block: impl Into<Arc<RecoveredBlock<N::Block>>>,
execution_outcome: ExecutionOutcome<N::Receipt>,
trie_data: LazyTrieData,
) -> Self
pub fn from_block( block: impl Into<Arc<RecoveredBlock<N::Block>>>, execution_outcome: ExecutionOutcome<N::Receipt>, trie_data: LazyTrieData, ) -> Self
Create new Chain from a single block and its state.
Sourcepub const fn blocks(
&self,
) -> &BTreeMap<BlockNumber, Arc<RecoveredBlock<N::Block>>>
pub const fn blocks( &self, ) -> &BTreeMap<BlockNumber, Arc<RecoveredBlock<N::Block>>>
Get the blocks in this chain.
Sourcepub fn into_blocks(self) -> BTreeMap<BlockNumber, Arc<RecoveredBlock<N::Block>>>
pub fn into_blocks(self) -> BTreeMap<BlockNumber, Arc<RecoveredBlock<N::Block>>>
Consumes the type and only returns the blocks in this chain.
Sourcepub fn headers(&self) -> impl Iterator<Item = SealedHeader<N::BlockHeader>> + '_
pub fn headers(&self) -> impl Iterator<Item = SealedHeader<N::BlockHeader>> + '_
Returns an iterator over all headers in the block with increasing block numbers.
Sourcepub const fn trie_data(&self) -> &BTreeMap<BlockNumber, LazyTrieData>
pub const fn trie_data(&self) -> &BTreeMap<BlockNumber, LazyTrieData>
Get all trie data for this chain.
Sourcepub fn trie_data_at(&self, block_number: BlockNumber) -> Option<&LazyTrieData>
pub fn trie_data_at(&self, block_number: BlockNumber) -> Option<&LazyTrieData>
Get trie data for a specific block number.
Sourcepub fn clear_trie_data(&mut self)
pub fn clear_trie_data(&mut self)
Remove all trie data for this chain.
Sourcepub const fn bals(&self) -> &BTreeMap<BlockNumber, Arc<DecodedEvmBal>>
pub const fn bals(&self) -> &BTreeMap<BlockNumber, Arc<DecodedEvmBal>>
Get all prepared block access lists for this chain.
Blocks without an available BAL have no entry; see the bals field for details.
Sourcepub fn bal_at(&self, block_number: BlockNumber) -> Option<&Arc<DecodedEvmBal>>
pub fn bal_at(&self, block_number: BlockNumber) -> Option<&Arc<DecodedEvmBal>>
Get the prepared block access list for a specific block number, if one is available.
None only means no BAL was attached for that block; see the bals field for details.
Sourcepub fn insert_bal(&mut self, block_number: BlockNumber, bal: Arc<DecodedEvmBal>)
pub fn insert_bal(&mut self, block_number: BlockNumber, bal: Arc<DecodedEvmBal>)
Attach a prepared block access list to a block of this chain.
Sourcepub const fn execution_outcome(&self) -> &ExecutionOutcome<N::Receipt>
pub const fn execution_outcome(&self) -> &ExecutionOutcome<N::Receipt>
Get execution outcome of this chain
Sourcepub const fn execution_outcome_mut(
&mut self,
) -> &mut ExecutionOutcome<N::Receipt>
pub const fn execution_outcome_mut( &mut self, ) -> &mut ExecutionOutcome<N::Receipt>
Get mutable execution outcome of this chain
Sourcepub fn block_number(&self, block_hash: BlockHash) -> Option<BlockNumber>
pub fn block_number(&self, block_hash: BlockHash) -> Option<BlockNumber>
Return block number of the block hash.
Sourcepub fn recovered_block(
&self,
block_hash: BlockHash,
) -> Option<&RecoveredBlock<N::Block>>
pub fn recovered_block( &self, block_hash: BlockHash, ) -> Option<&RecoveredBlock<N::Block>>
Returns the block with matching hash.
Sourcepub fn execution_outcome_at_block(
&self,
block_number: BlockNumber,
) -> Option<ExecutionOutcome<N::Receipt>>
pub fn execution_outcome_at_block( &self, block_number: BlockNumber, ) -> Option<ExecutionOutcome<N::Receipt>>
Return execution outcome at the block_number or None if block is not known
Sourcepub fn into_inner(
self,
) -> (ChainBlocks<'static, N::Block>, ExecutionOutcome<N::Receipt>, BTreeMap<BlockNumber, LazyTrieData>)
pub fn into_inner( self, ) -> (ChainBlocks<'static, N::Block>, ExecutionOutcome<N::Receipt>, BTreeMap<BlockNumber, LazyTrieData>)
Destructure the chain into its inner components:
- The blocks contained in the chain.
- The execution outcome representing the final state.
- The trie data map.
Sourcepub const fn inner(
&self,
) -> (ChainBlocks<'_, N::Block>, &ExecutionOutcome<N::Receipt>)
pub const fn inner( &self, ) -> (ChainBlocks<'_, N::Block>, &ExecutionOutcome<N::Receipt>)
Destructure the chain into its inner components:
- A reference to the blocks contained in the chain.
- A reference to the execution outcome representing the final state.
Sourcepub fn block_receipts_iter(&self) -> impl Iterator<Item = &Vec<N::Receipt>> + '_
pub fn block_receipts_iter(&self) -> impl Iterator<Item = &Vec<N::Receipt>> + '_
Returns an iterator over all the receipts of the blocks in the chain.
Sourcepub fn receipts_iter(&self) -> impl Iterator<Item = &N::Receipt> + '_
pub fn receipts_iter(&self) -> impl Iterator<Item = &N::Receipt> + '_
Returns an iterator over all receipts in the chain.
Sourcepub fn logs_iter(&self) -> impl Iterator<Item = &Log> + '_where
N::Receipt: TxReceipt<Log = Log>,
pub fn logs_iter(&self) -> impl Iterator<Item = &Log> + '_where
N::Receipt: TxReceipt<Log = Log>,
Returns an iterator over all logs in the chain.
Sourcepub fn blocks_iter(
&self,
) -> impl Iterator<Item = &Arc<RecoveredBlock<N::Block>>> + '_
pub fn blocks_iter( &self, ) -> impl Iterator<Item = &Arc<RecoveredBlock<N::Block>>> + '_
Returns an iterator over all blocks in the chain with increasing block number.
Sourcepub fn transactions_iter(&self) -> impl Iterator<Item = &N::SignedTx> + '_
pub fn transactions_iter(&self) -> impl Iterator<Item = &N::SignedTx> + '_
Returns an iterator over all transactions in the chain.
Sourcepub fn transaction_hashes(&self) -> impl Iterator<Item = &TxHash> + '_
pub fn transaction_hashes(&self) -> impl Iterator<Item = &TxHash> + '_
Returns an iterator over all transaction hashes in the chain.
Sourcepub fn transactions_recovered_iter(
&self,
) -> impl Iterator<Item = Recovered<&N::SignedTx>> + '_
pub fn transactions_recovered_iter( &self, ) -> impl Iterator<Item = Recovered<&N::SignedTx>> + '_
Returns an iterator over all [Recovered] transaction references in the chain.
Sourcepub fn blocks_and_receipts(
&self,
) -> impl Iterator<Item = (&Arc<RecoveredBlock<N::Block>>, &Vec<N::Receipt>)> + '_
pub fn blocks_and_receipts( &self, ) -> impl Iterator<Item = (&Arc<RecoveredBlock<N::Block>>, &Vec<N::Receipt>)> + '_
Returns an iterator over all blocks and their receipts in the chain.
Sourcepub fn blocks_and_bals(
&self,
) -> impl Iterator<Item = (&Arc<RecoveredBlock<N::Block>>, &Arc<DecodedEvmBal>)> + '_
pub fn blocks_and_bals( &self, ) -> impl Iterator<Item = (&Arc<RecoveredBlock<N::Block>>, &Arc<DecodedEvmBal>)> + '_
Returns an iterator over the blocks of this chain that have a prepared block access list, paired with that BAL.
Blocks without an available BAL are skipped; see the bals field for details.
Sourcepub fn find_transaction_and_receipt_by_hash(
&self,
tx_hash: TxHash,
) -> Option<(&'_ Arc<RecoveredBlock<<N as NodePrimitives>::Block>>, IndexedTx<'_, <N as NodePrimitives>::Block>, &'_ <N as NodePrimitives>::Receipt, &'_ [<N as NodePrimitives>::Receipt])>
pub fn find_transaction_and_receipt_by_hash( &self, tx_hash: TxHash, ) -> Option<(&'_ Arc<RecoveredBlock<<N as NodePrimitives>::Block>>, IndexedTx<'_, <N as NodePrimitives>::Block>, &'_ <N as NodePrimitives>::Receipt, &'_ [<N as NodePrimitives>::Receipt])>
Finds a transaction by hash and returns it along with its corresponding receipt data.
Returns None if the transaction is not found in this chain.
Sourcepub fn fork_block(&self) -> ForkBlock
pub fn fork_block(&self) -> ForkBlock
Get the block at which this chain forked.
Sourcepub fn range(&self) -> RangeInclusive<BlockNumber> ⓘ
pub fn range(&self) -> RangeInclusive<BlockNumber> ⓘ
Sourcepub fn receipts_by_block_hash(
&self,
block_hash: BlockHash,
) -> Option<Vec<&N::Receipt>>
pub fn receipts_by_block_hash( &self, block_hash: BlockHash, ) -> Option<Vec<&N::Receipt>>
Get all receipts for the given block.
Sourcepub fn receipts_with_attachment(&self) -> Vec<BlockReceipts<N::Receipt>>
pub fn receipts_with_attachment(&self) -> Vec<BlockReceipts<N::Receipt>>
Get all receipts with attachment.
Attachment includes block number, block hash, transaction hash and transaction index.
Sourcepub fn append_block(
&mut self,
block: impl Into<Arc<RecoveredBlock<N::Block>>>,
execution_outcome: ExecutionOutcome<N::Receipt>,
trie_data: LazyTrieData,
)
pub fn append_block( &mut self, block: impl Into<Arc<RecoveredBlock<N::Block>>>, execution_outcome: ExecutionOutcome<N::Receipt>, trie_data: LazyTrieData, )
Append a single block with state to the chain. This method assumes that blocks attachment to the chain has already been validated.
Sourcepub fn append_chain(&mut self, other: Self) -> Result<(), Self>
pub fn append_chain(&mut self, other: Self) -> Result<(), Self>
Merge two chains by appending the given chain into the current one.
The state of accounts for this chain is set to the state of the newest chain.
Returns the passed other chain in Result::Err variant if the chains could not be
connected.
Trait Implementations§
Source§impl<'de, N: NodePrimitives> Deserialize<'de> for Chain<N>
Available on crate feature serde only.
impl<'de, N: NodePrimitives> Deserialize<'de> for Chain<N>
serde only.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>,
Source§impl<'de, N> DeserializeAs<'de, Chain<N>> for Chain<'de, N>where
N: NodePrimitives,
Available on crate feature serde-bincode-compat only.
impl<'de, N> DeserializeAs<'de, Chain<N>> for Chain<'de, N>where
N: NodePrimitives,
serde-bincode-compat only.Source§fn deserialize_as<D>(deserializer: D) -> Result<Chain<N>, D::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(deserializer: D) -> Result<Chain<N>, D::Error>where
D: Deserializer<'de>,
impl<N: Eq + NodePrimitives> Eq for Chain<N>
Source§impl<'a, N> From<&'a Chain<N>> for Chain<'a, N>where
N: NodePrimitives,
Available on crate feature serde-bincode-compat only.
impl<'a, N> From<&'a Chain<N>> for Chain<'a, N>where
N: NodePrimitives,
serde-bincode-compat only.Source§impl<'a, N> From<Chain<'a, N>> for Chain<N>where
N: NodePrimitives,
Available on crate feature serde-bincode-compat only.
impl<'a, N> From<Chain<'a, N>> for Chain<N>where
N: NodePrimitives,
serde-bincode-compat only.Source§impl<N> SerializeAs<Chain<N>> for Chain<'_, N>where
N: NodePrimitives,
Available on crate feature serde-bincode-compat only.
impl<N> SerializeAs<Chain<N>> for Chain<'_, N>where
N: NodePrimitives,
serde-bincode-compat only.Source§fn serialize_as<S>(source: &Chain<N>, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize_as<S>(source: &Chain<N>, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
impl<N: PartialEq + NodePrimitives> StructuralPartialEq for Chain<N>
Auto Trait Implementations§
impl<N = EthPrimitives> !RefUnwindSafe for Chain<N>
impl<N = EthPrimitives> !UnwindSafe for Chain<N>
impl<N> Freeze for Chain<N>
impl<N> Send for Chain<N>
impl<N> Sync for Chain<N>
impl<N> Unpin for Chain<N>
impl<N> UnsafeUnpin for Chain<N>where
BTreeMap<u64, Arc<RecoveredBlock<<N as NodePrimitives>::Block>>>: UnsafeUnpin,
ExecutionOutcome<<N as NodePrimitives>::Receipt>: UnsafeUnpin,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreimpl<T> MaybeDebug for Twhere
T: Debug,
impl<T> MaybeSerde for Twhere
T: Serialize + for<'de> Deserialize<'de>,
§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 248 bytes