feat(rpc/otterscan): change BlockId to u64 in has_code (#9469)

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Delweng
2024-07-12 16:45:34 +08:00
committed by GitHub
parent 9aa44e1a90
commit b31167ba6a
3 changed files with 8 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
use reth_primitives::{Address, BlockId, Bytes, TxHash, B256};
use reth_primitives::{Address, Bytes, TxHash, B256};
use reth_rpc_types::{
trace::otterscan::{
BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
@@ -24,7 +24,7 @@ pub trait Otterscan {
/// Check if a certain address contains a deployed code.
#[method(name = "hasCode")]
async fn has_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<bool>;
async fn has_code(&self, address: Address, block_number: Option<u64>) -> RpcResult<bool>;
/// Very simple API versioning scheme. Every time we add a new capability, the number is
/// incremented. This allows for Otterscan to check if the node contains all API it

View File

@@ -304,6 +304,7 @@ where
OtterscanClient::get_header_by_number(client, block_number).await.unwrap();
OtterscanClient::has_code(client, address, None).await.unwrap();
OtterscanClient::has_code(client, address, Some(block_number)).await.unwrap();
OtterscanClient::get_api_level(client).await.unwrap();

View File

@@ -1,7 +1,7 @@
use alloy_primitives::Bytes;
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256};
use reth_primitives::{Address, BlockNumberOrTag, TxHash, B256};
use reth_rpc_api::{EthApiServer, OtterscanServer};
use reth_rpc_eth_api::helpers::TraceExt;
use reth_rpc_eth_types::EthApiError;
@@ -49,8 +49,8 @@ where
}
/// Handler for `ots_hasCode`
async fn has_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<bool> {
self.eth.get_code(address, block_number).await.map(|code| !code.is_empty())
async fn has_code(&self, address: Address, block_number: Option<u64>) -> RpcResult<bool> {
self.eth.get_code(address, block_number.map(Into::into)).await.map(|code| !code.is_empty())
}
/// Handler for `ots_getApiLevel`
@@ -152,9 +152,8 @@ where
page_size: usize,
) -> RpcResult<OtsBlockTransactions> {
// retrieve full block and its receipts
let block_number = BlockNumberOrTag::Number(block_number);
let block = self.eth.block_by_number(block_number, true);
let receipts = self.eth.block_receipts(BlockId::Number(block_number));
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)?;
let mut block = block.ok_or_else(|| internal_rpc_err("block not found"))?;