mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add alloy-compat for op prims (#14406)
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -8581,8 +8581,11 @@ version = "1.1.5"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"alloy-consensus",
|
"alloy-consensus",
|
||||||
"alloy-eips",
|
"alloy-eips",
|
||||||
|
"alloy-network",
|
||||||
"alloy-primitives",
|
"alloy-primitives",
|
||||||
"alloy-rlp",
|
"alloy-rlp",
|
||||||
|
"alloy-rpc-types-eth",
|
||||||
|
"alloy-serde",
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"bytes",
|
"bytes",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
|||||||
@ -27,6 +27,9 @@ secp256k1 = { workspace = true, optional = true }
|
|||||||
|
|
||||||
# op
|
# op
|
||||||
op-alloy-consensus.workspace = true
|
op-alloy-consensus.workspace = true
|
||||||
|
alloy-rpc-types-eth = { workspace = true, optional = true }
|
||||||
|
alloy-network = { workspace = true, optional = true }
|
||||||
|
alloy-serde = { workspace = true, optional = true }
|
||||||
|
|
||||||
# codec
|
# codec
|
||||||
bytes = { workspace = true, optional = true }
|
bytes = { workspace = true, optional = true }
|
||||||
@ -66,7 +69,10 @@ std = [
|
|||||||
"alloy-rlp/std",
|
"alloy-rlp/std",
|
||||||
"reth-zstd-compressors?/std",
|
"reth-zstd-compressors?/std",
|
||||||
"op-alloy-consensus/std",
|
"op-alloy-consensus/std",
|
||||||
|
"alloy-rpc-types-eth?/std",
|
||||||
|
"alloy-serde?/std",
|
||||||
]
|
]
|
||||||
|
alloy-compat = ["dep:alloy-network", "dep:alloy-serde", "dep:alloy-rpc-types-eth"]
|
||||||
reth-codec = [
|
reth-codec = [
|
||||||
"dep:reth-codecs",
|
"dep:reth-codecs",
|
||||||
"std",
|
"std",
|
||||||
@ -89,6 +95,7 @@ serde = [
|
|||||||
"rand?/serde",
|
"rand?/serde",
|
||||||
"revm-primitives?/serde",
|
"revm-primitives?/serde",
|
||||||
"secp256k1?/serde",
|
"secp256k1?/serde",
|
||||||
|
"alloy-rpc-types-eth?/serde",
|
||||||
]
|
]
|
||||||
serde-bincode-compat = [
|
serde-bincode-compat = [
|
||||||
"alloy-consensus/serde-bincode-compat",
|
"alloy-consensus/serde-bincode-compat",
|
||||||
@ -108,6 +115,8 @@ arbitrary = [
|
|||||||
"alloy-primitives/arbitrary",
|
"alloy-primitives/arbitrary",
|
||||||
"revm-primitives?/arbitrary",
|
"revm-primitives?/arbitrary",
|
||||||
"rand",
|
"rand",
|
||||||
|
"alloy-rpc-types-eth?/arbitrary",
|
||||||
|
"alloy-serde?/arbitrary",
|
||||||
]
|
]
|
||||||
optimism = [
|
optimism = [
|
||||||
"dep:revm-primitives",
|
"dep:revm-primitives",
|
||||||
|
|||||||
53
crates/optimism/primitives/src/alloy_compat.rs
Normal file
53
crates/optimism/primitives/src/alloy_compat.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//! Common conversions from alloy types.
|
||||||
|
|
||||||
|
use crate::OpTransactionSigned;
|
||||||
|
use alloc::string::ToString;
|
||||||
|
use alloy_consensus::TxEnvelope;
|
||||||
|
use alloy_network::{AnyRpcTransaction, AnyTxEnvelope};
|
||||||
|
use alloy_rpc_types_eth::Transaction as AlloyRpcTransaction;
|
||||||
|
use alloy_serde::WithOtherFields;
|
||||||
|
use op_alloy_consensus::OpTypedTransaction;
|
||||||
|
|
||||||
|
impl TryFrom<AnyRpcTransaction> for OpTransactionSigned {
|
||||||
|
type Error = alloy_rpc_types_eth::ConversionError;
|
||||||
|
|
||||||
|
fn try_from(tx: AnyRpcTransaction) -> Result<Self, Self::Error> {
|
||||||
|
use alloy_rpc_types_eth::ConversionError;
|
||||||
|
|
||||||
|
let WithOtherFields { inner: tx, other: _ } = tx;
|
||||||
|
|
||||||
|
let (transaction, signature, hash) = match tx.inner {
|
||||||
|
AnyTxEnvelope::Ethereum(TxEnvelope::Legacy(tx)) => {
|
||||||
|
let (tx, signature, hash) = tx.into_parts();
|
||||||
|
(OpTypedTransaction::Legacy(tx), signature, hash)
|
||||||
|
}
|
||||||
|
AnyTxEnvelope::Ethereum(TxEnvelope::Eip2930(tx)) => {
|
||||||
|
let (tx, signature, hash) = tx.into_parts();
|
||||||
|
(OpTypedTransaction::Eip2930(tx), signature, hash)
|
||||||
|
}
|
||||||
|
AnyTxEnvelope::Ethereum(TxEnvelope::Eip1559(tx)) => {
|
||||||
|
let (tx, signature, hash) = tx.into_parts();
|
||||||
|
(OpTypedTransaction::Eip1559(tx), signature, hash)
|
||||||
|
}
|
||||||
|
AnyTxEnvelope::Ethereum(TxEnvelope::Eip7702(tx)) => {
|
||||||
|
let (tx, signature, hash) = tx.into_parts();
|
||||||
|
(OpTypedTransaction::Eip7702(tx), signature, hash)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// TODO: support tx deposit: <https://github.com/alloy-rs/op-alloy/pull/427>
|
||||||
|
return Err(ConversionError::Custom("unknown transaction type".to_string()))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self::new(transaction, signature, hash))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<AlloyRpcTransaction<T>> for OpTransactionSigned
|
||||||
|
where
|
||||||
|
Self: From<T>,
|
||||||
|
{
|
||||||
|
fn from(value: AlloyRpcTransaction<T>) -> Self {
|
||||||
|
value.inner.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
#[cfg(feature = "alloy-compat")]
|
||||||
|
mod alloy_compat;
|
||||||
|
|
||||||
pub mod bedrock;
|
pub mod bedrock;
|
||||||
|
|
||||||
pub mod predeploys;
|
pub mod predeploys;
|
||||||
|
|||||||
Reference in New Issue
Block a user