1use 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#[rpc(server, namespace = "cfx")]
27pub trait CfxRpc {
28 #[method(name = "gasPrice")]
46 async fn gas_price(&self) -> JsonRpcResult<U256>;
47
48 #[method(name = "maxPriorityFeePerGas")]
50 async fn max_priority_fee_per_gas(&self) -> JsonRpcResult<U256>;
51
52 #[method(name = "epochNumber")]
54 async fn epoch_number(
55 &self, epoch_number: Option<EpochNumber>,
56 ) -> JsonRpcResult<U256>;
57
58 #[method(name = "getBalance")]
60 async fn balance(
61 &self, addr: RpcAddress,
62 block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
63 ) -> JsonRpcResult<U256>;
64
65 #[method(name = "getAdmin")]
67 async fn admin(
68 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
69 ) -> JsonRpcResult<Option<RpcAddress>>;
70
71 #[method(name = "getSponsorInfo")]
73 async fn sponsor_info(
74 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
75 ) -> JsonRpcResult<SponsorInfo>;
76
77 #[method(name = "getStakingBalance")]
79 async fn staking_balance(
80 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
81 ) -> JsonRpcResult<U256>;
82
83 #[method(name = "getDepositList")]
85 async fn deposit_list(
86 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
87 ) -> JsonRpcResult<Vec<DepositInfo>>;
88
89 #[method(name = "getVoteList")]
91 async fn vote_list(
92 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
93 ) -> JsonRpcResult<Vec<VoteStakeInfo>>;
94
95 #[method(name = "getCollateralForStorage")]
97 async fn collateral_for_storage(
98 &self, addr: RpcAddress, epoch_number: Option<EpochNumber>,
99 ) -> JsonRpcResult<U256>;
100
101 #[method(name = "getCode")]
103 async fn code(
104 &self, addr: RpcAddress,
105 block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
106 ) -> JsonRpcResult<Bytes>;
107
108 #[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 #[method(name = "getBlockByHash")]
122 async fn block_by_hash(
123 &self, block_hash: H256, include_txs: bool,
124 ) -> JsonRpcResult<Option<Block>>;
125
126 #[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 #[method(name = "getBlockByEpochNumber")]
134 async fn block_by_epoch_number(
135 &self, epoch_number: EpochNumber, include_txs: bool,
136 ) -> JsonRpcResult<Option<Block>>;
137
138 #[method(name = "getBlockByBlockNumber")]
140 async fn block_by_block_number(
141 &self, block_number: U64, include_txs: bool,
142 ) -> JsonRpcResult<Option<Block>>;
143
144 #[method(name = "getBestBlockHash")]
146 async fn best_block_hash(&self) -> JsonRpcResult<H256>;
147
148 #[method(name = "getNextNonce")]
151 async fn next_nonce(
152 &self, addr: RpcAddress, epoch_number: Option<BlockHashOrEpochNumber>,
153 ) -> JsonRpcResult<U256>;
154
155 #[method(name = "sendRawTransaction")]
167 async fn send_raw_transaction(&self, raw_tx: Bytes) -> JsonRpcResult<H256>;
168
169 #[method(name = "call")]
175 async fn call(
176 &self, tx: TransactionRequest,
177 block_hash_or_epoch_number: Option<BlockHashOrEpochNumber>,
178 ) -> JsonRpcResult<Bytes>;
179
180 #[method(name = "getLogs")]
182 async fn get_logs(
183 &self, filter: CfxRpcLogFilter,
184 ) -> JsonRpcResult<Vec<RpcLog>>;
185
186 #[method(name = "getTransactionByHash")]
188 async fn transaction_by_hash(
189 &self, tx_hash: H256,
190 ) -> JsonRpcResult<Option<Transaction>>;
191
192 #[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 #[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 #[method(name = "getAccount")]
229 async fn account(
230 &self, address: RpcAddress, epoch_num: Option<EpochNumber>,
231 ) -> JsonRpcResult<RpcAccount>;
232
233 #[method(name = "getInterestRate")]
235 async fn interest_rate(
236 &self, epoch_number: Option<EpochNumber>,
237 ) -> JsonRpcResult<U256>;
238
239 #[method(name = "getAccumulateInterestRate")]
241 async fn accumulate_interest_rate(
242 &self, epoch_number: Option<EpochNumber>,
243 ) -> JsonRpcResult<U256>;
244
245 #[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 #[method(name = "getBlockRewardInfo")]
261 async fn get_block_reward_info(
262 &self, num: EpochNumber,
263 ) -> JsonRpcResult<Vec<RpcRewardInfo>>;
264
265 #[method(name = "clientVersion")]
267 async fn get_client_version(&self) -> JsonRpcResult<String>;
268
269 #[method(name = "getSupplyInfo")]
271 async fn get_supply_info(
272 &self, epoch_number: Option<EpochNumber>,
273 ) -> JsonRpcResult<TokenSupplyInfo>;
274
275 #[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 }