mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-14 12:38:13 -07:00
global: snapshot
This commit is contained in:
+3
-3
@@ -92,7 +92,7 @@ impl Indexer<CACHED_GETS> {
|
||||
iterator::new(bitcoin_dir, Some(height.into()), Some(400_000), rpc)
|
||||
.iter()
|
||||
.try_for_each(|(_height, block, blockhash)| -> color_eyre::Result<()> {
|
||||
info!("Processing block {_height}...");
|
||||
info!("Indexing block {_height}...");
|
||||
|
||||
let blockhash = BlockHash::from(blockhash);
|
||||
height = Height::from(_height);
|
||||
@@ -440,13 +440,13 @@ impl Indexer<CACHED_GETS> {
|
||||
(txout, txindex, vout, addresstype, addressbytes_res, addressindex_opt, _tx),
|
||||
)|
|
||||
-> color_eyre::Result<()> {
|
||||
let amount = Amount::from(txout.value);
|
||||
let sats = Sats::from(txout.value);
|
||||
|
||||
if vout.is_zero() {
|
||||
vecs.txindex_to_first_txoutindex.push_if_needed(txindex, txoutindex)?;
|
||||
}
|
||||
|
||||
vecs.txoutindex_to_amount.push_if_needed(txoutindex, amount)?;
|
||||
vecs.txoutindex_to_value.push_if_needed(txoutindex, sats)?;
|
||||
|
||||
let mut addressindex = addressindex_global;
|
||||
|
||||
|
||||
@@ -5,11 +5,10 @@ use rayon::prelude::*;
|
||||
use storable_vec::{AnyJsonStorableVec, Version, CACHED_GETS};
|
||||
|
||||
use crate::structs::{
|
||||
Addressbytes, Addressindex, Addresstype, Addresstypeindex, Amount, BlockHash, Emptyindex, Height, LockTime,
|
||||
Multisigindex, Opreturnindex, P2PK33AddressBytes, P2PK33index, P2PK65AddressBytes, P2PK65index, P2PKHAddressBytes,
|
||||
P2PKHindex, P2SHAddressBytes, P2SHindex, P2TRAddressBytes, P2TRindex, P2WPKHAddressBytes, P2WPKHindex,
|
||||
P2WSHAddressBytes, P2WSHindex, Pushonlyindex, Timestamp, TxVersion, Txid, Txindex, Txinindex, Txoutindex,
|
||||
Unknownindex, Weight,
|
||||
Addressbytes, Addressindex, Addresstype, Addresstypeindex, BlockHash, Emptyindex, Height, LockTime, Multisigindex,
|
||||
Opreturnindex, P2PK33AddressBytes, P2PK33index, P2PK65AddressBytes, P2PK65index, P2PKHAddressBytes, P2PKHindex,
|
||||
P2SHAddressBytes, P2SHindex, P2TRAddressBytes, P2TRindex, P2WPKHAddressBytes, P2WPKHindex, P2WSHAddressBytes,
|
||||
P2WSHindex, Pushonlyindex, Sats, Timestamp, TxVersion, Txid, Txindex, Txinindex, Txoutindex, Unknownindex, Weight,
|
||||
};
|
||||
|
||||
mod base;
|
||||
@@ -56,7 +55,7 @@ pub struct StorableVecs<const MODE: u8> {
|
||||
pub txindex_to_txversion: StorableVec<Txindex, TxVersion, MODE>,
|
||||
pub txinindex_to_txoutindex: StorableVec<Txinindex, Txoutindex, MODE>,
|
||||
pub txoutindex_to_addressindex: StorableVec<Txoutindex, Addressindex, MODE>,
|
||||
pub txoutindex_to_amount: StorableVec<Txoutindex, Amount, MODE>,
|
||||
pub txoutindex_to_value: StorableVec<Txoutindex, Sats, MODE>,
|
||||
}
|
||||
|
||||
// const UNSAFE_BLOCKS: usize = 1000;
|
||||
@@ -177,7 +176,7 @@ impl<const MODE: u8> StorableVecs<MODE> {
|
||||
&path.join("txoutindex_to_addressindex"),
|
||||
Version::from(1),
|
||||
)?,
|
||||
txoutindex_to_amount: StorableVec::import(&path.join("txoutindex_to_amount"), Version::from(1))?,
|
||||
txoutindex_to_value: StorableVec::import(&path.join("txoutindex_to_value"), Version::from(1))?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -350,7 +349,7 @@ impl<const MODE: u8> StorableVecs<MODE> {
|
||||
&*self.txindex_to_txversion,
|
||||
&*self.txinindex_to_txoutindex,
|
||||
&*self.txoutindex_to_addressindex,
|
||||
&*self.txoutindex_to_amount,
|
||||
&*self.txoutindex_to_value,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -395,7 +394,7 @@ impl<const MODE: u8> StorableVecs<MODE> {
|
||||
&mut self.txindex_to_txversion,
|
||||
&mut self.txinindex_to_txoutindex,
|
||||
&mut self.txoutindex_to_addressindex,
|
||||
&mut self.txoutindex_to_amount,
|
||||
&mut self.txoutindex_to_value,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ mod addressbytes;
|
||||
mod addressindex;
|
||||
mod addresstype;
|
||||
mod addresstypeindex;
|
||||
mod amount;
|
||||
mod blockhash;
|
||||
mod compressed;
|
||||
mod height;
|
||||
mod locktime;
|
||||
mod sats;
|
||||
mod timestamp;
|
||||
mod txid;
|
||||
mod txindex;
|
||||
@@ -21,11 +21,11 @@ pub use addressbytes::*;
|
||||
pub use addressindex::*;
|
||||
pub use addresstype::*;
|
||||
pub use addresstypeindex::*;
|
||||
pub use amount::*;
|
||||
pub use blockhash::*;
|
||||
pub use compressed::*;
|
||||
pub use height::*;
|
||||
pub use locktime::*;
|
||||
pub use sats::*;
|
||||
pub use timestamp::*;
|
||||
pub use txid::*;
|
||||
pub use txindex::*;
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{
|
||||
};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use iterator::bitcoin;
|
||||
use iterator::bitcoin::Amount;
|
||||
use serde::Serialize;
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
@@ -27,85 +27,83 @@ use super::Height;
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
)]
|
||||
pub struct Amount(u64);
|
||||
pub struct Sats(u64);
|
||||
|
||||
impl Amount {
|
||||
impl Sats {
|
||||
pub const ZERO: Self = Self(0);
|
||||
pub const ONE_BTC_F32: f32 = 100_000_000.0;
|
||||
pub const ONE_BTC_F64: f64 = 100_000_000.0;
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
*self == Self::ZERO
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Amount {
|
||||
type Output = Amount;
|
||||
fn add(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self + *rhs)
|
||||
impl Add for Sats {
|
||||
type Output = Sats;
|
||||
fn add(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self + *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Amount {
|
||||
impl AddAssign for Sats {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for Amount {
|
||||
type Output = Amount;
|
||||
fn sub(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self - *rhs)
|
||||
impl Sub for Sats {
|
||||
type Output = Sats;
|
||||
fn sub(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self - *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign for Amount {
|
||||
impl SubAssign for Sats {
|
||||
fn sub_assign(&mut self, rhs: Self) {
|
||||
*self = *self - rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Amount> for Amount {
|
||||
type Output = Amount;
|
||||
fn mul(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self * *rhs)
|
||||
impl Mul<Sats> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self * *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<u64> for Amount {
|
||||
type Output = Amount;
|
||||
impl Mul<u64> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: u64) -> Self::Output {
|
||||
Amount::from(*self * rhs)
|
||||
Sats::from(*self * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Height> for Amount {
|
||||
type Output = Amount;
|
||||
impl Mul<Height> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: Height) -> Self::Output {
|
||||
Amount::from(*self * *rhs as u64)
|
||||
Sats::from(*self * *rhs as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sum for Amount {
|
||||
impl Sum for Sats {
|
||||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||
let sats: u64 = iter.map(|amt| *amt).sum();
|
||||
Amount::from(sats)
|
||||
let sats: u64 = iter.map(|sats| *sats).sum();
|
||||
Sats::from(sats)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Amount {
|
||||
impl From<u64> for Sats {
|
||||
fn from(value: u64) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bitcoin::Amount> for Amount {
|
||||
fn from(value: bitcoin::Amount) -> Self {
|
||||
impl From<Amount> for Sats {
|
||||
fn from(value: Amount) -> Self {
|
||||
Self(value.to_sat())
|
||||
}
|
||||
}
|
||||
impl From<Amount> for bitcoin::Amount {
|
||||
fn from(value: Amount) -> Self {
|
||||
impl From<Sats> for Amount {
|
||||
fn from(value: Sats) -> Self {
|
||||
Self::from_sat(value.0)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use derive_deref::Deref;
|
||||
pub struct Vout(u32);
|
||||
|
||||
impl Vout {
|
||||
const ZERO: Self = Vout(0_u32);
|
||||
const ZERO: Self = Vout(0);
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
*self == Self::ZERO
|
||||
|
||||
Reference in New Issue
Block a user