Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 26 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ reth-rpc-eth-types = { path = "crates/rpc/rpc-eth-types", default-features = fal
reth-rpc-layer = { path = "crates/rpc/rpc-layer" }
reth-rpc-server-types = { path = "crates/rpc/rpc-server-types" }
reth-rpc-convert = { path = "crates/rpc/rpc-convert" }
reth-rpc-traits = { version = "0.1.0", default-features = false }
reth-stages = { path = "crates/stages/stages" }
reth-stages-api = { path = "crates/stages/api" }
reth-stages-types = { path = "crates/stages/types", default-features = false }
Expand Down
10 changes: 1 addition & 9 deletions crates/rpc/rpc-convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ workspace = true
# reth
reth-primitives-traits.workspace = true
reth-evm.workspace = true
reth-rpc-traits.workspace = true

# ethereum
alloy-primitives.workspace = true
alloy-rpc-types-eth = { workspace = true, features = ["serde"] }
alloy-signer.workspace = true
alloy-consensus.workspace = true
alloy-network.workspace = true
alloy-json-rpc.workspace = true
alloy-evm = { workspace = true, features = ["rpc"] }

# optimism
op-alloy-consensus = { workspace = true, optional = true }
op-alloy-rpc-types = { workspace = true, optional = true }

# io
jsonrpsee-types.workspace = true

Expand All @@ -43,7 +39,3 @@ serde_json.workspace = true

[features]
default = []
op = [
"dep:op-alloy-consensus",
"dep:op-alloy-rpc-types",
]
10 changes: 7 additions & 3 deletions crates/rpc/rpc-convert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ mod rpc;
pub mod transaction;

pub use rpc::*;
pub use transaction::{
RpcConvert, RpcConverter, TransactionConversionError, TryIntoSimTx, TxInfoMapper,
};
pub use transaction::{RpcConvert, RpcConverter, TransactionConversionError};

pub use alloy_evm::rpc::{CallFees, CallFeesError, EthTxEnvError, TryIntoTxEnv};

// Re-export traits from reth-rpc-traits
pub use reth_rpc_traits::{
FromConsensusHeader, FromConsensusTx, SignTxRequestError, SignableTxRequest, TryIntoSimTx,
TxInfoMapper,
};
63 changes: 2 additions & 61 deletions crates/rpc/rpc-convert/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use std::{fmt::Debug, future::Future};
use std::fmt::Debug;

use alloy_consensus::{EthereumTxEnvelope, SignableTransaction, TxEip4844};
use alloy_json_rpc::RpcObject;
use alloy_network::{
primitives::HeaderResponse, Network, ReceiptResponse, TransactionResponse, TxSigner,
};
use alloy_primitives::Signature;
use alloy_network::{primitives::HeaderResponse, Network, ReceiptResponse, TransactionResponse};
use alloy_rpc_types_eth::TransactionRequest;

/// RPC types used by the `eth_` RPC API.
Expand Down Expand Up @@ -46,58 +42,3 @@ pub type RpcBlock<T> = alloy_rpc_types_eth::Block<RpcTransaction<T>, RpcHeader<T

/// Adapter for network specific transaction request.
pub type RpcTxReq<T> = <T as RpcTypes>::TransactionRequest;

/// Error for [`SignableTxRequest`] trait.
#[derive(Debug, thiserror::Error)]
pub enum SignTxRequestError {
/// The transaction request is invalid.
#[error("invalid transaction request")]
InvalidTransactionRequest,

/// The signer is not supported.
#[error(transparent)]
SignerNotSupported(#[from] alloy_signer::Error),
}

/// An abstraction over transaction requests that can be signed.
pub trait SignableTxRequest<T>: Send + Sync + 'static {
/// Attempts to build a transaction request and sign it with the given signer.
fn try_build_and_sign(
self,
signer: impl TxSigner<Signature> + Send,
) -> impl Future<Output = Result<T, SignTxRequestError>> + Send;
}

impl SignableTxRequest<EthereumTxEnvelope<TxEip4844>> for TransactionRequest {
async fn try_build_and_sign(
self,
signer: impl TxSigner<Signature> + Send,
) -> Result<EthereumTxEnvelope<TxEip4844>, SignTxRequestError> {
let mut tx =
self.build_typed_tx().map_err(|_| SignTxRequestError::InvalidTransactionRequest)?;
let signature = signer.sign_transaction(&mut tx).await?;
Ok(tx.into_signed(signature).into())
}
}

#[cfg(feature = "op")]
impl SignableTxRequest<op_alloy_consensus::OpTxEnvelope>
for op_alloy_rpc_types::OpTransactionRequest
{
async fn try_build_and_sign(
self,
signer: impl TxSigner<Signature> + Send,
) -> Result<op_alloy_consensus::OpTxEnvelope, SignTxRequestError> {
let mut tx =
self.build_typed_tx().map_err(|_| SignTxRequestError::InvalidTransactionRequest)?;

// sanity check: deposit transactions must not be signed by the user
if tx.is_deposit() {
return Err(SignTxRequestError::InvalidTransactionRequest);
}

let signature = signer.sign_transaction(&mut tx).await?;

Ok(tx.into_signed(signature).into())
}
}
Loading
Loading