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§

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

Implementors§