use jsonrpc 1.1, moved params deserialization to jsonrpc-core
This commit is contained in:
parent
bcfe40e743
commit
322c1a6cb2
@ -11,8 +11,8 @@ authors = ["Marek Kotewicz <marek.kotewicz@gmail.com"]
|
||||
serde = "0.6.7"
|
||||
serde_macros = "0.6.10"
|
||||
serde_json = "0.6.0"
|
||||
jsonrpc-core = "1.0"
|
||||
jsonrpc-http-server = "1.0"
|
||||
jsonrpc-core = "1.1"
|
||||
jsonrpc-http-server = "1.1"
|
||||
ethcore-util = { path = "../util" }
|
||||
ethcore = { path = ".." }
|
||||
|
||||
|
@ -6,7 +6,7 @@ use util::sha3::*;
|
||||
use ethcore::client::*;
|
||||
use ethcore::views::*;
|
||||
use traits::{Eth, EthFilter};
|
||||
use types::{Block, to_value, from_value};
|
||||
use types::Block;
|
||||
|
||||
pub struct EthClient {
|
||||
client: Arc<Client>,
|
||||
@ -30,7 +30,7 @@ impl Eth for EthClient {
|
||||
|
||||
fn author(&self, params: Params) -> Result<Value, Error> {
|
||||
match params {
|
||||
Params::None => Ok(to_value(&Address::new())),
|
||||
Params::None => to_value(&Address::new()),
|
||||
_ => Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
@ -68,10 +68,8 @@ impl Eth for EthClient {
|
||||
}
|
||||
|
||||
fn block(&self, params: Params) -> Result<Value, Error> {
|
||||
if let Params::Array(ref arr) = params {
|
||||
if let [ref h, Value::Bool(ref _include_txs)] = arr as &[Value] {
|
||||
if let Ok(hash) = from_value::<H256>(h.clone()) {
|
||||
return match (self.client.block_header(&hash), self.client.block_details(&hash)) {
|
||||
match from_params::<(H256, bool)>(params) {
|
||||
Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_details(&hash)) {
|
||||
(Some(bytes), Some(details)) => {
|
||||
let view = HeaderView::new(&bytes);
|
||||
let block = Block {
|
||||
@ -93,16 +91,14 @@ impl Eth for EthClient {
|
||||
uncles: vec![],
|
||||
transactions: vec![]
|
||||
};
|
||||
Ok(to_value(&block))
|
||||
to_value(&block)
|
||||
},
|
||||
_ => Ok(Value::Null),
|
||||
_ => Ok(Value::Null)
|
||||
},
|
||||
Err(err) => Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::invalid_params())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EthFilterClient {
|
||||
client: Arc<Client>
|
||||
@ -126,6 +122,6 @@ impl EthFilter for EthFilterClient {
|
||||
}
|
||||
|
||||
fn filter_changes(&self, _: Params) -> Result<Value, Error> {
|
||||
Ok(Value::Array(vec![to_value(&self.client.chain_info().best_block_hash)]))
|
||||
to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v]))
|
||||
}
|
||||
}
|
||||
|
@ -34,13 +34,3 @@ pub struct Block {
|
||||
pub uncles: Vec<U256>,
|
||||
pub transactions: Vec<U256>
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_serialize() {
|
||||
use serde_json;
|
||||
|
||||
let block = Block::default();
|
||||
let serialized = serde_json::to_string(&block).unwrap();
|
||||
println!("s: {:?}", serialized);
|
||||
//assert!(false);
|
||||
}
|
||||
|
@ -1,18 +1,3 @@
|
||||
use serde::{Serialize, Deserialize, de};
|
||||
use serde_json::value::{Value, Serializer, Deserializer};
|
||||
|
||||
mod block;
|
||||
|
||||
pub fn to_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;
|
||||
|
Loading…
Reference in New Issue
Block a user