global: snapshot

This commit is contained in:
nym21
2025-10-22 12:36:35 +02:00
parent 8072c4670c
commit 6cd60a064b
20 changed files with 385 additions and 214 deletions

View File

@@ -0,0 +1,49 @@
use std::vec;
use brk_reader::{Reader, Receiver};
use brk_rpc::Client;
use brk_structs::{BlockHash, Height, ReadBlock};
pub enum State {
Rpc {
client: Client,
heights: vec::IntoIter<Height>,
prev_hash: Option<BlockHash>,
},
Reader {
receiver: Receiver<ReadBlock>,
after_hash: Option<BlockHash>,
},
}
impl State {
pub fn new_rpc(
client: Client,
start: Height,
end: Height,
prev_hash: Option<BlockHash>,
) -> Self {
let heights = (*start..=*end)
.map(Height::new)
.collect::<Vec<_>>()
.into_iter();
Self::Rpc {
client,
heights,
prev_hash,
}
}
pub fn new_reader(
reader: Reader,
start: Height,
end: Height,
after_hash: Option<BlockHash>,
) -> Self {
State::Reader {
receiver: reader.read(Some(start), Some(end)),
after_hash,
}
}
}