1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This file is part of Frontier.
//
// Copyright (c) 2015-2020 Parity Technologies (UK) Ltd.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Eth rpc interface.

use ethereum_types::{H160, H256, H64, U256, U64};
use jsonrpc_core::{BoxFuture, Result};
use jsonrpc_derive::rpc;

use crate::types::{
	BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index, Log, Receipt,
	RichBlock, SyncStatus, Transaction, Work, TransactionRequest,
};
pub use rpc_impl_EthApi::gen_server::EthApi as EthApiServer;
pub use rpc_impl_EthFilterApi::gen_server::EthFilterApi as EthFilterApiServer;

/// Eth rpc interface.
#[rpc(server)]
pub trait EthApi {
	/// Returns protocol version encoded as a string (quotes are necessary).
	#[rpc(name = "eth_protocolVersion")]
	fn protocol_version(&self) -> Result<u64>;

	/// Returns an object with data about the sync status or false. (wtf?)
	#[rpc(name = "eth_syncing")]
	fn syncing(&self) -> Result<SyncStatus>;

	/// Returns the number of hashes per second that the node is mining with.
	#[rpc(name = "eth_hashrate")]
	fn hashrate(&self) -> Result<U256>;

	/// Returns block author.
	#[rpc(name = "eth_coinbase")]
	fn author(&self) -> Result<H160>;

	/// Returns true if client is actively mining new blocks.
	#[rpc(name = "eth_mining")]
	fn is_mining(&self) -> Result<bool>;

	/// Returns the chain ID used for transaction signing at the
	/// current best block. None is returned if not
	/// available.
	#[rpc(name = "eth_chainId")]
	fn chain_id(&self) -> Result<Option<U64>>;

	/// Returns current gas_price.
	#[rpc(name = "eth_gasPrice")]
	fn gas_price(&self) -> Result<U256>;

	/// Returns accounts list.
	#[rpc(name = "eth_accounts")]
	fn accounts(&self) -> Result<Vec<H160>>;

	/// Returns highest block number.
	#[rpc(name = "eth_blockNumber")]
	fn block_number(&self) -> Result<U256>;

	/// Returns balance of the given account.
	#[rpc(name = "eth_getBalance")]
	fn balance(&self, _: H160, _: Option<BlockNumber>) -> Result<U256>;

	/// Returns content of the storage at given address.
	#[rpc(name = "eth_getStorageAt")]
	fn storage_at(&self, _: H160, _: U256, _: Option<BlockNumber>) -> Result<H256>;

	/// Returns block with given hash.
	#[rpc(name = "eth_getBlockByHash")]
	fn block_by_hash(&self, _: H256, _: bool) -> Result<Option<RichBlock>>;

	/// Returns block with given number.
	#[rpc(name = "eth_getBlockByNumber")]
	fn block_by_number(&self, _: BlockNumber, _: bool) -> Result<Option<RichBlock>>;

	/// Returns the number of transactions sent from given address at given time (block number).
	#[rpc(name = "eth_getTransactionCount")]
	fn transaction_count(&self, _: H160, _: Option<BlockNumber>) -> Result<U256>;

	/// Returns the number of transactions in a block with given hash.
	#[rpc(name = "eth_getBlockTransactionCountByHash")]
	fn block_transaction_count_by_hash(&self, _: H256) -> Result<Option<U256>>;

	/// Returns the number of transactions in a block with given block number.
	#[rpc(name = "eth_getBlockTransactionCountByNumber")]
	fn block_transaction_count_by_number(&self, _: BlockNumber) -> Result<Option<U256>>;

	/// Returns the number of uncles in a block with given hash.
	#[rpc(name = "eth_getUncleCountByBlockHash")]
	fn block_uncles_count_by_hash(&self, _: H256) -> Result<U256>;

	/// Returns the number of uncles in a block with given block number.
	#[rpc(name = "eth_getUncleCountByBlockNumber")]
	fn block_uncles_count_by_number(&self, _: BlockNumber) -> Result<U256>;

	/// Returns the code at given address at given time (block number).
	#[rpc(name = "eth_getCode")]
	fn code_at(&self, _: H160, _: Option<BlockNumber>) -> Result<Bytes>;

	/// Sends transaction; will block waiting for signer to return the
	/// transaction hash.
	#[rpc(name = "eth_sendTransaction")]
	fn send_transaction(&self, _: TransactionRequest) -> BoxFuture<H256>;

	/// Sends signed transaction, returning its hash.
	#[rpc(name = "eth_sendRawTransaction")]
	fn send_raw_transaction(&self, _: Bytes) -> BoxFuture<H256>;

	/// Call contract, returning the output data.
	#[rpc(name = "eth_call")]
	fn call(&self, _: CallRequest, _: Option<BlockNumber>) -> Result<Bytes>;

	/// Estimate gas needed for execution of given contract.
	#[rpc(name = "eth_estimateGas")]
	fn estimate_gas(&self, _: CallRequest, _: Option<BlockNumber>) -> Result<U256>;

	/// Get transaction by its hash.
	#[rpc(name = "eth_getTransactionByHash")]
	fn transaction_by_hash(&self, _: H256) -> Result<Option<Transaction>>;

	/// Returns transaction at given block hash and index.
	#[rpc(name = "eth_getTransactionByBlockHashAndIndex")]
	fn transaction_by_block_hash_and_index(
		&self,
		_: H256,
		_: Index,
	) -> Result<Option<Transaction>>;

	/// Returns transaction by given block number and index.
	#[rpc(name = "eth_getTransactionByBlockNumberAndIndex")]
	fn transaction_by_block_number_and_index(
		&self,
		_: BlockNumber,
		_: Index,
	) -> Result<Option<Transaction>>;

	/// Returns transaction receipt by transaction hash.
	#[rpc(name = "eth_getTransactionReceipt")]
	fn transaction_receipt(&self, _: H256) -> Result<Option<Receipt>>;

	/// Returns an uncles at given block and index.
	#[rpc(name = "eth_getUncleByBlockHashAndIndex")]
	fn uncle_by_block_hash_and_index(&self, _: H256, _: Index) -> Result<Option<RichBlock>>;

	/// Returns an uncles at given block and index.
	#[rpc(name = "eth_getUncleByBlockNumberAndIndex")]
	fn uncle_by_block_number_and_index(
		&self,
		_: BlockNumber,
		_: Index,
	) -> Result<Option<RichBlock>>;

	/// Returns logs matching given filter object.
	#[rpc(name = "eth_getLogs")]
	fn logs(&self, _: Filter) -> Result<Vec<Log>>;

	/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
	#[rpc(name = "eth_getWork")]
	fn work(&self) -> Result<Work>;

	/// Used for submitting a proof-of-work solution.
	#[rpc(name = "eth_submitWork")]
	fn submit_work(&self, _: H64, _: H256, _: H256) -> Result<bool>;

	/// Used for submitting mining hashrate.
	#[rpc(name = "eth_submitHashrate")]
	fn submit_hashrate(&self, _: U256, _: H256) -> Result<bool>;
}

/// Eth filters rpc api (polling).
#[rpc(server)]
pub trait EthFilterApi {
	/// Returns id of new filter.
	#[rpc(name = "eth_newFilter")]
	fn new_filter(&self, _: Filter) -> Result<U256>;

	/// Returns id of new block filter.
	#[rpc(name = "eth_newBlockFilter")]
	fn new_block_filter(&self) -> Result<U256>;

	/// Returns id of new block filter.
	#[rpc(name = "eth_newPendingTransactionFilter")]
	fn new_pending_transaction_filter(&self) -> Result<U256>;

	/// Returns filter changes since last poll.
	#[rpc(name = "eth_getFilterChanges")]
	fn filter_changes(&self, _: Index) -> Result<FilterChanges>;

	/// Returns all logs matching given filter (in a range 'from' - 'to').
	#[rpc(name = "eth_getFilterLogs")]
	fn filter_logs(&self, _: Index) -> Result<Vec<Log>>;

	/// Uninstalls filter.
	#[rpc(name = "eth_uninstallFilter")]
	fn uninstall_filter(&self, _: Index) -> Result<bool>;
}