reth_rpc_api/
otterscan.rs

1use alloy_eips::BlockId;
2use alloy_json_rpc::RpcObject;
3use alloy_primitives::{Address, Bytes, TxHash, B256};
4use alloy_rpc_types_trace::otterscan::{
5    BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
6    TransactionsWithReceipts,
7};
8use jsonrpsee::{core::RpcResult, proc_macros::rpc};
9
10/// Otterscan rpc interface.
11#[cfg_attr(not(feature = "client"), rpc(server, namespace = "ots"))]
12#[cfg_attr(feature = "client", rpc(server, client, namespace = "ots"))]
13pub trait Otterscan<T: RpcObject, H: RpcObject> {
14    /// Get the block header by block number, required by otterscan.
15    /// Otterscan currently requires this endpoint, used as:
16    ///
17    /// 1. check if the node is Erigon or not
18    /// 2. get block header instead of the full block
19    ///
20    /// Ref: <https://github.com/otterscan/otterscan/blob/071d8c55202badf01804f6f8d53ef9311d4a9e47/src/useProvider.ts#L71>
21    #[method(name = "getHeaderByNumber", aliases = ["erigon_getHeaderByNumber"])]
22    async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<H>>;
23
24    /// Check if a certain address contains a deployed code.
25    #[method(name = "hasCode")]
26    async fn has_code(&self, address: Address, block_id: Option<BlockId>) -> RpcResult<bool>;
27
28    /// Very simple API versioning scheme. Every time we add a new capability, the number is
29    /// incremented. This allows for Otterscan to check if the node contains all API it
30    /// needs.
31    #[method(name = "getApiLevel")]
32    async fn get_api_level(&self) -> RpcResult<u64>;
33
34    /// Return the internal ETH transfers inside a transaction.
35    #[method(name = "getInternalOperations")]
36    async fn get_internal_operations(&self, tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>>;
37
38    /// Given a transaction hash, returns its raw revert reason.
39    #[method(name = "getTransactionError")]
40    async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<Option<Bytes>>;
41
42    /// Extract all variations of calls, contract creation and self-destructs and returns a call
43    /// tree.
44    #[method(name = "traceTransaction")]
45    async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<Option<Vec<TraceEntry>>>;
46
47    /// Tailor-made and expanded version of eth_getBlockByNumber for block details page in
48    /// Otterscan.
49    #[method(name = "getBlockDetails")]
50    async fn get_block_details(&self, block_number: u64) -> RpcResult<BlockDetails<H>>;
51
52    /// Tailor-made and expanded version of eth_getBlockByHash for block details page in Otterscan.
53    #[method(name = "getBlockDetailsByHash")]
54    async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult<BlockDetails<H>>;
55
56    /// Get paginated transactions for a certain block. Also remove some verbose fields like logs.
57    #[method(name = "getBlockTransactions")]
58    async fn get_block_transactions(
59        &self,
60        block_number: u64,
61        page_number: usize,
62        page_size: usize,
63    ) -> RpcResult<OtsBlockTransactions<T, H>>;
64
65    /// Gets paginated inbound/outbound transaction calls for a certain address.
66    #[method(name = "searchTransactionsBefore")]
67    async fn search_transactions_before(
68        &self,
69        address: Address,
70        block_number: u64,
71        page_size: usize,
72    ) -> RpcResult<TransactionsWithReceipts>;
73
74    /// Gets paginated inbound/outbound transaction calls for a certain address.
75    #[method(name = "searchTransactionsAfter")]
76    async fn search_transactions_after(
77        &self,
78        address: Address,
79        block_number: u64,
80        page_size: usize,
81    ) -> RpcResult<TransactionsWithReceipts>;
82
83    /// Gets the transaction hash for a certain sender address, given its nonce.
84    #[method(name = "getTransactionBySenderAndNonce")]
85    async fn get_transaction_by_sender_and_nonce(
86        &self,
87        sender: Address,
88        nonce: u64,
89    ) -> RpcResult<Option<TxHash>>;
90
91    /// Gets the transaction hash and the address who created a contract.
92    #[method(name = "getContractCreator")]
93    async fn get_contract_creator(&self, address: Address) -> RpcResult<Option<ContractCreator>>;
94}