diff --git a/Cargo.lock b/Cargo.lock index 6ac21f0..5f910f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -847,6 +847,7 @@ dependencies = [ "jsonrpsee", "reth-optimism-rpc", "reth-primitives", + "reth-rpc-eth-api", "reth-storage-api", "reth-transaction-pool", "serde", diff --git a/Cargo.toml b/Cargo.toml index 67a5d8d..e670535 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,6 +80,7 @@ reth-chainspec = { git = "https://github.com/paradigmxyz/reth.git", rev = "78426 ] } reth-cli = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673" } reth-cli-util = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673" } +reth-rpc-eth-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673" } reth-node-api = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673" } reth-node-builder = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673" } reth-node-core = { git = "https://github.com/paradigmxyz/reth.git", rev = "7842673", features = [ diff --git a/bin/alphanet/src/main.rs b/bin/alphanet/src/main.rs index 083978a..e810211 100644 --- a/bin/alphanet/src/main.rs +++ b/bin/alphanet/src/main.rs @@ -65,6 +65,7 @@ fn main() { AlphaNetWallet::new( ctx.provider().clone(), ctx.pool().clone(), + ctx.registry.eth_api().clone(), sequencer_client.clone(), ctx.config().chain.chain().id(), Vec::new(), diff --git a/crates/wallet/Cargo.toml b/crates/wallet/Cargo.toml index 53bd193..fff738f 100644 --- a/crates/wallet/Cargo.toml +++ b/crates/wallet/Cargo.toml @@ -16,6 +16,7 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] } reth-optimism-rpc.workspace = true reth-primitives.workspace = true reth-storage-api.workspace = true +reth-rpc-eth-api.workspace = true reth-transaction-pool.workspace = true serde = { workspace = true, features = ["derive"] } thiserror.workspace = true diff --git a/crates/wallet/src/lib.rs b/crates/wallet/src/lib.rs index 46c3953..162e117 100644 --- a/crates/wallet/src/lib.rs +++ b/crates/wallet/src/lib.rs @@ -19,10 +19,17 @@ use alloy_primitives::{map::HashMap, Address, ChainId, TxHash, TxKind, U256}; use alloy_rpc_types::TransactionRequest; -use jsonrpsee::{core::RpcResult, proc_macros::rpc}; +use jsonrpsee::{ + core::{async_trait, RpcResult}, + proc_macros::rpc, +}; use reth_optimism_rpc::SequencerClient; -use reth_primitives::revm_primitives::Bytecode; -use reth_storage_api::StateProvider; +use reth_primitives::{revm_primitives::Bytecode, BlockId}; +use reth_rpc_eth_api::{ + helpers::{EthCall, EthState, FullEthApi}, + EthApiTypes, +}; +use reth_storage_api::{StateProvider, StateProviderFactory}; use reth_transaction_pool::TransactionPool; use serde::{Deserialize, Serialize}; use tracing::trace; @@ -86,7 +93,7 @@ pub trait AlphaNetWalletApi { /// [eip-7702]: https://eips.ethereum.org/EIPS/eip-7702 /// [eip-1559]: https://eips.ethereum.org/EIPS/eip-1559 #[method(name = "sendTransaction")] - fn send_transaction(&self, request: TransactionRequest) -> RpcResult; + async fn send_transaction(&self, request: TransactionRequest) -> RpcResult; } #[derive(Debug, thiserror::Error)] @@ -115,18 +122,20 @@ impl From for jsonrpsee::types::error::ErrorObject<'static> } } -pub struct AlphaNetWallet { +pub struct AlphaNetWallet { provider: Provider, pool: Pool, sequencer_client: Option, chain_id: ChainId, capabilities: WalletCapabilities, + eth_api: Eth, } -impl AlphaNetWallet { +impl AlphaNetWallet { pub fn new( provider: Provider, pool: Pool, + eth_api: Eth, sequencer_client: Option, chain_id: ChainId, valid_designations: Vec
, @@ -137,21 +146,30 @@ impl AlphaNetWallet { Capabilities { delegation: DelegationCapability { addresses: valid_designations } }, ); - Self { provider, pool, sequencer_client, chain_id, capabilities: WalletCapabilities(caps) } + Self { + provider, + pool, + eth_api, + sequencer_client, + chain_id, + capabilities: WalletCapabilities(caps), + } } } -impl AlphaNetWalletApiServer for AlphaNetWallet +#[async_trait] +impl AlphaNetWalletApiServer for AlphaNetWallet where Pool: TransactionPool + Clone + 'static, - Provider: StateProvider + Send + Sync + 'static, + Provider: StateProviderFactory + Send + Sync + 'static, + Eth: FullEthApi + Send + Sync + 'static, { fn get_capabilities(&self) -> RpcResult { trace!(target: "rpc::wallet", "Serving wallet_getCapabilities"); Ok(self.capabilities.clone()) } - fn send_transaction(&self, mut request: TransactionRequest) -> RpcResult { + async fn send_transaction(&self, mut request: TransactionRequest) -> RpcResult { trace!(target: "rpc::wallet", ?request, "Serving wallet_sendTransaction"); // reject transactions that have a non-zero value to prevent draining the sequencer. @@ -177,7 +195,7 @@ where .get(self.chain_id) .map(|caps| caps.delegation.addresses.as_ref()) .unwrap_or_default(); - if let Some(authorizations) = request.authorization_list { + if let Some(authorizations) = &request.authorization_list { // check that all auth items delegate to a valid address if authorizations.iter().any(|auth| !valid_delegations.contains(&auth.address)) { return Err(AlphaNetWalletError::InvalidAuthorization.into()); @@ -187,7 +205,8 @@ where // if this is not a 7702 tx match request.to { Some(TxKind::Call(addr)) => { - if let Ok(Some(code)) = self.provider.account_code(addr) { + let state = self.provider.latest().unwrap(); + if let Ok(Some(code)) = state.account_code(addr) { match code.0 { Bytecode::Eip7702(code) => { // not a whitelisted address @@ -208,6 +227,14 @@ where } } + let tx_count = + EthState::transaction_count(&self.eth_api, Address::ZERO, Some(BlockId::pending())) + .await + .map_err(Into::into)?; + + let estimate = EthCall::estimate_gas_at(&self.eth_api, request, BlockId::latest(), None) + .await + .map_err(Into::into)?; // build and sign // add to pool, or send to sequencer todo!()