alloy_network::eip2718

Trait Encodable2718

source
pub trait Encodable2718:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn type_flag(&self) -> Option<u8>;
    fn encode_2718_len(&self) -> usize;
    fn encode_2718(&self, out: &mut dyn BufMut);

    // Provided methods
    fn is_legacy(&self) -> bool { ... }
    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§

source

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

Return the type flag (if any).

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

source

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.

source

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§

source

fn is_legacy(&self) -> bool

True if the envelope is the legacy variant.

source

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.

source

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.

source

fn seal(self) -> Sealed<Self>

Seal the encodable, by encoding and hashing it.

source

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.

source

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§

source§

impl Encodable2718 for ReceiptEnvelope

source§

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

source§

fn encode_2718_len(&self) -> usize

source§

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

source§

impl Encodable2718 for TxEnvelope

source§

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

source§

fn encode_2718_len(&self) -> usize

source§

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

source§

impl Encodable2718 for AnyReceiptEnvelope

source§

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

source§

fn encode_2718_len(&self) -> usize

source§

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

Implementors§