fetch gas price corpus from network when needed
This commit is contained in:
@@ -241,6 +241,14 @@ impl HeaderChain {
|
||||
self.block_header(BlockId::Latest).expect("Header for best block always stored; qed")
|
||||
}
|
||||
|
||||
/// Get an iterator over a block and its ancestry.
|
||||
pub fn ancestry_iter(&self, start: BlockId) -> AncestryIter {
|
||||
AncestryIter {
|
||||
next: self.block_header(start),
|
||||
chain: self,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the nth CHT root, if it's been computed.
|
||||
///
|
||||
/// CHT root 0 is from block `1..2048`.
|
||||
@@ -295,6 +303,25 @@ impl HeapSizeOf for HeaderChain {
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator over a block's ancestry.
|
||||
pub struct AncestryIter<'a> {
|
||||
next: Option<encoded::Header>,
|
||||
chain: &'a HeaderChain,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for AncestryIter<'a> {
|
||||
type Item = encoded::Header;
|
||||
|
||||
fn next(&mut self) -> Option<encoded::Header> {
|
||||
let next = self.next.take();
|
||||
if let Some(p_hash) = next.as_ref().map(|hdr| hdr.parent_hash()) {
|
||||
self.next = self.chain.block_header(BlockId::Hash(p_hash));
|
||||
}
|
||||
|
||||
next
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::HeaderChain;
|
||||
|
||||
@@ -33,7 +33,7 @@ use io::IoChannel;
|
||||
|
||||
use util::{Bytes, H256, Mutex, RwLock};
|
||||
|
||||
use self::header_chain::HeaderChain;
|
||||
use self::header_chain::{AncestryIter, HeaderChain};
|
||||
|
||||
pub use self::service::Service;
|
||||
|
||||
@@ -62,6 +62,9 @@ pub trait LightChainClient: Send + Sync {
|
||||
/// Get the best block header.
|
||||
fn best_block_header(&self) -> encoded::Header;
|
||||
|
||||
/// Get an iterator over a block and its ancestry.
|
||||
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<Iterator<Item=encoded::Header> + 'a>;
|
||||
|
||||
/// Get the signing network ID.
|
||||
fn signing_network_id(&self) -> Option<u64>;
|
||||
|
||||
@@ -167,6 +170,11 @@ impl Client {
|
||||
self.chain.best_header()
|
||||
}
|
||||
|
||||
/// Get an iterator over a block and its ancestry.
|
||||
pub fn ancestry_iter(&self, start: BlockId) -> AncestryIter {
|
||||
self.chain.ancestry_iter(start)
|
||||
}
|
||||
|
||||
/// Get the signing network id.
|
||||
pub fn signing_network_id(&self) -> Option<u64> {
|
||||
self.engine.signing_network_id(&self.latest_env_info())
|
||||
@@ -269,6 +277,10 @@ impl LightChainClient for Client {
|
||||
Client::best_block_header(self)
|
||||
}
|
||||
|
||||
fn ancestry_iter<'a>(&'a self, start: BlockId) -> Box<Iterator<Item=encoded::Header> + 'a> {
|
||||
Box::new(Client::ancestry_iter(self, start))
|
||||
}
|
||||
|
||||
fn signing_network_id(&self) -> Option<u64> {
|
||||
Client::signing_network_id(self)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user