Skip to content

Commit

Permalink
feat: implement compact for alloy ethereum transaction (#14908)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
stevencartavia and mattsse authored Mar 10, 2025
1 parent d9a00b8 commit 7300872
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 28 deletions.
56 changes: 28 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -456,34 +456,34 @@ alloy-trie = { version = "0.7", default-features = false }

alloy-hardforks = { git = "https://github.com/alloy-rs/hardforks", rev = "ae4176c" }

alloy-consensus = { version = "0.12.2", default-features = false }
alloy-contract = { version = "0.12.2", default-features = false }
alloy-eips = { version = "0.12.2", default-features = false }
alloy-genesis = { version = "0.12.2", default-features = false }
alloy-json-rpc = { version = "0.12.2", default-features = false }
alloy-network = { version = "0.12.2", default-features = false }
alloy-network-primitives = { version = "0.12.2", default-features = false }
alloy-node-bindings = { version = "0.12.2", default-features = false }
alloy-provider = { version = "0.12.2", features = ["reqwest"], default-features = false }
alloy-pubsub = { version = "0.12.2", default-features = false }
alloy-rpc-client = { version = "0.12.2", default-features = false }
alloy-rpc-types = { version = "0.12.2", features = ["eth"], default-features = false }
alloy-rpc-types-admin = { version = "0.12.2", default-features = false }
alloy-rpc-types-anvil = { version = "0.12.2", default-features = false }
alloy-rpc-types-beacon = { version = "0.12.2", default-features = false }
alloy-rpc-types-debug = { version = "0.12.2", default-features = false }
alloy-rpc-types-engine = { version = "0.12.2", default-features = false }
alloy-rpc-types-eth = { version = "0.12.2", default-features = false }
alloy-rpc-types-mev = { version = "0.12.2", default-features = false }
alloy-rpc-types-trace = { version = "0.12.2", default-features = false }
alloy-rpc-types-txpool = { version = "0.12.2", default-features = false }
alloy-serde = { version = "0.12.2", default-features = false }
alloy-signer = { version = "0.12.2", default-features = false }
alloy-signer-local = { version = "0.12.2", default-features = false }
alloy-transport = { version = "0.12.2" }
alloy-transport-http = { version = "0.12.2", features = ["reqwest-rustls-tls"], default-features = false }
alloy-transport-ipc = { version = "0.12.2", default-features = false }
alloy-transport-ws = { version = "0.12.2", default-features = false }
alloy-consensus = { version = "0.12.4", default-features = false }
alloy-contract = { version = "0.12.4", default-features = false }
alloy-eips = { version = "0.12.4", default-features = false }
alloy-genesis = { version = "0.12.4", default-features = false }
alloy-json-rpc = { version = "0.12.4", default-features = false }
alloy-network = { version = "0.12.4", default-features = false }
alloy-network-primitives = { version = "0.12.4", default-features = false }
alloy-node-bindings = { version = "0.12.4", default-features = false }
alloy-provider = { version = "0.12.4", features = ["reqwest"], default-features = false }
alloy-pubsub = { version = "0.12.4", default-features = false }
alloy-rpc-client = { version = "0.12.4", default-features = false }
alloy-rpc-types = { version = "0.12.4", features = ["eth"], default-features = false }
alloy-rpc-types-admin = { version = "0.12.4", default-features = false }
alloy-rpc-types-anvil = { version = "0.12.4", default-features = false }
alloy-rpc-types-beacon = { version = "0.12.4", default-features = false }
alloy-rpc-types-debug = { version = "0.12.4", default-features = false }
alloy-rpc-types-engine = { version = "0.12.4", default-features = false }
alloy-rpc-types-eth = { version = "0.12.4", default-features = false }
alloy-rpc-types-mev = { version = "0.12.4", default-features = false }
alloy-rpc-types-trace = { version = "0.12.4", default-features = false }
alloy-rpc-types-txpool = { version = "0.12.4", default-features = false }
alloy-serde = { version = "0.12.4", default-features = false }
alloy-signer = { version = "0.12.4", default-features = false }
alloy-signer-local = { version = "0.12.4", default-features = false }
alloy-transport = { version = "0.12.4" }
alloy-transport-http = { version = "0.12.4", features = ["reqwest-rustls-tls"], default-features = false }
alloy-transport-ipc = { version = "0.12.4", default-features = false }
alloy-transport-ws = { version = "0.12.4", default-features = false }

# op
alloy-op-evm = { git = "https://github.com/alloy-rs/evm", rev = "f9ed4d3", default-features = false }
Expand Down
51 changes: 51 additions & 0 deletions crates/storage/codecs/src/alloy/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,55 @@
//! Compact implementation for transaction types
use crate::Compact;
use alloy_consensus::{EthereumTypedTransaction, TxType, transaction::{TxEip7702, TxEip1559, TxEip2930, TxLegacy}};
use alloy_primitives::bytes::BufMut;
use alloy_consensus::transaction::RlpEcdsaEncodableTx;

impl<Eip4844> Compact for EthereumTypedTransaction<Eip4844>
where
Eip4844: Compact + RlpEcdsaEncodableTx,
{
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: BufMut + AsMut<[u8]>,
{
let identifier = self.tx_type().to_compact(buf);
match self {
Self::Legacy(tx) => tx.to_compact(buf),
Self::Eip2930(tx) => tx.to_compact(buf),
Self::Eip1559(tx) => tx.to_compact(buf),
Self::Eip4844(tx) => tx.to_compact(buf),
Self::Eip7702(tx) => tx.to_compact(buf),
};
identifier
}

fn from_compact(buf: &[u8], identifier: usize) -> (Self, &[u8]) {
let (tx_type, buf) = TxType::from_compact(buf, identifier);

match tx_type {
TxType::Legacy => {
let (tx, buf) = TxLegacy::from_compact(buf, buf.len());
(Self::Legacy(tx), buf)
}
TxType::Eip4844 => {
let (tx, buf) = Eip4844::from_compact(buf, buf.len());
(Self::Eip4844(tx), buf)
}
TxType::Eip7702 => {
let (tx, buf) = TxEip7702::from_compact(buf, buf.len());
(Self::Eip7702(tx), buf)
}
TxType::Eip1559 => {
let (tx, buf) = TxEip1559::from_compact(buf, buf.len());
(Self::Eip1559(tx), buf)
}
TxType::Eip2930 => {
let (tx, buf) = TxEip2930::from_compact(buf, buf.len());
(Self::Eip2930(tx), buf)
}
}
}
}

cond_mod!(
eip1559,
Expand Down

0 comments on commit 7300872

Please sign in to comment.