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§
Sourcefn type_flag(&self) -> Option<u8>
fn type_flag(&self) -> Option<u8>
Return the type flag (if any).
This should return None
for the default (legacy) variant of the
envelope.
Sourcefn encode_2718_len(&self) -> usize
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.
Sourcefn encode_2718(&self, out: &mut dyn BufMut)
fn encode_2718(&self, out: &mut dyn BufMut)
Provided Methods§
Sourcefn encoded_2718(&self) -> Vec<u8> ⓘ
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.
Sourcefn trie_hash(&self) -> FixedBytes<32>
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.
Sourcefn network_len(&self) -> usize
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.
Sourcefn network_encode(&self, out: &mut dyn BufMut)
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.