mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add traces to rpc (#1904)
This commit is contained in:
@ -23,6 +23,7 @@ use reth_rpc_types::{
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use serde_json::Value;
|
||||
use std::collections::BTreeMap;
|
||||
use tracing::trace;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Client, Pool, Network> EthApiServer for EthApi<Client, Pool, Network>
|
||||
@ -34,11 +35,13 @@ where
|
||||
{
|
||||
/// Handler for: `eth_protocolVersion`
|
||||
async fn protocol_version(&self) -> Result<U64> {
|
||||
trace!(target: "rpc::eth", "Serving eth_protocolVersion");
|
||||
EthApiSpec::protocol_version(self).await.to_rpc_result()
|
||||
}
|
||||
|
||||
/// Handler for: `eth_syncing`
|
||||
fn syncing(&self) -> Result<SyncStatus> {
|
||||
trace!(target: "rpc::eth", "Serving eth_syncing");
|
||||
EthApiSpec::sync_status(self).to_rpc_result()
|
||||
}
|
||||
|
||||
@ -49,11 +52,13 @@ where
|
||||
|
||||
/// Handler for: `eth_accounts`
|
||||
async fn accounts(&self) -> Result<Vec<Address>> {
|
||||
trace!(target: "rpc::eth", "Serving eth_accounts");
|
||||
Ok(EthApiSpec::accounts(self))
|
||||
}
|
||||
|
||||
/// Handler for: `eth_blockNumber`
|
||||
fn block_number(&self) -> Result<U256> {
|
||||
trace!(target: "rpc::eth", "Serving eth_blockNumber");
|
||||
Ok(U256::from(
|
||||
EthApiSpec::chain_info(self).with_message("failed to read chain info")?.best_number,
|
||||
))
|
||||
@ -61,11 +66,13 @@ where
|
||||
|
||||
/// Handler for: `eth_chainId`
|
||||
async fn chain_id(&self) -> Result<Option<U64>> {
|
||||
trace!(target: "rpc::eth", "Serving eth_chainId");
|
||||
Ok(Some(EthApiSpec::chain_id(self)))
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getBlockByHash`
|
||||
async fn block_by_hash(&self, hash: H256, full: bool) -> Result<Option<RichBlock>> {
|
||||
trace!(target: "rpc::eth", ?hash, ?full, "Serving eth_getBlockByHash");
|
||||
Ok(EthApi::block(self, hash, full).await?)
|
||||
}
|
||||
|
||||
@ -75,11 +82,13 @@ where
|
||||
number: BlockNumberOrTag,
|
||||
full: bool,
|
||||
) -> Result<Option<RichBlock>> {
|
||||
trace!(target: "rpc::eth", ?number, ?full, "Serving eth_getBlockByNumber");
|
||||
Ok(EthApi::block(self, number, full).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getBlockTransactionCountByHash`
|
||||
async fn block_transaction_count_by_hash(&self, hash: H256) -> Result<Option<U256>> {
|
||||
trace!(target: "rpc::eth", ?hash, "Serving eth_getBlockTransactionCountByHash");
|
||||
Ok(EthApi::block_transaction_count(self, hash).await?.map(U256::from))
|
||||
}
|
||||
|
||||
@ -88,16 +97,19 @@ where
|
||||
&self,
|
||||
number: BlockNumberOrTag,
|
||||
) -> Result<Option<U256>> {
|
||||
trace!(target: "rpc::eth", ?number, "Serving eth_getBlockTransactionCountByNumber");
|
||||
Ok(EthApi::block_transaction_count(self, number).await?.map(U256::from))
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getUncleCountByBlockHash`
|
||||
async fn block_uncles_count_by_hash(&self, hash: H256) -> Result<Option<U256>> {
|
||||
trace!(target: "rpc::eth", ?hash, "Serving eth_getUncleCountByBlockHash");
|
||||
Ok(EthApi::ommers(self, hash)?.map(|ommers| U256::from(ommers.len())))
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getUncleCountByBlockNumber`
|
||||
async fn block_uncles_count_by_number(&self, number: BlockNumberOrTag) -> Result<Option<U256>> {
|
||||
trace!(target: "rpc::eth", ?number, "Serving eth_getUncleCountByBlockNumber");
|
||||
Ok(EthApi::ommers(self, number)?.map(|ommers| U256::from(ommers.len())))
|
||||
}
|
||||
|
||||
@ -107,6 +119,7 @@ where
|
||||
hash: H256,
|
||||
index: Index,
|
||||
) -> Result<Option<RichBlock>> {
|
||||
trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getUncleByBlockHashAndIndex");
|
||||
Ok(EthApi::ommer_by_block_and_index(self, hash, index).await?)
|
||||
}
|
||||
|
||||
@ -116,11 +129,13 @@ where
|
||||
number: BlockNumberOrTag,
|
||||
index: Index,
|
||||
) -> Result<Option<RichBlock>> {
|
||||
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex");
|
||||
Ok(EthApi::ommer_by_block_and_index(self, number, index).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getTransactionByHash`
|
||||
async fn transaction_by_hash(&self, hash: H256) -> Result<Option<reth_rpc_types::Transaction>> {
|
||||
trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionByHash");
|
||||
Ok(EthTransactions::transaction_by_hash(self, hash).await?.map(Into::into))
|
||||
}
|
||||
|
||||
@ -130,6 +145,7 @@ where
|
||||
hash: H256,
|
||||
index: Index,
|
||||
) -> Result<Option<reth_rpc_types::Transaction>> {
|
||||
trace!(target: "rpc::eth", ?hash, ?index, "Serving eth_getTransactionByBlockHashAndIndex");
|
||||
Ok(EthApi::transaction_by_block_and_tx_index(self, hash, index).await?)
|
||||
}
|
||||
|
||||
@ -139,6 +155,7 @@ where
|
||||
number: BlockNumberOrTag,
|
||||
index: Index,
|
||||
) -> Result<Option<reth_rpc_types::Transaction>> {
|
||||
trace!(target: "rpc::eth", ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex");
|
||||
Ok(EthApi::transaction_by_block_and_tx_index(self, number, index).await?)
|
||||
}
|
||||
|
||||
@ -149,6 +166,7 @@ where
|
||||
|
||||
/// Handler for: `eth_getBalance`
|
||||
async fn balance(&self, address: Address, block_number: Option<BlockId>) -> Result<U256> {
|
||||
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getBalance");
|
||||
Ok(EthApi::balance(self, address, block_number)?)
|
||||
}
|
||||
|
||||
@ -159,6 +177,7 @@ where
|
||||
index: U256,
|
||||
block_number: Option<BlockId>,
|
||||
) -> Result<H256> {
|
||||
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getStorageAt");
|
||||
Ok(EthApi::storage_at(self, address, index, block_number)?)
|
||||
}
|
||||
|
||||
@ -168,11 +187,13 @@ where
|
||||
address: Address,
|
||||
block_number: Option<BlockId>,
|
||||
) -> Result<U256> {
|
||||
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getTransactionCount");
|
||||
Ok(EthApi::get_transaction_count(self, address, block_number)?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_getCode`
|
||||
async fn get_code(&self, address: Address, block_number: Option<BlockId>) -> Result<Bytes> {
|
||||
trace!(target: "rpc::eth", ?address, ?block_number, "Serving eth_getCode");
|
||||
Ok(EthApi::get_code(self, address, block_number)?)
|
||||
}
|
||||
|
||||
@ -183,6 +204,7 @@ where
|
||||
block_number: Option<BlockId>,
|
||||
state_overrides: Option<StateOverride>,
|
||||
) -> Result<Bytes> {
|
||||
trace!(target: "rpc::eth", ?request, ?block_number, ?state_overrides, "Serving eth_call");
|
||||
let (res, _env) = self
|
||||
.execute_call_at(
|
||||
request,
|
||||
@ -200,6 +222,7 @@ where
|
||||
mut request: CallRequest,
|
||||
block_number: Option<BlockId>,
|
||||
) -> Result<AccessListWithGasUsed> {
|
||||
trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_createAccessList");
|
||||
let block_id = block_number.unwrap_or(BlockId::Number(BlockNumberOrTag::Pending));
|
||||
let access_list = self.create_access_list_at(request.clone(), block_number).await?;
|
||||
request.access_list = Some(access_list.clone());
|
||||
@ -213,6 +236,7 @@ where
|
||||
request: CallRequest,
|
||||
block_number: Option<BlockId>,
|
||||
) -> Result<U256> {
|
||||
trace!(target: "rpc::eth", ?request, ?block_number, "Serving eth_estimateGas");
|
||||
Ok(EthApi::estimate_gas_at(
|
||||
self,
|
||||
request,
|
||||
@ -241,6 +265,7 @@ where
|
||||
newest_block: BlockId,
|
||||
_reward_percentiles: Option<Vec<f64>>,
|
||||
) -> Result<FeeHistory> {
|
||||
trace!(target: "rpc::eth", ?block_count, ?newest_block, ?_reward_percentiles, "Serving eth_feeHistory");
|
||||
let block_count = block_count.as_u64();
|
||||
|
||||
if block_count == 0 {
|
||||
@ -368,11 +393,13 @@ where
|
||||
|
||||
/// Handler for: `eth_sendRawTransaction`
|
||||
async fn send_raw_transaction(&self, tx: Bytes) -> Result<H256> {
|
||||
trace!(target: "rpc::eth", ?tx, "Serving eth_sendRawTransaction");
|
||||
Ok(EthApi::send_raw_transaction(self, tx).await?)
|
||||
}
|
||||
|
||||
/// Handler for: `eth_sign`
|
||||
async fn sign(&self, address: Address, message: Bytes) -> Result<Bytes> {
|
||||
trace!(target: "rpc::eth", ?address, ?message, "Serving eth_sign");
|
||||
Ok(EthApi::sign(self, address, message).await?)
|
||||
}
|
||||
|
||||
@ -383,6 +410,7 @@ where
|
||||
|
||||
/// Handler for: `eth_signTypedData`
|
||||
async fn sign_typed_data(&self, address: Address, data: Value) -> Result<Bytes> {
|
||||
trace!(target: "rpc::eth", ?address, ?data, "Serving eth_signTypedData");
|
||||
Ok(EthApi::sign_typed_data(self, data, address).await?)
|
||||
}
|
||||
|
||||
@ -393,6 +421,7 @@ where
|
||||
keys: Vec<H256>,
|
||||
block_number: Option<BlockId>,
|
||||
) -> Result<EIP1186AccountProofResponse> {
|
||||
trace!(target: "rpc::eth", ?address, ?keys, ?block_number, "Serving eth_getProof");
|
||||
let res = EthApi::get_proof(self, address, keys, block_number);
|
||||
|
||||
Ok(res.map_err(|e| match e {
|
||||
|
||||
Reference in New Issue
Block a user