Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 7fefc15

Browse files
committed
Merge pull request #251 from ethcore/rpc_eth_stub
stubs for rpc methods
2 parents 10dd07f + f8568e1 commit 7fefc15

File tree

5 files changed

+129
-27
lines changed

5 files changed

+129
-27
lines changed

rpc/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ extern crate ethcore;
1313

1414
use self::jsonrpc_core::{IoHandler, IoDelegate};
1515

16-
macro_rules! rpcerr {
17-
() => (Err(Error::internal_error()))
18-
}
19-
2016
pub mod v1;
2117

2218
/// Http server.

rpc/src/v1/traits/eth.rs

+116-20
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,159 @@ use jsonrpc_core::*;
55
/// Eth rpc interface.
66
pub trait Eth: Sized + Send + Sync + 'static {
77
/// Returns protocol version.
8-
fn protocol_version(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
8+
fn protocol_version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
9+
10+
/// Returns the number of hashes per second that the node is mining with.
11+
fn hashrate(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
912

1013
/// Returns block author.
11-
fn author(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
14+
fn author(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
15+
16+
/// Returns true if client is actively mining new blocks.
17+
fn is_mining(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
1218

1319
/// Returns current gas_price.
14-
fn gas_price(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
20+
fn gas_price(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
21+
22+
/// Returns accounts list.
23+
fn accounts(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
1524

1625
/// Returns highest block number.
17-
fn block_number(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
26+
fn block_number(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
27+
28+
/// Returns balance of the given account.
29+
fn balance(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
30+
31+
/// Returns content of the storage at given address.
32+
fn storage_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
1833

1934
/// Returns block with given index / hash.
20-
fn block(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
35+
fn block(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
2136

22-
/// Returns true if client is actively mining new blocks.
23-
fn is_mining(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
24-
25-
/// Returns the number of hashes per second that the node is mining with.
26-
fn hashrate(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
37+
/// Returns the number of transactions sent from given address at given time (block number).
38+
fn transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
2739

2840
/// Returns the number of transactions in a block.
29-
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
41+
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
42+
43+
/// Returns the number of uncles in a given block.
44+
fn block_uncles_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
45+
46+
/// Returns the code at given address at given time (block number).
47+
fn code_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
48+
49+
/// Sends transaction.
50+
fn send_transaction(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
51+
52+
/// Call contract.
53+
fn call(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
54+
55+
/// Estimate gas needed for execution of given contract.
56+
fn estimate_gas(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
57+
58+
/// Returns transaction at given block and index.
59+
fn transaction_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
60+
61+
/// Returns transaction receipt.
62+
fn transaction_receipt(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
63+
64+
/// Returns an uncles at given block and index.
65+
fn uncle_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
66+
67+
/// Returns available compilers.
68+
fn compilers(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
69+
70+
/// Compiles lll code.
71+
fn compile_lll(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
72+
73+
/// Compiles solidity.
74+
fn compile_solidity(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
75+
76+
/// Compiles serpent.
77+
fn compile_serpent(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
78+
79+
/// Returns logs matching given filter object.
80+
fn logs(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
81+
82+
/// Returns the hash of the current block, the seedHash, and the boundary condition to be met.
83+
fn work(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
84+
85+
/// Used for submitting a proof-of-work solution.
86+
fn submit_work(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
87+
88+
/// Used for submitting mining hashrate.
89+
fn submit_hashrate(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
3090

3191
/// Should be used to convert object to io delegate.
3292
fn to_delegate(self) -> IoDelegate<Self> {
3393
let mut delegate = IoDelegate::new(Arc::new(self));
3494
delegate.add_method("eth_protocolVersion", Eth::protocol_version);
95+
delegate.add_method("eth_hashrate", Eth::hashrate);
3596
delegate.add_method("eth_coinbase", Eth::author);
97+
delegate.add_method("eth_mining", Eth::is_mining);
3698
delegate.add_method("eth_gasPrice", Eth::gas_price);
99+
delegate.add_method("eth_accounts", Eth::accounts);
37100
delegate.add_method("eth_blockNumber", Eth::block_number);
101+
delegate.add_method("eth_balance", Eth::balance);
102+
delegate.add_method("eth_getStorageAt", Eth::storage_at);
103+
delegate.add_method("eth_getTransactionCount", Eth::transaction_count);
104+
delegate.add_method("eth_getBlockTransactionCountByHash", Eth::block_transaction_count);
105+
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count);
106+
delegate.add_method("eth_getUncleCountByBlockHash", Eth::block_uncles_count);
107+
delegate.add_method("eth_getUncleCountByBlockNumber", Eth::block_uncles_count);
108+
delegate.add_method("eth_code", Eth::code_at);
109+
delegate.add_method("eth_sendTransaction", Eth::send_transaction);
110+
delegate.add_method("eth_call", Eth::call);
111+
delegate.add_method("eth_estimateGas", Eth::estimate_gas);
38112
delegate.add_method("eth_getBlockByHash", Eth::block);
39113
delegate.add_method("eth_getBlockByNumber", Eth::block);
40-
delegate.add_method("eth_mining", Eth::is_mining);
41-
delegate.add_method("eth_hashrate", Eth::hashrate);
42-
delegate.add_method("eth_getBlockTransactionCountByNumber", Eth::block_transaction_count);
114+
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_at);
115+
delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_at);
116+
delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt);
117+
delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_at);
118+
delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_at);
119+
delegate.add_method("eth_getCompilers", Eth::compilers);
120+
delegate.add_method("eth_compileLLL", Eth::compile_lll);
121+
delegate.add_method("eth_compileSolidity", Eth::compile_solidity);
122+
delegate.add_method("eth_compileSerpent", Eth::compile_serpent);
123+
delegate.add_method("eth_getLogs", Eth::logs);
124+
delegate.add_method("eth_getWork", Eth::work);
125+
delegate.add_method("eth_submitWork", Eth::submit_work);
126+
delegate.add_method("eth_submitHashrate", Eth::submit_hashrate);
43127
delegate
44128
}
45129
}
46130

47131
/// Eth filters rpc api (polling).
48132
// TODO: do filters api properly
49133
pub trait EthFilter: Sized + Send + Sync + 'static {
50-
/// Returns id of new block filter
51-
fn new_block_filter(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
134+
/// Returns id of new filter.
135+
fn new_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
136+
137+
/// Returns id of new block filter.
138+
fn new_block_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
139+
140+
/// Returns id of new block filter.
141+
fn new_pending_transaction_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
142+
143+
/// Returns filter changes since last poll.
144+
fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
52145

53-
/// Returns id of new block filter
54-
fn new_pending_transaction_filter(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
146+
/// Returns filter logs.
147+
fn filter_logs(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
55148

56-
/// Returns filter changes since last poll
57-
fn filter_changes(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
149+
/// Uninstalls filter.
150+
fn uninstall_filter(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
58151

59152
/// Should be used to convert object to io delegate.
60153
fn to_delegate(self) -> IoDelegate<Self> {
61154
let mut delegate = IoDelegate::new(Arc::new(self));
155+
delegate.add_method("eth_newFilter", EthFilter::new_filter);
62156
delegate.add_method("eth_newBlockFilter", EthFilter::new_block_filter);
63157
delegate.add_method("eth_newPendingTransactionFilter", EthFilter::new_pending_transaction_filter);
64158
delegate.add_method("eth_getFilterChanges", EthFilter::filter_changes);
159+
delegate.add_method("eth_getFilterLogs", EthFilter::filter_logs);
160+
delegate.add_method("eth_uninstallFilter", EthFilter::uninstall_filter);
65161
delegate
66162
}
67163
}

rpc/src/v1/traits/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//! Ethereum rpc interfaces.
2+
3+
macro_rules! rpc_unimplemented {
4+
() => (Err(Error::internal_error()))
5+
}
6+
27
pub mod web3;
38
pub mod eth;
49
pub mod net;

rpc/src/v1/traits/net.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ use jsonrpc_core::*;
55
/// Net rpc interface.
66
pub trait Net: Sized + Send + Sync + 'static {
77
/// Returns protocol version.
8-
fn version(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
8+
fn version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
99

1010
/// Returns number of peers connected to node.
11-
fn peer_count(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
11+
fn peer_count(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
12+
13+
/// Returns true if client is actively listening for network connections.
14+
/// Otherwise false.
15+
fn is_listening(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
1216

1317
/// Should be used to convert object to io delegate.
1418
fn to_delegate(self) -> IoDelegate<Self> {
1519
let mut delegate = IoDelegate::new(Arc::new(self));
1620
delegate.add_method("net_version", Net::version);
1721
delegate.add_method("net_peerCount", Net::peer_count);
22+
delegate.add_method("net_listening", Net::is_listening);
1823
delegate
1924
}
2025
}

rpc/src/v1/traits/web3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use jsonrpc_core::*;
55
/// Web3 rpc interface.
66
pub trait Web3: Sized + Send + Sync + 'static {
77
/// Returns current client version.
8-
fn client_version(&self, _: Params) -> Result<Value, Error> { rpcerr!() }
8+
fn client_version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
99

1010
/// Should be used to convert object to io delegate.
1111
fn to_delegate(self) -> IoDelegate<Self> {

0 commit comments

Comments
 (0)