Struct alloy_rpc_types_eth::Block
source · pub struct Block<T = Transaction<TxEnvelope>, H = Header> {
pub header: H,
pub uncles: Vec<B256>,
pub transactions: BlockTransactions<T>,
pub withdrawals: Option<Withdrawals>,
}
Expand description
Block representation for RPC.
Fields§
§header: H
Header of the block.
uncles: Vec<B256>
Uncles’ hashes.
transactions: BlockTransactions<T>
Block Transactions. In the case of an uncle block, this field is not included in RPC responses, and when deserialized, it will be set to BlockTransactions::Uncle.
withdrawals: Option<Withdrawals>
Withdrawals in the block.
Implementations§
source§impl<T, H> Block<T, H>
impl<T, H> Block<T, H>
sourcepub const fn new(header: H, transactions: BlockTransactions<T>) -> Self
pub const fn new(header: H, transactions: BlockTransactions<T>) -> Self
Creates a new Block
with the given header and transactions.
Note: This does not set the withdrawals for the block.
use alloy_eips::eip4895::Withdrawals;
use alloy_network_primitives::BlockTransactions;
use alloy_rpc_types_eth::{Block, Header, Transaction};
let block = Block::new(
Header::new(alloy_consensus::Header::default()),
BlockTransactions::<Transaction>::Full(vec![]),
)
.with_withdrawals(Some(Withdrawals::default()));
sourcepub fn with_transactions(self, transactions: BlockTransactions<T>) -> Self
pub fn with_transactions(self, transactions: BlockTransactions<T>) -> Self
Sets the transactions for the block.
sourcepub fn with_withdrawals(self, withdrawals: Option<Withdrawals>) -> Self
pub fn with_withdrawals(self, withdrawals: Option<Withdrawals>) -> Self
Sets the withdrawals for the block.
sourcepub fn with_uncles(self, uncles: Vec<B256>) -> Self
pub fn with_uncles(self, uncles: Vec<B256>) -> Self
Sets the uncles for the block.
sourcepub fn map_header<U>(self, f: impl FnOnce(H) -> U) -> Block<T, U>
pub fn map_header<U>(self, f: impl FnOnce(H) -> U) -> Block<T, U>
Converts the block’s header type by applying a function to it.
sourcepub fn try_map_header<U, E>(
self,
f: impl FnOnce(H) -> Result<U, E>,
) -> Result<Block<T, U>, E>
pub fn try_map_header<U, E>( self, f: impl FnOnce(H) -> Result<U, E>, ) -> Result<Block<T, U>, E>
Converts the block’s header type by applying a fallible function to it.
sourcepub fn map_transactions<U>(self, f: impl FnMut(T) -> U) -> Block<U, H>
pub fn map_transactions<U>(self, f: impl FnMut(T) -> U) -> Block<U, H>
Converts the block’s transaction type by applying a function to each transaction.
Returns the block with the new transaction type.
source§impl<T: TransactionResponse, H> Block<T, H>
impl<T: TransactionResponse, H> Block<T, H>
sourcepub fn into_full_block(self, txs: Vec<T>) -> Self
pub fn into_full_block(self, txs: Vec<T>) -> Self
Converts a block with Tx hashes into a full block.
source§impl<T, H: Sealable + Encodable> Block<T, Header<H>>
impl<T, H: Sealable + Encodable> Block<T, Header<H>>
sourcepub fn uncle_from_header(header: H) -> Self
pub fn uncle_from_header(header: H) -> Self
Constructs an “uncle block” from the provided header.
This function creates a new Block
structure for uncle blocks (ommer blocks),
using the provided alloy_consensus::Header
.
source§impl<T> Block<T>
impl<T> Block<T>
sourcepub fn from_consensus(block: Block<T>, total_difficulty: Option<U256>) -> Selfwhere
T: Encodable,
pub fn from_consensus(block: Block<T>, total_difficulty: Option<U256>) -> Selfwhere
T: Encodable,
Constructs block from a consensus block and total_difficulty
.
sourcepub fn into_consensus(self) -> Block<T>
pub fn into_consensus(self) -> Block<T>
Consumes the block and returns the alloy_consensus::Block
.
This has two caveats:
- The returned block will always have empty uncles.
- If the block’s transaction is not
BlockTransactions::Full
, the returned block will have an empty transaction vec.
Trait Implementations§
source§impl<T: TransactionResponse, H> BlockResponse for Block<T, H>
impl<T: TransactionResponse, H> BlockResponse for Block<T, H>
§type Transaction = T
type Transaction = T
source§fn transactions(&self) -> &BlockTransactions<T>
fn transactions(&self) -> &BlockTransactions<T>
source§fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction>
fn transactions_mut(&mut self) -> &mut BlockTransactions<Self::Transaction>
source§fn other_fields(&self) -> Option<&OtherFields>
fn other_fields(&self) -> Option<&OtherFields>
other
field from WithOtherFields
type.source§impl<'de, T, H> Deserialize<'de> for Block<T, H>where
T: Deserialize<'de>,
H: Deserialize<'de>,
impl<'de, T, H> Deserialize<'de> for Block<T, H>where
T: Deserialize<'de>,
H: Deserialize<'de>,
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<T: PartialEq, H: PartialEq> PartialEq for Block<T, H>
impl<T: PartialEq, H: PartialEq> PartialEq for Block<T, H>
impl<T: Eq, H: Eq> Eq for Block<T, H>
impl<T, H> StructuralPartialEq for Block<T, H>
Auto Trait Implementations§
impl<T, H> Freeze for Block<T, H>where
H: Freeze,
impl<T, H> RefUnwindSafe for Block<T, H>where
H: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, H> Send for Block<T, H>
impl<T, H> Sync for Block<T, H>
impl<T, H> Unpin for Block<T, H>
impl<T, H> UnwindSafe for Block<T, H>where
H: UnwindSafe,
T: 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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<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