pub struct Block<T, H = Header> {
pub header: H,
pub body: BlockBody<T, H>,
}Expand description
Ethereum full block.
Withdrawals can be optionally included at the end of the RLP encoded message.
Taken from reth-primitives
See p2p block encoding reference: https://github.com/ethereum/devp2p/blob/master/caps/eth.md#block-encoding-and-validity
Fields§
§header: HBlock header.
body: BlockBody<T, H>Block body.
Implementations§
Source§impl<T: Decodable, H: Decodable> Block<T, H>
impl<T: Decodable, H: Decodable> Block<T, H>
Sourcepub fn decode_sealed(buf: &mut &[u8]) -> Result<Sealed<Self>>
pub fn decode_sealed(buf: &mut &[u8]) -> Result<Sealed<Self>>
Decodes the block from RLP, computing the header hash directly from the RLP bytes.
This is more efficient than decoding the block and then sealing it, as the header hash is computed from the raw RLP bytes without re-encoding.
Source§impl<T, H> Block<T, H>
impl<T, H> Block<T, H>
Sourcepub const fn new(header: H, body: BlockBody<T, H>) -> Self
pub const fn new(header: H, body: BlockBody<T, H>) -> Self
Creates a new block with the given header and body.
Sourcepub fn into_header(self) -> H
pub fn into_header(self) -> H
Consumes the block and returns the header.
Sourcepub fn map_header<U>(self, f: impl FnMut(H) -> U) -> Block<T, U>
pub fn map_header<U>(self, f: impl FnMut(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 FnMut(H) -> Result<U, E>,
) -> Result<Block<T, U>, E>
pub fn try_map_header<U, E>( self, f: impl FnMut(H) -> Result<U, E>, ) -> Result<Block<T, U>, E>
Converts the block’s header type by applying a fallible function to it.
Sourcepub fn convert_transactions<U>(self) -> Block<U, H>where
U: From<T>,
pub fn convert_transactions<U>(self) -> Block<U, H>where
U: From<T>,
Converts the block’s transaction type to the given alternative that is From<T>
Sourcepub fn try_convert_transactions<U>(self) -> Result<Block<U, H>, U::Error>where
U: TryFrom<T>,
pub fn try_convert_transactions<U>(self) -> Result<Block<U, H>, U::Error>where
U: TryFrom<T>,
Converts the block’s transaction to the given alternative that is TryFrom<T>
Returns the block with the new transaction type if all conversions were successful.
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.
Sourcepub fn try_map_transactions<U, E>(
self,
f: impl FnMut(T) -> Result<U, E>,
) -> Result<Block<U, H>, E>
pub fn try_map_transactions<U, E>( self, f: impl FnMut(T) -> Result<U, E>, ) -> Result<Block<U, H>, E>
Converts the block’s transaction type by applying a fallible function to each transaction.
Returns the block with the new transaction type if all transactions were successfully.
Sourcepub fn into_with_encoded2718(self) -> Block<WithEncoded<T>, H>where
T: Encodable2718,
pub fn into_with_encoded2718(self) -> Block<WithEncoded<T>, H>where
T: Encodable2718,
Converts the transactions in the block’s body to WithEncoded<T> by encoding them via
Encodable2718
Sourcepub fn with_header(self, header: H) -> Self
pub fn with_header(self, header: H) -> Self
Replaces the header of the block.
Note: This method only replaces the main block header. If you need to transform
the ommer headers as well, use map_header instead.
Sourcepub fn rlp_encoded_from_parts(header: &H, body: &BlockBody<T, H>) -> Vec<u8> ⓘ
pub fn rlp_encoded_from_parts(header: &H, body: &BlockBody<T, H>) -> Vec<u8> ⓘ
Encodes the Block given header and block body.
Returns the rlp encoded block.
This is equivalent to block.encode.
Source§impl<T: Encodable2718> Block<T, Header>
impl<T: Encodable2718> Block<T, Header>
Sourcepub fn from_transactions(
header: Header,
transactions: impl IntoIterator<Item = T>,
) -> Self
pub fn from_transactions( header: Header, transactions: impl IntoIterator<Item = T>, ) -> Self
Creates a new block from a header and an iterator of transactions.
Computes and sets the transactions_root on the header automatically.
ommers_hash is set to EMPTY_OMMER_ROOT_HASH.
Trait Implementations§
Source§impl<'a, T, H> Arbitrary<'a> for Block<T, H>
Available on crate features arbitrary only.
impl<'a, T, H> Arbitrary<'a> for Block<T, H>
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<T, H> BorshDeserialize for Block<T, H>where
T: BorshDeserialize,
H: BorshDeserialize,
impl<T, H> BorshDeserialize for Block<T, H>where
T: BorshDeserialize,
H: BorshDeserialize,
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl<T, H> BorshSerialize for Block<T, H>where
T: BorshSerialize,
H: BorshSerialize,
impl<T, H> BorshSerialize for Block<T, H>where
T: BorshSerialize,
H: BorshSerialize,
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>,
impl<T: Eq, H: Eq> Eq for Block<T, H>
Source§impl<T, H> EthBlock for Block<T, H>
impl<T, H> EthBlock for Block<T, H>
Source§fn withdrawals(&self) -> Option<&Withdrawals>
fn withdrawals(&self) -> Option<&Withdrawals>
Source§impl<T: InMemorySize, H: InMemorySize> InMemorySize for Block<T, H>
impl<T: InMemorySize, H: InMemorySize> InMemorySize for Block<T, H>
Source§impl<T: PartialEq, H: PartialEq> PartialEq for Block<T, H>
impl<T: PartialEq, H: PartialEq> PartialEq 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> UnsafeUnpin for Block<T, H>where
H: UnsafeUnpin,
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.