mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: add rlp codec for Sidecar (#5390)
This commit is contained in:
@ -9,6 +9,7 @@ use crate::kzg::{
|
||||
self, Blob, Bytes48, KzgSettings, BYTES_PER_BLOB, BYTES_PER_COMMITMENT, BYTES_PER_PROOF,
|
||||
};
|
||||
use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header};
|
||||
use bytes::BufMut;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -325,6 +326,7 @@ impl BlobTransactionSidecar {
|
||||
/// - `blobs`
|
||||
/// - `commitments`
|
||||
/// - `proofs`
|
||||
#[inline]
|
||||
pub(crate) fn encode_inner(&self, out: &mut dyn bytes::BufMut) {
|
||||
BlobTransactionSidecarRlp::wrap_ref(self).encode(out);
|
||||
}
|
||||
@ -340,6 +342,7 @@ impl BlobTransactionSidecar {
|
||||
/// - `blobs`
|
||||
/// - `commitments`
|
||||
/// - `proofs`
|
||||
#[inline]
|
||||
pub(crate) fn decode_inner(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
Ok(BlobTransactionSidecarRlp::decode(buf)?.unwrap())
|
||||
}
|
||||
@ -367,6 +370,24 @@ impl From<BlobTransactionSidecar> for reth_rpc_types::BlobTransactionSidecar {
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for BlobTransactionSidecar {
|
||||
/// Encodes the inner [BlobTransactionSidecar] fields as RLP bytes, without a RLP header.
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
self.encode_inner(out)
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
self.fields_len()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for BlobTransactionSidecar {
|
||||
/// Decodes the inner [BlobTransactionSidecar] fields from RLP bytes, without a RLP header.
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
Self::decode_inner(buf)
|
||||
}
|
||||
}
|
||||
|
||||
// Wrapper for c-kzg rlp
|
||||
#[repr(C)]
|
||||
struct BlobTransactionSidecarRlp {
|
||||
@ -437,8 +458,6 @@ impl<'a> arbitrary::Arbitrary<'a> for BlobTransactionSidecar {
|
||||
#[cfg(any(test, feature = "arbitrary"))]
|
||||
impl proptest::arbitrary::Arbitrary for BlobTransactionSidecar {
|
||||
type Parameters = ParamsFor<String>;
|
||||
type Strategy = BoxedStrategy<BlobTransactionSidecar>;
|
||||
|
||||
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
|
||||
proptest_vec(proptest_vec(proptest_any::<u8>(), BYTES_PER_BLOB), 1..=5)
|
||||
.prop_map(move |blobs| {
|
||||
@ -462,6 +481,8 @@ impl proptest::arbitrary::Arbitrary for BlobTransactionSidecar {
|
||||
})
|
||||
.boxed()
|
||||
}
|
||||
|
||||
type Strategy = BoxedStrategy<BlobTransactionSidecar>;
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "arbitrary"))]
|
||||
|
||||
Reference in New Issue
Block a user