pub trait Decodable2718: Sized {
// Required methods
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self>;
fn fallback_decode(buf: &mut &[u8]) -> Eip2718Result<Self>;
// Provided methods
fn extract_type_byte(buf: &mut &[u8]) -> Option<u8> { ... }
fn decode_2718(buf: &mut &[u8]) -> Eip2718Result<Self> { ... }
fn network_decode(buf: &mut &[u8]) -> Eip2718Result<Self> { ... }
}
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§
Sourcefn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self>
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self>
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.
Sourcefn fallback_decode(buf: &mut &[u8]) -> Eip2718Result<Self>
fn fallback_decode(buf: &mut &[u8]) -> Eip2718Result<Self>
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§
Sourcefn extract_type_byte(buf: &mut &[u8]) -> Option<u8>
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.
Sourcefn decode_2718(buf: &mut &[u8]) -> Eip2718Result<Self>
fn decode_2718(buf: &mut &[u8]) -> Eip2718Result<Self>
Sourcefn network_decode(buf: &mut &[u8]) -> Eip2718Result<Self>
fn network_decode(buf: &mut &[u8]) -> Eip2718Result<Self>
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.