openethereum/rpc/src/impls/eth.rs

97 lines
2.1 KiB
Rust
Raw Normal View History

2016-01-26 11:37:24 +01:00
use std::sync::Arc;
2016-01-21 01:19:29 +01:00
use rustc_serialize::hex::ToHex;
use util::hash::*;
use ethcore::client::*;
2016-01-26 13:14:22 +01:00
use jsonrpc_core::*;
use traits::{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())
}
}
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
fn block(&self, _: Params) -> Result<Value, Error> {
Ok(Value::Null)
}
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-25 17:45:26 +01:00
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
}