1use ethereum_types::{H160, H256, H64, U256, U64};
22use jsonrpsee::{core::RpcResult, proc_macros::rpc};
23use std::collections::BTreeMap;
24
25use crate::types::*;
26
27#[rpc(server)]
29#[async_trait]
30pub trait EthApi {
31 #[method(name = "eth_protocolVersion")]
37 fn protocol_version(&self) -> RpcResult<u64>;
38
39 #[method(name = "eth_syncing")]
41 async fn syncing(&self) -> RpcResult<SyncStatus>;
42
43 #[method(name = "eth_coinbase")]
45 fn author(&self) -> RpcResult<H160>;
46
47 #[method(name = "eth_accounts")]
49 fn accounts(&self) -> RpcResult<Vec<H160>>;
50
51 #[method(name = "eth_blockNumber")]
53 fn block_number(&self) -> RpcResult<U256>;
54
55 #[method(name = "eth_chainId")]
59 fn chain_id(&self) -> RpcResult<Option<U64>>;
60
61 #[method(name = "eth_getBlockByHash")]
67 async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult<Option<RichBlock>>;
68
69 #[method(name = "eth_getBlockByNumber")]
71 async fn block_by_number(
72 &self,
73 number_or_hash: BlockNumberOrHash,
74 full: bool,
75 ) -> RpcResult<Option<RichBlock>>;
76
77 #[method(name = "eth_getBlockTransactionCountByHash")]
79 async fn block_transaction_count_by_hash(&self, hash: H256) -> RpcResult<Option<U256>>;
80
81 #[method(name = "eth_getBlockTransactionCountByNumber")]
83 async fn block_transaction_count_by_number(
84 &self,
85 number_or_hash: BlockNumberOrHash,
86 ) -> RpcResult<Option<U256>>;
87
88 #[method(name = "eth_getBlockReceipts")]
90 async fn block_transaction_receipts(
91 &self,
92 number_or_hash: BlockNumberOrHash,
93 ) -> RpcResult<Option<Vec<Receipt>>>;
94
95 #[method(name = "eth_getUncleCountByBlockHash")]
97 fn block_uncles_count_by_hash(&self, hash: H256) -> RpcResult<U256>;
98
99 #[method(name = "eth_getUncleCountByBlockNumber")]
101 fn block_uncles_count_by_number(&self, number_or_hash: BlockNumberOrHash) -> RpcResult<U256>;
102
103 #[method(name = "eth_getUncleByBlockHashAndIndex")]
105 fn uncle_by_block_hash_and_index(
106 &self,
107 hash: H256,
108 index: Index,
109 ) -> RpcResult<Option<RichBlock>>;
110
111 #[method(name = "eth_getUncleByBlockNumberAndIndex")]
113 fn uncle_by_block_number_and_index(
114 &self,
115 number_or_hash: BlockNumberOrHash,
116 index: Index,
117 ) -> RpcResult<Option<RichBlock>>;
118
119 #[method(name = "eth_getTransactionByHash")]
125 async fn transaction_by_hash(&self, hash: H256) -> RpcResult<Option<Transaction>>;
126
127 #[method(name = "eth_getTransactionByBlockHashAndIndex")]
129 async fn transaction_by_block_hash_and_index(
130 &self,
131 hash: H256,
132 index: Index,
133 ) -> RpcResult<Option<Transaction>>;
134
135 #[method(name = "eth_getTransactionByBlockNumberAndIndex")]
137 async fn transaction_by_block_number_and_index(
138 &self,
139 number_or_hash: BlockNumberOrHash,
140 index: Index,
141 ) -> RpcResult<Option<Transaction>>;
142
143 #[method(name = "eth_getTransactionReceipt")]
145 async fn transaction_receipt(&self, hash: H256) -> RpcResult<Option<Receipt>>;
146
147 #[method(name = "eth_getBalance")]
153 async fn balance(
154 &self,
155 address: H160,
156 number_or_hash: Option<BlockNumberOrHash>,
157 ) -> RpcResult<U256>;
158
159 #[method(name = "eth_getStorageAt")]
161 async fn storage_at(
162 &self,
163 address: H160,
164 index: U256,
165 number_or_hash: Option<BlockNumberOrHash>,
166 ) -> RpcResult<H256>;
167
168 #[method(name = "eth_getTransactionCount")]
170 async fn transaction_count(
171 &self,
172 address: H160,
173 number_or_hash: Option<BlockNumberOrHash>,
174 ) -> RpcResult<U256>;
175
176 #[method(name = "eth_getCode")]
178 async fn code_at(
179 &self,
180 address: H160,
181 number_or_hash: Option<BlockNumberOrHash>,
182 ) -> RpcResult<Bytes>;
183
184 #[method(name = "eth_call")]
190 async fn call(
191 &self,
192 request: TransactionRequest,
193 number_or_hash: Option<BlockNumberOrHash>,
194 state_overrides: Option<BTreeMap<H160, CallStateOverride>>,
195 ) -> RpcResult<Bytes>;
196
197 #[method(name = "eth_estimateGas")]
199 async fn estimate_gas(
200 &self,
201 request: TransactionRequest,
202 number_or_hash: Option<BlockNumberOrHash>,
203 ) -> RpcResult<U256>;
204
205 #[method(name = "eth_pendingTransactions")]
207 async fn pending_transactions(&self) -> RpcResult<Vec<Transaction>>;
208
209 #[method(name = "eth_gasPrice")]
215 fn gas_price(&self) -> RpcResult<U256>;
216
217 #[method(name = "eth_feeHistory")]
219 async fn fee_history(
220 &self,
221 block_count: BlockCount,
222 newest_block: BlockNumberOrHash,
223 reward_percentiles: Option<Vec<f64>>,
224 ) -> RpcResult<FeeHistory>;
225
226 #[method(name = "eth_maxPriorityFeePerGas")]
229 fn max_priority_fee_per_gas(&self) -> RpcResult<U256>;
230
231 #[method(name = "eth_mining")]
237 fn is_mining(&self) -> RpcResult<bool>;
238
239 #[method(name = "eth_hashrate")]
241 fn hashrate(&self) -> RpcResult<U256>;
242
243 #[method(name = "eth_getWork")]
245 fn work(&self) -> RpcResult<Work>;
246
247 #[method(name = "eth_submitHashrate")]
249 fn submit_hashrate(&self, hashrate: U256, id: H256) -> RpcResult<bool>;
250
251 #[method(name = "eth_submitWork")]
253 fn submit_work(&self, nonce: H64, pow_hash: H256, mix_digest: H256) -> RpcResult<bool>;
254
255 #[method(name = "eth_sendTransaction")]
262 async fn send_transaction(&self, request: TransactionRequest) -> RpcResult<H256>;
263
264 #[method(name = "eth_sendRawTransaction")]
266 async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<H256>;
267}
268
269#[rpc(server)]
271pub trait EthFilterApi {
272 #[method(name = "eth_newFilter")]
274 fn new_filter(&self, filter: Filter) -> RpcResult<U256>;
275
276 #[method(name = "eth_newBlockFilter")]
278 fn new_block_filter(&self) -> RpcResult<U256>;
279
280 #[method(name = "eth_newPendingTransactionFilter")]
282 fn new_pending_transaction_filter(&self) -> RpcResult<U256>;
283
284 #[method(name = "eth_getFilterChanges")]
286 async fn filter_changes(&self, index: Index) -> RpcResult<FilterChanges>;
287
288 #[method(name = "eth_getFilterLogs")]
290 async fn filter_logs(&self, index: Index) -> RpcResult<Vec<Log>>;
291
292 #[method(name = "eth_uninstallFilter")]
294 fn uninstall_filter(&self, index: Index) -> RpcResult<bool>;
295
296 #[method(name = "eth_getLogs")]
298 async fn logs(&self, filter: Filter) -> RpcResult<Vec<Log>>;
299}