rpc eth_getFilterChanges returns new blocks, implemented eth_uninstallFilter
This commit is contained in:
parent
932b31227f
commit
0318907fb3
@ -114,6 +114,9 @@ pub trait BlockChainClient : Sync + Send {
|
||||
/// Get block total difficulty.
|
||||
fn block_total_difficulty(&self, id: BlockId) -> Option<U256>;
|
||||
|
||||
/// Get block hash.
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256>;
|
||||
|
||||
/// Get address code.
|
||||
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)
|
||||
}
|
||||
|
||||
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> {
|
||||
self.state().code(address)
|
||||
}
|
||||
|
@ -267,11 +267,18 @@ impl EthFilter for EthFilterClient {
|
||||
None => Ok(Value::Array(vec![] as Vec<Value>)),
|
||||
Some(info) => match info.filter {
|
||||
PollFilter::Block => {
|
||||
//unimplemented!()
|
||||
to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v]))
|
||||
let current_number = self.client.chain_info().best_block_number;
|
||||
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 => {
|
||||
//unimplemented!()
|
||||
// TODO: fix implementation
|
||||
to_value(&self.client.chain_info().best_block_hash).map(|v| Value::Array(vec![v]))
|
||||
},
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,10 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
Some(U256::zero())
|
||||
}
|
||||
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn code(&self, _address: &Address) -> Option<Bytes> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user