mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: implement EIP-7685 (#8424)
Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com> Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -15,8 +15,9 @@ workspace = true
|
||||
reth-codecs-derive = { path = "./derive", default-features = false }
|
||||
|
||||
# eth
|
||||
alloy-consensus = { workspace = true, optional = true }
|
||||
alloy-eips = { workspace = true, optional = true }
|
||||
alloy-genesis = { workspace = true, optional = true }
|
||||
alloy-genesis = { workspace = true, optional = true }
|
||||
alloy-primitives.workspace = true
|
||||
|
||||
# misc
|
||||
@ -25,7 +26,10 @@ modular-bitfield = { workspace = true, optional = true }
|
||||
serde.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
alloy-eips = { workspace = true, default-features = false, features = ["arbitrary", "serde"] }
|
||||
alloy-eips = { workspace = true, default-features = false, features = [
|
||||
"arbitrary",
|
||||
"serde",
|
||||
] }
|
||||
alloy-primitives = { workspace = true, features = ["arbitrary", "serde"] }
|
||||
test-fuzz.workspace = true
|
||||
serde_json.workspace = true
|
||||
@ -37,5 +41,10 @@ proptest-derive.workspace = true
|
||||
[features]
|
||||
default = ["std", "alloy"]
|
||||
std = ["alloy-primitives/std", "bytes/std"]
|
||||
alloy = ["dep:alloy-eips", "dep:alloy-genesis", "dep:modular-bitfield"]
|
||||
alloy = [
|
||||
"dep:alloy-consensus",
|
||||
"dep:alloy-eips",
|
||||
"dep:alloy-genesis",
|
||||
"dep:modular-bitfield",
|
||||
]
|
||||
optimism = ["reth-codecs-derive/optimism"]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
mod access_list;
|
||||
mod genesis_account;
|
||||
mod log;
|
||||
mod request;
|
||||
mod txkind;
|
||||
mod withdrawal;
|
||||
|
||||
39
crates/storage/codecs/src/alloy/request.rs
Normal file
39
crates/storage/codecs/src/alloy/request.rs
Normal file
@ -0,0 +1,39 @@
|
||||
//! Native Compact codec impl for EIP-7685 requests.
|
||||
|
||||
use crate::Compact;
|
||||
use alloy_consensus::Request;
|
||||
use alloy_eips::eip7685::{Decodable7685, Encodable7685};
|
||||
use alloy_primitives::Bytes;
|
||||
use bytes::BufMut;
|
||||
|
||||
impl Compact for Request {
|
||||
fn to_compact<B>(self, buf: &mut B) -> usize
|
||||
where
|
||||
B: BufMut + AsMut<[u8]>,
|
||||
{
|
||||
let encoded: Bytes = self.encoded_7685().into();
|
||||
encoded.to_compact(buf)
|
||||
}
|
||||
|
||||
fn from_compact(buf: &[u8], _: usize) -> (Self, &[u8]) {
|
||||
let (raw, buf) = Bytes::from_compact(buf, buf.len());
|
||||
|
||||
(Request::decode_7685(&mut raw.as_ref()).expect("invalid eip-7685 request in db"), buf)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use proptest::proptest;
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn roundtrip(request: Request) {
|
||||
let mut buf = Vec::<u8>::new();
|
||||
request.to_compact(&mut buf);
|
||||
let (decoded, _) = Request::from_compact(&buf, buf.len());
|
||||
assert_eq!(request, decoded);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user