openethereum/rpc/src/v1/traits/eth.rs

219 lines
8.0 KiB
Rust
Raw Normal View History

// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
2016-02-05 13:40:41 +01:00
// Parity Ethereum is free software: you can redistribute it and/or modify
2016-02-05 13:40:41 +01:00
// 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 Ethereum is distributed in the hope that it will be useful,
2016-02-05 13:40:41 +01:00
// 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
2016-02-05 13:40:41 +01:00
2016-01-21 01:19:29 +01:00
//! Eth rpc interface.
2017-11-14 11:38:17 +01:00
use jsonrpc_core::{Result, BoxFuture};
use jsonrpc_macros::Trailing;
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index, EthAccount};
use v1::types::{Log, Receipt, SyncStatus, Transaction, Work};
use v1::types::{H64, H160, H256, U256, U64};
build_rpc_trait! {
/// Eth rpc interface.
pub trait Eth {
type Metadata;
/// Returns protocol version encoded as a string (quotes are necessary).
#[rpc(name = "eth_protocolVersion")]
2017-11-14 11:38:17 +01:00
fn protocol_version(&self) -> Result<String>;
2016-02-05 13:21:34 +01:00
/// Returns an object with data about the sync status or false. (wtf?)
#[rpc(name = "eth_syncing")]
2017-11-14 11:38:17 +01:00
fn syncing(&self) -> Result<SyncStatus>;
2016-01-21 01:19:29 +01:00
/// Returns the number of hashes per second that the node is mining with.
#[rpc(name = "eth_hashrate")]
2017-11-14 11:38:17 +01:00
fn hashrate(&self) -> Result<U256>;
2016-01-27 18:17:20 +01:00
/// Returns block author.
#[rpc(name = "eth_coinbase")]
fn author(&self) -> Result<H160>;
2016-01-21 01:19:29 +01:00
/// Returns true if client is actively mining new blocks.
#[rpc(name = "eth_mining")]
2017-11-14 11:38:17 +01:00
fn is_mining(&self) -> Result<bool>;
2016-01-27 18:17:20 +01:00
/// 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")]
2017-11-14 11:38:17 +01:00
fn gas_price(&self) -> Result<U256>;
2016-01-21 01:19:29 +01:00
/// Returns accounts list.
#[rpc(name = "eth_accounts")]
fn accounts(&self) -> Result<Vec<H160>>;
2016-01-27 18:17:20 +01:00
/// Returns highest block number.
#[rpc(name = "eth_blockNumber")]
2017-11-14 11:38:17 +01:00
fn block_number(&self) -> Result<U256>;
2016-01-27 18:17:20 +01:00
/// Returns balance of the given account.
#[rpc(name = "eth_getBalance")]
2017-11-14 11:38:17 +01:00
fn balance(&self, H160, Trailing<BlockNumber>) -> BoxFuture<U256>;
2016-01-21 01:19:29 +01:00
EIP-1186: add `eth_getProof` RPC-Method (#9001) * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed imports;2C * removed spaces * fixed whitespace * fixed docker * added doc * fixed Compile-error * expose more ports * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * fixed Compile-error * added eth_getAccount * changed to getProof * implemented storage_proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed warnings * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * Update Dockerfile * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * added eth_getAccount * changed to getProof * implemented storage_proof * removed spaces * fixed whitespace * fixed docker * added eth_getAccount * changed to getProof * implemented storage_proof * better formatting of storage proof * fixed docker * removed slockit-changes * fixed Dockerfile * intend * spaces * removed spaces * fixed whitespace * fixed docker * tabs * merged changes * fixed merge error * fixed formatting * fixed rename_all = "camelCase" * fixed tabs * fixed spaces * removed port exposer * formatting * fixed comment * use filter_map * formatting * use better variable names * changed casting * fixed tabs * remote into() from address * remove space Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed storage_index Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed clone * fixed format Co-Authored-By: simon-jentzsch <simon@slock.it> * fixed empty lines * removed Option from EthAccount * fixed storage_index * implemented test and fixed the struct-spaces * fixed tests * added experimental RPCs flag for getProof * optmized code
2018-11-21 20:09:33 +01:00
/// Returns the account- and storage-values of the specified account including the Merkle-proof
#[rpc(name = "eth_getProof")]
fn proof(&self, H160, Vec<H256>, Trailing<BlockNumber>) -> BoxFuture<EthAccount>;
/// Returns content of the storage at given address.
#[rpc(name = "eth_getStorageAt")]
2017-11-14 11:38:17 +01:00
fn storage_at(&self, H160, U256, Trailing<BlockNumber>) -> BoxFuture<H256>;
/// Returns block with given hash.
#[rpc(name = "eth_getBlockByHash")]
2017-11-14 11:38:17 +01:00
fn block_by_hash(&self, H256, bool) -> BoxFuture<Option<RichBlock>>;
/// Returns block with given number.
#[rpc(name = "eth_getBlockByNumber")]
2017-11-14 11:38:17 +01:00
fn block_by_number(&self, BlockNumber, bool) -> BoxFuture<Option<RichBlock>>;
/// Returns the number of transactions sent from given address at given time (block number).
#[rpc(name = "eth_getTransactionCount")]
2017-11-14 11:38:17 +01:00
fn transaction_count(&self, H160, Trailing<BlockNumber>) -> BoxFuture<U256>;
/// Returns the number of transactions in a block with given hash.
#[rpc(name = "eth_getBlockTransactionCountByHash")]
2017-11-14 11:38:17 +01:00
fn block_transaction_count_by_hash(&self, H256) -> BoxFuture<Option<U256>>;
/// Returns the number of transactions in a block with given block number.
#[rpc(name = "eth_getBlockTransactionCountByNumber")]
2017-11-14 11:38:17 +01:00
fn block_transaction_count_by_number(&self, BlockNumber) -> BoxFuture<Option<U256>>;
/// Returns the number of uncles in a block with given hash.
#[rpc(name = "eth_getUncleCountByBlockHash")]
2017-11-14 11:38:17 +01:00
fn block_uncles_count_by_hash(&self, H256) -> BoxFuture<Option<U256>>;
/// Returns the number of uncles in a block with given block number.
#[rpc(name = "eth_getUncleCountByBlockNumber")]
2017-11-14 11:38:17 +01:00
fn block_uncles_count_by_number(&self, BlockNumber) -> BoxFuture<Option<U256>>;
/// Returns the code at given address at given time (block number).
#[rpc(name = "eth_getCode")]
2017-11-14 11:38:17 +01:00
fn code_at(&self, H160, Trailing<BlockNumber>) -> BoxFuture<Bytes>;
/// Sends signed transaction, returning its hash.
#[rpc(name = "eth_sendRawTransaction")]
2017-11-14 11:38:17 +01:00
fn send_raw_transaction(&self, Bytes) -> Result<H256>;
/// @alias of `eth_sendRawTransaction`.
2016-11-18 11:03:29 +01:00
#[rpc(name = "eth_submitTransaction")]
2017-11-14 11:38:17 +01:00
fn submit_transaction(&self, Bytes) -> Result<H256>;
2016-11-18 11:03:29 +01:00
/// Call contract, returning the output data.
#[rpc(name = "eth_call")]
fn call(&self, CallRequest, Trailing<BlockNumber>) -> BoxFuture<Bytes>;
/// Estimate gas needed for execution of given contract.
#[rpc(name = "eth_estimateGas")]
fn estimate_gas(&self, CallRequest, Trailing<BlockNumber>) -> BoxFuture<U256>;
/// Get transaction by its hash.
#[rpc(name = "eth_getTransactionByHash")]
2017-11-14 11:38:17 +01:00
fn transaction_by_hash(&self, H256) -> BoxFuture<Option<Transaction>>;
/// Returns transaction at given block hash and index.
#[rpc(name = "eth_getTransactionByBlockHashAndIndex")]
2017-11-14 11:38:17 +01:00
fn transaction_by_block_hash_and_index(&self, H256, Index) -> BoxFuture<Option<Transaction>>;
/// Returns transaction by given block number and index.
#[rpc(name = "eth_getTransactionByBlockNumberAndIndex")]
2017-11-14 11:38:17 +01:00
fn transaction_by_block_number_and_index(&self, BlockNumber, Index) -> BoxFuture<Option<Transaction>>;
/// Returns transaction receipt by transaction hash.
#[rpc(name = "eth_getTransactionReceipt")]
2017-11-14 11:38:17 +01:00
fn transaction_receipt(&self, H256) -> BoxFuture<Option<Receipt>>;
/// Returns an uncles at given block and index.
#[rpc(name = "eth_getUncleByBlockHashAndIndex")]
2017-11-14 11:38:17 +01:00
fn uncle_by_block_hash_and_index(&self, H256, Index) -> BoxFuture<Option<RichBlock>>;
2016-02-10 22:54:12 +01:00
/// Returns an uncles at given block and index.
#[rpc(name = "eth_getUncleByBlockNumberAndIndex")]
2017-11-14 11:38:17 +01:00
fn uncle_by_block_number_and_index(&self, BlockNumber, Index) -> BoxFuture<Option<RichBlock>>;
/// Returns available compilers.
/// @deprecated
#[rpc(name = "eth_getCompilers")]
2017-11-14 11:38:17 +01:00
fn compilers(&self) -> Result<Vec<String>>;
2016-01-21 01:19:29 +01:00
/// Compiles lll code.
/// @deprecated
#[rpc(name = "eth_compileLLL")]
2017-11-14 11:38:17 +01:00
fn compile_lll(&self, String) -> Result<Bytes>;
2016-01-27 18:17:20 +01:00
/// Compiles solidity.
/// @deprecated
#[rpc(name = "eth_compileSolidity")]
2017-11-14 11:38:17 +01:00
fn compile_solidity(&self, String) -> Result<Bytes>;
/// Compiles serpent.
/// @deprecated
#[rpc(name = "eth_compileSerpent")]
2017-11-14 11:38:17 +01:00
fn compile_serpent(&self, String) -> Result<Bytes>;
/// Returns logs matching given filter object.
#[rpc(name = "eth_getLogs")]
2017-11-14 11:38:17 +01:00
fn logs(&self, Filter) -> BoxFuture<Vec<Log>>;
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
#[rpc(name = "eth_getWork")]
2017-11-14 11:38:17 +01:00
fn work(&self, Trailing<u64>) -> Result<Work>;
/// Used for submitting a proof-of-work solution.
#[rpc(name = "eth_submitWork")]
2017-11-14 11:38:17 +01:00
fn submit_work(&self, H64, H256, H256) -> Result<bool>;
/// Used for submitting mining hashrate.
#[rpc(name = "eth_submitHashrate")]
2017-11-14 11:38:17 +01:00
fn submit_hashrate(&self, U256, H256) -> Result<bool>;
2016-01-21 01:19:29 +01:00
}
}
build_rpc_trait! {
/// Eth filters rpc api (polling).
// TODO: do filters api properly
pub trait EthFilter {
/// Returns id of new filter.
#[rpc(name = "eth_newFilter")]
2017-11-14 11:38:17 +01:00
fn new_filter(&self, Filter) -> Result<U256>;
/// Returns id of new block filter.
#[rpc(name = "eth_newBlockFilter")]
2017-11-14 11:38:17 +01:00
fn new_block_filter(&self) -> Result<U256>;
/// Returns id of new block filter.
#[rpc(name = "eth_newPendingTransactionFilter")]
2017-11-14 11:38:17 +01:00
fn new_pending_transaction_filter(&self) -> Result<U256>;
/// Returns filter changes since last poll.
#[rpc(name = "eth_getFilterChanges")]
2017-11-14 11:38:17 +01:00
fn filter_changes(&self, Index) -> BoxFuture<FilterChanges>;
/// Returns all logs matching given filter (in a range 'from' - 'to').
#[rpc(name = "eth_getFilterLogs")]
2017-11-14 11:38:17 +01:00
fn filter_logs(&self, Index) -> BoxFuture<Vec<Log>>;
/// Uninstalls filter.
#[rpc(name = "eth_uninstallFilter")]
2017-11-14 11:38:17 +01:00
fn uninstall_filter(&self, Index) -> Result<bool>;
2016-01-21 11:25:39 +01:00
}
}