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 = "0.6.7"
|
||||||
serde_macros = "0.6.10"
|
serde_macros = "0.6.10"
|
||||||
serde_json = "0.6.0"
|
serde_json = "0.6.0"
|
||||||
jsonrpc-core = "1.0"
|
jsonrpc-core = "1.1"
|
||||||
jsonrpc-http-server = "1.0"
|
jsonrpc-http-server = "1.1"
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
ethcore = { path = ".." }
|
ethcore = { path = ".." }
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use util::sha3::*;
|
|||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
use traits::{Eth, EthFilter};
|
use traits::{Eth, EthFilter};
|
||||||
use types::{Block, to_value, from_value};
|
use types::Block;
|
||||||
|
|
||||||
pub struct EthClient {
|
pub struct EthClient {
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
@ -30,7 +30,7 @@ impl Eth for EthClient {
|
|||||||
|
|
||||||
fn author(&self, params: Params) -> Result<Value, Error> {
|
fn author(&self, params: Params) -> Result<Value, Error> {
|
||||||
match params {
|
match params {
|
||||||
Params::None => Ok(to_value(&Address::new())),
|
Params::None => to_value(&Address::new()),
|
||||||
_ => Err(Error::invalid_params())
|
_ => Err(Error::invalid_params())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,39 +68,35 @@ impl Eth for EthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn block(&self, params: Params) -> Result<Value, Error> {
|
fn block(&self, params: Params) -> Result<Value, Error> {
|
||||||
if let Params::Array(ref arr) = params {
|
match from_params::<(H256, bool)>(params) {
|
||||||
if let [ref h, Value::Bool(ref _include_txs)] = arr as &[Value] {
|
Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_details(&hash)) {
|
||||||
if let Ok(hash) = from_value::<H256>(h.clone()) {
|
(Some(bytes), Some(details)) => {
|
||||||
return match (self.client.block_header(&hash), self.client.block_details(&hash)) {
|
let view = HeaderView::new(&bytes);
|
||||||
(Some(bytes), Some(details)) => {
|
let block = Block {
|
||||||
let view = HeaderView::new(&bytes);
|
hash: view.sha3(),
|
||||||
let block = Block {
|
parent_hash: view.parent_hash(),
|
||||||
hash: view.sha3(),
|
uncles_hash: view.uncles_hash(),
|
||||||
parent_hash: view.parent_hash(),
|
author: view.author(),
|
||||||
uncles_hash: view.uncles_hash(),
|
miner: view.author(),
|
||||||
author: view.author(),
|
state_root: view.state_root(),
|
||||||
miner: view.author(),
|
transactions_root: view.transactions_root(),
|
||||||
state_root: view.state_root(),
|
receipts_root: view.receipts_root(),
|
||||||
transactions_root: view.transactions_root(),
|
number: U256::from(view.number()),
|
||||||
receipts_root: view.receipts_root(),
|
gas_used: view.gas_used(),
|
||||||
number: U256::from(view.number()),
|
gas_limit: view.gas_limit(),
|
||||||
gas_used: view.gas_used(),
|
logs_bloom: view.log_bloom(),
|
||||||
gas_limit: view.gas_limit(),
|
timestamp: U256::from(view.timestamp()),
|
||||||
logs_bloom: view.log_bloom(),
|
difficulty: view.difficulty(),
|
||||||
timestamp: U256::from(view.timestamp()),
|
total_difficulty: details.total_difficulty,
|
||||||
difficulty: view.difficulty(),
|
uncles: vec![],
|
||||||
total_difficulty: details.total_difficulty,
|
transactions: vec![]
|
||||||
uncles: vec![],
|
};
|
||||||
transactions: vec![]
|
to_value(&block)
|
||||||
};
|
},
|
||||||
Ok(to_value(&block))
|
_ => Ok(Value::Null)
|
||||||
},
|
},
|
||||||
_ => Ok(Value::Null),
|
Err(err) => Err(err)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(Error::invalid_params())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +122,6 @@ impl EthFilter for EthFilterClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn filter_changes(&self, _: Params) -> Result<Value, Error> {
|
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 uncles: Vec<U256>,
|
||||||
pub transactions: 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;
|
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;
|
pub use self::block::Block;
|
||||||
|
Loading…
Reference in New Issue
Block a user