parity on netstats
This commit is contained in:
parent
e05fe2e0eb
commit
2f42e0eda0
@ -8,7 +8,6 @@ authors = ["Marek Kotewicz <marek.kotewicz@gmail.com"]
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
rustc-serialize = "0.3"
|
||||
serde = "0.6.7"
|
||||
serde_macros = "0.6.10"
|
||||
serde_json = "0.6.0"
|
||||
|
@ -1,9 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use serde_json;
|
||||
use jsonrpc_core::*;
|
||||
use util::hash::*;
|
||||
use ethcore::client::*;
|
||||
use jsonrpc_core::*;
|
||||
use traits::{Eth, EthFilter};
|
||||
use types::{Block, as_value, from_value};
|
||||
|
||||
pub struct EthClient {
|
||||
client: Arc<Client>,
|
||||
@ -27,7 +28,7 @@ impl Eth for EthClient {
|
||||
|
||||
fn author(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => Ok(Value::String(Address::new().to_hex())),
|
||||
Params::None => Ok(as_value(&Address::new())),
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
@ -64,8 +65,15 @@ impl Eth for EthClient {
|
||||
Ok(Value::U64(0))
|
||||
}
|
||||
|
||||
fn block(&self, _: Params) -> Result<Value, Error> {
|
||||
Ok(Value::Null)
|
||||
fn block(&self, params: Params) -> Result<Value, Error> {
|
||||
if let Params::Array(ref arr) = params {
|
||||
if let [ref h, Value::Bool(ref include_transactions)] = arr as &[Value] {
|
||||
if let Ok(hash) = from_value::<H256>(h.clone()) {
|
||||
return Ok(as_value(&Block::default()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +99,6 @@ impl EthFilter for EthFilterClient {
|
||||
}
|
||||
|
||||
fn filter_changes(&self, _: Params) -> Result<Value, Error> {
|
||||
Ok(Value::Array(vec![Value::String(self.client.chain_info().best_block_hash.to_hex())]))
|
||||
Ok(Value::Array(vec![as_value(&self.client.chain_info().best_block_hash)]))
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#![feature(custom_derive, custom_attribute, plugin)]
|
||||
#![feature(slice_patterns)]
|
||||
#![plugin(serde_macros)]
|
||||
|
||||
extern crate rustc_serialize;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate jsonrpc_core;
|
||||
extern crate jsonrpc_http_server;
|
||||
extern crate ethcore_util as util;
|
||||
|
@ -35,6 +35,7 @@ pub trait Eth: Sized + Send + Sync + 'static {
|
||||
delegate.add_method("eth_coinbase", Eth::author);
|
||||
delegate.add_method("eth_gasPrice", Eth::gas_price);
|
||||
delegate.add_method("eth_blockNumber", Eth::block_number);
|
||||
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);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use util::hash::*;
|
||||
use util::uint::*;
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Default, Serialize)]
|
||||
pub struct Block {
|
||||
hash: H256,
|
||||
#[serde(rename="parentHash")]
|
||||
@ -35,7 +35,7 @@ fn test_block_serialize() {
|
||||
use serde_json;
|
||||
|
||||
let block = Block::default();
|
||||
//let serialized = serde_json::to_string(&block).unwrap();
|
||||
//println!("s: {:?}", serialized);
|
||||
let serialized = serde_json::to_string(&block).unwrap();
|
||||
println!("s: {:?}", serialized);
|
||||
//assert!(false);
|
||||
}
|
||||
|
@ -1 +1,18 @@
|
||||
use serde::{Serialize, Deserialize, de};
|
||||
use serde_json::value::{Value, Serializer, Deserializer};
|
||||
|
||||
mod block;
|
||||
|
||||
pub fn as_value<S>(s: &S) -> Value where S: Serialize {
|
||||
let mut serializer = Serializer::new();
|
||||
// should never panic!
|
||||
s.serialize(&mut serializer).unwrap();
|
||||
serializer.unwrap()
|
||||
}
|
||||
|
||||
pub fn from_value<D>(value: Value) -> Result<D, <Deserializer as de::Deserializer>::Error> where D: Deserialize {
|
||||
let mut deserialier = Deserializer::new(value);
|
||||
Deserialize::deserialize(&mut deserialier)
|
||||
}
|
||||
|
||||
pub use self::block::Block;
|
||||
|
@ -25,6 +25,7 @@ itertools = "0.4"
|
||||
crossbeam = "0.2"
|
||||
slab = { git = "https://github.com/arkpar/slab.git" }
|
||||
sha3 = { path = "sha3" }
|
||||
serde = "0.6.7"
|
||||
clippy = "*" # Always newest, since we use nightly
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -8,6 +8,8 @@ use rand::os::OsRng;
|
||||
use bytes::{BytesConvertable,Populatable};
|
||||
use from_json::*;
|
||||
use uint::{Uint, U256};
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use serde;
|
||||
|
||||
/// Trait for a fixed-size byte array to be used as the output of hash functions.
|
||||
///
|
||||
@ -205,6 +207,41 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for $from {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: serde::Serializer {
|
||||
let mut hex = "0x".to_owned();
|
||||
hex.push_str(self.to_hex().as_ref());
|
||||
serializer.visit_str(hex.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Deserialize for $from {
|
||||
fn deserialize<D>(deserializer: &mut D) -> Result<$from, D::Error>
|
||||
where D: serde::Deserializer {
|
||||
struct HashVisitor;
|
||||
|
||||
impl serde::de::Visitor for HashVisitor {
|
||||
type Value = $from;
|
||||
|
||||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
|
||||
// 0x + len
|
||||
if value.len() != 2 + $size * 2 {
|
||||
return Err(serde::Error::syntax("Invalid length."));
|
||||
}
|
||||
|
||||
value[2..].from_hex().map(|ref v| $from::from_slice(v)).map_err(|_| serde::Error::syntax("Invalid valid hex."))
|
||||
}
|
||||
|
||||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
|
||||
self.visit_str(value.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.visit(HashVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJson for $from {
|
||||
fn from_json(json: &Json) -> Self {
|
||||
match *json {
|
||||
|
@ -55,6 +55,7 @@ extern crate secp256k1;
|
||||
extern crate arrayvec;
|
||||
extern crate elastic_array;
|
||||
extern crate crossbeam;
|
||||
extern crate serde;
|
||||
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod standard;
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
use standard::*;
|
||||
use from_json::*;
|
||||
use rustc_serialize::hex::ToHex;
|
||||
use serde;
|
||||
|
||||
macro_rules! impl_map_from {
|
||||
($thing:ident, $from:ty, $to:ty) => {
|
||||
@ -436,6 +438,17 @@ macro_rules! construct_uint {
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for $name {
|
||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||
where S: serde::Serializer {
|
||||
let mut hex = "0x".to_owned();
|
||||
let mut bytes = [0u8; 8 * $n_words];
|
||||
self.to_bytes(&mut bytes);
|
||||
hex.push_str(bytes.to_hex().as_ref());
|
||||
serializer.visit_str(hex.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for $name {
|
||||
fn from(value: u64) -> $name {
|
||||
let mut ret = [0; $n_words];
|
||||
|
Loading…
Reference in New Issue
Block a user