alloy_eips/eip7594/
rlp.rs

1use alloc::vec::Vec;
2use alloy_rlp::BufMut;
3
4/// A helper trait for encoding [EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) sidecars.
5pub trait Encodable7594 {
6    /// The length of the 7594 encoded envelope. This is the length of the wrapper
7    /// version + the length of the inner encoding.
8    fn encode_7594_len(&self) -> usize;
9
10    /// Encode the sidecar according to [EIP-7594] rules. First a 1-byte
11    /// wrapper version (if any), then the body of the sidecar.
12    ///
13    /// [EIP-7594] inner encodings are unspecified, and produce an opaque
14    /// bytestring.
15    ///
16    /// [EIP-7594]: https://eips.ethereum.org/EIPS/eip-7594
17    fn encode_7594(&self, out: &mut dyn BufMut);
18
19    /// Encode the sidecar according to [EIP-7594] rules. First a 1-byte
20    /// wrapper version (if any), then the body of the sidecar.
21    ///
22    /// This is a convenience method for encoding into a vec, and returning the
23    /// vec.
24    fn encoded_7594(&self) -> Vec<u8> {
25        let mut out = Vec::with_capacity(self.encode_7594_len());
26        self.encode_7594(&mut out);
27        out
28    }
29}
30
31/// A helper trait for decoding [EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) sidecars.
32pub trait Decodable7594: Sized {
33    /// Decode the sidecar according to [EIP-7594] rules. First a 1-byte
34    /// wrapper version (if any), then the body of the sidecar.
35    ///
36    /// [EIP-7594] inner encodings are unspecified, and produce an opaque
37    /// bytestring.
38    ///
39    /// [EIP-7594]: https://eips.ethereum.org/EIPS/eip-7594
40    fn decode_7594(buf: &mut &[u8]) -> alloy_rlp::Result<Self>;
41}