Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc/otterscan): set total_fees in ots_getBlockDetails #9477

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Changes from 2 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
34 changes: 28 additions & 6 deletions crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_primitives::Bytes;
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_primitives::{Address, BlockNumberOrTag, TxHash, B256};
use reth_primitives::{Address, BlockNumberOrTag, TxHash, B256, U256};
use reth_rpc_api::{EthApiServer, OtterscanServer};
use reth_rpc_eth_api::helpers::TraceExt;
use reth_rpc_eth_types::EthApiError;
Expand All @@ -14,7 +14,7 @@ use reth_rpc_types::{
},
parity::{Action, CreateAction, CreateOutput, TraceOutput},
},
BlockTransactions, Header,
AnyTransactionReceipt, BlockTransactions, Header, RichBlock,
};
use revm_inspectors::{
tracing::{types::CallTraceNode, TracingInspectorConfig},
Expand All @@ -36,6 +36,24 @@ impl<Eth> OtterscanApi<Eth> {
pub const fn new(eth: Eth) -> Self {
Self { eth }
}

/// Constructs a `BlockDetails` from a block and its receipts.
fn into_block_details(
&self,
block: Option<RichBlock>,
receipts: Option<Vec<AnyTransactionReceipt>>,
) -> RpcResult<Option<BlockDetails>> {
let block = block.ok_or_else(|| internal_rpc_err("block not found"))?;
let receipts = receipts.ok_or_else(|| internal_rpc_err("receipts not found"))?;

// blob fee is burnt, so we don't need to calculate it
let total_fees = receipts
.iter()
.map(|receipt| receipt.gas_used.saturating_mul(receipt.effective_gas_price))
.sum::<u128>();

Ok(Some(BlockDetails::new(block, Default::default(), U256::from(total_fees))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the lint err is blocked on alloy bump, which should be coming soon

}
}

#[async_trait]
Expand Down Expand Up @@ -134,14 +152,18 @@ where

/// Handler for `ots_getBlockDetails`
async fn get_block_details(&self, block_number: u64) -> RpcResult<Option<BlockDetails>> {
let block = self.eth.block_by_number(BlockNumberOrTag::Number(block_number), true).await?;
Ok(block.map(Into::into))
let block = self.eth.block_by_number(block_number.into(), true);
let receipts = self.eth.block_receipts(block_number.into());
let (block, receipts) = futures::try_join!(block, receipts)?;
self.into_block_details(block, receipts)
}

/// Handler for `getBlockDetailsByHash`
async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult<Option<BlockDetails>> {
let block = self.eth.block_by_hash(block_hash, true).await?;
Ok(block.map(Into::into))
let block = self.eth.block_by_hash(block_hash.into(), true);
let receipts = self.eth.block_receipts(block_hash.into());
let (block, receipts) = futures::try_join!(block, receipts)?;
self.into_block_details(block, receipts)
}

/// Handler for `getBlockTransactions`
Expand Down
Loading