From 533c3ebe982c3e03e647bc6567fb5030d6ac3ac6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 14 Oct 2022 21:01:00 +0200 Subject: [PATCH] feat(rpc): add EthApiServer impl skeleton (#75) --- Cargo.lock | 3 + crates/net/rpc-api/src/eth.rs | 58 +++++---- crates/net/rpc/Cargo.toml | 7 +- crates/net/rpc/src/eth.rs | 238 ++++++++++++++++++++++++++++++++++ crates/net/rpc/src/lib.rs | 4 +- 5 files changed, 283 insertions(+), 27 deletions(-) create mode 100644 crates/net/rpc/src/eth.rs diff --git a/Cargo.lock b/Cargo.lock index 14f533766..f08350cbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2126,9 +2126,12 @@ dependencies = [ name = "reth-rpc" version = "0.1.0" dependencies = [ + "async-trait", + "jsonrpsee", "reth-primitives", "reth-rpc-api", "reth-rpc-types", + "reth-transaction-pool", "serde", "serde_json", "thiserror", diff --git a/crates/net/rpc-api/src/eth.rs b/crates/net/rpc-api/src/eth.rs index f115bf7c3..c4096c76f 100644 --- a/crates/net/rpc-api/src/eth.rs +++ b/crates/net/rpc-api/src/eth.rs @@ -18,29 +18,29 @@ use reth_rpc_types::{ pub trait EthApi { /// Returns protocol version encoded as a string (quotes are necessary). #[method(name = "eth_protocolVersion")] - fn protocol_version(&self) -> Result; + async fn protocol_version(&self) -> Result; /// Returns an object with data about the sync status or false. #[method(name = "eth_syncing")] - fn syncing(&self) -> Result; + async fn syncing(&self) -> Result; /// Returns block author. #[method(name = "eth_coinbase")] - fn author(&self) -> Result
; + async fn author(&self) -> Result
; /// Returns accounts list. #[method(name = "eth_accounts")] - fn accounts(&self) -> Result>; + async fn accounts(&self) -> Result>; /// Returns highest block number. #[method(name = "eth_blockNumber")] - fn block_number(&self) -> Result; + async fn block_number(&self) -> Result; /// Returns the chain ID used for transaction signing at the /// current best block. None is returned if not /// available. #[method(name = "eth_chainId")] - fn chain_id(&self) -> Result>; + async fn chain_id(&self) -> Result>; /// Returns block with given hash. #[method(name = "eth_getBlockByHash")] @@ -52,27 +52,31 @@ pub trait EthApi { /// Returns the number of transactions in a block with given hash. #[method(name = "eth_getBlockTransactionCountByHash")] - fn block_transaction_count_by_hash(&self, hash: H256) -> Result>; + async fn block_transaction_count_by_hash(&self, hash: H256) -> Result>; /// Returns the number of transactions in a block with given block number. #[method(name = "eth_getBlockTransactionCountByNumber")] - fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result>; + async fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result>; /// Returns the number of uncles in a block with given hash. #[method(name = "eth_getUncleCountByBlockHash")] - fn block_uncles_count_by_hash(&self, hash: H256) -> Result; + async fn block_uncles_count_by_hash(&self, hash: H256) -> Result; /// Returns the number of uncles in a block with given block number. #[method(name = "eth_getUncleCountByBlockNumber")] - fn block_uncles_count_by_number(&self, number: BlockNumber) -> Result; + async fn block_uncles_count_by_number(&self, number: BlockNumber) -> Result; /// Returns an uncles at given block and index. #[method(name = "eth_getUncleByBlockHashAndIndex")] - fn uncle_by_block_hash_and_index(&self, hash: H256, index: Index) -> Result>; + async fn uncle_by_block_hash_and_index( + &self, + hash: H256, + index: Index, + ) -> Result>; /// Returns an uncles at given block and index. #[method(name = "eth_getUncleByBlockNumberAndIndex")] - fn uncle_by_block_number_and_index( + async fn uncle_by_block_number_and_index( &self, number: BlockNumber, index: Index, @@ -104,11 +108,11 @@ pub trait EthApi { /// Returns balance of the given account. #[method(name = "eth_getBalance")] - fn balance(&self, address: Address, block_number: Option) -> Result; + async fn balance(&self, address: Address, block_number: Option) -> Result; /// Returns content of the storage at given address. #[method(name = "eth_getStorageAt")] - fn storage_at( + async fn storage_at( &self, address: Address, index: U256, @@ -117,15 +121,19 @@ pub trait EthApi { /// Returns the number of transactions sent from given address at given time (block number). #[method(name = "eth_getTransactionCount")] - fn transaction_count(&self, address: Address, block_number: Option) -> Result; + async fn transaction_count( + &self, + address: Address, + block_number: Option, + ) -> Result; /// Returns the code at given address at given time (block number). #[method(name = "eth_getCode")] - fn code_at(&self, address: Address, block_number: Option) -> Result; + async fn code_at(&self, address: Address, block_number: Option) -> Result; /// Call contract, returning the output data. #[method(name = "eth_call")] - fn call(&self, request: CallRequest, block_number: Option) -> Result; + async fn call(&self, request: CallRequest, block_number: Option) -> Result; /// This method creates an EIP2930 type accessList based on a given Transaction. The accessList /// contains all storage slots and addresses read and written by the transaction, except for the @@ -155,11 +163,11 @@ pub trait EthApi { /// Returns current gas_price. #[method(name = "eth_gasPrice")] - fn gas_price(&self) -> Result; + async fn gas_price(&self) -> Result; /// Introduced in EIP-1159 for getting information on the appropriate priority fee to use. #[method(name = "eth_feeHistory")] - fn fee_history( + async fn fee_history( &self, block_count: U256, newest_block: BlockNumber, @@ -169,27 +177,27 @@ pub trait EthApi { /// Introduced in EIP-1159, a Geth-specific and simplified priority fee oracle. /// Leverages the already existing fee history cache. #[method(name = "eth_maxPriorityFeePerGas")] - fn max_priority_fee_per_gas(&self) -> Result; + async fn max_priority_fee_per_gas(&self) -> Result; /// Returns true if client is actively mining new blocks. #[method(name = "eth_mining")] - fn is_mining(&self) -> Result; + async fn is_mining(&self) -> Result; /// Returns the number of hashes per second that the node is mining with. #[method(name = "eth_hashrate")] - fn hashrate(&self) -> Result; + async fn hashrate(&self) -> Result; /// Returns the hash of the current block, the seedHash, and the boundary condition to be met. #[method(name = "eth_getWork")] - fn work(&self) -> Result; + async fn work(&self) -> Result; /// Used for submitting mining hashrate. #[method(name = "eth_submitHashrate")] - fn submit_hashrate(&self, hashrate: U256, id: H256) -> Result; + async fn submit_hashrate(&self, hashrate: U256, id: H256) -> Result; /// Used for submitting a proof-of-work solution. #[method(name = "eth_submitWork")] - fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> Result; + async fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> Result; /// Sends transaction; will block waiting for signer to return the /// transaction hash. diff --git a/crates/net/rpc/Cargo.toml b/crates/net/rpc/Cargo.toml index 57fd4fee9..21dd3a792 100644 --- a/crates/net/rpc/Cargo.toml +++ b/crates/net/rpc/Cargo.toml @@ -13,8 +13,13 @@ Reth RPC implementation reth-primitives = { path = "../../primitives" } reth-rpc-api = { path = "../rpc-api" } reth-rpc-types = { path = "../rpc-types" } +reth-transaction-pool = { path = "../../transaction-pool" } + +# rpc +jsonrpsee = { version = "0.15" } # misc +async-trait = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -thiserror = "1.0" \ No newline at end of file +thiserror = "1.0" diff --git a/crates/net/rpc/src/eth.rs b/crates/net/rpc/src/eth.rs new file mode 100644 index 000000000..8c883914a --- /dev/null +++ b/crates/net/rpc/src/eth.rs @@ -0,0 +1,238 @@ +//! Implementation for the `eth` namespace rpc request handler. + +use jsonrpsee::core::RpcResult as Result; +use reth_primitives::{ + rpc::{transaction::eip2930::AccessListWithGasUsed, BlockId}, + Address, BlockNumber, Bytes, Transaction, H256, H64, U256, U64, +}; +use reth_rpc_api::EthApiServer; +use reth_rpc_types::{ + CallRequest, EIP1186AccountProofResponse, FeeHistory, Index, RichBlock, SyncStatus, + TransactionReceipt, TransactionRequest, Work, +}; +use reth_transaction_pool::TransactionPool; +use serde_json::Value; + +/// `Eth` API implementation. +/// +/// This type serves as the handler for RPCs for the `eth` namespace. +#[derive(Debug, Clone)] +pub struct EthApi { + /// The transaction pool. + _pool: Pool, +} + +#[async_trait::async_trait] +impl EthApiServer for EthApi +where + Pool: TransactionPool, +{ + async fn protocol_version(&self) -> Result { + todo!() + } + + async fn syncing(&self) -> Result { + todo!() + } + + async fn author(&self) -> Result
{ + todo!() + } + + async fn accounts(&self) -> Result> { + todo!() + } + + async fn block_number(&self) -> Result { + todo!() + } + + async fn chain_id(&self) -> Result> { + todo!() + } + + async fn block_by_hash(&self, _hash: H256, _full: bool) -> Result> { + todo!() + } + + async fn block_by_number( + &self, + _number: BlockNumber, + _full: bool, + ) -> Result> { + todo!() + } + + async fn block_transaction_count_by_hash(&self, _hash: H256) -> Result> { + todo!() + } + + async fn block_transaction_count_by_number( + &self, + _number: BlockNumber, + ) -> Result> { + todo!() + } + + async fn block_uncles_count_by_hash(&self, _hash: H256) -> Result { + todo!() + } + + async fn block_uncles_count_by_number(&self, _number: BlockNumber) -> Result { + todo!() + } + + async fn uncle_by_block_hash_and_index( + &self, + _hash: H256, + _index: Index, + ) -> Result> { + todo!() + } + + async fn uncle_by_block_number_and_index( + &self, + _number: BlockNumber, + _index: Index, + ) -> Result> { + todo!() + } + + async fn transaction_by_hash( + &self, + _hash: H256, + ) -> Result> { + todo!() + } + + async fn transaction_by_block_hash_and_index( + &self, + _hash: H256, + _index: Index, + ) -> Result> { + todo!() + } + + async fn transaction_by_block_number_and_index( + &self, + _number: BlockNumber, + _index: Index, + ) -> Result> { + todo!() + } + + async fn transaction_receipt(&self, _hash: H256) -> Result> { + todo!() + } + + async fn balance(&self, _address: Address, _block_number: Option) -> Result { + todo!() + } + + async fn storage_at( + &self, + _address: Address, + _index: U256, + _block_number: Option, + ) -> Result { + todo!() + } + + async fn transaction_count( + &self, + _address: Address, + _block_number: Option, + ) -> Result { + todo!() + } + + async fn code_at(&self, _address: Address, _block_number: Option) -> Result { + todo!() + } + + async fn call(&self, _request: CallRequest, _block_number: Option) -> Result { + todo!() + } + + async fn create_access_list( + &self, + _request: CallRequest, + _block_number: Option, + ) -> Result { + todo!() + } + + async fn estimate_gas( + &self, + _request: CallRequest, + _block_number: Option, + ) -> Result { + todo!() + } + + async fn gas_price(&self) -> Result { + todo!() + } + + async fn fee_history( + &self, + _block_count: U256, + _newest_block: BlockNumber, + _reward_percentiles: Option>, + ) -> Result { + todo!() + } + + async fn max_priority_fee_per_gas(&self) -> Result { + todo!() + } + + async fn is_mining(&self) -> Result { + todo!() + } + + async fn hashrate(&self) -> Result { + todo!() + } + + async fn work(&self) -> Result { + todo!() + } + + async fn submit_hashrate(&self, _hashrate: U256, _id: H256) -> Result { + todo!() + } + + async fn submit_work(&self, _nonce: H64, _pow_hash: H256, _mix_digest: H256) -> Result { + todo!() + } + + async fn send_transaction(&self, _request: TransactionRequest) -> Result { + todo!() + } + + async fn send_raw_transaction(&self, _bytes: Bytes) -> Result { + todo!() + } + + async fn sign(&self, _address: Address, _message: Bytes) -> Result { + todo!() + } + + async fn sign_transaction(&self, _transaction: CallRequest) -> Result { + todo!() + } + + async fn sign_typed_data(&self, _address: Address, _data: Value) -> Result { + todo!() + } + + async fn get_proof( + &self, + _address: Address, + _keys: Vec, + _block_number: Option, + ) -> Result { + todo!() + } +} diff --git a/crates/net/rpc/src/lib.rs b/crates/net/rpc/src/lib.rs index 4236c0d6f..7137e1ca6 100644 --- a/crates/net/rpc/src/lib.rs +++ b/crates/net/rpc/src/lib.rs @@ -7,4 +7,6 @@ //! Reth RPC implementation //! -//! Provides the implementation of all RPC interfaces +//! Provides the implementation of all RPC interfaces. + +pub mod eth;