small clenaup

This commit is contained in:
debris 2016-02-10 10:12:56 +01:00
parent 4df096fed3
commit bceae29fca
2 changed files with 26 additions and 30 deletions

View File

@ -96,36 +96,30 @@ impl Eth for EthClient {
}
fn block_transaction_count(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256,)>(params) {
Ok((hash,)) => match self.client.block(&hash) {
from_params::<(H256,)>(params)
.and_then(|(hash,)| match self.client.block(&hash) {
Some(bytes) => to_value(&BlockView::new(&bytes).transactions_count()),
None => Ok(Value::Null)
},
Err(err) => Err(err)
}
})
}
fn block_uncles_count(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256,)>(params) {
Ok((hash,)) => match self.client.block(&hash) {
from_params::<(H256,)>(params)
.and_then(|(hash,)| match self.client.block(&hash) {
Some(bytes) => to_value(&BlockView::new(&bytes).uncles_count()),
None => Ok(Value::Null)
},
Err(err) => Err(err)
}
})
}
// TODO: do not ignore block number param
fn code_at(&self, params: Params) -> Result<Value, Error> {
match from_params::<(Address, BlockNumber)>(params) {
Ok((address, _block_number)) => to_value(&self.client.code(&address).map_or_else(Bytes::default, Bytes::new)),
Err(err) => Err(err)
}
from_params::<(Address, BlockNumber)>(params)
.and_then(|(address, _block_number)| to_value(&self.client.code(&address).map_or_else(Bytes::default, Bytes::new)))
}
fn block(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256, bool)>(params) {
Ok((hash, include_txs)) => match (self.client.block(&hash), self.client.block_total_difficulty(&hash)) {
from_params::<(H256, bool)>(params)
.and_then(|(hash, include_txs)| match (self.client.block(&hash), self.client.block_total_difficulty(&hash)) {
(Some(bytes), Some(total_difficulty)) => {
let block_view = BlockView::new(&bytes);
let view = block_view.header_view();
@ -158,19 +152,15 @@ impl Eth for EthClient {
to_value(&block)
},
_ => Ok(Value::Null)
},
Err(err) => Err(err)
}
})
}
fn transaction_at(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256,)>(params) {
Ok((hash,)) => match self.client.transaction(&hash) {
fn transaction_by_hash(&self, params: Params) -> Result<Value, Error> {
from_params::<(H256,)>(params)
.and_then(|(hash,)| match self.client.transaction(&hash) {
Some(t) => to_value(&Transaction::from(t)),
None => Ok(Value::Null)
},
Err(err) => Err(err)
}
})
}
}

View File

@ -74,8 +74,14 @@ pub trait Eth: Sized + Send + Sync + 'static {
/// Estimate gas needed for execution of given contract.
fn estimate_gas(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction at given block and index.
fn transaction_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Get transaction by it's hash.
fn transaction_by_hash(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction at given block hash and index.
fn transaction_by_block_hash_and_index(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction by given block number and index.
fn transaction_by_block_number_and_index(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns transaction receipt.
fn transaction_receipt(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
@ -131,9 +137,9 @@ pub trait Eth: Sized + Send + Sync + 'static {
delegate.add_method("eth_estimateGas", Eth::estimate_gas);
delegate.add_method("eth_getBlockByHash", Eth::block);
delegate.add_method("eth_getBlockByNumber", Eth::block);
delegate.add_method("eth_getTransactionByHash", Eth::transaction_at);
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_at);
delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_at);
delegate.add_method("eth_getTransactionByHash", Eth::transaction_by_hash);
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_by_block_hash_and_index);
delegate.add_method("eth_getTransactionByBlockNumberAndIndex", Eth::transaction_by_block_number_and_index);
delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt);
delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_at);
delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_at);