cfx_rpc_cfx_api/cfx/
mod.rs

1// Copyright 2019 Conflux Foundation. All rights reserved.
2// Conflux is free software and distributed under GNU General Public License.
3// See http://www.gnu.org/licenses/
4
5use cfx_rpc_cfx_types::{
6    pos::PoSEpochReward, Account as RpcAccount, Block, BlockHashOrEpochNumber,
7    Bytes, CfxFeeHistory, CfxRpcLogFilter,
8    CheckBalanceAgainstTransactionResponse, EpochNumber,
9    EstimateGasAndCollateralResponse, Log as RpcLog, PoSEconomics,
10    Receipt as RpcReceipt, RewardInfo as RpcRewardInfo, RpcAddress,
11    SponsorInfo, Status as RpcStatus, StorageCollateralInfo, TokenSupplyInfo,
12    Transaction, TransactionRequest, VoteParamsInfo,
13};
14use cfx_rpc_primitives::U64 as HexU64;
15use cfx_types::{H256, U256, U64};
16use jsonrpsee::{core::RpcResult as JsonRpcResult, proc_macros::rpc};
17use primitives::{DepositInfo, StorageRoot, VoteStakeInfo};
18
19mod cfx_filter;
20mod debug;
21
22pub use cfx_filter::*;
23pub use debug::*;
24
25/// Cfx rpc interface.
26#[rpc(server, namespace = "cfx")]
27pub trait CfxRpc {
28    //        /// Returns protocol version encoded as a string (quotes are
29    // necessary).        #[method(name = "protocolVersion")]
30    //        fn protocol_version(&self) -> JsonRpcResult<String>;
31    //
32    /// Returns the number of hashes per second that the node is mining with.
33    //        #[method(name = "hashrate")]
34    //        fn hashrate(&self) -> JsonRpcResult<U256>;
35
36    //        /// Returns block author.
37    //        #[method(name = "coinbase")]
38    //        fn author(&self) -> JsonRpcResult<H160>;
39
40    //        /// Returns true if client is actively mining new blocks.
41    //        #[method(name = "mining")]
42    //        fn is_mining(&self) -> JsonRpcResult<bool>;
43
44    /// Returns current gas price.
45    #[method(name = "gasPrice")]
46    async fn gas_price(&self) -> JsonRpcResult<U256>;
47
48    /// Returns current max_priority_fee
49    #[method(name = "maxPriorityFeePerGas")]
50    async fn max_priority_fee_per_gas(&self) -> JsonRpcResult<U256>;
51
52    /// Returns highest epoch number.
53    #[method(name = "epochNumber")]
54    async fn epoch_number(
55        &self, epoch_number: Option<EpochNumber>,
56    ) -> JsonRpcResult<U256>;
57
58    /// Returns balance of the given account.
59    #[method(name = "getBalance")]
60    async fn balance(
61        &self, addr: RpcAddress,
62        block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
63    ) -> JsonRpcResult<U256>;
64
65    /// Returns admin of the given contract
66    #[method(name = "getAdmin")]
67    async fn admin(
68        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
69    ) -> JsonRpcResult<Option<RpcAddress>>;
70
71    /// Returns sponsor information of the given contract
72    #[method(name = "getSponsorInfo")]
73    async fn sponsor_info(
74        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
75    ) -> JsonRpcResult<SponsorInfo>;
76
77    /// Returns balance of the given account.
78    #[method(name = "getStakingBalance")]
79    async fn staking_balance(
80        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
81    ) -> JsonRpcResult<U256>;
82
83    /// Returns deposit list of the given account.
84    #[method(name = "getDepositList")]
85    async fn deposit_list(
86        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
87    ) -> JsonRpcResult<Vec<DepositInfo>>;
88
89    /// Returns vote list of the given account.
90    #[method(name = "getVoteList")]
91    async fn vote_list(
92        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
93    ) -> JsonRpcResult<Vec<VoteStakeInfo>>;
94
95    /// Returns balance of the given account.
96    #[method(name = "getCollateralForStorage")]
97    async fn collateral_for_storage(
98        &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
99    ) -> JsonRpcResult<U256>;
100
101    /// Returns the code at given address at given time (epoch number).
102    #[method(name = "getCode")]
103    async fn code(
104        &self, addr: RpcAddress,
105        block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
106    ) -> JsonRpcResult<Bytes>;
107
108    /// Returns storage entries from a given contract.
109    #[method(name = "getStorageAt")]
110    async fn storage_at(
111        &self, addr: RpcAddress, pos: U256,
112        block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
113    ) -> JsonRpcResult<Option<H256>>;
114
115    #[method(name = "getStorageRoot")]
116    async fn storage_root(
117        &self, address: RpcAddress, epoch_num: Option<EpochNumber>,
118    ) -> JsonRpcResult<Option<StorageRoot>>;
119
120    /// Returns block with given hash.
121    #[method(name = "getBlockByHash")]
122    async fn block_by_hash(
123        &self, block_hash: H256, include_txs: bool,
124    ) -> JsonRpcResult<Option<Block>>;
125
126    /// Returns block with given hash and pivot chain assumption.
127    #[method(name = "getBlockByHashWithPivotAssumption")]
128    async fn block_by_hash_with_pivot_assumption(
129        &self, block_hash: H256, pivot_hash: H256, epoch_number: U64,
130    ) -> JsonRpcResult<Block>;
131
132    /// Returns block with given epoch number.
133    #[method(name = "getBlockByEpochNumber")]
134    async fn block_by_epoch_number(
135        &self, epoch_number: EpochNumber, include_txs: bool,
136    ) -> JsonRpcResult<Option<Block>>;
137
138    /// Returns block with given block number.
139    #[method(name = "getBlockByBlockNumber")]
140    async fn block_by_block_number(
141        &self, block_number: U64, include_txs: bool,
142    ) -> JsonRpcResult<Option<Block>>;
143
144    /// Returns best block hash.
145    #[method(name = "getBestBlockHash")]
146    async fn best_block_hash(&self) -> JsonRpcResult<H256>;
147
148    /// Returns the nonce should be filled in next sending transaction from
149    /// given address at given time (epoch number).
150    #[method(name = "getNextNonce")]
151    async fn next_nonce(
152        &self, addr: RpcAddress, epoch_number: Option<BlockHashOrEpochNumber>,
153    ) -> JsonRpcResult<U256>;
154
155    //        /// Returns the number of transactions in a block with given hash.
156    //        #[method(name = "getBlockTransactionCountByHash")]
157    //        fn block_transaction_count_by_hash(&self, H256) ->
158    // Option<U256>;
159
160    //        /// Returns the number of transactions in a block with given block
161    // number.        #[method(name = "getBlockTransactionCountByNumber")]
162    //        fn block_trasaction_count_by_number(&self, BlockNumber) ->
163    // Option<U256>;
164
165    /// Sends signed transaction, returning its hash.
166    #[method(name = "sendRawTransaction")]
167    async fn send_raw_transaction(&self, raw_tx: Bytes) -> JsonRpcResult<H256>;
168
169    //        /// @alias of `sendRawTransaction`.
170    //        #[method(name = "submitTransaction")]
171    //        async fn submit_transaction(&self, Bytes) -> JsonRpcResult<H256>;
172
173    /// Call contract, returning the output data.
174    #[method(name = "call")]
175    async fn call(
176        &self, tx: TransactionRequest,
177        block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
178    ) -> JsonRpcResult<Bytes>;
179
180    /// Returns logs matching the filter provided.
181    #[method(name = "getLogs")]
182    async fn get_logs(
183        &self, filter: CfxRpcLogFilter,
184    ) -> JsonRpcResult<Vec<RpcLog>>;
185
186    /// Get transaction by its hash.
187    #[method(name = "getTransactionByHash")]
188    async fn transaction_by_hash(
189        &self, tx_hash: H256,
190    ) -> JsonRpcResult<Option<Transaction>>;
191
192    /// Return estimated gas and collateral usage.
193    #[method(name = "estimateGasAndCollateral")]
194    async fn estimate_gas_and_collateral(
195        &self, request: TransactionRequest, epoch_number: Option<EpochNumber>,
196    ) -> JsonRpcResult<EstimateGasAndCollateralResponse>;
197
198    #[method(name = "feeHistory")]
199    async fn fee_history(
200        &self, block_count: HexU64, newest_block: EpochNumber,
201        reward_percentiles: Option<Vec<f64>>,
202    ) -> JsonRpcResult<CfxFeeHistory>;
203
204    /// Check if user balance is enough for the transaction.
205    #[method(name = "checkBalanceAgainstTransaction")]
206    async fn check_balance_against_transaction(
207        &self, account_addr: RpcAddress, contract_addr: RpcAddress,
208        gas_limit: U256, gas_price: U256, storage_limit: U256,
209        epoch: Option<EpochNumber>,
210    ) -> JsonRpcResult<CheckBalanceAgainstTransactionResponse>;
211
212    #[method(name = "getBlocksByEpoch")]
213    async fn blocks_by_epoch(
214        &self, epoch_number: EpochNumber,
215    ) -> JsonRpcResult<Vec<H256>>;
216
217    #[method(name = "getSkippedBlocksByEpoch")]
218    async fn skipped_blocks_by_epoch(
219        &self, epoch_number: EpochNumber,
220    ) -> JsonRpcResult<Vec<H256>>;
221
222    #[method(name = "getTransactionReceipt")]
223    async fn transaction_receipt(
224        &self, tx_hash: H256,
225    ) -> JsonRpcResult<Option<RpcReceipt>>;
226
227    /// Return account related states of the given account
228    #[method(name = "getAccount")]
229    async fn account(
230        &self, address: RpcAddress, epoch_num: Option<EpochNumber>,
231    ) -> JsonRpcResult<RpcAccount>;
232
233    /// Returns interest rate of the given epoch
234    #[method(name = "getInterestRate")]
235    async fn interest_rate(
236        &self, epoch_number: Option<EpochNumber>,
237    ) -> JsonRpcResult<U256>;
238
239    /// Returns accumulate interest rate of the given epoch
240    #[method(name = "getAccumulateInterestRate")]
241    async fn accumulate_interest_rate(
242        &self, epoch_number: Option<EpochNumber>,
243    ) -> JsonRpcResult<U256>;
244
245    /// Returns accumulate interest rate of the given epoch
246    #[method(name = "getPoSEconomics")]
247    async fn pos_economics(
248        &self, epoch_number: Option<EpochNumber>,
249    ) -> JsonRpcResult<PoSEconomics>;
250
251    #[method(name = "getConfirmationRiskByHash")]
252    async fn confirmation_risk_by_hash(
253        &self, block_hash: H256,
254    ) -> JsonRpcResult<Option<U256>>;
255
256    #[method(name = "getStatus")]
257    async fn get_status(&self) -> JsonRpcResult<RpcStatus>;
258
259    /// Returns block reward information in an epoch
260    #[method(name = "getBlockRewardInfo")]
261    async fn get_block_reward_info(
262        &self, num: EpochNumber,
263    ) -> JsonRpcResult<Vec<RpcRewardInfo>>;
264
265    /// Return the client version as a string
266    #[method(name = "clientVersion")]
267    async fn get_client_version(&self) -> JsonRpcResult<String>;
268
269    /// Return information about total token supply.
270    #[method(name = "getSupplyInfo")]
271    async fn get_supply_info(
272        &self, epoch_number: Option<EpochNumber>,
273    ) -> JsonRpcResult<TokenSupplyInfo>;
274
275    /// Return information about total token supply.
276    #[method(name = "getCollateralInfo")]
277    async fn get_collateral_info(
278        &self, epoch_number: Option<EpochNumber>,
279    ) -> JsonRpcResult<StorageCollateralInfo>;
280
281    #[method(name = "getFeeBurnt")]
282    async fn get_fee_burnt(
283        &self, epoch_number: Option<EpochNumber>,
284    ) -> JsonRpcResult<U256>;
285
286    #[method(name = "getPoSRewardByEpoch")]
287    async fn get_pos_reward_by_epoch(
288        &self, epoch: EpochNumber,
289    ) -> JsonRpcResult<Option<PoSEpochReward>>;
290
291    #[method(name = "getParamsFromVote")]
292    async fn get_vote_params(
293        &self, epoch_number: Option<EpochNumber>,
294    ) -> JsonRpcResult<VoteParamsInfo>;
295
296    //        /// Returns transaction at given block hash and index.
297    //        #[method(name = "getTransactionByBlockHashAndIndex")]
298    //        fn transaction_by_block_hash_and_index(&self, H256, Index) ->
299    // Option<Transaction>;
300
301    //        /// Returns transaction by given block number and index.
302    //        #[method(name = "getTransactionByBlockNumberAndIndex")]
303    //        fn transaction_by_block_number_and_index(&self, BlockNumber,
304    // Index) -> Option<Transaction>;
305
306    //        /// Returns uncles at given block and index.
307    //        #[method(name = "getUnclesByBlockHashAndIndex")]
308    //        fn uncles_by_block_hash_and_index(&self, H256, Index) ->
309    // Option<Block>;
310
311    //        /// Returns uncles at given block and index.
312    //        #[method(name = "getUnclesByBlockNumberAndIndex")]
313    //        fn uncles_by_block_number_and_index(&self, BlockNumber, Index) ->
314    // Option<Block>;
315}