Trait Encodable2718

pub trait Encodable2718:
    Sized
    + Typed2718
    + Send
    + Sync {
    // Required methods
    fn encode_2718_len(&self) -> usize;
    fn encode_2718(&self, out: &mut dyn BufMut);

    // Provided methods
    fn type_flag(&self) -> Option<u8> { ... }
    fn encoded_2718(&self) -> Vec<u8>  { ... }
    fn trie_hash(&self) -> FixedBytes<32> { ... }
    fn seal(self) -> Sealed<Self> { ... }
    fn network_len(&self) -> usize { ... }
    fn network_encode(&self, out: &mut dyn BufMut) { ... }
}
Expand description

Encoding trait for EIP-2718 envelopes.

These envelopes wrap a transaction or a receipt with a type flag. EIP-2718 encodings are used by the eth_sendRawTransaction RPC call, the Ethereum block header’s tries, and the peer-to-peer protocol.

Users should rarely import this trait, and should instead prefer letting the alloy Provider methods handle encoding

§Implementing

Implement this trait when you need to make custom TransactionEnvelope and ReceiptEnvelope types for your network. These types should be enums over the accepted transaction types.

Required Methods§

fn encode_2718_len(&self) -> usize

The length of the 2718 encoded envelope. This is the length of the type flag + the length of the inner encoding.

fn encode_2718(&self, out: &mut dyn BufMut)

Encode the transaction according to EIP-2718 rules. First a 1-byte type flag in the range 0x0-0x7f, then the body of the transaction.

EIP-2718 inner encodings are unspecified, and produce an opaque bytestring.

Provided Methods§

fn type_flag(&self) -> Option<u8>

Return the type flag (if any).

This should return None for the default (legacy) variant of the envelope.

fn encoded_2718(&self) -> Vec<u8>

Encode the transaction according to [EIP-2718] rules. First a 1-byte type flag in the range 0x0-0x7f, then the body of the transaction.

This is a convenience method for encoding into a vec, and returning the vec.

fn trie_hash(&self) -> FixedBytes<32>

Compute the hash as committed to in the MPT trie. This hash is used ONLY by the Ethereum merkle-patricia trie and associated proofs. Do not call this method unless you are building a full or light client.

The trie hash is the keccak256 hash of the 2718-encoded envelope.

fn seal(self) -> Sealed<Self>

Seal the encodable, by encoding and hashing it.

fn network_len(&self) -> usize

The length of the 2718 encoded envelope in network format. This is the length of the header + the length of the type flag and inner encoding.

fn network_encode(&self, out: &mut dyn BufMut)

Encode in the network format. The network format is used ONLY by the Ethereum p2p protocol. Do not call this method unless you are building a p2p protocol client.

The network encoding is the RLP encoding of the eip2718-encoded envelope.

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§

§

impl Encodable2718 for AnyReceiptEnvelope

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl Encodable2718 for AnyTxEnvelope

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

§

impl Encodable2718 for OpPooledTransaction

§

fn type_flag(&self) -> Option<u8>

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

§

impl Encodable2718 for OpReceiptEnvelope

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl Encodable2718 for OpTxEnvelope

§

fn type_flag(&self) -> Option<u8>

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

§

impl Encodable2718 for ReceiptEnvelope

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl Encodable2718 for TransactionSigned

§

fn type_flag(&self) -> Option<u8>

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

§

impl Encodable2718 for TxDeposit

§

fn type_flag(&self) -> Option<u8>

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl<Eip4844> Encodable2718 for EthereumTxEnvelope<Eip4844>
where Eip4844: RlpEcdsaEncodableTx + Typed2718 + Send + Sync,

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

§

impl<L, R> Encodable2718 for Either<L, R>

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl<R> Encodable2718 for ReceiptWithBloom<R>
where R: Eip2718EncodableReceipt + Send + Sync,

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

impl<T> Encodable2718 for Recovered<T>
where T: Encodable2718,

§

fn encode_2718_len(&self) -> usize

§

fn encode_2718(&self, out: &mut dyn BufMut)

§

fn trie_hash(&self) -> FixedBytes<32>

Implementors§

impl Encodable2718 for OvmTransactionSigned

impl Encodable2718 for OpTransactionSigned