mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-30 17:40:00 -07:00
general: snapshot
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use std::{fs, io};
|
||||
|
||||
use crate::{structs::WNaiveDate, utils::log};
|
||||
use crate::{
|
||||
structs::{Date, Height},
|
||||
utils::log,
|
||||
};
|
||||
|
||||
use super::databases_folder_path;
|
||||
|
||||
@@ -10,7 +13,7 @@ where
|
||||
{
|
||||
fn import() -> Self;
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()>;
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()>;
|
||||
|
||||
fn folder<'a>() -> &'a str;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use allocative::Allocative;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
structs::{AddressData, WNaiveDate},
|
||||
structs::{AddressData, Date, Height},
|
||||
utils::time,
|
||||
};
|
||||
|
||||
@@ -97,7 +97,11 @@ impl AddressIndexToAddressData {
|
||||
}
|
||||
|
||||
fn open_all(&mut self) {
|
||||
fs::read_dir(databases_folder_path(Self::folder()))
|
||||
let path = Self::full_path();
|
||||
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
|
||||
fs::read_dir(path)
|
||||
.unwrap()
|
||||
.map(|entry| {
|
||||
entry
|
||||
@@ -128,7 +132,7 @@ impl AnyDatabaseGroup for AddressIndexToAddressData {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
mem::take(&mut self.map)
|
||||
.into_par_iter()
|
||||
.try_for_each(|(_, db)| db.export())?;
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::{
|
||||
use allocative::Allocative;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::structs::{EmptyAddressData, WNaiveDate};
|
||||
use crate::structs::{Date, EmptyAddressData, Height};
|
||||
|
||||
use super::{AnyDatabaseGroup, Metadata, SizedDatabase};
|
||||
|
||||
@@ -103,7 +103,7 @@ impl AnyDatabaseGroup for AddressIndexToEmptyAddressData {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
mem::take(&mut self.map)
|
||||
.into_par_iter()
|
||||
.try_for_each(|(_, db)| db.export())?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::{collections::BTreeMap, mem, thread};
|
||||
use allocative::Allocative;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::structs::{Address, WNaiveDate};
|
||||
use crate::structs::{Address, Date, Height};
|
||||
|
||||
use super::{
|
||||
AnyDatabaseGroup, Database, Metadata, SizedDatabase, U8x19, U8x31,
|
||||
@@ -261,7 +261,7 @@ impl AnyDatabaseGroup for AddressToAddressIndex {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
thread::scope(|s| {
|
||||
s.spawn(|| {
|
||||
mem::take(&mut self.p2pk)
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
io::Binary,
|
||||
structs::{Counter, WNaiveDate},
|
||||
structs::{Counter, Date, Height},
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Encode, Decode, Allocative)]
|
||||
@@ -39,7 +39,7 @@ impl Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
pub fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
if self.last_height.unwrap_or_default() < height {
|
||||
self.last_height.replace(height);
|
||||
}
|
||||
@@ -77,8 +77,8 @@ impl Metadata {
|
||||
pub struct MetadataData {
|
||||
pub serial: usize,
|
||||
pub len: Counter,
|
||||
pub last_height: Option<usize>,
|
||||
pub last_date: Option<WNaiveDate>,
|
||||
pub last_height: Option<Height>,
|
||||
pub last_date: Option<Date>,
|
||||
}
|
||||
|
||||
impl MetadataData {
|
||||
|
||||
@@ -22,7 +22,10 @@ pub use txid_to_tx_data::*;
|
||||
pub use txout_index_to_address_index::*;
|
||||
pub use txout_index_to_amount::*;
|
||||
|
||||
use crate::{structs::WNaiveDate, utils::time};
|
||||
use crate::{
|
||||
structs::{Date, Height},
|
||||
utils::time,
|
||||
};
|
||||
|
||||
#[derive(Allocative)]
|
||||
pub struct Databases {
|
||||
@@ -58,7 +61,7 @@ impl Databases {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
pub fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
thread::scope(|s| {
|
||||
s.spawn(|| {
|
||||
time("> Database txid_to_tx_data", || {
|
||||
@@ -115,13 +118,13 @@ impl Databases {
|
||||
let _ = self.txout_index_to_amount.reset();
|
||||
}
|
||||
|
||||
pub fn check_if_needs_to_compute_addresses(&self, height: usize, date: WNaiveDate) -> bool {
|
||||
let check_height = |last_height: Option<usize>| {
|
||||
pub fn check_if_needs_to_compute_addresses(&self, height: Height, date: Date) -> bool {
|
||||
let check_height = |last_height: Option<Height>| {
|
||||
last_height.map_or(true, |last_height| last_height < height)
|
||||
};
|
||||
|
||||
let check_date =
|
||||
|last_date: Option<WNaiveDate>| last_date.map_or(true, |last_date| last_date < date);
|
||||
|last_date: Option<Date>| last_date.map_or(true, |last_date| last_date < date);
|
||||
|
||||
let check_metadata = |metadata: &Metadata| {
|
||||
check_height(metadata.last_height) || check_date(metadata.last_date)
|
||||
@@ -133,8 +136,8 @@ impl Databases {
|
||||
|
||||
pub fn check_if_usable(
|
||||
&self,
|
||||
min_initial_last_address_height: Option<usize>,
|
||||
min_initial_last_address_date: Option<WNaiveDate>,
|
||||
min_initial_last_address_height: Option<Height>,
|
||||
min_initial_last_address_date: Option<Date>,
|
||||
) -> bool {
|
||||
let are_tx_databases_in_sync = self
|
||||
.txout_index_to_amount
|
||||
|
||||
@@ -8,7 +8,7 @@ use allocative::Allocative;
|
||||
use bitcoin::Txid;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::structs::{TxData, WNaiveDate};
|
||||
use crate::structs::{Date, Height, TxData};
|
||||
|
||||
use super::{AnyDatabaseGroup, Metadata, SizedDatabase, U8x31};
|
||||
|
||||
@@ -127,7 +127,7 @@ impl AnyDatabaseGroup for TxidToTxData {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
mem::take(&mut self.map)
|
||||
.into_par_iter()
|
||||
.try_for_each(|(_, db)| db.export())?;
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::{
|
||||
use allocative::Allocative;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::structs::{TxoutIndex, WNaiveDate};
|
||||
use crate::structs::{Date, Height, TxoutIndex};
|
||||
|
||||
use super::{AnyDatabaseGroup, Metadata, SizedDatabase};
|
||||
|
||||
@@ -94,7 +94,7 @@ impl AnyDatabaseGroup for TxoutIndexToAddressIndex {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
mem::take(&mut self.map)
|
||||
.into_par_iter()
|
||||
.try_for_each(|(_, db)| db.export())?;
|
||||
|
||||
@@ -7,12 +7,12 @@ use std::{
|
||||
use allocative::Allocative;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::structs::{TxoutIndex, WAmount, WNaiveDate};
|
||||
use crate::structs::{Amount, Date, Height, TxoutIndex};
|
||||
|
||||
use super::{AnyDatabaseGroup, Metadata, SizedDatabase};
|
||||
|
||||
type Key = TxoutIndex;
|
||||
type Value = WAmount;
|
||||
type Value = Amount;
|
||||
type Database = SizedDatabase<Key, Value>;
|
||||
|
||||
#[derive(Allocative)]
|
||||
@@ -94,7 +94,7 @@ impl AnyDatabaseGroup for TxoutIndexToAmount {
|
||||
}
|
||||
}
|
||||
|
||||
fn export(&mut self, height: usize, date: WNaiveDate) -> color_eyre::Result<()> {
|
||||
fn export(&mut self, height: Height, date: Date) -> color_eyre::Result<()> {
|
||||
mem::take(&mut self.map)
|
||||
.into_par_iter()
|
||||
.try_for_each(|(_, db)| db.export())?;
|
||||
|
||||
Reference in New Issue
Block a user