pub mod pubsub;
use ethereum_types::{Address, H256, U256, U64};
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
pub use self::pubsub::*;
use crate::types::{
access_list::AccessListResult,
block::Block,
block_id::{BlockNumberOrTag, BlockNumberOrTagOrHash},
bytes::Bytes,
fee::FeeHistoryResult,
filter::{Filter, FilterChanges},
index::Index,
log::Log,
proof::AccountProof,
state::StateOverrides,
sync::SyncingStatus,
transaction::{Transaction, TransactionReceipt, TransactionRequest},
};
pub trait EthApiClient:
EthBlockApiClient
+ EthClientApiClient
+ EthExecuteApiClient
+ EthFeeMarketApiClient
+ EthFilterApiClient
+ EthSignApiClient
+ EthStateApiClient
+ EthSubmitApiClient
+ EthTransactionApiClient
+ EthPubSubApiClient
{
}
impl<T> EthApiClient for T where
T: EthBlockApiClient
+ EthClientApiClient
+ EthExecuteApiClient
+ EthFeeMarketApiClient
+ EthFilterApiClient
+ EthSignApiClient
+ EthStateApiClient
+ EthSubmitApiClient
+ EthTransactionApiClient
+ EthPubSubApiClient
{
}
pub trait EthApiServer:
EthBlockApiServer
+ EthClientApiServer
+ EthExecuteApiServer
+ EthFeeMarketApiServer
+ EthFilterApiServer
+ EthSignApiServer
+ EthStateApiServer
+ EthSubmitApiServer
+ EthTransactionApiServer
+ EthPubSubApiServer
{
}
impl<T> EthApiServer for T where
T: EthBlockApiServer
+ EthClientApiServer
+ EthExecuteApiServer
+ EthFeeMarketApiServer
+ EthFilterApiServer
+ EthSignApiServer
+ EthStateApiServer
+ EthSubmitApiServer
+ EthTransactionApiServer
+ EthPubSubApiServer
{
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthBlockApi {
#[method(name = "getBlockByHash")]
async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult<Option<Block>>;
#[method(name = "getBlockByNumber")]
async fn block_by_number(
&self,
block: BlockNumberOrTag,
full: bool,
) -> RpcResult<Option<Block>>;
#[method(name = "getBlockTransactionCountByHash")]
async fn block_transaction_count_by_hash(&self, block_hash: H256) -> RpcResult<Option<U256>>;
#[method(name = "getBlockTransactionCountByNumber")]
async fn block_transaction_count_by_number(
&self,
block: BlockNumberOrTag,
) -> RpcResult<Option<U256>>;
#[method(name = "getUncleCountByBlockHash")]
async fn block_uncles_count_by_hash(&self, block_hash: H256) -> RpcResult<U256>;
#[method(name = "getUncleCountByBlockNumber")]
async fn block_uncles_count_by_number(&self, block: BlockNumberOrTag) -> RpcResult<U256>;
#[method(name = "getBlockReceipts")]
async fn block_transaction_receipts(
&self,
number_or_hash: BlockNumberOrTagOrHash,
) -> RpcResult<Option<Vec<TransactionReceipt>>>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthClientApi {
#[method(name = "chainId")]
async fn chain_id(&self) -> RpcResult<U64>;
#[method(name = "syncing")]
async fn syncing(&self) -> RpcResult<SyncingStatus>;
#[method(name = "coinbase")]
async fn author(&self) -> RpcResult<Address>;
#[method(name = "accounts")]
async fn accounts(&self) -> RpcResult<Vec<Address>>;
#[method(name = "blockNumber")]
async fn block_number(&self) -> RpcResult<U64>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthExecuteApi {
#[method(name = "call")]
async fn call(
&self,
request: TransactionRequest,
number_or_hash: Option<BlockNumberOrTagOrHash>,
state_overrides: Option<StateOverrides>,
) -> RpcResult<Bytes>;
#[method(name = "estimateGas")]
async fn estimate_gas(
&self,
request: TransactionRequest,
number_or_hash: Option<BlockNumberOrTag>,
state_overrides: Option<StateOverrides>,
) -> RpcResult<U256>;
#[method(name = "createAccessList")]
async fn create_access_list(
&self,
request: TransactionRequest,
number_or_hash: Option<BlockNumberOrTag>,
) -> RpcResult<AccessListResult>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthFeeMarketApi {
#[method(name = "gasPrice")]
async fn gas_price(&self) -> RpcResult<U256>;
#[method(name = "maxPriorityFeePerGas")]
async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
#[method(name = "feeHistory")]
async fn fee_history(
&self,
block_count: U256,
newest_block: BlockNumberOrTag,
reward_percentiles: Option<Vec<f64>>,
) -> RpcResult<FeeHistoryResult>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthFilterApi {
#[method(name = "newFilter")]
async fn new_filter(&self, filter: Filter) -> RpcResult<U256>;
#[method(name = "newBlockFilter")]
async fn new_block_filter(&self) -> RpcResult<U256>;
#[method(name = "newPendingTransactionFilter")]
async fn new_pending_transaction_filter(&self, full: Option<bool>) -> RpcResult<U256>;
#[method(name = "uninstallFilter")]
async fn uninstall_filter(&self, filter_id: Index) -> RpcResult<bool>;
#[method(name = "getFilterChanges")]
async fn filter_changes(&self, filter_id: Index) -> RpcResult<FilterChanges>;
#[method(name = "getFilterLogs")]
async fn filter_logs(&self, filter_id: Index) -> RpcResult<Vec<Log>>;
#[method(name = "getLogs")]
async fn logs(&self, filter: Filter) -> RpcResult<Vec<Log>>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthSignApi {
#[method(name = "sign")]
async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
#[method(name = "signTransaction")]
async fn sign_transaction(&self, request: TransactionRequest) -> RpcResult<Bytes>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthStateApi {
#[method(name = "getBalance")]
async fn balance(
&self,
address: Address,
block: Option<BlockNumberOrTagOrHash>,
) -> RpcResult<U256>;
#[method(name = "getStorageAt")]
async fn storage_at(
&self,
address: Address,
slot: U256,
block: Option<BlockNumberOrTagOrHash>,
) -> RpcResult<H256>;
#[method(name = "getTransactionCount")]
async fn transaction_count(
&self,
address: Address,
block: Option<BlockNumberOrTagOrHash>,
) -> RpcResult<U256>;
#[method(name = "getCode")]
async fn code(
&self,
address: Address,
block: Option<BlockNumberOrTagOrHash>,
) -> RpcResult<Bytes>;
#[method(name = "getProof")]
async fn proof(
&self,
address: Address,
storage_keys: H256,
block: Option<BlockNumberOrTagOrHash>,
) -> RpcResult<AccountProof>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthSubmitApi {
#[method(name = "eth_sendTransaction")]
async fn send_transaction(&self, request: TransactionRequest) -> RpcResult<H256>;
#[method(name = "eth_sendRawTransaction")]
async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<H256>;
}
#[rpc(client, server, namespace = "eth")]
#[async_trait]
pub trait EthTransactionApi {
#[method(name = "getTransactionByHash")]
async fn transaction_by_hash(&self, transaction_hash: H256) -> RpcResult<Option<Transaction>>;
#[method(name = "getTransactionByBlockHashAndIndex")]
async fn transaction_by_block_hash_and_index(
&self,
block_hash: H256,
transaction_index: Index,
) -> RpcResult<Option<Transaction>>;
#[method(name = "getTransactionByBlockNumberAndIndex")]
async fn transaction_by_block_number_and_index(
&self,
block: BlockNumberOrTag,
transaction_index: Index,
) -> RpcResult<Option<Transaction>>;
#[method(name = "getTransactionReceipt")]
async fn transaction_receipt(
&self,
transaction_hash: H256,
) -> RpcResult<Option<TransactionReceipt>>;
}