mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(rpc): add EthApiServer impl skeleton (#75)
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -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",
|
||||
|
||||
@ -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<u64>;
|
||||
async fn protocol_version(&self) -> Result<u64>;
|
||||
|
||||
/// Returns an object with data about the sync status or false.
|
||||
#[method(name = "eth_syncing")]
|
||||
fn syncing(&self) -> Result<SyncStatus>;
|
||||
async fn syncing(&self) -> Result<SyncStatus>;
|
||||
|
||||
/// Returns block author.
|
||||
#[method(name = "eth_coinbase")]
|
||||
fn author(&self) -> Result<Address>;
|
||||
async fn author(&self) -> Result<Address>;
|
||||
|
||||
/// Returns accounts list.
|
||||
#[method(name = "eth_accounts")]
|
||||
fn accounts(&self) -> Result<Vec<Address>>;
|
||||
async fn accounts(&self) -> Result<Vec<Address>>;
|
||||
|
||||
/// Returns highest block number.
|
||||
#[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
|
||||
/// current best block. None is returned if not
|
||||
/// available.
|
||||
#[method(name = "eth_chainId")]
|
||||
fn chain_id(&self) -> Result<Option<U64>>;
|
||||
async fn chain_id(&self) -> Result<Option<U64>>;
|
||||
|
||||
/// 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<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.
|
||||
#[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.
|
||||
#[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.
|
||||
#[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.
|
||||
#[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.
|
||||
#[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<BlockId>) -> Result<U256>;
|
||||
async fn balance(&self, address: Address, block_number: Option<BlockId>) -> Result<U256>;
|
||||
|
||||
/// 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<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).
|
||||
#[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.
|
||||
#[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
|
||||
/// 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<U256>;
|
||||
async fn gas_price(&self) -> Result<U256>;
|
||||
|
||||
/// 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<U256>;
|
||||
async fn max_priority_fee_per_gas(&self) -> Result<U256>;
|
||||
|
||||
/// Returns true if client is actively mining new blocks.
|
||||
#[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.
|
||||
#[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.
|
||||
#[method(name = "eth_getWork")]
|
||||
fn work(&self) -> Result<Work>;
|
||||
async fn work(&self) -> Result<Work>;
|
||||
|
||||
/// Used for submitting mining hashrate.
|
||||
#[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.
|
||||
#[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
|
||||
/// transaction hash.
|
||||
|
||||
@ -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"
|
||||
thiserror = "1.0"
|
||||
|
||||
238
crates/net/rpc/src/eth.rs
Normal file
238
crates/net/rpc/src/eth.rs
Normal 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!()
|
||||
}
|
||||
}
|
||||
@ -7,4 +7,6 @@
|
||||
|
||||
//! Reth RPC implementation
|
||||
//!
|
||||
//! Provides the implementation of all RPC interfaces
|
||||
//! Provides the implementation of all RPC interfaces.
|
||||
|
||||
pub mod eth;
|
||||
|
||||
Reference in New Issue
Block a user