mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
20
parser/src/structs/epoch.rs
Normal file
20
parser/src/structs/epoch.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use super::{Height, MapKey};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Epoch(pub u16);
|
||||
|
||||
impl Epoch {
|
||||
pub const BLOCKS_PER_EPOCH: usize = 210_000;
|
||||
}
|
||||
|
||||
impl From<Height> for Epoch {
|
||||
fn from(height: Height) -> Self {
|
||||
Self(((height.to_usize() / Self::BLOCKS_PER_EPOCH) + 1) as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Height> for Epoch {
|
||||
fn from(height: &Height) -> Self {
|
||||
Self(((height.to_usize() / Self::BLOCKS_PER_EPOCH) + 1) as u16)
|
||||
}
|
||||
}
|
||||
@@ -202,10 +202,12 @@ where
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: Key, value: Value) -> Value {
|
||||
self.to_insert
|
||||
.entry(key.to_chunk_id())
|
||||
.or_default()
|
||||
.insert(key.to_serialized_key(), value);
|
||||
if !self.is_key_safe(key) {
|
||||
self.to_insert
|
||||
.entry(key.to_chunk_id())
|
||||
.or_default()
|
||||
.insert(key.to_serialized_key(), value);
|
||||
}
|
||||
|
||||
value
|
||||
}
|
||||
@@ -443,15 +445,14 @@ where
|
||||
SourceValue,
|
||||
&Key,
|
||||
&mut GenericMap<Key, SourceValue, ChunkId, SourceSerialized>,
|
||||
&Self,
|
||||
&mut Self,
|
||||
),
|
||||
) -> Value,
|
||||
{
|
||||
keys.iter().for_each(|key| {
|
||||
self.insert(
|
||||
*key,
|
||||
transform((source.get_or_import(key).unwrap(), key, source, self)),
|
||||
);
|
||||
let value = transform((source.get_or_import(key).unwrap(), key, source, self));
|
||||
|
||||
self.insert(*key, value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ mod date_data;
|
||||
mod date_map;
|
||||
mod date_map_chunk_id;
|
||||
mod empty_address_data;
|
||||
mod epoch;
|
||||
mod exit;
|
||||
mod generic_map;
|
||||
mod height;
|
||||
@@ -53,6 +54,7 @@ pub use date_data::*;
|
||||
pub use date_map::*;
|
||||
pub use date_map_chunk_id::*;
|
||||
pub use empty_address_data::*;
|
||||
pub use epoch::*;
|
||||
pub use exit::*;
|
||||
pub use generic_map::*;
|
||||
pub use height::*;
|
||||
|
||||
Reference in New Issue
Block a user