feat(rpc): add EthApiServer impl skeleton (#75)

This commit is contained in:
Matthias Seitz
2022-10-14 21:01:00 +02:00
committed by GitHub
parent a7cf915677
commit 533c3ebe98
5 changed files with 283 additions and 27 deletions

3
Cargo.lock generated
View File

@ -2126,9 +2126,12 @@ dependencies = [
name = "reth-rpc" name = "reth-rpc"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-trait",
"jsonrpsee",
"reth-primitives", "reth-primitives",
"reth-rpc-api", "reth-rpc-api",
"reth-rpc-types", "reth-rpc-types",
"reth-transaction-pool",
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",

View File

@ -18,29 +18,29 @@ use reth_rpc_types::{
pub trait EthApi { pub trait EthApi {
/// Returns protocol version encoded as a string (quotes are necessary). /// Returns protocol version encoded as a string (quotes are necessary).
#[method(name = "eth_protocolVersion")] #[method(name = "eth_protocolVersion")]
fn protocol_version(&self) -> Result<u64>; async fn protocol_version(&self) -> Result<u64>;
/// Returns an object with data about the sync status or false. /// Returns an object with data about the sync status or false.
#[method(name = "eth_syncing")] #[method(name = "eth_syncing")]
fn syncing(&self) -> Result<SyncStatus>; async fn syncing(&self) -> Result<SyncStatus>;
/// Returns block author. /// Returns block author.
#[method(name = "eth_coinbase")] #[method(name = "eth_coinbase")]
fn author(&self) -> Result<Address>; async fn author(&self) -> Result<Address>;
/// Returns accounts list. /// Returns accounts list.
#[method(name = "eth_accounts")] #[method(name = "eth_accounts")]
fn accounts(&self) -> Result<Vec<Address>>; async fn accounts(&self) -> Result<Vec<Address>>;
/// Returns highest block number. /// Returns highest block number.
#[method(name = "eth_blockNumber")] #[method(name = "eth_blockNumber")]
fn block_number(&self) -> Result<U256>; async fn block_number(&self) -> Result<U256>;
/// Returns the chain ID used for transaction signing at the /// Returns the chain ID used for transaction signing at the
/// current best block. None is returned if not /// current best block. None is returned if not
/// available. /// available.
#[method(name = "eth_chainId")] #[method(name = "eth_chainId")]
fn chain_id(&self) -> Result<Option<U64>>; async fn chain_id(&self) -> Result<Option<U64>>;
/// Returns block with given hash. /// Returns block with given hash.
#[method(name = "eth_getBlockByHash")] #[method(name = "eth_getBlockByHash")]
@ -52,27 +52,31 @@ pub trait EthApi {
/// Returns the number of transactions in a block with given hash. /// Returns the number of transactions in a block with given hash.
#[method(name = "eth_getBlockTransactionCountByHash")] #[method(name = "eth_getBlockTransactionCountByHash")]
fn block_transaction_count_by_hash(&self, hash: H256) -> Result<Option<U256>>; async fn block_transaction_count_by_hash(&self, hash: H256) -> Result<Option<U256>>;
/// Returns the number of transactions in a block with given block number. /// Returns the number of transactions in a block with given block number.
#[method(name = "eth_getBlockTransactionCountByNumber")] #[method(name = "eth_getBlockTransactionCountByNumber")]
fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result<Option<U256>>; async fn block_transaction_count_by_number(&self, number: BlockNumber) -> Result<Option<U256>>;
/// Returns the number of uncles in a block with given hash. /// Returns the number of uncles in a block with given hash.
#[method(name = "eth_getUncleCountByBlockHash")] #[method(name = "eth_getUncleCountByBlockHash")]
fn block_uncles_count_by_hash(&self, hash: H256) -> Result<U256>; async fn block_uncles_count_by_hash(&self, hash: H256) -> Result<U256>;
/// Returns the number of uncles in a block with given block number. /// Returns the number of uncles in a block with given block number.
#[method(name = "eth_getUncleCountByBlockNumber")] #[method(name = "eth_getUncleCountByBlockNumber")]
fn block_uncles_count_by_number(&self, number: BlockNumber) -> Result<U256>; async fn block_uncles_count_by_number(&self, number: BlockNumber) -> Result<U256>;
/// Returns an uncles at given block and index. /// Returns an uncles at given block and index.
#[method(name = "eth_getUncleByBlockHashAndIndex")] #[method(name = "eth_getUncleByBlockHashAndIndex")]
fn uncle_by_block_hash_and_index(&self, hash: H256, index: Index) -> Result<Option<RichBlock>>; async fn uncle_by_block_hash_and_index(
&self,
hash: H256,
index: Index,
) -> Result<Option<RichBlock>>;
/// Returns an uncles at given block and index. /// Returns an uncles at given block and index.
#[method(name = "eth_getUncleByBlockNumberAndIndex")] #[method(name = "eth_getUncleByBlockNumberAndIndex")]
fn uncle_by_block_number_and_index( async fn uncle_by_block_number_and_index(
&self, &self,
number: BlockNumber, number: BlockNumber,
index: Index, index: Index,
@ -104,11 +108,11 @@ pub trait EthApi {
/// Returns balance of the given account. /// Returns balance of the given account.
#[method(name = "eth_getBalance")] #[method(name = "eth_getBalance")]
fn balance(&self, address: Address, block_number: Option<BlockId>) -> Result<U256>; async fn balance(&self, address: Address, block_number: Option<BlockId>) -> Result<U256>;
/// Returns content of the storage at given address. /// Returns content of the storage at given address.
#[method(name = "eth_getStorageAt")] #[method(name = "eth_getStorageAt")]
fn storage_at( async fn storage_at(
&self, &self,
address: Address, address: Address,
index: U256, index: U256,
@ -117,15 +121,19 @@ pub trait EthApi {
/// Returns the number of transactions sent from given address at given time (block number). /// Returns the number of transactions sent from given address at given time (block number).
#[method(name = "eth_getTransactionCount")] #[method(name = "eth_getTransactionCount")]
fn transaction_count(&self, address: Address, block_number: Option<BlockId>) -> Result<U256>; async fn transaction_count(
&self,
address: Address,
block_number: Option<BlockId>,
) -> Result<U256>;
/// Returns the code at given address at given time (block number). /// Returns the code at given address at given time (block number).
#[method(name = "eth_getCode")] #[method(name = "eth_getCode")]
fn code_at(&self, address: Address, block_number: Option<BlockId>) -> Result<Bytes>; async fn code_at(&self, address: Address, block_number: Option<BlockId>) -> Result<Bytes>;
/// Call contract, returning the output data. /// Call contract, returning the output data.
#[method(name = "eth_call")] #[method(name = "eth_call")]
fn call(&self, request: CallRequest, block_number: Option<BlockId>) -> Result<Bytes>; async fn call(&self, request: CallRequest, block_number: Option<BlockId>) -> Result<Bytes>;
/// This method creates an EIP2930 type accessList based on a given Transaction. The accessList /// 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 /// 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. /// Returns current gas_price.
#[method(name = "eth_gasPrice")] #[method(name = "eth_gasPrice")]
fn gas_price(&self) -> Result<U256>; async fn gas_price(&self) -> Result<U256>;
/// Introduced in EIP-1159 for getting information on the appropriate priority fee to use. /// Introduced in EIP-1159 for getting information on the appropriate priority fee to use.
#[method(name = "eth_feeHistory")] #[method(name = "eth_feeHistory")]
fn fee_history( async fn fee_history(
&self, &self,
block_count: U256, block_count: U256,
newest_block: BlockNumber, newest_block: BlockNumber,
@ -169,27 +177,27 @@ pub trait EthApi {
/// Introduced in EIP-1159, a Geth-specific and simplified priority fee oracle. /// Introduced in EIP-1159, a Geth-specific and simplified priority fee oracle.
/// Leverages the already existing fee history cache. /// Leverages the already existing fee history cache.
#[method(name = "eth_maxPriorityFeePerGas")] #[method(name = "eth_maxPriorityFeePerGas")]
fn max_priority_fee_per_gas(&self) -> Result<U256>; async fn max_priority_fee_per_gas(&self) -> Result<U256>;
/// Returns true if client is actively mining new blocks. /// Returns true if client is actively mining new blocks.
#[method(name = "eth_mining")] #[method(name = "eth_mining")]
fn is_mining(&self) -> Result<bool>; async fn is_mining(&self) -> Result<bool>;
/// Returns the number of hashes per second that the node is mining with. /// Returns the number of hashes per second that the node is mining with.
#[method(name = "eth_hashrate")] #[method(name = "eth_hashrate")]
fn hashrate(&self) -> Result<U256>; async fn hashrate(&self) -> Result<U256>;
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met. /// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
#[method(name = "eth_getWork")] #[method(name = "eth_getWork")]
fn work(&self) -> Result<Work>; async fn work(&self) -> Result<Work>;
/// Used for submitting mining hashrate. /// Used for submitting mining hashrate.
#[method(name = "eth_submitHashrate")] #[method(name = "eth_submitHashrate")]
fn submit_hashrate(&self, hashrate: U256, id: H256) -> Result<bool>; async fn submit_hashrate(&self, hashrate: U256, id: H256) -> Result<bool>;
/// Used for submitting a proof-of-work solution. /// Used for submitting a proof-of-work solution.
#[method(name = "eth_submitWork")] #[method(name = "eth_submitWork")]
fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> Result<bool>; async fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> Result<bool>;
/// Sends transaction; will block waiting for signer to return the /// Sends transaction; will block waiting for signer to return the
/// transaction hash. /// transaction hash.

View File

@ -13,8 +13,13 @@ Reth RPC implementation
reth-primitives = { path = "../../primitives" } reth-primitives = { path = "../../primitives" }
reth-rpc-api = { path = "../rpc-api" } reth-rpc-api = { path = "../rpc-api" }
reth-rpc-types = { path = "../rpc-types" } reth-rpc-types = { path = "../rpc-types" }
reth-transaction-pool = { path = "../../transaction-pool" }
# rpc
jsonrpsee = { version = "0.15" }
# misc # misc
async-trait = "0.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0" thiserror = "1.0"

238
crates/net/rpc/src/eth.rs Normal file
View File

@ -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<Pool> {
/// The transaction pool.
_pool: Pool,
}
#[async_trait::async_trait]
impl<Pool> EthApiServer for EthApi<Pool>
where
Pool: TransactionPool<Transaction = Transaction>,
{
async fn protocol_version(&self) -> Result<u64> {
todo!()
}
async fn syncing(&self) -> Result<SyncStatus> {
todo!()
}
async fn author(&self) -> Result<Address> {
todo!()
}
async fn accounts(&self) -> Result<Vec<Address>> {
todo!()
}
async fn block_number(&self) -> Result<U256> {
todo!()
}
async fn chain_id(&self) -> Result<Option<U64>> {
todo!()
}
async fn block_by_hash(&self, _hash: H256, _full: bool) -> Result<Option<RichBlock>> {
todo!()
}
async fn block_by_number(
&self,
_number: BlockNumber,
_full: bool,
) -> Result<Option<RichBlock>> {
todo!()
}
async fn block_transaction_count_by_hash(&self, _hash: H256) -> Result<Option<U256>> {
todo!()
}
async fn block_transaction_count_by_number(
&self,
_number: BlockNumber,
) -> Result<Option<U256>> {
todo!()
}
async fn block_uncles_count_by_hash(&self, _hash: H256) -> Result<U256> {
todo!()
}
async fn block_uncles_count_by_number(&self, _number: BlockNumber) -> Result<U256> {
todo!()
}
async fn uncle_by_block_hash_and_index(
&self,
_hash: H256,
_index: Index,
) -> Result<Option<RichBlock>> {
todo!()
}
async fn uncle_by_block_number_and_index(
&self,
_number: BlockNumber,
_index: Index,
) -> Result<Option<RichBlock>> {
todo!()
}
async fn transaction_by_hash(
&self,
_hash: H256,
) -> Result<Option<reth_rpc_types::Transaction>> {
todo!()
}
async fn transaction_by_block_hash_and_index(
&self,
_hash: H256,
_index: Index,
) -> Result<Option<reth_rpc_types::Transaction>> {
todo!()
}
async fn transaction_by_block_number_and_index(
&self,
_number: BlockNumber,
_index: Index,
) -> Result<Option<reth_rpc_types::Transaction>> {
todo!()
}
async fn transaction_receipt(&self, _hash: H256) -> Result<Option<TransactionReceipt>> {
todo!()
}
async fn balance(&self, _address: Address, _block_number: Option<BlockId>) -> Result<U256> {
todo!()
}
async fn storage_at(
&self,
_address: Address,
_index: U256,
_block_number: Option<BlockId>,
) -> Result<H256> {
todo!()
}
async fn transaction_count(
&self,
_address: Address,
_block_number: Option<BlockId>,
) -> Result<U256> {
todo!()
}
async fn code_at(&self, _address: Address, _block_number: Option<BlockId>) -> Result<Bytes> {
todo!()
}
async fn call(&self, _request: CallRequest, _block_number: Option<BlockId>) -> Result<Bytes> {
todo!()
}
async fn create_access_list(
&self,
_request: CallRequest,
_block_number: Option<BlockId>,
) -> Result<AccessListWithGasUsed> {
todo!()
}
async fn estimate_gas(
&self,
_request: CallRequest,
_block_number: Option<BlockId>,
) -> Result<U256> {
todo!()
}
async fn gas_price(&self) -> Result<U256> {
todo!()
}
async fn fee_history(
&self,
_block_count: U256,
_newest_block: BlockNumber,
_reward_percentiles: Option<Vec<f64>>,
) -> Result<FeeHistory> {
todo!()
}
async fn max_priority_fee_per_gas(&self) -> Result<U256> {
todo!()
}
async fn is_mining(&self) -> Result<bool> {
todo!()
}
async fn hashrate(&self) -> Result<U256> {
todo!()
}
async fn work(&self) -> Result<Work> {
todo!()
}
async fn submit_hashrate(&self, _hashrate: U256, _id: H256) -> Result<bool> {
todo!()
}
async fn submit_work(&self, _nonce: H64, _pow_hash: H256, _mix_digest: H256) -> Result<bool> {
todo!()
}
async fn send_transaction(&self, _request: TransactionRequest) -> Result<H256> {
todo!()
}
async fn send_raw_transaction(&self, _bytes: Bytes) -> Result<H256> {
todo!()
}
async fn sign(&self, _address: Address, _message: Bytes) -> Result<Bytes> {
todo!()
}
async fn sign_transaction(&self, _transaction: CallRequest) -> Result<Bytes> {
todo!()
}
async fn sign_typed_data(&self, _address: Address, _data: Value) -> Result<Bytes> {
todo!()
}
async fn get_proof(
&self,
_address: Address,
_keys: Vec<H256>,
_block_number: Option<BlockId>,
) -> Result<EIP1186AccountProofResponse> {
todo!()
}
}

View File

@ -7,4 +7,6 @@
//! Reth RPC implementation //! Reth RPC implementation
//! //!
//! Provides the implementation of all RPC interfaces //! Provides the implementation of all RPC interfaces.
pub mod eth;