From 09b9001c65279c0449635f17ecd65e5b2322ce34 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 27 Jan 2016 18:17:20 +0100 Subject: [PATCH 1/3] stub for rpc eth methods --- rpc/src/lib.rs | 4 -- rpc/src/v1/traits/eth.rs | 132 +++++++++++++++++++++++++++++++------- rpc/src/v1/traits/mod.rs | 5 ++ rpc/src/v1/traits/net.rs | 4 +- rpc/src/v1/traits/web3.rs | 2 +- 5 files changed, 116 insertions(+), 31 deletions(-) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 7bc1d6987..a27afb5f6 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -13,10 +13,6 @@ extern crate ethcore; use self::jsonrpc_core::{IoHandler, IoDelegate}; -macro_rules! rpcerr { - () => (Err(Error::internal_error())) -} - pub mod v1; /// Http server. diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 25756a713..1586e7069 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -5,41 +5,125 @@ use jsonrpc_core::*; /// Eth rpc interface. pub trait Eth: Sized + Send + Sync + 'static { /// Returns protocol version. - fn protocol_version(&self, _: Params) -> Result { rpcerr!() } - - /// Returns block author. - fn author(&self, _: Params) -> Result { rpcerr!() } - - /// Returns current gas_price. - fn gas_price(&self, _: Params) -> Result { rpcerr!() } - - /// Returns highest block number. - fn block_number(&self, _: Params) -> Result { rpcerr!() } - - /// Returns block with given index / hash. - fn block(&self, _: Params) -> Result { rpcerr!() } - - /// Returns true if client is actively mining new blocks. - fn is_mining(&self, _: Params) -> Result { rpcerr!() } + fn protocol_version(&self, _: Params) -> Result { rpc_unimplemented!() } /// Returns the number of hashes per second that the node is mining with. - fn hashrate(&self, _: Params) -> Result { rpcerr!() } + fn hashrate(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns block author. + fn author(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns true if client is actively mining new blocks. + fn is_mining(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns current gas_price. + fn gas_price(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns accounts list. + fn accounts(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns highest block number. + fn block_number(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns balance of the given account. + fn balance(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns content of the storage at given address. + fn storage_at(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns block with given index / hash. + fn block(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns the number of transactions sent from given address at given time (block number). + fn transaction_count(&self, _: Params) -> Result { rpc_unimplemented!() } /// Returns the number of transactions in a block. - fn block_transaction_count(&self, _: Params) -> Result { rpcerr!() } + fn block_transaction_count(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns the number of uncles in a given block. + fn block_uncles_count(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns the code at given address at given time (block number). + fn code_at(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Sends transaction. + fn send_transaction(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Call contract. + fn call(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Estimate gas needed for execution of given contract. + fn estimate_gas(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns transaction at given block and index. + fn transaction_at(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns transaction receipt. + fn transaction_receipt(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns an uncles at given block and index. + fn uncle_at(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns available compilers. + fn compilers(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Compiles lll code. + fn compile_lll(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Compiles solidity. + fn compile_solidity(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Compiles serpent. + fn compile_serpent(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns logs matching given filter object. + fn logs(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns the hash of the current block, the seedHash, and the boundary condition to be met. + fn work(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Used for submitting a proof-of-work solution. + fn submit_work(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Used for submitting mining hashrate. + fn submit_hashrate(&self, _: Params) -> Result { rpc_unimplemented!() } /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { let mut delegate = IoDelegate::new(Arc::new(self)); delegate.add_method("eth_protocolVersion", Eth::protocol_version); + delegate.add_method("eth_hashrate", Eth::hashrate); delegate.add_method("eth_coinbase", Eth::author); + delegate.add_method("eth_mining", Eth::is_mining); delegate.add_method("eth_gasPrice", Eth::gas_price); + delegate.add_method("eth_accounts", Eth::accounts); delegate.add_method("eth_blockNumber", Eth::block_number); + delegate.add_method("eth_balance", Eth::balance); + delegate.add_method("eth_getStorageAt", Eth::storage_at); + delegate.add_method("eth_getTransactionCount", Eth::transaction_count); + delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count); + delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count); + delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count); + delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count); + delegate.add_method("eth_code", Eth::code_at); + delegate.add_method("eth_sendTransaction", Eth::send_transaction); + delegate.add_method("eth_call", Eth::call); + delegate.add_method("eth_estimateGas", Eth::estimate_gas); delegate.add_method("eth_getBlockByHash", Eth::block); delegate.add_method("eth_getBlockByNumber", Eth::block); - delegate.add_method("eth_mining", Eth::is_mining); - delegate.add_method("eth_hashrate", Eth::hashrate); - delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count); + delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_at); + delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_at); + delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt); + delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_at); + delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_at); + 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); delegate } } @@ -48,13 +132,13 @@ pub trait Eth: Sized + Send + Sync + 'static { // TODO: do filters api properly pub trait EthFilter: Sized + Send + Sync + 'static { /// Returns id of new block filter - fn new_block_filter(&self, _: Params) -> Result { rpcerr!() } + fn new_block_filter(&self, _: Params) -> Result { rpc_unimplemented!() } /// Returns id of new block filter - fn new_pending_transaction_filter(&self, _: Params) -> Result { rpcerr!() } + fn new_pending_transaction_filter(&self, _: Params) -> Result { rpc_unimplemented!() } /// Returns filter changes since last poll - fn filter_changes(&self, _: Params) -> Result { rpcerr!() } + fn filter_changes(&self, _: Params) -> Result { rpc_unimplemented!() } /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { diff --git a/rpc/src/v1/traits/mod.rs b/rpc/src/v1/traits/mod.rs index 2fa52d538..70c825175 100644 --- a/rpc/src/v1/traits/mod.rs +++ b/rpc/src/v1/traits/mod.rs @@ -1,4 +1,9 @@ //! Ethereum rpc interfaces. + +macro_rules! rpc_unimplemented { + () => (Err(Error::internal_error())) +} + pub mod web3; pub mod eth; pub mod net; diff --git a/rpc/src/v1/traits/net.rs b/rpc/src/v1/traits/net.rs index 4df8d7114..9196503d2 100644 --- a/rpc/src/v1/traits/net.rs +++ b/rpc/src/v1/traits/net.rs @@ -5,10 +5,10 @@ use jsonrpc_core::*; /// Net rpc interface. pub trait Net: Sized + Send + Sync + 'static { /// Returns protocol version. - fn version(&self, _: Params) -> Result { rpcerr!() } + fn version(&self, _: Params) -> Result { rpc_unimplemented!() } /// Returns number of peers connected to node. - fn peer_count(&self, _: Params) -> Result { rpcerr!() } + fn peer_count(&self, _: Params) -> Result { rpc_unimplemented!() } /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { diff --git a/rpc/src/v1/traits/web3.rs b/rpc/src/v1/traits/web3.rs index 8e73d4304..118316155 100644 --- a/rpc/src/v1/traits/web3.rs +++ b/rpc/src/v1/traits/web3.rs @@ -5,7 +5,7 @@ use jsonrpc_core::*; /// Web3 rpc interface. pub trait Web3: Sized + Send + Sync + 'static { /// Returns current client version. - fn client_version(&self, _: Params) -> Result { rpcerr!() } + fn client_version(&self, _: Params) -> Result { rpc_unimplemented!() } /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { From b13d68c7e99319420b0ee500308635442c8594d2 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 27 Jan 2016 19:00:42 +0100 Subject: [PATCH 2/3] missing eth filter interface --- rpc/src/v1/traits/eth.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 1586e7069..3dcdfdf05 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -131,21 +131,33 @@ pub trait Eth: Sized + Send + Sync + 'static { /// Eth filters rpc api (polling). // TODO: do filters api properly pub trait EthFilter: Sized + Send + Sync + 'static { - /// Returns id of new block filter + /// Returns id of new filter. + fn new_filter(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Returns id of new block filter. fn new_block_filter(&self, _: Params) -> Result { rpc_unimplemented!() } - /// Returns id of new block filter + /// Returns id of new block filter. fn new_pending_transaction_filter(&self, _: Params) -> Result { rpc_unimplemented!() } - /// Returns filter changes since last poll + /// Returns filter changes since last poll. fn filter_changes(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Returns filter logs. + fn filter_logs(&self, _: Params) -> Result { rpc_unimplemented!() } + + /// Uninstalls filter. + fn uninstall_filter(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { let mut delegate = IoDelegate::new(Arc::new(self)); + delegate.add_method("eth_newFilter", EthFilter::new_filter); delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter); delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter); delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes); + delegate.add_method("eth_getFilterLogs", EthFilter::filter_logs); + delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter); delegate } } From f8568e10b7fe4ffbc525188ca360cd8e09fd55e8 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 27 Jan 2016 19:03:12 +0100 Subject: [PATCH 3/3] missing net_ methods --- rpc/src/v1/traits/net.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rpc/src/v1/traits/net.rs b/rpc/src/v1/traits/net.rs index 9196503d2..84877cab7 100644 --- a/rpc/src/v1/traits/net.rs +++ b/rpc/src/v1/traits/net.rs @@ -10,11 +10,16 @@ pub trait Net: Sized + Send + Sync + 'static { /// Returns number of peers connected to node. fn peer_count(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Returns true if client is actively listening for network connections. + /// Otherwise false. + fn is_listening(&self, _: Params) -> Result { rpc_unimplemented!() } + /// Should be used to convert object to io delegate. fn to_delegate(self) -> IoDelegate { let mut delegate = IoDelegate::new(Arc::new(self)); delegate.add_method("net_version", Net::version); delegate.add_method("net_peerCount", Net::peer_count); + delegate.add_method("net_listening", Net::is_listening); delegate } }