fc_rpc_core/
eth.rs

1// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
2// This file is part of Frontier.
3//
4// Copyright (c) 2015-2020 Parity Technologies (UK) Ltd.
5//
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Eth rpc interface.
20
21use ethereum_types::{H160, H256, H64, U256, U64};
22use jsonrpc_core::{BoxFuture, Result};
23use jsonrpc_derive::rpc;
24
25use crate::types::{
26	BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index, Log, Receipt,
27	RichBlock, SyncStatus, Transaction, Work, TransactionRequest,
28};
29pub use rpc_impl_EthApi::gen_server::EthApi as EthApiServer;
30pub use rpc_impl_EthFilterApi::gen_server::EthFilterApi as EthFilterApiServer;
31
32/// Eth rpc interface.
33#[rpc(server)]
34pub trait EthApi {
35	/// Returns protocol version encoded as a string (quotes are necessary).
36	#[rpc(name = "eth_protocolVersion")]
37	fn protocol_version(&self) -> Result<u64>;
38
39	/// Returns an object with data about the sync status or false. (wtf?)
40	#[rpc(name = "eth_syncing")]
41	fn syncing(&self) -> Result<SyncStatus>;
42
43	/// Returns the number of hashes per second that the node is mining with.
44	#[rpc(name = "eth_hashrate")]
45	fn hashrate(&self) -> Result<U256>;
46
47	/// Returns block author.
48	#[rpc(name = "eth_coinbase")]
49	fn author(&self) -> Result<H160>;
50
51	/// Returns true if client is actively mining new blocks.
52	#[rpc(name = "eth_mining")]
53	fn is_mining(&self) -> Result<bool>;
54
55	/// Returns the chain ID used for transaction signing at the
56	/// current best block. None is returned if not
57	/// available.
58	#[rpc(name = "eth_chainId")]
59	fn chain_id(&self) -> Result<Option<U64>>;
60
61	/// Returns current gas_price.
62	#[rpc(name = "eth_gasPrice")]
63	fn gas_price(&self) -> Result<U256>;
64
65	/// Returns accounts list.
66	#[rpc(name = "eth_accounts")]
67	fn accounts(&self) -> Result<Vec<H160>>;
68
69	/// Returns highest block number.
70	#[rpc(name = "eth_blockNumber")]
71	fn block_number(&self) -> Result<U256>;
72
73	/// Returns balance of the given account.
74	#[rpc(name = "eth_getBalance")]
75	fn balance(&self, _: H160, _: Option<BlockNumber>) -> Result<U256>;
76
77	/// Returns content of the storage at given address.
78	#[rpc(name = "eth_getStorageAt")]
79	fn storage_at(&self, _: H160, _: U256, _: Option<BlockNumber>) -> Result<H256>;
80
81	/// Returns block with given hash.
82	#[rpc(name = "eth_getBlockByHash")]
83	fn block_by_hash(&self, _: H256, _: bool) -> Result<Option<RichBlock>>;
84
85	/// Returns block with given number.
86	#[rpc(name = "eth_getBlockByNumber")]
87	fn block_by_number(&self, _: BlockNumber, _: bool) -> Result<Option<RichBlock>>;
88
89	/// Returns the number of transactions sent from given address at given time (block number).
90	#[rpc(name = "eth_getTransactionCount")]
91	fn transaction_count(&self, _: H160, _: Option<BlockNumber>) -> Result<U256>;
92
93	/// Returns the number of transactions in a block with given hash.
94	#[rpc(name = "eth_getBlockTransactionCountByHash")]
95	fn block_transaction_count_by_hash(&self, _: H256) -> Result<Option<U256>>;
96
97	/// Returns the number of transactions in a block with given block number.
98	#[rpc(name = "eth_getBlockTransactionCountByNumber")]
99	fn block_transaction_count_by_number(&self, _: BlockNumber) -> Result<Option<U256>>;
100
101	/// Returns the number of uncles in a block with given hash.
102	#[rpc(name = "eth_getUncleCountByBlockHash")]
103	fn block_uncles_count_by_hash(&self, _: H256) -> Result<U256>;
104
105	/// Returns the number of uncles in a block with given block number.
106	#[rpc(name = "eth_getUncleCountByBlockNumber")]
107	fn block_uncles_count_by_number(&self, _: BlockNumber) -> Result<U256>;
108
109	/// Returns the code at given address at given time (block number).
110	#[rpc(name = "eth_getCode")]
111	fn code_at(&self, _: H160, _: Option<BlockNumber>) -> Result<Bytes>;
112
113	/// Sends transaction; will block waiting for signer to return the
114	/// transaction hash.
115	#[rpc(name = "eth_sendTransaction")]
116	fn send_transaction(&self, _: TransactionRequest) -> BoxFuture<H256>;
117
118	/// Sends signed transaction, returning its hash.
119	#[rpc(name = "eth_sendRawTransaction")]
120	fn send_raw_transaction(&self, _: Bytes) -> BoxFuture<H256>;
121
122	/// Call contract, returning the output data.
123	#[rpc(name = "eth_call")]
124	fn call(&self, _: CallRequest, _: Option<BlockNumber>) -> Result<Bytes>;
125
126	/// Estimate gas needed for execution of given contract.
127	#[rpc(name = "eth_estimateGas")]
128	fn estimate_gas(&self, _: CallRequest, _: Option<BlockNumber>) -> Result<U256>;
129
130	/// Get transaction by its hash.
131	#[rpc(name = "eth_getTransactionByHash")]
132	fn transaction_by_hash(&self, _: H256) -> Result<Option<Transaction>>;
133
134	/// Returns transaction at given block hash and index.
135	#[rpc(name = "eth_getTransactionByBlockHashAndIndex")]
136	fn transaction_by_block_hash_and_index(
137		&self,
138		_: H256,
139		_: Index,
140	) -> Result<Option<Transaction>>;
141
142	/// Returns transaction by given block number and index.
143	#[rpc(name = "eth_getTransactionByBlockNumberAndIndex")]
144	fn transaction_by_block_number_and_index(
145		&self,
146		_: BlockNumber,
147		_: Index,
148	) -> Result<Option<Transaction>>;
149
150	/// Returns transaction receipt by transaction hash.
151	#[rpc(name = "eth_getTransactionReceipt")]
152	fn transaction_receipt(&self, _: H256) -> Result<Option<Receipt>>;
153
154	/// Returns an uncles at given block and index.
155	#[rpc(name = "eth_getUncleByBlockHashAndIndex")]
156	fn uncle_by_block_hash_and_index(&self, _: H256, _: Index) -> Result<Option<RichBlock>>;
157
158	/// Returns an uncles at given block and index.
159	#[rpc(name = "eth_getUncleByBlockNumberAndIndex")]
160	fn uncle_by_block_number_and_index(
161		&self,
162		_: BlockNumber,
163		_: Index,
164	) -> Result<Option<RichBlock>>;
165
166	/// Returns logs matching given filter object.
167	#[rpc(name = "eth_getLogs")]
168	fn logs(&self, _: Filter) -> Result<Vec<Log>>;
169
170	/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
171	#[rpc(name = "eth_getWork")]
172	fn work(&self) -> Result<Work>;
173
174	/// Used for submitting a proof-of-work solution.
175	#[rpc(name = "eth_submitWork")]
176	fn submit_work(&self, _: H64, _: H256, _: H256) -> Result<bool>;
177
178	/// Used for submitting mining hashrate.
179	#[rpc(name = "eth_submitHashrate")]
180	fn submit_hashrate(&self, _: U256, _: H256) -> Result<bool>;
181}
182
183/// Eth filters rpc api (polling).
184#[rpc(server)]
185pub trait EthFilterApi {
186	/// Returns id of new filter.
187	#[rpc(name = "eth_newFilter")]
188	fn new_filter(&self, _: Filter) -> Result<U256>;
189
190	/// Returns id of new block filter.
191	#[rpc(name = "eth_newBlockFilter")]
192	fn new_block_filter(&self) -> Result<U256>;
193
194	/// Returns id of new block filter.
195	#[rpc(name = "eth_newPendingTransactionFilter")]
196	fn new_pending_transaction_filter(&self) -> Result<U256>;
197
198	/// Returns filter changes since last poll.
199	#[rpc(name = "eth_getFilterChanges")]
200	fn filter_changes(&self, _: Index) -> Result<FilterChanges>;
201
202	/// Returns all logs matching given filter (in a range 'from' - 'to').
203	#[rpc(name = "eth_getFilterLogs")]
204	fn filter_logs(&self, _: Index) -> Result<Vec<Log>>;
205
206	/// Uninstalls filter.
207	#[rpc(name = "eth_uninstallFilter")]
208	fn uninstall_filter(&self, _: Index) -> Result<bool>;
209}