rpc eth_getFilterChanges returns new blocks, implemented eth_uninstallFilter

This commit is contained in:
debris 2016-02-24 14:16:05 +01:00
parent 932b31227f
commit 0318907fb3
3 changed files with 30 additions and 3 deletions

View File

@ -114,6 +114,9 @@ pub trait BlockChainClient : Sync + Send {
/// Get block total difficulty. /// Get block total difficulty.
fn block_total_difficulty(&self, id: BlockId) -> Option<U256>; fn block_total_difficulty(&self, id: BlockId) -> Option<U256>;
/// Get block hash.
fn block_hash(&self, id: BlockId) -> Option<H256>;
/// Get address code. /// Get address code.
fn code(&self, address: &Address) -> Option<Bytes>; fn code(&self, address: &Address) -> Option<Bytes>;
@ -416,6 +419,11 @@ impl BlockChainClient for Client {
Self::block_hash(&chain, id).and_then(|hash| chain.block_details(&hash)).map(|d| d.total_difficulty) Self::block_hash(&chain, id).and_then(|hash| chain.block_details(&hash)).map(|d| d.total_difficulty)
} }
fn block_hash(&self, id: BlockId) -> Option<H256> {
let chain = self.chain.read().unwrap();
Self::block_hash(&chain, id)
}
fn code(&self, address: &Address) -> Option<Bytes> { fn code(&self, address: &Address) -> Option<Bytes> {
self.state().code(address) self.state().code(address)
} }

View File

@ -267,11 +267,18 @@ impl EthFilter for EthFilterClient {
None => Ok(Value::Array(vec![] as Vec<Value>)), None => Ok(Value::Array(vec![] as Vec<Value>)),
Some(info) => match info.filter { Some(info) => match info.filter {
PollFilter::Block => { PollFilter::Block => {
//unimplemented!() let current_number = self.client.chain_info().best_block_number;
to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v])) let hashes = (info.block_number..current_number).into_iter()
.map(BlockId::Number)
.filter_map(|id| self.client.block_hash(id))
.collect::<Vec<H256>>();
self.polls.lock().unwrap().update_poll(&index.value(), current_number);
to_value(&hashes)
}, },
PollFilter::PendingTransaction => { PollFilter::PendingTransaction => {
//unimplemented!() // TODO: fix implementation
to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v])) to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v]))
}, },
PollFilter::Logs(mut filter) => { PollFilter::Logs(mut filter) => {
@ -291,4 +298,12 @@ impl EthFilter for EthFilterClient {
} }
}) })
} }
fn uninstall_filter(&self, params: Params) -> Result<Value, Error> {
from_params::<(Index,)>(params)
.and_then(|(index,)| {
self.polls.lock().unwrap().remove_poll(&index.value());
to_value(&true)
})
}
} }

View File

@ -105,6 +105,10 @@ impl BlockChainClient for TestBlockChainClient {
Some(U256::zero()) Some(U256::zero())
} }
fn block_hash(&self, id: BlockId) -> Option<H256> {
unimplemented!();
}
fn code(&self, _address: &Address) -> Option<Bytes> { fn code(&self, _address: &Address) -> Option<Bytes> {
unimplemented!(); unimplemented!();
} }