mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 00:28:20 -05:00
feat(rpc/ots): add rpc erigon_getHeaderByNumber (#9300)
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
@@ -5,13 +5,23 @@ use reth_rpc_types::{
|
||||
BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
|
||||
TransactionsWithReceipts,
|
||||
},
|
||||
Transaction,
|
||||
Header, Transaction,
|
||||
};
|
||||
|
||||
/// Otterscan rpc interface.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "ots"))]
|
||||
#[cfg_attr(feature = "client", rpc(server, client, namespace = "ots"))]
|
||||
pub trait Otterscan {
|
||||
/// Get the block header by block number, required by otterscan.
|
||||
/// Otterscan currently requires this endpoint, used as:
|
||||
///
|
||||
/// 1. check if the node is Erigon or not
|
||||
/// 2. get block header instead of the full block
|
||||
///
|
||||
/// Ref: <https://github.com/otterscan/otterscan/blob/071d8c55202badf01804f6f8d53ef9311d4a9e47/src/useProvider.ts#L71>
|
||||
#[method(name = "getHeaderByNumber", aliases = ["erigon_getHeaderByNumber"])]
|
||||
async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<Header>>;
|
||||
|
||||
/// 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>;
|
||||
|
||||
@@ -301,6 +301,8 @@ where
|
||||
let nonce = 1;
|
||||
let block_hash = B256::default();
|
||||
|
||||
OtterscanClient::get_header_by_number(client, 1).await.unwrap();
|
||||
|
||||
OtterscanClient::has_code(client, address, None).await.unwrap();
|
||||
|
||||
OtterscanClient::get_api_level(client).await.unwrap();
|
||||
|
||||
@@ -10,7 +10,7 @@ use reth_rpc_types::{
|
||||
BlockDetails, ContractCreator, InternalOperation, OperationType, OtsBlockTransactions,
|
||||
OtsReceipt, OtsTransactionReceipt, TraceEntry, TransactionsWithReceipts,
|
||||
},
|
||||
BlockTransactions, Transaction,
|
||||
BlockTransactions, Header, Transaction,
|
||||
};
|
||||
use revm_inspectors::transfer::{TransferInspector, TransferKind};
|
||||
use revm_primitives::ExecutionResult;
|
||||
@@ -35,6 +35,11 @@ impl<Eth> OtterscanServer for OtterscanApi<Eth>
|
||||
where
|
||||
Eth: EthApiServer + TraceExt + 'static,
|
||||
{
|
||||
/// Handler for `{ots,erigon}_getHeaderByNumber`
|
||||
async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<Header>> {
|
||||
self.eth.header_by_number(BlockNumberOrTag::Number(block_number)).await
|
||||
}
|
||||
|
||||
/// 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())
|
||||
|
||||
Reference in New Issue
Block a user