openethereum/src/bin/client/rpc/impls/eth.rs

90 lines
2.0 KiB
Rust
Raw Normal View History

2016-01-21 01:19:29 +01:00
use std::sync::{Arc, RwLock};
use rustc_serialize::hex::ToHex;
use util::hash::*;
use ethcore::client::*;
use rpc::jsonrpc_core::*;
2016-01-21 11:25:39 +01:00
use rpc::{Eth, EthFilter};
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 {
Params::None => Ok(Value::String(Address::new().to_hex())),
_ => 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())
}
}
}
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-25 17:45:26 +01:00
println!("filter changes: {:?}", self.client.chain_info().best_block_hash.to_hex());
Ok(Value::Array(vec![Value::String(self.client.chain_info().best_block_hash.to_hex())]))
2016-01-21 11:25:39 +01:00
}
2016-01-21 01:19:29 +01:00
}