alloy_network::eip2718

Trait Decodable2718

source
pub trait Decodable2718: Sized {
    // Required methods
    fn typed_decode(ty: u8, buf: &mut &[u8]) -> Result<Self, Eip2718Error>;
    fn fallback_decode(buf: &mut &[u8]) -> Result<Self, Eip2718Error>;

    // Provided methods
    fn extract_type_byte(buf: &mut &[u8]) -> Option<u8> { ... }
    fn decode_2718(buf: &mut &[u8]) -> Result<Self, Eip2718Error> { ... }
    fn network_decode(buf: &mut &[u8]) -> Result<Self, Eip2718Error> { ... }
}
Expand description

Decoding trait for EIP-2718 envelopes. These envelopes wrap a transaction or a receipt with a type flag.

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 typed_decode(ty: u8, buf: &mut &[u8]) -> Result<Self, Eip2718Error>

Decode the appropriate variant, based on the type flag.

This function is invoked by Self::decode_2718 with the type byte, and the tail of the buffer.

§Implementing

This should be a simple match block that invokes an inner type’s specific decoder.

source

fn fallback_decode(buf: &mut &[u8]) -> Result<Self, Eip2718Error>

Decode the default variant.

§Implementing

This function is invoked by Self::decode_2718 when no type byte can be extracted. It should be a simple wrapper around the default type’s decoder.

Provided Methods§

source

fn extract_type_byte(buf: &mut &[u8]) -> Option<u8>

Extract the type byte from the buffer, if any. The type byte is the first byte, provided that that first byte is 0x7f or lower.

source

fn decode_2718(buf: &mut &[u8]) -> Result<Self, Eip2718Error>

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.

source

fn network_decode(buf: &mut &[u8]) -> Result<Self, Eip2718Error>

Decode an EIP-2718 transaction 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 Decodable2718 for ReceiptEnvelope

source§

impl Decodable2718 for TxEnvelope

source§

impl Decodable2718 for AnyReceiptEnvelope

Implementors§