mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-25 01:38:12 -07:00
global: snapshot
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use brk_structs::Block;
|
||||
use brk_types::Block;
|
||||
|
||||
use crate::State;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use brk_error::Result;
|
||||
use brk_reader::Reader;
|
||||
use brk_rpc::Client;
|
||||
use brk_structs::{BlockHash, Height};
|
||||
use brk_types::{BlockHash, Height};
|
||||
|
||||
mod iterator;
|
||||
mod range;
|
||||
@@ -67,7 +67,7 @@ impl Blocks {
|
||||
}
|
||||
|
||||
/// Iterate after hash
|
||||
pub fn after(&self, hash: BlockHash) -> Result<BlockIterator> {
|
||||
pub fn after(&self, hash: Option<BlockHash>) -> Result<BlockIterator> {
|
||||
self.iter(BlockRange::After { hash })
|
||||
}
|
||||
|
||||
@@ -109,10 +109,14 @@ impl Blocks {
|
||||
Ok((start, end, None))
|
||||
}
|
||||
BlockRange::After { hash } => {
|
||||
let block_info = client.get_block_header_info(&hash)?;
|
||||
let start = (block_info.height + 1).into();
|
||||
let start = if let Some(hash) = hash.as_ref() {
|
||||
let block_info = client.get_block_header_info(hash)?;
|
||||
(block_info.height + 1).into()
|
||||
} else {
|
||||
Height::ZERO
|
||||
};
|
||||
let end = client.get_last_height()?;
|
||||
Ok((start, end, Some(hash)))
|
||||
Ok((start, end, hash))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use brk_structs::{BlockHash, Height};
|
||||
use brk_types::{BlockHash, Height};
|
||||
|
||||
pub enum BlockRange {
|
||||
Span { start: Height, end: Height },
|
||||
Start { start: Height },
|
||||
End { end: Height },
|
||||
Last { n: u32 },
|
||||
After { hash: BlockHash },
|
||||
After { hash: Option<BlockHash> },
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::vec;
|
||||
|
||||
use brk_reader::{Reader, Receiver};
|
||||
use brk_rpc::Client;
|
||||
use brk_structs::{BlockHash, Height, ReadBlock};
|
||||
use brk_types::{BlockHash, Height, ReadBlock};
|
||||
|
||||
pub enum State {
|
||||
Rpc {
|
||||
|
||||
Reference in New Issue
Block a user