ic_solidity_bindgen/
rpc_methods.rs

1use ic_web3_rs::{
2    helpers,
3    types::{Address, BlockNumber, U256},
4};
5use serde_json::Value;
6
7pub enum EVMRpcMethod {
8    TransactionCount(Address, BlockNumber),
9    GasPrice,
10    /// BlockCount, BlockTag, RewardPercentile
11    FeeHistory(U256, BlockNumber, Option<Vec<f64>>),
12    MaxPriorityFeePerGas,
13}
14
15impl EVMRpcMethod {
16    pub fn method(&self) -> &str {
17        match self {
18            Self::TransactionCount(_, _) => "eth_getTransactionCount",
19            Self::GasPrice => "eth_gasPrice",
20            Self::MaxPriorityFeePerGas => "eth_maxPriorityFeePerGas",
21            Self::FeeHistory(_, _, _) => "eth_feeHistory",
22        }
23    }
24    pub fn params(&self) -> Vec<Value> {
25        match self {
26            EVMRpcMethod::FeeHistory(block_count, newest_block, reward_percentiles) => {
27                vec![
28                    helpers::serialize(&block_count),
29                    helpers::serialize(&newest_block),
30                    helpers::serialize(&reward_percentiles),
31                ]
32            }
33            EVMRpcMethod::TransactionCount(address, block_number) => vec![
34                helpers::serialize(&address),
35                helpers::serialize(&block_number),
36            ],
37            _ => vec![],
38        }
39    }
40}