bloom possibilities in progress

This commit is contained in:
debris
2016-02-13 13:05:28 +01:00
parent c9e0071fde
commit 3fcade9f6d
2 changed files with 86 additions and 12 deletions

View File

@@ -144,6 +144,9 @@ pub trait BlockChainClient : Sync + Send {
fn best_block_header(&self) -> Bytes {
self.block_header(BlockId::Hash(self.chain_info().best_block_hash)).unwrap()
}
/// Returns numbers of blocks containing given bloom.
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>>;
}
#[derive(Default, Clone, Debug, Eq, PartialEq)]
@@ -358,6 +361,15 @@ impl Client {
BlockId::Latest => Some(self.chain.read().unwrap().best_block_hash())
}
}
fn block_number(&self, id: BlockId) -> Option<BlockNumber> {
match id {
BlockId::Number(number) => Some(number),
BlockId::Hash(ref hash) => self.chain.read().unwrap().block_number(hash),
BlockId::Earliest => Some(0),
BlockId::Latest => Some(self.chain.read().unwrap().best_block_number())
}
}
}
impl BlockChainClient for Client {
@@ -450,6 +462,13 @@ impl BlockChainClient for Client {
best_block_number: From::from(chain.best_block_number())
}
}
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>> {
match (self.block_number(from_block), self.block_number(to_block)) {
(Some(from), Some(to)) => Some(self.chain.read().unwrap().blocks_with_bloom(bloom, from, to)),
_ => None
}
}
}
impl MayPanic for Client {