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/ots): add rpc erigon_getHeaderByNumber #9300

Merged
merged 2 commits into from
Jul 4, 2024
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
12 changes: 11 additions & 1 deletion crates/rpc/rpc-api/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
2 changes: 2 additions & 0 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down
Loading