1use cfx_rpc_eth_types::{
2 AccessListResult, AccountPendingTransactions, Block, BlockId,
3 BlockOverrides, Bundle, EthCallResponse, EthRpcLogFilter as Filter,
4 FeeHistory, Header, Log, Receipt, RpcStateOverride, SimulatePayload,
5 SimulatedBlock, StateContext, SyncStatus, Transaction, TransactionRequest,
6};
7use cfx_rpc_primitives::{Bytes, Index};
8use cfx_types::{Address, H256, H64, U256, U64};
9use jsonrpsee::{core::RpcResult, proc_macros::rpc};
10
11type BlockNumberOrTag = BlockId;
12
13type JsonStorageKey = U256;
14
15#[rpc(server, namespace = "eth")]
16pub trait EthApi {
17 #[method(name = "protocolVersion")]
19 async fn protocol_version(&self) -> RpcResult<U64>;
20
21 #[method(name = "syncing")]
23 fn syncing(&self) -> RpcResult<SyncStatus>;
24
25 #[method(name = "coinbase")]
27 async fn author(&self) -> RpcResult<Address>;
28
29 #[method(name = "accounts")]
31 fn accounts(&self) -> RpcResult<Vec<Address>>;
32
33 #[method(name = "blockNumber")]
35 fn block_number(&self) -> RpcResult<U256>;
36
37 #[method(name = "chainId")]
39 async fn chain_id(&self) -> RpcResult<Option<U64>>;
40
41 #[method(name = "getBlockByHash")]
43 async fn block_by_hash(
44 &self, hash: H256, full: bool,
45 ) -> RpcResult<Option<Block>>;
46
47 #[method(name = "getBlockByNumber")]
49 async fn block_by_number(
50 &self, number: BlockNumberOrTag, full: bool,
51 ) -> RpcResult<Option<Block>>;
52
53 #[method(name = "getBlockTransactionCountByHash")]
56 async fn block_transaction_count_by_hash(
57 &self, hash: H256,
58 ) -> RpcResult<Option<U256>>;
59
60 #[method(name = "getBlockTransactionCountByNumber")]
63 async fn block_transaction_count_by_number(
64 &self, number: BlockNumberOrTag,
65 ) -> RpcResult<Option<U256>>;
66
67 #[method(name = "getUncleCountByBlockHash")]
70 async fn block_uncles_count_by_hash(
71 &self, hash: H256,
72 ) -> RpcResult<Option<U256>>;
73
74 #[method(name = "getUncleCountByBlockNumber")]
76 async fn block_uncles_count_by_number(
77 &self, number: BlockNumberOrTag,
78 ) -> RpcResult<Option<U256>>;
79
80 #[method(name = "getBlockReceipts")]
82 async fn block_receipts(
83 &self, block_id: BlockId,
84 ) -> RpcResult<Option<Vec<Receipt>>>;
85
86 #[method(name = "getUncleByBlockHashAndIndex")]
88 async fn uncle_by_block_hash_and_index(
89 &self, hash: H256, index: Index,
90 ) -> RpcResult<Option<Block>>;
91
92 #[method(name = "getUncleByBlockNumberAndIndex")]
94 async fn uncle_by_block_number_and_index(
95 &self, number: BlockNumberOrTag, index: Index,
96 ) -> RpcResult<Option<Block>>;
97
98 #[method(name = "getRawTransactionByHash")]
103 async fn raw_transaction_by_hash(
104 &self, hash: H256,
105 ) -> RpcResult<Option<Bytes>>;
106
107 #[method(name = "getTransactionByHash")]
110 async fn transaction_by_hash(
111 &self, hash: H256,
112 ) -> RpcResult<Option<Transaction>>;
113
114 #[method(name = "getRawTransactionByBlockHashAndIndex")]
117 async fn raw_transaction_by_block_hash_and_index(
118 &self, hash: H256, index: Index,
119 ) -> RpcResult<Option<Bytes>>;
120
121 #[method(name = "getTransactionByBlockHashAndIndex")]
124 async fn transaction_by_block_hash_and_index(
125 &self, hash: H256, index: Index,
126 ) -> RpcResult<Option<Transaction>>;
127
128 #[method(name = "getRawTransactionByBlockNumberAndIndex")]
131 async fn raw_transaction_by_block_number_and_index(
132 &self, number: BlockNumberOrTag, index: Index,
133 ) -> RpcResult<Option<Bytes>>;
134
135 #[method(name = "getTransactionByBlockNumberAndIndex")]
138 async fn transaction_by_block_number_and_index(
139 &self, number: BlockNumberOrTag, index: Index,
140 ) -> RpcResult<Option<Transaction>>;
141
142 #[method(name = "getTransactionBySenderAndNonce")]
144 async fn transaction_by_sender_and_nonce(
145 &self, address: Address, nonce: U64,
146 ) -> RpcResult<Option<Transaction>>;
147
148 #[method(name = "getTransactionReceipt")]
150 async fn transaction_receipt(
151 &self, hash: H256,
152 ) -> RpcResult<Option<Receipt>>;
153
154 #[method(name = "getBalance")]
156 async fn balance(
157 &self, address: Address, block_number: Option<BlockId>,
158 ) -> RpcResult<U256>;
159
160 #[method(name = "getStorageAt")]
162 async fn storage_at(
163 &self, address: Address, index: JsonStorageKey,
164 block_number: Option<BlockId>,
165 ) -> RpcResult<H256>;
166
167 #[method(name = "getTransactionCount")]
170 async fn transaction_count(
171 &self, address: Address, block_number: Option<BlockId>,
172 ) -> RpcResult<U256>;
173
174 #[method(name = "getCode")]
176 async fn get_code(
177 &self, address: Address, block_number: Option<BlockId>,
178 ) -> RpcResult<Bytes>;
179
180 #[method(name = "getHeaderByNumber")]
182 async fn header_by_number(
183 &self, hash: BlockNumberOrTag,
184 ) -> RpcResult<Option<Header>>;
185
186 #[method(name = "getHeaderByHash")]
188 async fn header_by_hash(&self, hash: H256) -> RpcResult<Option<Header>>;
189
190 #[method(name = "simulateV1")]
194 async fn simulate_v1(
195 &self, opts: SimulatePayload, block_number: Option<BlockId>,
196 ) -> RpcResult<Vec<SimulatedBlock>>;
197
198 #[method(name = "call")]
201 async fn call(
202 &self, request: TransactionRequest, block_number: Option<BlockId>,
203 state_overrides: Option<RpcStateOverride>,
204 block_overrides: Option<Box<BlockOverrides>>,
205 ) -> RpcResult<Bytes>;
206
207 #[method(name = "callMany")]
210 async fn call_many(
211 &self, bundle: Bundle, state_context: Option<StateContext>,
212 state_override: Option<RpcStateOverride>,
213 ) -> RpcResult<Vec<EthCallResponse>>;
214
215 #[method(name = "createAccessList")]
232 async fn create_access_list(
233 &self, request: TransactionRequest, block_number: Option<BlockId>,
234 state_override: Option<RpcStateOverride>,
235 ) -> RpcResult<AccessListResult>;
236
237 #[method(name = "estimateGas")]
240 async fn estimate_gas(
241 &self, request: TransactionRequest, block_number: Option<BlockId>,
242 state_override: Option<RpcStateOverride>,
243 ) -> RpcResult<U256>;
244
245 #[method(name = "gasPrice")]
247 async fn gas_price(&self) -> RpcResult<U256>;
248
249 #[method(name = "maxPriorityFeePerGas")]
261 async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
262
263 #[method(name = "feeHistory")]
277 async fn fee_history(
278 &self, block_count: U64, newest_block: BlockNumberOrTag,
279 reward_percentiles: Option<Vec<f64>>,
280 ) -> RpcResult<FeeHistory>;
281
282 #[method(name = "mining")]
284 async fn is_mining(&self) -> RpcResult<bool>;
285
286 #[method(name = "hashrate")]
288 async fn hashrate(&self) -> RpcResult<U256>;
289
290 #[method(name = "submitHashrate")]
302 async fn submit_hashrate(
303 &self, hashrate: U256, id: H256,
304 ) -> RpcResult<bool>;
305
306 #[method(name = "submitWork")]
308 async fn submit_work(
309 &self, nonce: H64, pow_hash: H256, mix_digest: H256,
310 ) -> RpcResult<bool>;
311
312 #[method(name = "sendTransaction")]
315 async fn send_transaction(
316 &self, request: TransactionRequest,
317 ) -> RpcResult<H256>;
318
319 #[method(name = "sendRawTransaction")]
321 async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<H256>;
322
323 #[method(name = "submitTransaction")]
325 async fn submit_transaction(&self, transaction: Bytes) -> RpcResult<H256>;
326
327 #[method(name = "sign")]
331 async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
332
333 #[method(name = "signTransaction")]
336 async fn sign_transaction(
337 &self, transaction: TransactionRequest,
338 ) -> RpcResult<Bytes>;
339
340 #[method(name = "getLogs")]
359 async fn logs(&self, filter: Filter) -> RpcResult<Vec<Log>>;
360
361 #[method(name = "getAccountPendingTransactions")]
362 async fn account_pending_transactions(
363 &self, address: Address, maybe_start_nonce: Option<U256>,
364 maybe_limit: Option<U64>,
365 ) -> RpcResult<AccountPendingTransactions>;
366}