pub trait BlockBody:
Send
+ Sync
+ Unpin
+ Clone
+ Default
+ Debug
+ PartialEq
+ Eq
+ Encodable
+ Decodable
+ InMemorySize
+ MaybeSerde
+ 'static {
type Transaction: SignedTransaction;
type OmmerHeader: BlockHeader;
Show 24 methods
// Required methods
fn transactions(&self) -> &[Self::Transaction];
fn into_ethereum_body(
self,
) -> BlockBody<Self::Transaction, Self::OmmerHeader>;
fn into_transactions(self) -> Vec<Self::Transaction>;
fn withdrawals(&self) -> Option<&Withdrawals>;
fn ommers(&self) -> Option<&[Self::OmmerHeader]>;
// Provided methods
fn transactions_iter(&self) -> impl Iterator<Item = &Self::Transaction> + '_ { ... }
fn transaction_by_hash(&self, hash: &B256) -> Option<&Self::Transaction> { ... }
fn contains_transaction(&self, hash: &B256) -> bool { ... }
fn clone_transactions(&self) -> Vec<Self::Transaction> { ... }
fn transaction_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_ { ... }
fn transaction_count(&self) -> usize { ... }
fn contains_transaction_type(&self, tx_type: u8) -> bool { ... }
fn calculate_tx_root(&self) -> B256 { ... }
fn calculate_withdrawals_root(&self) -> Option<B256> { ... }
fn calculate_ommers_root(&self) -> Option<B256> { ... }
fn blob_gas_used(&self) -> u64 { ... }
fn blob_versioned_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_ { ... }
fn encoded_2718_transactions_iter(
&self,
) -> impl Iterator<Item = Vec<u8>> + '_ { ... }
fn encoded_2718_transactions(&self) -> Vec<Bytes> { ... }
fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError> { ... }
fn try_recover_signers(&self) -> Result<Vec<Address>, RecoveryError> { ... }
fn recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError> { ... }
fn try_recover_signers_unchecked(
&self,
) -> Result<Vec<Address>, RecoveryError> { ... }
fn recover_transactions(
&self,
) -> Result<Vec<Recovered<Self::Transaction>>, RecoveryError> { ... }
}
Expand description
Abstraction for block’s body.
This type is a container for everything that is included in a block except the header. For ethereum this includes transactions, ommers, and withdrawals.
Required Associated Types§
Sourcetype Transaction: SignedTransaction
type Transaction: SignedTransaction
Ordered list of signed transactions as committed in the block.
Sourcetype OmmerHeader: BlockHeader
type OmmerHeader: BlockHeader
Ommer header type.
Required Methods§
Sourcefn transactions(&self) -> &[Self::Transaction]
fn transactions(&self) -> &[Self::Transaction]
Returns reference to transactions in the block.
Sourcefn into_ethereum_body(self) -> BlockBody<Self::Transaction, Self::OmmerHeader>
fn into_ethereum_body(self) -> BlockBody<Self::Transaction, Self::OmmerHeader>
A Convenience function to convert this type into the regular ethereum block body that consists of:
- Transactions
- Withdrawals
- Ommers
Note: This conversion can be incomplete. It is not expected that this Body
is the same as
[alloy_consensus::BlockBody
] only that it can be converted into it which is useful for
the eth_
RPC namespace (e.g. RPC block).
Sourcefn into_transactions(self) -> Vec<Self::Transaction>
fn into_transactions(self) -> Vec<Self::Transaction>
Consume the block body and return a Vec
of transactions.
Sourcefn withdrawals(&self) -> Option<&Withdrawals>
fn withdrawals(&self) -> Option<&Withdrawals>
Returns block withdrawals if any.
Sourcefn ommers(&self) -> Option<&[Self::OmmerHeader]>
fn ommers(&self) -> Option<&[Self::OmmerHeader]>
Returns block ommers if any.
Provided Methods§
Sourcefn transactions_iter(&self) -> impl Iterator<Item = &Self::Transaction> + '_
fn transactions_iter(&self) -> impl Iterator<Item = &Self::Transaction> + '_
Returns an iterator over the transactions in the block.
Sourcefn transaction_by_hash(&self, hash: &B256) -> Option<&Self::Transaction>
fn transaction_by_hash(&self, hash: &B256) -> Option<&Self::Transaction>
Returns the transaction with the matching hash.
This is a convenience function for transactions_iter().find()
Sourcefn contains_transaction(&self, hash: &B256) -> bool
fn contains_transaction(&self, hash: &B256) -> bool
Returns true if the block body contains a transaction with the given hash.
This is a convenience function for transaction_by_hash().is_some()
Sourcefn clone_transactions(&self) -> Vec<Self::Transaction>
fn clone_transactions(&self) -> Vec<Self::Transaction>
Clones the transactions in the block.
This is a convenience function for transactions().to_vec()
Sourcefn transaction_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_
fn transaction_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_
Returns an iterator over all transaction hashes in the block body.
Sourcefn transaction_count(&self) -> usize
fn transaction_count(&self) -> usize
Returns the number of the transactions in the block.
Sourcefn contains_transaction_type(&self, tx_type: u8) -> bool
fn contains_transaction_type(&self, tx_type: u8) -> bool
Returns true
if the block body contains a transaction of the given type.
Sourcefn calculate_tx_root(&self) -> B256
fn calculate_tx_root(&self) -> B256
Calculate the transaction root for the block body.
Sourcefn calculate_withdrawals_root(&self) -> Option<B256>
fn calculate_withdrawals_root(&self) -> Option<B256>
Calculate the withdrawals root for the block body.
Returns Some(root)
if withdrawals are present, otherwise None
.
Sourcefn calculate_ommers_root(&self) -> Option<B256>
fn calculate_ommers_root(&self) -> Option<B256>
Calculate the ommers root for the block body.
Returns Some(root)
if ommers are present, otherwise None
.
Sourcefn blob_gas_used(&self) -> u64
fn blob_gas_used(&self) -> u64
Calculates the total blob gas used by all EIP-4844 transactions in the block.
Sourcefn blob_versioned_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_
fn blob_versioned_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_
Returns an iterator over all blob versioned hashes in the block body.
Sourcefn encoded_2718_transactions_iter(&self) -> impl Iterator<Item = Vec<u8>> + '_
fn encoded_2718_transactions_iter(&self) -> impl Iterator<Item = Vec<u8>> + '_
Returns an iterator over the encoded 2718 transactions.
This is also known as raw transactions
.
See also [Encodable2718
].
Sourcefn encoded_2718_transactions(&self) -> Vec<Bytes>
fn encoded_2718_transactions(&self) -> Vec<Bytes>
Returns a vector of encoded 2718 transactions.
This is also known as raw transactions
.
See also [Encodable2718
].
Sourcefn recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
Recover signer addresses for all transactions in the block body.
Sourcefn try_recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
fn try_recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
Recover signer addresses for all transactions in the block body.
Returns an error if some transaction’s signature is invalid.
Sourcefn recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
fn recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
Recover signer addresses for all transactions in the block body without ensuring that the
signature has a low s
value.
Returns RecoveryError
, if some transaction’s signature is invalid.
Sourcefn try_recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
fn try_recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
Recover signer addresses for all transactions in the block body without ensuring that the
signature has a low s
value.
Returns an error if some transaction’s signature is invalid.
Sourcefn recover_transactions(
&self,
) -> Result<Vec<Recovered<Self::Transaction>>, RecoveryError>
fn recover_transactions( &self, ) -> Result<Vec<Recovered<Self::Transaction>>, RecoveryError>
Recovers signers for all transactions in the block body and returns a vector of
Recovered
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.