Merge branch 'master' into bettermining
This commit is contained in:
@@ -36,7 +36,7 @@ impl<S> NetClient<S> where S: SyncProvider {
|
||||
|
||||
impl<S> Net for NetClient<S> where S: SyncProvider + 'static {
|
||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||
Ok(Value::String(format!("{}", take_weak!(self.sync).status().protocol_version).to_owned()))
|
||||
Ok(Value::String(format!("{}", take_weak!(self.sync).status().network_id).to_owned()))
|
||||
}
|
||||
|
||||
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
use jsonrpc_core::*;
|
||||
use util::version;
|
||||
use v1::traits::Web3;
|
||||
use v1::types::Bytes;
|
||||
use util::sha3::Hashable;
|
||||
|
||||
/// Web3 rpc implementation.
|
||||
pub struct Web3Client;
|
||||
@@ -34,4 +36,14 @@ impl Web3 for Web3Client {
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
|
||||
fn sha3(&self, params: Params) -> Result<Value, Error> {
|
||||
from_params::<(Bytes,)>(params).and_then(
|
||||
|(data,)| {
|
||||
let Bytes(ref v) = data;
|
||||
let sha3 = v.sha3();
|
||||
to_value(&sha3)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fn accounts_provider() -> Arc<TestAccountProvider> {
|
||||
|
||||
fn sync_provider() -> Arc<TestSyncProvider> {
|
||||
Arc::new(TestSyncProvider::new(Config {
|
||||
protocol_version: 65,
|
||||
network_id: U256::from(3),
|
||||
num_peers: 120,
|
||||
}))
|
||||
}
|
||||
@@ -83,7 +83,7 @@ impl Default for EthTester {
|
||||
#[test]
|
||||
fn rpc_eth_protocol_version() {
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "eth_protocolVersion", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"65","id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"63","id":1}"#;
|
||||
|
||||
assert_eq!(EthTester::default().io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
//! Test implementation of SyncProvider.
|
||||
|
||||
use util::U256;
|
||||
use ethsync::{SyncProvider, SyncStatus, SyncState};
|
||||
use std::sync::{RwLock};
|
||||
|
||||
/// TestSyncProvider config.
|
||||
pub struct Config {
|
||||
/// Protocol version.
|
||||
pub protocol_version: u8,
|
||||
pub network_id: U256,
|
||||
/// Number of peers.
|
||||
pub num_peers: usize,
|
||||
}
|
||||
@@ -39,7 +40,8 @@ impl TestSyncProvider {
|
||||
TestSyncProvider {
|
||||
status: RwLock::new(SyncStatus {
|
||||
state: SyncState::NotSynced,
|
||||
protocol_version: config.protocol_version,
|
||||
network_id: config.network_id,
|
||||
protocol_version: 63,
|
||||
start_block_number: 0,
|
||||
last_imported_block_number: None,
|
||||
highest_block_number: None,
|
||||
|
||||
@@ -18,10 +18,11 @@ use std::sync::Arc;
|
||||
use jsonrpc_core::IoHandler;
|
||||
use v1::{Net, NetClient};
|
||||
use v1::tests::helpers::{Config, TestSyncProvider};
|
||||
use util::numbers::*;
|
||||
|
||||
fn sync_provider() -> Arc<TestSyncProvider> {
|
||||
Arc::new(TestSyncProvider::new(Config {
|
||||
protocol_version: 65,
|
||||
network_id: U256::from(3),
|
||||
num_peers: 120,
|
||||
}))
|
||||
}
|
||||
@@ -34,7 +35,7 @@ fn rpc_net_version() {
|
||||
io.add_delegate(net);
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "net_version", "params": [], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"65","id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"3","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -31,3 +31,31 @@ fn rpc_web3_version() {
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_web3_sha3() {
|
||||
let web3 = Web3Client::new().to_delegate();
|
||||
let io = IoHandler::new();
|
||||
io.add_delegate(web3);
|
||||
|
||||
let v = version().to_owned().replace("Parity/", "Parity//");
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "web3_sha3", "params": ["0x00"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0xbc36789e7a1e281436464229828f817d6612f7b477d66591ff96a9e064bcc98a","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rpc_web3_sha3_wiki() {
|
||||
let web3 = Web3Client::new().to_delegate();
|
||||
let io = IoHandler::new();
|
||||
io.add_delegate(web3);
|
||||
|
||||
let v = version().to_owned().replace("Parity/", "Parity//");
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "web3_sha3", "params": ["0x68656c6c6f20776f726c64"], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad","id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -23,10 +23,14 @@ pub trait Web3: Sized + Send + Sync + 'static {
|
||||
/// Returns current client version.
|
||||
fn client_version(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
/// Returns sha3 of the given data
|
||||
fn sha3(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
|
||||
|
||||
/// 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("web3_clientVersion", Web3::client_version);
|
||||
delegate.add_method("web3_sha3", Web3::sha3);
|
||||
delegate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use util::common::FromHex;
|
||||
|
||||
/// Wrapper structure around vector of bytes.
|
||||
#[derive(Debug, PartialEq, Default)]
|
||||
pub struct Bytes(Vec<u8>);
|
||||
pub struct Bytes(pub Vec<u8>);
|
||||
|
||||
impl Bytes {
|
||||
/// Simple constructor.
|
||||
|
||||
Reference in New Issue
Block a user