cfx_rpc_eth_api/
eth.rs

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    /// Returns the protocol version encoded as a string.
18    #[method(name = "protocolVersion")]
19    async fn protocol_version(&self) -> RpcResult<U64>;
20
21    /// Returns an object with data about the sync status or false.
22    #[method(name = "syncing")]
23    fn syncing(&self) -> RpcResult<SyncStatus>;
24
25    /// Returns the client coinbase address.
26    #[method(name = "coinbase")]
27    async fn author(&self) -> RpcResult<Address>;
28
29    /// Returns a list of addresses owned by client.
30    #[method(name = "accounts")]
31    fn accounts(&self) -> RpcResult<Vec<Address>>;
32
33    /// Returns the number of most recent block.
34    #[method(name = "blockNumber")]
35    fn block_number(&self) -> RpcResult<U256>;
36
37    /// Returns the chain ID of the current network.
38    #[method(name = "chainId")]
39    async fn chain_id(&self) -> RpcResult<Option<U64>>;
40
41    /// Returns information about a block by hash.
42    #[method(name = "getBlockByHash")]
43    async fn block_by_hash(
44        &self, hash: H256, full: bool,
45    ) -> RpcResult<Option<Block>>;
46
47    /// Returns information about a block by number.
48    #[method(name = "getBlockByNumber")]
49    async fn block_by_number(
50        &self, number: BlockNumberOrTag, full: bool,
51    ) -> RpcResult<Option<Block>>;
52
53    /// Returns the number of transactions in a block from a block matching the
54    /// given block hash.
55    #[method(name = "getBlockTransactionCountByHash")]
56    async fn block_transaction_count_by_hash(
57        &self, hash: H256,
58    ) -> RpcResult<Option<U256>>;
59
60    /// Returns the number of transactions in a block matching the given block
61    /// number.
62    #[method(name = "getBlockTransactionCountByNumber")]
63    async fn block_transaction_count_by_number(
64        &self, number: BlockNumberOrTag,
65    ) -> RpcResult<Option<U256>>;
66
67    /// Returns the number of uncles in a block from a block matching the given
68    /// block hash.
69    #[method(name = "getUncleCountByBlockHash")]
70    async fn block_uncles_count_by_hash(
71        &self, hash: H256,
72    ) -> RpcResult<Option<U256>>;
73
74    /// Returns the number of uncles in a block with given block number.
75    #[method(name = "getUncleCountByBlockNumber")]
76    async fn block_uncles_count_by_number(
77        &self, number: BlockNumberOrTag,
78    ) -> RpcResult<Option<U256>>;
79
80    /// Returns all transaction receipts for a given block.
81    #[method(name = "getBlockReceipts")]
82    async fn block_receipts(
83        &self, block_id: BlockId,
84    ) -> RpcResult<Option<Vec<Receipt>>>;
85
86    /// Returns an uncle block of the given block and index.
87    #[method(name = "getUncleByBlockHashAndIndex")]
88    async fn uncle_by_block_hash_and_index(
89        &self, hash: H256, index: Index,
90    ) -> RpcResult<Option<Block>>;
91
92    /// Returns an uncle block of the given block and index.
93    #[method(name = "getUncleByBlockNumberAndIndex")]
94    async fn uncle_by_block_number_and_index(
95        &self, number: BlockNumberOrTag, index: Index,
96    ) -> RpcResult<Option<Block>>;
97
98    /// Returns the EIP-2718 encoded transaction if it exists.
99    ///
100    /// If this is a EIP-4844 transaction that is in the pool it will include
101    /// the sidecar.
102    #[method(name = "getRawTransactionByHash")]
103    async fn raw_transaction_by_hash(
104        &self, hash: H256,
105    ) -> RpcResult<Option<Bytes>>;
106
107    /// Returns the information about a transaction requested by transaction
108    /// hash.
109    #[method(name = "getTransactionByHash")]
110    async fn transaction_by_hash(
111        &self, hash: H256,
112    ) -> RpcResult<Option<Transaction>>;
113
114    /// Returns information about a raw transaction by block hash and
115    /// transaction index position.
116    #[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    /// Returns information about a transaction by block hash and transaction
122    /// index position.
123    #[method(name = "getTransactionByBlockHashAndIndex")]
124    async fn transaction_by_block_hash_and_index(
125        &self, hash: H256, index: Index,
126    ) -> RpcResult<Option<Transaction>>;
127
128    /// Returns information about a raw transaction by block number and
129    /// transaction index position.
130    #[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    /// Returns information about a transaction by block number and transaction
136    /// index position.
137    #[method(name = "getTransactionByBlockNumberAndIndex")]
138    async fn transaction_by_block_number_and_index(
139        &self, number: BlockNumberOrTag, index: Index,
140    ) -> RpcResult<Option<Transaction>>;
141
142    /// Returns information about a transaction by sender and nonce.
143    #[method(name = "getTransactionBySenderAndNonce")]
144    async fn transaction_by_sender_and_nonce(
145        &self, address: Address, nonce: U64,
146    ) -> RpcResult<Option<Transaction>>;
147
148    /// Returns the receipt of a transaction by transaction hash.
149    #[method(name = "getTransactionReceipt")]
150    async fn transaction_receipt(
151        &self, hash: H256,
152    ) -> RpcResult<Option<Receipt>>;
153
154    /// Returns the balance of the account of given address.
155    #[method(name = "getBalance")]
156    async fn balance(
157        &self, address: Address, block_number: Option<BlockId>,
158    ) -> RpcResult<U256>;
159
160    /// Returns the value from a storage position at a given address
161    #[method(name = "getStorageAt")]
162    async fn storage_at(
163        &self, address: Address, index: JsonStorageKey,
164        block_number: Option<BlockId>,
165    ) -> RpcResult<H256>;
166
167    /// Returns the number of transactions sent from an address at given block
168    /// number.
169    #[method(name = "getTransactionCount")]
170    async fn transaction_count(
171        &self, address: Address, block_number: Option<BlockId>,
172    ) -> RpcResult<U256>;
173
174    /// Returns code at a given address at given block number.
175    #[method(name = "getCode")]
176    async fn get_code(
177        &self, address: Address, block_number: Option<BlockId>,
178    ) -> RpcResult<Bytes>;
179
180    /// Returns the block's header at given number.
181    #[method(name = "getHeaderByNumber")]
182    async fn header_by_number(
183        &self, hash: BlockNumberOrTag,
184    ) -> RpcResult<Option<Header>>;
185
186    /// Returns the block's header at given hash.
187    #[method(name = "getHeaderByHash")]
188    async fn header_by_hash(&self, hash: H256) -> RpcResult<Option<Header>>;
189
190    /// `eth_simulateV1` executes an arbitrary number of transactions on top of
191    /// the requested state. The transactions are packed into individual
192    /// blocks. Overrides can be provided.
193    #[method(name = "simulateV1")]
194    async fn simulate_v1(
195        &self, opts: SimulatePayload, block_number: Option<BlockId>,
196    ) -> RpcResult<Vec<SimulatedBlock>>;
197
198    /// Executes a new message call immediately without creating a transaction
199    /// on the block chain.
200    #[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    /// Simulate arbitrary number of transactions at an arbitrary blockchain
208    /// index, with the optionality of state overrides
209    #[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    /// Generates an access list for a transaction.
216    ///
217    /// This method creates an [EIP2930](https://eips.ethereum.org/EIPS/eip-2930) type accessList based on a given Transaction.
218    ///
219    /// An access list contains all storage slots and addresses touched by the
220    /// transaction, except for the sender account and the chain's
221    /// precompiles.
222    ///
223    /// It returns list of addresses and storage keys used by the transaction,
224    /// plus the gas consumed when the access list is added. That is, it
225    /// gives you the list of addresses and storage keys that will be used
226    /// by that transaction, plus the gas consumed if the access
227    /// list is included. Like eth_estimateGas, this is an estimation; the list
228    /// could change when the transaction is actually mined. Adding an
229    /// accessList to your transaction does not necessary result in lower
230    /// gas usage compared to a transaction without an access list.
231    #[method(name = "createAccessList")]
232    async fn create_access_list(
233        &self, request: TransactionRequest, block_number: Option<BlockId>,
234    ) -> RpcResult<AccessListResult>;
235
236    /// Generates and returns an estimate of how much gas is necessary to allow
237    /// the transaction to complete.
238    #[method(name = "estimateGas")]
239    async fn estimate_gas(
240        &self, request: TransactionRequest, block_number: Option<BlockId>,
241        state_override: Option<RpcStateOverride>,
242    ) -> RpcResult<U256>;
243
244    /// Returns the current price per gas in wei.
245    #[method(name = "gasPrice")]
246    async fn gas_price(&self) -> RpcResult<U256>;
247
248    /// Returns the account details by specifying an address and a block
249    /// number/tag
250    // #[method(name = "getAccount")]
251    // async fn get_account(
252    //     &self,
253    //     address: Address,
254    //     block: BlockId,
255    // ) -> RpcResult<Option<reth_rpc_types::Account>>;
256
257    /// Introduced in EIP-1559, returns suggestion for the priority for dynamic
258    /// fee transactions.
259    #[method(name = "maxPriorityFeePerGas")]
260    async fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
261
262    /// Introduced in EIP-4844, returns the current blob base fee in wei.
263    // #[method(name = "blobBaseFee")]
264    // async fn blob_base_fee(&self) -> RpcResult<U256>;
265
266    /// Returns the Transaction fee history
267    ///
268    /// Introduced in EIP-1559 for getting information on the appropriate
269    /// priority fee to use.
270    ///
271    /// Returns transaction base fee per gas and effective priority fee per gas
272    /// for the requested/supported block range. The returned Fee history
273    /// for the returned block range can be a subsection of the requested
274    /// range if not all blocks are available.
275    #[method(name = "feeHistory")]
276    async fn fee_history(
277        &self, block_count: U64, newest_block: BlockNumberOrTag,
278        reward_percentiles: Option<Vec<f64>>,
279    ) -> RpcResult<FeeHistory>;
280
281    /// Returns whether the client is actively mining new blocks.
282    #[method(name = "mining")]
283    async fn is_mining(&self) -> RpcResult<bool>;
284
285    /// Returns the number of hashes per second that the node is mining with.
286    #[method(name = "hashrate")]
287    async fn hashrate(&self) -> RpcResult<U256>;
288
289    /// Returns the hash of the current block, the seedHash, and the boundary
290    /// condition to be met (“target”)
291    // #[method(name = "getWork")]
292    // async fn get_work(&self) -> RpcResult<Work>;
293
294    /// Used for submitting mining hashrate.
295    ///
296    /// Can be used for remote miners to submit their hash rate.
297    /// It accepts the miner hash rate and an identifier which must be unique
298    /// between nodes. Returns `true` if the block was successfully
299    /// submitted, `false` otherwise.
300    #[method(name = "submitHashrate")]
301    async fn submit_hashrate(
302        &self, hashrate: U256, id: H256,
303    ) -> RpcResult<bool>;
304
305    /// Used for submitting a proof-of-work solution.
306    #[method(name = "submitWork")]
307    async fn submit_work(
308        &self, nonce: H64, pow_hash: H256, mix_digest: H256,
309    ) -> RpcResult<bool>;
310
311    /// Sends transaction; will block waiting for signer to return the
312    /// transaction hash.
313    #[method(name = "sendTransaction")]
314    async fn send_transaction(
315        &self, request: TransactionRequest,
316    ) -> RpcResult<H256>;
317
318    /// Sends signed transaction, returning its hash.
319    #[method(name = "sendRawTransaction")]
320    async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<H256>;
321
322    /// @alias of `eth_sendRawTransaction`.
323    #[method(name = "submitTransaction")]
324    async fn submit_transaction(&self, transaction: Bytes) -> RpcResult<H256>;
325
326    /// Returns an Ethereum specific signature with:
327    /// sign(keccak256("\x19Ethereum Signed Message:\n"
328    /// + len(message) + message))).
329    #[method(name = "sign")]
330    async fn sign(&self, address: Address, message: Bytes) -> RpcResult<Bytes>;
331
332    /// Signs a transaction that can be submitted to the network at a later time
333    /// using with `sendRawTransaction.`
334    #[method(name = "signTransaction")]
335    async fn sign_transaction(
336        &self, transaction: TransactionRequest,
337    ) -> RpcResult<Bytes>;
338
339    // Signs data via [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md).
340    // #[method(name = "signTypedData")]
341    // async fn sign_typed_data(&self, address: Address, data: TypedData) ->
342    // RpcResult<Bytes>;
343
344    // Returns the account and storage values of the specified account including
345    // the Merkle-proof. This call can be used to verify that the data you
346    // are pulling from is not tampered with.
347
348    // #[method(name = "getProof")]
349    // async fn get_proof(
350    //     &self,
351    //     address: Address,
352    //     keys: Vec<JsonStorageKey>,
353    //     block_number: Option<BlockId>,
354    // ) -> RpcResult<EIP1186AccountProofResponse>;
355
356    /// Returns logs matching given filter object.
357    #[method(name = "getLogs")]
358    async fn logs(&self, filter: Filter) -> RpcResult<Vec<Log>>;
359
360    #[method(name = "getAccountPendingTransactions")]
361    async fn account_pending_transactions(
362        &self, address: Address, maybe_start_nonce: Option<U256>,
363        maybe_limit: Option<U64>,
364    ) -> RpcResult<AccountPendingTransactions>;
365}