feat: EthApi traits abstraction (#13170)

This commit is contained in:
Arsenii Kulikov
2024-12-06 16:30:50 +04:00
committed by GitHub
parent ab87f22cab
commit cf2a6a1ee8
53 changed files with 851 additions and 511 deletions

View File

@ -1,7 +1,6 @@
use alloy_eips::BlockId;
use alloy_json_rpc::RpcObject;
use alloy_primitives::{Address, Bytes, TxHash, B256};
use alloy_rpc_types_eth::Header;
use alloy_rpc_types_trace::otterscan::{
BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry,
TransactionsWithReceipts,
@ -11,7 +10,7 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc};
/// Otterscan rpc interface.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "ots"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "ots"))]
pub trait Otterscan<T: RpcObject> {
pub trait Otterscan<T: RpcObject, H: RpcObject> {
/// Get the block header by block number, required by otterscan.
/// Otterscan currently requires this endpoint, used as:
///
@ -20,7 +19,7 @@ pub trait Otterscan<T: RpcObject> {
///
/// 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>>;
async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<H>>;
/// Check if a certain address contains a deployed code.
#[method(name = "hasCode")]
@ -48,11 +47,11 @@ pub trait Otterscan<T: RpcObject> {
/// Tailor-made and expanded version of eth_getBlockByNumber for block details page in
/// Otterscan.
#[method(name = "getBlockDetails")]
async fn get_block_details(&self, block_number: u64) -> RpcResult<BlockDetails>;
async fn get_block_details(&self, block_number: u64) -> RpcResult<BlockDetails<H>>;
/// Tailor-made and expanded version of eth_getBlockByHash for block details page in Otterscan.
#[method(name = "getBlockDetailsByHash")]
async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult<BlockDetails>;
async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult<BlockDetails<H>>;
/// Get paginated transactions for a certain block. Also remove some verbose fields like logs.
#[method(name = "getBlockTransactions")]
@ -61,7 +60,7 @@ pub trait Otterscan<T: RpcObject> {
block_number: u64,
page_number: usize,
page_size: usize,
) -> RpcResult<OtsBlockTransactions<T>>;
) -> RpcResult<OtsBlockTransactions<T, H>>;
/// Gets paginated inbound/outbound transaction calls for a certain address.
#[method(name = "searchTransactionsBefore")]