Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
777 changes: 771 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ edition = "2021"
[workspace]
members = [
"crate-template",
"crates/primitives",
"crates/net/p2p",
"crates/net/rpc",
"crates/net/rpc-api",
"crates/net/rpc-types",
"crates/primitives",
"crates/stages"
]

Expand Down
18 changes: 18 additions & 0 deletions crates/net/rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "reth-rpc-api"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/foundry-rs/reth"
readme = "README.md"
description = """
Reth RPC interfaces
"""

[dependencies]
# reth
reth-primitives = { path = "../../primitives" }
reth-rpc-types = { path = "../rpc-types" }

# misc
jsonrpsee = { version = "0.15", features = ["server", "macros"] }
27 changes: 27 additions & 0 deletions crates/net/rpc-api/src/debug.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
use reth_primitives::{BlockId, Bytes, H256};
use reth_rpc_types::RichBlock;

/// Debug rpc interface.
#[rpc(server)]
pub trait DebugApi {
/// Returns an RLP-encoded header.
#[method(name = "debug_getRawHeader")]
async fn raw_header(&self, block_id: BlockId) -> Result<Bytes>;

/// Returns an RLP-encoded block.
#[method(name = "debug_getRawBlock")]
async fn raw_block(&self, block_id: BlockId) -> Result<Bytes>;

/// Returns a EIP-2718 binary-encoded transaction.
#[method(name = "debug_getRawTransaction")]
async fn raw_transaction(&self, hash: H256) -> Result<Bytes>;

/// Returns an array of EIP-2718 binary-encoded receipts.
#[method(name = "debug_getRawReceipts")]
async fn raw_receipts(&self, block_id: BlockId) -> Result<Vec<Bytes>>;

/// Returns an array of recent bad blocks that the client has seen on the network.
#[method(name = "debug_getBadBlocks")]
async fn bad_blocks(&self) -> Result<Vec<RichBlock>>;
}
32 changes: 32 additions & 0 deletions crates/net/rpc-api/src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
use reth_primitives::H64;
use reth_rpc_types::engine::{
ExecutionPayload, ForkchoiceState, ForkchoiceUpdated, PayloadAttributes, PayloadStatus,
TransitionConfiguration,
};

#[rpc(server)]
pub trait EngineApi {
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_newpayloadv1>
#[method(name = "engine_newPayloadV1")]
async fn new_payload(&self, payload: ExecutionPayload) -> Result<PayloadStatus>;

/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_forkchoiceUpdatedV1>
#[method(name = "engine_forkchoiceUpdatedV1")]
async fn fork_choice_updated(
&self,
fork_choice_state: ForkchoiceState,
payload_attributes: Option<PayloadAttributes>,
) -> Result<ForkchoiceUpdated>;

/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_getPayloadV1>
#[method(name = "engine_getPayloadV1")]
async fn get_payload(&self, payload_id: H64) -> Result<ExecutionPayload>;

/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_exchangeTransitionConfigurationV1>
#[method(name = "engine_exchangeTransitionConfigurationV1")]
async fn exchange_transition_configuration(
&self,
transition_configuration: TransitionConfiguration,
) -> Result<TransitionConfiguration>;
}
225 changes: 225 additions & 0 deletions crates/net/rpc-api/src/eth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
use jsonrpsee::{
core::{RpcResult as Result, __reexports::serde_json},
proc_macros::rpc,
};
use reth_primitives::{
transaction::eip2930::AccessListWithGasUsed, Address, BlockId, BlockNumber, Bytes, H256, H64,
U256, U64,
};
use reth_rpc_types::{
CallRequest, EIP1186AccountProofResponse, FeeHistory, Index, RichBlock, SyncStatus,
Transaction, TransactionReceipt, TransactionRequest, Work,
};

/// Eth rpc interface.
#[rpc(server)]
#[async_trait]
pub trait EthApi {
/// Returns protocol version encoded as a string (quotes are necessary).
#[method(name = "eth_protocolVersion")]
fn protocol_version(&self) -> Result<u64>;

/// Returns an object with data about the sync status or false. (wtf?)
#[method(name = "eth_syncing")]
fn syncing(&self) -> Result<SyncStatus>;

/// Returns block author.
#[method(name = "eth_coinbase")]
fn author(&self) -> Result<Address>;

/// Returns accounts list.
#[method(name = "eth_accounts")]
fn accounts(&self) -> Result<Vec<Address>>;

/// Returns highest block number.
#[method(name = "eth_blockNumber")]
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>>;

/// Returns block with given hash.
#[method(name = "eth_getBlockByHash")]
async fn block_by_hash(&self, hash: H256, full: bool) -> Result<Option<RichBlock>>;

/// Returns block with given number.
#[method(name = "eth_getBlockByNumber")]
async fn block_by_number(&self, number: BlockNumber, full: bool) -> Result<Option<RichBlock>>;

/// 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>>;

/// 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>>;

/// 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>;

/// 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>;

/// 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>>;

/// Returns an uncles at given block and index.
#[method(name = "eth_getUncleByBlockNumberAndIndex")]
fn uncle_by_block_number_and_index(
&self,
number: BlockNumber,
index: Index,
) -> Result<Option<RichBlock>>;

/// Get transaction by its hash.
#[method(name = "eth_getTransactionByHash")]
async fn transaction_by_hash(&self, hash: H256) -> Result<Option<Transaction>>;

/// Returns transaction at given block hash and index.
#[method(name = "eth_getTransactionByBlockHashAndIndex")]
async fn transaction_by_block_hash_and_index(
&self,
hash: H256,
index: Index,
) -> Result<Option<Transaction>>;

/// Returns transaction by given block number and index.
#[method(name = "eth_getTransactionByBlockNumberAndIndex")]
async fn transaction_by_block_number_and_index(
&self,
number: BlockNumber,
index: Index,
) -> Result<Option<Transaction>>;

/// Returns transaction receipt by transaction hash.
#[method(name = "eth_getTransactionReceipt")]
async fn transaction_receipt(&self, hash: H256) -> Result<Option<TransactionReceipt>>;

/// Returns balance of the given account.
#[method(name = "eth_getBalance")]
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(
&self,
address: Address,
index: U256,
block_number: Option<BlockId>,
) -> Result<H256>;

/// 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>;

/// 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>;

/// Call contract, returning the output data.
#[method(name = "eth_call")]
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.
#[method(name = "eth_estimateGas")]
async fn estimate_gas(
&self,
request: CallRequest,
block_number: Option<BlockId>,
) -> Result<U256>;

/// Returns current gas_price.
#[method(name = "eth_gasPrice")]
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(
&self,
block_count: U256,
newest_block: BlockNumber,
reward_percentiles: Option<Vec<f64>>,
) -> Result<FeeHistory>;

/// 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>;

/// Returns true if client is actively mining new blocks.
#[method(name = "eth_mining")]
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>;

/// 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>;

/// Used for submitting mining hashrate.
#[method(name = "eth_submitHashrate")]
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>;

/// Sends transaction; will block waiting for signer to return the
/// transaction hash.
#[method(name = "eth_sendTransaction")]
async fn send_transaction(&self, request: TransactionRequest) -> Result<H256>;

/// Sends signed transaction, returning its hash.
#[method(name = "eth_sendRawTransaction")]
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>;
}
35 changes: 35 additions & 0 deletions crates/net/rpc-api/src/eth_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
use reth_primitives::U256;
use reth_rpc_types::{Filter, FilterChanges, Index, Log};

/// Rpc Interface for poll-based ethereum filter API.
#[rpc(server)]
pub trait EthFilterApi {
/// Creates anew filter and returns its id.
#[method(name = "eth_newFilter")]
fn new_filter(&self, filter: Filter) -> Result<U256>;

/// Creates a new block filter and returns its id.
#[method(name = "eth_newBlockFilter")]
fn new_block_filter(&self) -> Result<U256>;

/// Creates a pending transaction filter and returns its id.
#[method(name = "eth_newPendingTransactionFilter")]
fn new_pending_transaction_filter(&self) -> Result<U256>;

/// Returns all filter changes since last poll.
#[method(name = "eth_getFilterChanges")]
async fn filter_changes(&self, index: Index) -> Result<FilterChanges>;

/// Returns all logs matching given filter (in a range 'from' - 'to').
#[method(name = "eth_getFilterLogs")]
async fn filter_logs(&self, index: Index) -> Result<Vec<Log>>;

/// Uninstalls filter.
#[method(name = "eth_uninstallFilter")]
fn uninstall_filter(&self, index: Index) -> Result<bool>;

/// Returns logs matching given filter object.
#[method(name = "eth_getLogs")]
async fn logs(&self, filter: Filter) -> Result<Vec<Log>>;
}
14 changes: 14 additions & 0 deletions crates/net/rpc-api/src/eth_pubsub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use jsonrpsee::proc_macros::rpc;
use reth_rpc_types::pubsub::{Kind, Params};

/// Ethereum pub-sub rpc interface.
#[rpc(server)]
pub trait EthPubSubApi {
/// Create an ethereum subscription.
#[subscription(
name = "eth_subscribe" => "eth_subscription",
unsubscribe = "eth_unsubscribe",
item = pubsub::Result
)]
fn subscribe(&self, kind: Kind, params: Option<Params>);
}
25 changes: 25 additions & 0 deletions crates/net/rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![warn(missing_debug_implementations, missing_docs, unreachable_pub, unused_crate_dependencies)]
#![deny(unused_must_use, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]

//! Reth RPC interface definitions
//!
//! Provides all RPC interfaces.

mod debug;
mod engine;
mod eth;
mod eth_filter;
mod eth_pubsub;
mod net;
mod trace;
mod web3;

pub use self::{
debug::DebugApiServer, engine::EngineApiServer, eth::EthApiServer,
eth_filter::EthFilterApiServer, eth_pubsub::EthPubSubApiServer, net::NetApiServer,
web3::Web3ApiServer,
};
Loading