2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity 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.
|
|
|
|
|
|
|
|
// Parity 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 Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-21 01:19:29 +01:00
|
|
|
//! Eth rpc interface.
|
|
|
|
use std::sync::Arc;
|
2016-01-26 13:14:22 +01:00
|
|
|
use jsonrpc_core::*;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
/// Eth rpc interface.
|
|
|
|
pub trait Eth: Sized + Send + Sync + 'static {
|
|
|
|
/// Returns protocol version.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn protocol_version(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
2016-02-05 13:21:34 +01:00
|
|
|
/// Returns an object with data about the sync status or false. (wtf?)
|
2016-05-27 20:04:41 +02:00
|
|
|
fn syncing(&self, _: Params) -> Result<Value, Error>;
|
2016-02-05 13:21:34 +01:00
|
|
|
|
2016-01-27 18:17:20 +01:00
|
|
|
/// Returns the number of hashes per second that the node is mining with.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn hashrate(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
/// Returns block author.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn author(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns true if client is actively mining new blocks.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn is_mining(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
/// Returns current gas_price.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn gas_price(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns accounts list.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn accounts(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
/// Returns highest block number.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_number(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns balance of the given account.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn balance(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns content of the storage at given address.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn storage_at(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
2016-02-10 22:54:12 +01:00
|
|
|
/// Returns block with given hash.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_by_hash(&self, _: Params) -> Result<Value, Error>;
|
2016-02-10 22:54:12 +01:00
|
|
|
|
|
|
|
/// Returns block with given number.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_by_number(&self, _: Params) -> Result<Value, Error>;
|
2016-02-25 16:58:18 +01:00
|
|
|
|
2016-01-27 18:17:20 +01:00
|
|
|
/// Returns the number of transactions sent from given address at given time (block number).
|
2016-05-27 20:04:41 +02:00
|
|
|
fn transaction_count(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
2016-03-13 14:37:33 +01:00
|
|
|
/// Returns the number of transactions in a block with given hash.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_transaction_count_by_hash(&self, _: Params) -> Result<Value, Error>;
|
2016-02-25 16:58:18 +01:00
|
|
|
|
2016-03-13 14:37:33 +01:00
|
|
|
/// Returns the number of transactions in a block with given block number.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_transaction_count_by_number(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
2016-03-13 14:37:33 +01:00
|
|
|
/// Returns the number of uncles in a block with given hash.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_uncles_count_by_hash(&self, _: Params) -> Result<Value, Error>;
|
2016-03-13 14:37:33 +01:00
|
|
|
|
|
|
|
/// Returns the number of uncles in a block with given block number.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn block_uncles_count_by_number(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns the code at given address at given time (block number).
|
2016-05-27 20:04:41 +02:00
|
|
|
fn code_at(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
2016-03-13 14:57:26 +01:00
|
|
|
/// Sends signed transaction.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn send_raw_transaction(&self, _: Params) -> Result<Value, Error>;
|
2016-03-13 14:57:26 +01:00
|
|
|
|
2016-01-27 18:17:20 +01:00
|
|
|
/// Call contract.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn call(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Estimate gas needed for execution of given contract.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn estimate_gas(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
2016-07-19 20:42:23 +02:00
|
|
|
/// Get transaction by its hash.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn transaction_by_hash(&self, _: Params) -> Result<Value, Error>;
|
2016-02-10 10:12:56 +01:00
|
|
|
|
|
|
|
/// Returns transaction at given block hash and index.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn transaction_by_block_hash_and_index(&self, _: Params) -> Result<Value, Error>;
|
2016-02-10 10:12:56 +01:00
|
|
|
|
|
|
|
/// Returns transaction by given block number and index.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn transaction_by_block_number_and_index(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns transaction receipt.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn transaction_receipt(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns an uncles at given block and index.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn uncle_by_block_hash_and_index(&self, _: Params) -> Result<Value, Error>;
|
2016-03-14 17:01:10 +01:00
|
|
|
|
|
|
|
/// Returns an uncles at given block and index.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn uncle_by_block_number_and_index(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns available compilers.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn compilers(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Compiles lll code.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn compile_lll(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Compiles solidity.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn compile_solidity(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Compiles serpent.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn compile_serpent(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns logs matching given filter object.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn logs(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn work(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Used for submitting a proof-of-work solution.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn submit_work(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 18:17:20 +01:00
|
|
|
|
|
|
|
/// Used for submitting mining hashrate.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn submit_hashrate(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
/// Should be used to convert object to io delegate.
|
|
|
|
fn to_delegate(self) -> IoDelegate<Self> {
|
|
|
|
let mut delegate = IoDelegate::new(Arc::new(self));
|
|
|
|
delegate.add_method("eth_protocolVersion", Eth::protocol_version);
|
2016-02-05 13:21:34 +01:00
|
|
|
delegate.add_method("eth_syncing", Eth::syncing);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_hashrate", Eth::hashrate);
|
2016-01-21 01:19:29 +01:00
|
|
|
delegate.add_method("eth_coinbase", Eth::author);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_mining", Eth::is_mining);
|
2016-01-21 01:19:29 +01:00
|
|
|
delegate.add_method("eth_gasPrice", Eth::gas_price);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_accounts", Eth::accounts);
|
2016-01-21 01:19:29 +01:00
|
|
|
delegate.add_method("eth_blockNumber", Eth::block_number);
|
2016-03-12 19:51:24 +01:00
|
|
|
delegate.add_method("eth_getBalance", Eth::balance);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_getStorageAt", Eth::storage_at);
|
|
|
|
delegate.add_method("eth_getTransactionCount", Eth::transaction_count);
|
2016-02-25 16:58:18 +01:00
|
|
|
delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count_by_hash);
|
|
|
|
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count_by_number);
|
2016-03-13 14:37:33 +01:00
|
|
|
delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count_by_hash);
|
|
|
|
delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count_by_number);
|
2016-03-13 14:45:39 +01:00
|
|
|
delegate.add_method("eth_getCode", Eth::code_at);
|
2016-03-13 14:57:26 +01:00
|
|
|
delegate.add_method("eth_sendRawTransaction", Eth::send_raw_transaction);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_call", Eth::call);
|
|
|
|
delegate.add_method("eth_estimateGas", Eth::estimate_gas);
|
2016-02-10 22:54:12 +01:00
|
|
|
delegate.add_method("eth_getBlockByHash", Eth::block_by_hash);
|
|
|
|
delegate.add_method("eth_getBlockByNumber", Eth::block_by_number);
|
2016-02-10 10:12:56 +01:00
|
|
|
delegate.add_method("eth_getTransactionByHash", Eth::transaction_by_hash);
|
|
|
|
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_by_block_hash_and_index);
|
|
|
|
delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_by_block_number_and_index);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt);
|
2016-03-14 17:01:10 +01:00
|
|
|
delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_by_block_hash_and_index);
|
|
|
|
delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_by_block_number_and_index);
|
2016-01-27 18:17:20 +01:00
|
|
|
delegate.add_method("eth_getCompilers", Eth::compilers);
|
|
|
|
delegate.add_method("eth_compileLLL", Eth::compile_lll);
|
|
|
|
delegate.add_method("eth_compileSolidity", Eth::compile_solidity);
|
|
|
|
delegate.add_method("eth_compileSerpent", Eth::compile_serpent);
|
|
|
|
delegate.add_method("eth_getLogs", Eth::logs);
|
|
|
|
delegate.add_method("eth_getWork", Eth::work);
|
|
|
|
delegate.add_method("eth_submitWork", Eth::submit_work);
|
|
|
|
delegate.add_method("eth_submitHashrate", Eth::submit_hashrate);
|
2016-01-21 01:19:29 +01:00
|
|
|
delegate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-27 17:08:59 +01:00
|
|
|
/// Eth filters rpc api (polling).
|
2016-01-27 14:32:10 +01:00
|
|
|
// TODO: do filters api properly
|
2016-01-21 11:25:39 +01:00
|
|
|
pub trait EthFilter: Sized + Send + Sync + 'static {
|
2016-01-27 19:00:42 +01:00
|
|
|
/// Returns id of new filter.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn new_filter(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 19:00:42 +01:00
|
|
|
|
|
|
|
/// Returns id of new block filter.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn new_block_filter(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 11:25:39 +01:00
|
|
|
|
2016-01-27 19:00:42 +01:00
|
|
|
/// Returns id of new block filter.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn new_pending_transaction_filter(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 11:25:39 +01:00
|
|
|
|
2016-01-27 19:00:42 +01:00
|
|
|
/// Returns filter changes since last poll.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn filter_changes(&self, _: Params) -> Result<Value, Error>;
|
2016-01-21 11:25:39 +01:00
|
|
|
|
2016-04-10 20:42:03 +02:00
|
|
|
/// Returns all logs matching given filter (in a range 'from' - 'to').
|
2016-05-27 20:04:41 +02:00
|
|
|
fn filter_logs(&self, _: Params) -> Result<Value, Error>;
|
2016-04-10 20:42:03 +02:00
|
|
|
|
2016-01-27 19:00:42 +01:00
|
|
|
/// Uninstalls filter.
|
2016-05-27 20:04:41 +02:00
|
|
|
fn uninstall_filter(&self, _: Params) -> Result<Value, Error>;
|
2016-01-27 19:00:42 +01:00
|
|
|
|
2016-01-21 11:25:39 +01:00
|
|
|
/// Should be used to convert object to io delegate.
|
|
|
|
fn to_delegate(self) -> IoDelegate<Self> {
|
|
|
|
let mut delegate = IoDelegate::new(Arc::new(self));
|
2016-01-27 19:00:42 +01:00
|
|
|
delegate.add_method("eth_newFilter", EthFilter::new_filter);
|
2016-01-21 11:25:39 +01:00
|
|
|
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
|
|
|
|
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
|
2016-01-25 17:45:26 +01:00
|
|
|
delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes);
|
2016-04-10 20:42:03 +02:00
|
|
|
delegate.add_method("eth_getFilterLogs", EthFilter::filter_logs);
|
2016-01-27 19:00:42 +01:00
|
|
|
delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter);
|
2016-01-21 11:25:39 +01:00
|
|
|
delegate
|
|
|
|
}
|
|
|
|
}
|
2016-06-01 19:37:34 +02:00
|
|
|
|
|
|
|
/// Signing methods implementation relying on unlocked accounts.
|
|
|
|
pub trait EthSigning: Sized + Send + Sync + 'static {
|
|
|
|
/// Signs the data with given address signature.
|
2016-09-01 12:00:00 +02:00
|
|
|
fn sign(&self, _: Params, _: Ready);
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Posts sign request asynchronously.
|
|
|
|
/// Will return a confirmation ID for later use with check_transaction.
|
|
|
|
fn post_sign(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-07-19 09:19:58 +02:00
|
|
|
/// Sends transaction; will block for 20s to try to return the
|
|
|
|
/// transaction hash.
|
|
|
|
/// If it cannot yet be signed, it will return a transaction ID for
|
2016-08-03 10:36:54 +02:00
|
|
|
/// later use with check_transaction.
|
2016-09-01 12:00:00 +02:00
|
|
|
fn send_transaction(&self, _: Params, _: Ready);
|
2016-06-01 19:37:34 +02:00
|
|
|
|
2016-07-19 09:19:58 +02:00
|
|
|
/// Posts transaction asynchronously.
|
2016-08-03 10:36:54 +02:00
|
|
|
/// Will return a transaction ID for later use with check_transaction.
|
2016-07-19 09:19:58 +02:00
|
|
|
fn post_transaction(&self, _: Params) -> Result<Value, Error>;
|
|
|
|
|
2016-08-04 16:42:29 +02:00
|
|
|
/// Checks the progress of a previously posted request (transaction/sign).
|
2016-07-19 09:19:58 +02:00
|
|
|
/// Should be given a valid send_transaction ID.
|
|
|
|
/// Returns the transaction hash, the zero hash (not yet available),
|
2016-08-04 16:42:29 +02:00
|
|
|
/// or the signature,
|
2016-08-03 10:36:54 +02:00
|
|
|
/// or an error.
|
2016-08-04 16:42:29 +02:00
|
|
|
fn check_request(&self, _: Params) -> Result<Value, Error>;
|
2016-07-19 09:19:58 +02:00
|
|
|
|
2016-06-01 19:37:34 +02:00
|
|
|
/// Should be used to convert object to io delegate.
|
|
|
|
fn to_delegate(self) -> IoDelegate<Self> {
|
|
|
|
let mut delegate = IoDelegate::new(Arc::new(self));
|
2016-09-01 12:00:00 +02:00
|
|
|
delegate.add_async_method("eth_sign", EthSigning::sign);
|
|
|
|
delegate.add_async_method("eth_sendTransaction", EthSigning::send_transaction);
|
2016-08-04 16:42:29 +02:00
|
|
|
delegate.add_method("eth_postSign", EthSigning::post_sign);
|
2016-07-19 09:19:58 +02:00
|
|
|
delegate.add_method("eth_postTransaction", EthSigning::post_transaction);
|
2016-08-04 16:42:29 +02:00
|
|
|
delegate.add_method("eth_checkRequest", EthSigning::check_request);
|
2016-06-01 19:37:34 +02:00
|
|
|
delegate
|
|
|
|
}
|
|
|
|
}
|