2016-01-26 11:37:24 +01:00
|
|
|
use std::sync::Arc;
|
2016-01-26 19:24:33 +01:00
|
|
|
use serde_json;
|
|
|
|
use jsonrpc_core::*;
|
2016-01-21 01:19:29 +01:00
|
|
|
use util::hash::*;
|
|
|
|
use ethcore::client::*;
|
2016-01-26 13:14:22 +01:00
|
|
|
use traits::{Eth, EthFilter};
|
2016-01-26 19:24:33 +01:00
|
|
|
use types::{Block, as_value, from_value};
|
2016-01-21 01:19:29 +01:00
|
|
|
|
|
|
|
pub struct EthClient {
|
2016-01-25 13:09:46 +01:00
|
|
|
client: Arc<Client>,
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EthClient {
|
2016-01-25 13:09:46 +01:00
|
|
|
pub fn new(client: Arc<Client>) -> Self {
|
2016-01-21 01:19:29 +01:00
|
|
|
EthClient {
|
|
|
|
client: client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eth for EthClient {
|
|
|
|
fn protocol_version(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
|
|
|
Params::None => Ok(Value::U64(63)),
|
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn author(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
2016-01-26 19:24:33 +01:00
|
|
|
Params::None => Ok(as_value(&Address::new())),
|
2016-01-21 01:19:29 +01:00
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 11:25:39 +01:00
|
|
|
fn gas_price(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
|
|
|
Params::None => Ok(Value::U64(0)),
|
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:19:29 +01:00
|
|
|
fn block_number(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
2016-01-25 13:09:46 +01:00
|
|
|
Params::None => Ok(Value::U64(self.client.chain_info().best_block_number)),
|
2016-01-21 01:19:29 +01:00
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_mining(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
|
|
|
Params::None => Ok(Value::Bool(false)),
|
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
|
|
|
|
fn hashrate(&self, params: Params) -> Result<Value, Error> {
|
|
|
|
match params {
|
|
|
|
Params::None => Ok(Value::U64(0)),
|
|
|
|
_ => Err(Error::invalid_params())
|
|
|
|
}
|
|
|
|
}
|
2016-01-26 00:42:07 +01:00
|
|
|
|
|
|
|
fn block_transaction_count(&self, _: Params) -> Result<Value, Error> {
|
|
|
|
Ok(Value::U64(0))
|
|
|
|
}
|
2016-01-26 11:37:24 +01:00
|
|
|
|
2016-01-26 19:24:33 +01:00
|
|
|
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())
|
2016-01-26 11:37:24 +01:00
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct EthFilterClient {
|
2016-01-25 13:09:46 +01:00
|
|
|
client: Arc<Client>
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl EthFilterClient {
|
2016-01-25 13:09:46 +01:00
|
|
|
pub fn new(client: Arc<Client>) -> Self {
|
2016-01-21 11:25:39 +01:00
|
|
|
EthFilterClient {
|
|
|
|
client: client
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EthFilter for EthFilterClient {
|
|
|
|
fn new_block_filter(&self, _params: Params) -> Result<Value, Error> {
|
|
|
|
Ok(Value::U64(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn new_pending_transaction_filter(&self, _params: Params) -> Result<Value, Error> {
|
|
|
|
Ok(Value::U64(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn filter_changes(&self, _: Params) -> Result<Value, Error> {
|
2016-01-26 19:24:33 +01:00
|
|
|
Ok(Value::Array(vec![as_value(&self.client.chain_info().best_block_hash)]))
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
2016-01-21 01:19:29 +01:00
|
|
|
}
|