Trait Block

Source
pub trait Block:
    Send
    + Sync
    + Unpin
    + Clone
    + Default
    + Debug
    + PartialEq
    + Eq
    + InMemorySize
    + MaybeSerde
    + Encodable
    + Decodable {
    type Header: BlockHeader;
    type Body: BlockBody<OmmerHeader = Self::Header>;

Show 17 methods // Required methods fn new(header: Self::Header, body: Self::Body) -> Self; fn header(&self) -> &Self::Header; fn body(&self) -> &Self::Body; fn split(self) -> (Self::Header, Self::Body); fn rlp_length(header: &Self::Header, body: &Self::Body) -> usize; // Provided methods fn new_sealed( header: SealedHeader<Self::Header>, body: Self::Body, ) -> SealedBlock<Self> { ... } fn seal_unchecked(self, hash: B256) -> SealedBlock<Self> { ... } fn seal(self) -> SealedBlock<Self> { ... } fn seal_slow(self) -> SealedBlock<Self> { ... } fn split_ref(&self) -> (&Self::Header, &Self::Body) { ... } fn into_header(self) -> Self::Header { ... } fn into_body(self) -> Self::Body { ... } fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError> where <Self::Body as BlockBody>::Transaction: SignedTransaction { ... } fn try_into_recovered_unchecked( self, senders: Vec<Address>, ) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>> where <Self::Body as BlockBody>::Transaction: SignedTransaction { ... } fn into_recovered_with_signers( self, signers: Vec<Address>, ) -> RecoveredBlock<Self> where <Self::Body as BlockBody>::Transaction: SignedTransaction { ... } fn try_into_recovered( self, ) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>> where <Self::Body as BlockBody>::Transaction: SignedTransaction { ... } fn into_ethereum_block( self, ) -> Block<<Self::Body as BlockBody>::Transaction, Self::Header> { ... }
}
Expand description

Abstraction of block data type.

This type defines the structure of a block in the blockchain. A Block is composed of a header and a body. It is expected that a block can always be completely reconstructed from its header and body.

Required Associated Types§

Source

type Header: BlockHeader

Header part of the block.

Source

type Body: BlockBody<OmmerHeader = Self::Header>

The block’s body contains the transactions in the block and additional data, e.g. withdrawals in ethereum.

Required Methods§

Source

fn new(header: Self::Header, body: Self::Body) -> Self

Create new block instance.

Source

fn header(&self) -> &Self::Header

Returns reference to block header.

Source

fn body(&self) -> &Self::Body

Returns reference to block body.

Source

fn split(self) -> (Self::Header, Self::Body)

Splits the block into its header and body.

Source

fn rlp_length(header: &Self::Header, body: &Self::Body) -> usize

Returns the rlp length of the block with the given header and body.

Provided Methods§

Source

fn new_sealed( header: SealedHeader<Self::Header>, body: Self::Body, ) -> SealedBlock<Self>

Create new a sealed block instance from a sealed header and the block body.

Source

fn seal_unchecked(self, hash: B256) -> SealedBlock<Self>

Seal the block with a known hash.

WARNING: This method does not perform validation whether the hash is correct.

Source

fn seal(self) -> SealedBlock<Self>

Creates the SealedBlock from the block’s parts without calculating the hash upfront.

Source

fn seal_slow(self) -> SealedBlock<Self>

Calculate the header hash and seal the block so that it can’t be changed.

Source

fn split_ref(&self) -> (&Self::Header, &Self::Body)

Returns a tuple of references to the block’s header and body.

Source

fn into_header(self) -> Self::Header

Consumes the block and returns the header.

Source

fn into_body(self) -> Self::Body

Consumes the block and returns the body.

Source

fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError>

Expensive operation that recovers transaction signer.

Source

fn try_into_recovered_unchecked( self, senders: Vec<Address>, ) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>>

Transform the block into a RecoveredBlock using the given senders.

If the number of senders does not match the number of transactions in the block, this falls back to manually recovery, but without ensuring that the signature has a low s value.

Returns the block as error if a signature is invalid.

Source

fn into_recovered_with_signers( self, signers: Vec<Address>, ) -> RecoveredBlock<Self>

Transform the block into a RecoveredBlock using the given signers.

Note: This method assumes the signers are correct and does not validate them.

Source

fn try_into_recovered( self, ) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>>

Expensive. Transform into a RecoveredBlock by recovering senders in the contained transactions.

Returns the block as error if a signature is invalid.

Source

fn into_ethereum_block( self, ) -> Block<<Self::Body as BlockBody>::Transaction, Self::Header>

A Convenience function to convert this type into the regular ethereum block that consists of:

  • Header

And the ethereum block body [alloy_consensus::BlockBody], see also BlockBody::into_ethereum_body.

  • Transactions
  • Withdrawals
  • Ommers

Note: This conversion can be incomplete. It is not expected that this Block is the same as [alloy_consensus::Block] only that it can be converted into it which is useful for the eth_ RPC namespace (e.g. RPC block).

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.

Implementations on Foreign Types§

Source§

impl<T, H> Block for Block<T, H>

Source§

type Header = H

Source§

type Body = BlockBody<T, H>

Source§

fn new(header: Self::Header, body: Self::Body) -> Self

Source§

fn header(&self) -> &Self::Header

Source§

fn body(&self) -> &Self::Body

Source§

fn split(self) -> (Self::Header, Self::Body)

Source§

fn rlp_length(header: &Self::Header, body: &Self::Body) -> usize

Source§

fn into_ethereum_block(self) -> Self

Implementors§