feat: add missing eth_ functions

This commit is contained in:
Matthias Seitz
2022-10-03 15:06:58 +02:00
parent 7c35e68f8e
commit eeda03a3f3
3 changed files with 93 additions and 12 deletions

31
Cargo.lock generated
View File

@ -1143,6 +1143,37 @@ dependencies = [
"ethers-core", "ethers-core",
] ]
[[package]]
name = "reth-rpc"
version = "0.1.0"
dependencies = [
"reth-primitives",
"reth-rpc-api",
"reth-rpc-types",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "reth-rpc-api"
version = "0.1.0"
dependencies = [
"jsonrpsee",
"reth-primitives",
"reth-rpc-types",
]
[[package]]
name = "reth-rpc-types"
version = "0.1.0"
dependencies = [
"fastrlp",
"reth-primitives",
"serde",
"serde_json",
]
[[package]] [[package]]
name = "reth-stages" name = "reth-stages"
version = "0.1.0" version = "0.1.0"

View File

@ -11,7 +11,6 @@ members = [
"crates/net/rpc-api", "crates/net/rpc-api",
"crates/net/rpc-types", "crates/net/rpc-types",
"crates/primitives", "crates/primitives",
"crates/net/p2p",
"crates/stages" "crates/stages"
] ]

View File

@ -1,8 +1,14 @@
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc}; use jsonrpsee::{
use reth_primitives::{Address, BlockNumber, Bytes, H256, H64, U256, U64}; core::{RpcResult as Result, __reexports::serde_json},
proc_macros::rpc,
};
use reth_primitives::{
transaction, transaction::eip2930::AccessListWithGasUsed, Address, BlockId, BlockNumber, Bytes,
H256, H64, U256, U64,
};
use reth_rpc_types::{ use reth_rpc_types::{
CallRequest, FeeHistory, Index, RichBlock, SyncStatus, Transaction, TransactionReceipt, CallRequest, EIP1186AccountProofResponse, FeeHistory, Index, RichBlock, SyncStatus,
TransactionRequest, Work, Transaction, TransactionReceipt, TransactionRequest, Work,
}; };
/// Eth rpc interface. /// Eth rpc interface.
@ -97,7 +103,7 @@ 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, number: Option<BlockNumber>) -> Result<U256>; 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")]
@ -105,25 +111,46 @@ pub trait EthApi {
&self, &self,
address: Address, address: Address,
index: U256, index: U256,
number: Option<BlockNumber>, block_number: Option<BlockId>,
) -> Result<H256>; ) -> Result<H256>;
/// 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, number: Option<BlockNumber>) -> Result<U256>; 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, number: Option<BlockNumber>) -> Result<Bytes>; 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, number: Option<BlockNumber>) -> Result<Bytes>; 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
/// sender account and the precompiles.
///
/// It returns list of addresses and storage keys used by the transaction, plus the gas
/// consumed when the access list is added. That is, it gives you the list of addresses and
/// storage keys that will be used by that transaction, plus the gas consumed if the access
/// list is included. Like eth_estimateGas, this is an estimation; the list could change
/// when the transaction is actually mined. Adding an accessList to your transaction does
/// not necessary result in lower gas usage compared to a transaction without an access
/// list.
#[method(name = "eth_createAccessList")]
async fn create_access_list(
&self,
request: CallRequest,
block_number: Option<BlockId>,
) -> Result<AccessListWithGasUsed>;
/// Estimate gas needed for execution of given contract. /// Estimate gas needed for execution of given contract.
#[method(name = "eth_estimateGas")] #[method(name = "eth_estimateGas")]
async fn estimate_gas(&self, request: CallRequest, number: Option<BlockNumber>) async fn estimate_gas(
-> Result<U256>; &self,
request: CallRequest,
block_number: Option<BlockId>,
) -> Result<U256>;
/// Returns current gas_price. /// Returns current gas_price.
#[method(name = "eth_gasPrice")] #[method(name = "eth_gasPrice")]
@ -171,4 +198,28 @@ pub trait EthApi {
/// Sends signed transaction, returning its hash. /// Sends signed transaction, returning its hash.
#[method(name = "eth_sendRawTransaction")] #[method(name = "eth_sendRawTransaction")]
async fn send_raw_transaction(&self, bytes: Bytes) -> Result<H256>; async fn send_raw_transaction(&self, bytes: Bytes) -> Result<H256>;
/// Returns an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n"
/// + len(message) + message))).
#[method(name = "eth_sign")]
async fn sign(&self, address: Address, message: Bytes) -> Result<Bytes>;
/// Signs a transaction that can be submitted to the network at a later time using with
/// `eth_sendRawTransaction.`
#[method(name = "eth_signTransaction")]
async fn sign_transaction(&self, transaction: CallRequest) -> Result<Bytes>;
/// Signs data via [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md).
#[method(name = "eth_signTypedData")]
async fn sign_typed_data(&self, address: Address, data: serde_json::Value) -> Result<Bytes>;
/// Returns the account and storage values of the specified account including the Merkle-proof.
/// This call can be used to verify that the data you are pulling from is not tampered with.
#[method(name = "eth_getProof")]
async fn get_proof(
&self,
address: Address,
keys: Vec<H256>,
block_number: Option<BlockId>,
) -> Result<EIP1186AccountProofResponse>;
} }