uncle method mock

This commit is contained in:
debris 2016-03-14 17:01:10 +01:00
parent 47ca84041b
commit 9b241faf01
3 changed files with 27 additions and 4 deletions

View File

@ -223,6 +223,11 @@ impl<'a> BlockView<'a> {
pub fn uncle_hashes(&self) -> Vec<H256> { pub fn uncle_hashes(&self) -> Vec<H256> {
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect() self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
} }
/// Return nth uncle.
pub fn uncle_at(&self, index: usize) -> Option<Header> {
self.rlp.at(2).iter().nth(index).map(|rlp| rlp.as_val())
}
} }
impl<'a> Hashable for BlockView<'a> { impl<'a> Hashable for BlockView<'a> {
@ -280,7 +285,7 @@ impl<'a> HeaderView<'a> {
/// Returns block number. /// Returns block number.
pub fn number(&self) -> BlockNumber { self.rlp.val_at(8) } pub fn number(&self) -> BlockNumber { self.rlp.val_at(8) }
/// Returns block gas limit. /// Returns block gas limit.
pub fn gas_limit(&self) -> U256 { self.rlp.val_at(9) } pub fn gas_limit(&self) -> U256 { self.rlp.val_at(9) }

View File

@ -125,6 +125,11 @@ impl<C, S, A, M, EM> EthClient<C, S, A, M, EM>
None => Ok(Value::Null) None => Ok(Value::Null)
} }
} }
fn uncle(&self, _block: BlockId, _index: usize) -> Result<Value, Error> {
// TODO: implement!
Ok(Value::Null)
}
} }
impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
@ -285,6 +290,16 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
.and_then(|(number, index)| self.transaction(TransactionId::Location(number.into(), index.value()))) .and_then(|(number, index)| self.transaction(TransactionId::Location(number.into(), index.value())))
} }
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(H256, Index)>(params)
.and_then(|(hash, index)| self.uncle(BlockId::Hash(hash), index.value()))
}
fn uncle_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> {
from_params::<(BlockNumber, Index)>(params)
.and_then(|(number, index)| self.uncle(number.into(), index.value()))
}
fn compilers(&self, params: Params) -> Result<Value, Error> { fn compilers(&self, params: Params) -> Result<Value, Error> {
match params { match params {
Params::None => to_value(&vec![] as &Vec<String>), Params::None => to_value(&vec![] as &Vec<String>),

View File

@ -102,7 +102,10 @@ pub trait Eth: Sized + Send + Sync + 'static {
fn transaction_receipt(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } fn transaction_receipt(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns an uncles at given block and index. /// Returns an uncles at given block and index.
fn uncle_at(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } fn uncle_by_block_hash_and_index(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns an uncles at given block and index.
fn uncle_by_block_number_and_index(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
/// Returns available compilers. /// Returns available compilers.
fn compilers(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() } fn compilers(&self, _: Params) -> Result<Value, Error> { rpc_unimplemented!() }
@ -158,8 +161,8 @@ pub trait Eth: Sized + Send + Sync + 'static {
delegate.add_method("eth_getTransactionByBlockHashAndIndex", Eth::transaction_by_block_hash_and_index); 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_getTransactionByBlockNumberAndIndex", Eth::transaction_by_block_number_and_index);
delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt); delegate.add_method("eth_getTransactionReceipt", Eth::transaction_receipt);
delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_at); delegate.add_method("eth_getUncleByBlockHashAndIndex", Eth::uncle_by_block_hash_and_index);
delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_at); delegate.add_method("eth_getUncleByBlockNumberAndIndex", Eth::uncle_by_block_number_and_index);
delegate.add_method("eth_getCompilers", Eth::compilers); delegate.add_method("eth_getCompilers", Eth::compilers);
delegate.add_method("eth_compileLLL", Eth::compile_lll); delegate.add_method("eth_compileLLL", Eth::compile_lll);
delegate.add_method("eth_compileSolidity", Eth::compile_solidity); delegate.add_method("eth_compileSolidity", Eth::compile_solidity);