mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-19 14:24:47 -07:00
global: fmt
This commit is contained in:
@@ -30,40 +30,52 @@ impl IndexesExt for Indexes {
|
||||
.first_txout_index
|
||||
.checked_push(height, self.txout_index)?;
|
||||
vecs.scripts
|
||||
.empty.first_index
|
||||
.empty
|
||||
.first_index
|
||||
.checked_push(height, self.empty_output_index)?;
|
||||
vecs.scripts
|
||||
.p2ms.first_index
|
||||
.p2ms
|
||||
.first_index
|
||||
.checked_push(height, self.p2ms_output_index)?;
|
||||
vecs.scripts
|
||||
.op_return.first_index
|
||||
.op_return
|
||||
.first_index
|
||||
.checked_push(height, self.op_return_index)?;
|
||||
vecs.addrs
|
||||
.p2a.first_index
|
||||
.p2a
|
||||
.first_index
|
||||
.checked_push(height, self.p2a_addr_index)?;
|
||||
vecs.scripts
|
||||
.unknown.first_index
|
||||
.unknown
|
||||
.first_index
|
||||
.checked_push(height, self.unknown_output_index)?;
|
||||
vecs.addrs
|
||||
.p2pk33.first_index
|
||||
.p2pk33
|
||||
.first_index
|
||||
.checked_push(height, self.p2pk33_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2pk65.first_index
|
||||
.p2pk65
|
||||
.first_index
|
||||
.checked_push(height, self.p2pk65_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2pkh.first_index
|
||||
.p2pkh
|
||||
.first_index
|
||||
.checked_push(height, self.p2pkh_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2sh.first_index
|
||||
.p2sh
|
||||
.first_index
|
||||
.checked_push(height, self.p2sh_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2tr.first_index
|
||||
.p2tr
|
||||
.first_index
|
||||
.checked_push(height, self.p2tr_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2wpkh.first_index
|
||||
.p2wpkh
|
||||
.first_index
|
||||
.checked_push(height, self.p2wpkh_addr_index)?;
|
||||
vecs.addrs
|
||||
.p2wsh.first_index
|
||||
.p2wsh
|
||||
.first_index
|
||||
.checked_push(height, self.p2wsh_addr_index)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -104,7 +104,8 @@ pub(super) fn store_tx_metadata(
|
||||
md.txid.checked_push(ct.tx_index, ct.txid)?;
|
||||
md.raw_locktime
|
||||
.checked_push(ct.tx_index, ct.tx.lock_time.into())?;
|
||||
md.base_size.checked_push(ct.tx_index, ct.base_size.into())?;
|
||||
md.base_size
|
||||
.checked_push(ct.tx_index, ct.base_size.into())?;
|
||||
md.total_size
|
||||
.checked_push(ct.tx_index, ct.total_size.into())?;
|
||||
md.is_explicitly_rbf
|
||||
|
||||
@@ -2,8 +2,8 @@ use brk_cohort::ByAddrType;
|
||||
use brk_error::{Error, Result};
|
||||
use brk_store::Store;
|
||||
use brk_types::{
|
||||
AddrBytes, AddrHash, AddrIndexOutPoint, AddrIndexTxIndex, OutPoint, OutputType,
|
||||
Sats, TxIndex, TxOutIndex, TypeIndex, Unit, Vout,
|
||||
AddrBytes, AddrHash, AddrIndexOutPoint, AddrIndexTxIndex, OutPoint, OutputType, Sats, TxIndex,
|
||||
TxOutIndex, TypeIndex, Unit, Vout,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
@@ -119,9 +119,7 @@ pub(super) fn finalize_outputs(
|
||||
already_added_addr_hash: &mut ByAddrType<FxHashMap<AddrHash, TypeIndex>>,
|
||||
same_block_output_info: &mut FxHashMap<OutPoint, SameBlockOutputInfo>,
|
||||
) -> Result<()> {
|
||||
already_added_addr_hash
|
||||
.values_mut()
|
||||
.for_each(|m| m.clear());
|
||||
already_added_addr_hash.values_mut().for_each(|m| m.clear());
|
||||
same_block_output_info.clear();
|
||||
|
||||
for ProcessedOutput {
|
||||
@@ -168,25 +166,29 @@ pub(super) fn finalize_outputs(
|
||||
match output_type {
|
||||
OutputType::P2MS => {
|
||||
scripts
|
||||
.p2ms.to_tx_index
|
||||
.p2ms
|
||||
.to_tx_index
|
||||
.checked_push(indexes.p2ms_output_index, tx_index)?;
|
||||
indexes.p2ms_output_index.copy_then_increment()
|
||||
}
|
||||
OutputType::OpReturn => {
|
||||
scripts
|
||||
.op_return.to_tx_index
|
||||
.op_return
|
||||
.to_tx_index
|
||||
.checked_push(indexes.op_return_index, tx_index)?;
|
||||
indexes.op_return_index.copy_then_increment()
|
||||
}
|
||||
OutputType::Empty => {
|
||||
scripts
|
||||
.empty.to_tx_index
|
||||
.empty
|
||||
.to_tx_index
|
||||
.checked_push(indexes.empty_output_index, tx_index)?;
|
||||
indexes.empty_output_index.copy_then_increment()
|
||||
}
|
||||
OutputType::Unknown => {
|
||||
scripts
|
||||
.unknown.to_tx_index
|
||||
.unknown
|
||||
.to_tx_index
|
||||
.checked_push(indexes.unknown_output_index, tx_index)?;
|
||||
indexes.unknown_output_index.copy_then_increment()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use bitcoin::{Transaction, TxOut};
|
||||
use brk_cohort::ByAddrType;
|
||||
use brk_types::{
|
||||
AddrBytes, AddrHash, OutPoint, OutputType, TxIndex, TxOutIndex, Txid, TxidPrefix,
|
||||
TypeIndex, Vin, Vout,
|
||||
AddrBytes, AddrHash, OutPoint, OutputType, TxIndex, TxOutIndex, Txid, TxidPrefix, TypeIndex,
|
||||
Vin, Vout,
|
||||
};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use bitcoin::ScriptBuf;
|
||||
use brk_types::{
|
||||
AddrBytes, OutputType, P2AAddrIndex, P2ABytes, P2PK33AddrIndex, P2PK33Bytes,
|
||||
P2PK65AddrIndex, P2PK65Bytes, P2PKHAddrIndex, P2PKHBytes, P2SHAddrIndex, P2SHBytes,
|
||||
P2TRAddrIndex, P2TRBytes, P2WPKHAddrIndex, P2WPKHBytes, P2WSHAddrIndex, P2WSHBytes,
|
||||
TxIndex, TxOutIndex, Txid, TypeIndex,
|
||||
AddrBytes, OutputType, P2AAddrIndex, P2ABytes, P2PK33AddrIndex, P2PK33Bytes, P2PK65AddrIndex,
|
||||
P2PK65Bytes, P2PKHAddrIndex, P2PKHBytes, P2SHAddrIndex, P2SHBytes, P2TRAddrIndex, P2TRBytes,
|
||||
P2WPKHAddrIndex, P2WPKHBytes, P2WSHAddrIndex, P2WSHBytes, TxIndex, TxOutIndex, Txid, TypeIndex,
|
||||
};
|
||||
use vecdb::{BytesStrategy, VecReader};
|
||||
|
||||
|
||||
@@ -219,7 +219,10 @@ impl Stores {
|
||||
for store in self.addr_type_to_addr_index_and_tx_index.values_mut() {
|
||||
take!(store);
|
||||
}
|
||||
for store in self.addr_type_to_addr_index_and_unspent_outpoint.values_mut() {
|
||||
for store in self
|
||||
.addr_type_to_addr_index_and_unspent_outpoint
|
||||
.values_mut()
|
||||
{
|
||||
take!(store);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
AddrBytes, AddrHash, Height, OutputType, P2AAddrIndex, P2ABytes, P2PK33AddrIndex,
|
||||
P2PK33Bytes, P2PK65AddrIndex, P2PK65Bytes, P2PKHAddrIndex, P2PKHBytes, P2SHAddrIndex,
|
||||
P2SHBytes, P2TRAddrIndex, P2TRBytes, P2WPKHAddrIndex, P2WPKHBytes, P2WSHAddrIndex,
|
||||
P2WSHBytes, TypeIndex, Version,
|
||||
AddrBytes, AddrHash, Height, OutputType, P2AAddrIndex, P2ABytes, P2PK33AddrIndex, P2PK33Bytes,
|
||||
P2PK65AddrIndex, P2PK65Bytes, P2PKHAddrIndex, P2PKHBytes, P2SHAddrIndex, P2SHBytes,
|
||||
P2TRAddrIndex, P2TRBytes, P2WPKHAddrIndex, P2WPKHBytes, P2WSHAddrIndex, P2WSHBytes, TypeIndex,
|
||||
Version,
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
use schemars::JsonSchema;
|
||||
@@ -18,7 +18,11 @@ use crate::parallel_import;
|
||||
use crate::readers::AddrReaders;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct AddrTypeVecs<I: VecIndex + PcoVecValue + Formattable + Serialize + JsonSchema, B: BytesVecValue + Formattable + Serialize + JsonSchema, M: StorageMode = Rw> {
|
||||
pub struct AddrTypeVecs<
|
||||
I: VecIndex + PcoVecValue + Formattable + Serialize + JsonSchema,
|
||||
B: BytesVecValue + Formattable + Serialize + JsonSchema,
|
||||
M: StorageMode = Rw,
|
||||
> {
|
||||
pub first_index: M::Stored<PcoVec<Height, I>>,
|
||||
pub bytes: M::Stored<BytesVec<I, B>>,
|
||||
}
|
||||
@@ -73,14 +77,38 @@ impl AddrsVecs {
|
||||
p2a_bytes = BytesVec::forced_import(db, "p2a_bytes", version),
|
||||
};
|
||||
Ok(Self {
|
||||
p2pk65: AddrTypeVecs { first_index: first_p2pk65_addr_index, bytes: p2pk65_bytes },
|
||||
p2pk33: AddrTypeVecs { first_index: first_p2pk33_addr_index, bytes: p2pk33_bytes },
|
||||
p2pkh: AddrTypeVecs { first_index: first_p2pkh_addr_index, bytes: p2pkh_bytes },
|
||||
p2sh: AddrTypeVecs { first_index: first_p2sh_addr_index, bytes: p2sh_bytes },
|
||||
p2wpkh: AddrTypeVecs { first_index: first_p2wpkh_addr_index, bytes: p2wpkh_bytes },
|
||||
p2wsh: AddrTypeVecs { first_index: first_p2wsh_addr_index, bytes: p2wsh_bytes },
|
||||
p2tr: AddrTypeVecs { first_index: first_p2tr_addr_index, bytes: p2tr_bytes },
|
||||
p2a: AddrTypeVecs { first_index: first_p2a_addr_index, bytes: p2a_bytes },
|
||||
p2pk65: AddrTypeVecs {
|
||||
first_index: first_p2pk65_addr_index,
|
||||
bytes: p2pk65_bytes,
|
||||
},
|
||||
p2pk33: AddrTypeVecs {
|
||||
first_index: first_p2pk33_addr_index,
|
||||
bytes: p2pk33_bytes,
|
||||
},
|
||||
p2pkh: AddrTypeVecs {
|
||||
first_index: first_p2pkh_addr_index,
|
||||
bytes: p2pkh_bytes,
|
||||
},
|
||||
p2sh: AddrTypeVecs {
|
||||
first_index: first_p2sh_addr_index,
|
||||
bytes: p2sh_bytes,
|
||||
},
|
||||
p2wpkh: AddrTypeVecs {
|
||||
first_index: first_p2wpkh_addr_index,
|
||||
bytes: p2wpkh_bytes,
|
||||
},
|
||||
p2wsh: AddrTypeVecs {
|
||||
first_index: first_p2wsh_addr_index,
|
||||
bytes: p2wsh_bytes,
|
||||
},
|
||||
p2tr: AddrTypeVecs {
|
||||
first_index: first_p2tr_addr_index,
|
||||
bytes: p2tr_bytes,
|
||||
},
|
||||
p2a: AddrTypeVecs {
|
||||
first_index: first_p2a_addr_index,
|
||||
bytes: p2a_bytes,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,37 +126,53 @@ impl AddrsVecs {
|
||||
p2a_addr_index: P2AAddrIndex,
|
||||
stamp: Stamp,
|
||||
) -> Result<()> {
|
||||
self.p2pk65.first_index
|
||||
self.p2pk65
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2pk33.first_index
|
||||
self.p2pk33
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2pkh.first_index
|
||||
self.p2pkh
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2sh.first_index
|
||||
self.p2sh
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2wpkh.first_index
|
||||
self.p2wpkh
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2wsh.first_index
|
||||
self.p2wsh
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2tr.first_index
|
||||
self.p2tr
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2a.first_index
|
||||
self.p2a
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2pk65.bytes
|
||||
self.p2pk65
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2pk65_addr_index, stamp)?;
|
||||
self.p2pk33.bytes
|
||||
self.p2pk33
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2pk33_addr_index, stamp)?;
|
||||
self.p2pkh.bytes
|
||||
self.p2pkh
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2pkh_addr_index, stamp)?;
|
||||
self.p2sh.bytes
|
||||
self.p2sh
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2sh_addr_index, stamp)?;
|
||||
self.p2wpkh.bytes
|
||||
self.p2wpkh
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2wpkh_addr_index, stamp)?;
|
||||
self.p2wsh.bytes
|
||||
self.p2wsh
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2wsh_addr_index, stamp)?;
|
||||
self.p2tr.bytes
|
||||
self.p2tr
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2tr_addr_index, stamp)?;
|
||||
self.p2a.bytes
|
||||
self.p2a
|
||||
.bytes
|
||||
.truncate_if_needed_with_stamp(p2a_addr_index, stamp)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -165,35 +209,43 @@ impl AddrsVecs {
|
||||
) -> Option<AddrBytes> {
|
||||
match addr_type {
|
||||
OutputType::P2PK65 => self
|
||||
.p2pk65.bytes
|
||||
.p2pk65
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2pk65)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2PK33 => self
|
||||
.p2pk33.bytes
|
||||
.p2pk33
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2pk33)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2PKH => self
|
||||
.p2pkh.bytes
|
||||
.p2pkh
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2pkh)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2SH => self
|
||||
.p2sh.bytes
|
||||
.p2sh
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2sh)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2WPKH => self
|
||||
.p2wpkh.bytes
|
||||
.p2wpkh
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2wpkh)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2WSH => self
|
||||
.p2wsh.bytes
|
||||
.p2wsh
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2wsh)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2TR => self
|
||||
.p2tr.bytes
|
||||
.p2tr
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2tr)
|
||||
.map(AddrBytes::from),
|
||||
OutputType::P2A => self
|
||||
.p2a.bytes
|
||||
.p2a
|
||||
.bytes
|
||||
.get_pushed_or_read(type_index.into(), &readers.p2a)
|
||||
.map(AddrBytes::from),
|
||||
_ => unreachable!("get_bytes_by_type called with non-address type"),
|
||||
@@ -237,8 +289,7 @@ impl AddrsVecs {
|
||||
as Box<dyn Iterator<Item = AddrHash> + '_>)
|
||||
}
|
||||
None => {
|
||||
Ok(Box::new(std::iter::empty())
|
||||
as Box<dyn Iterator<Item = AddrHash> + '_>)
|
||||
Ok(Box::new(std::iter::empty()) as Box<dyn Iterator<Item = AddrHash> + '_>)
|
||||
}
|
||||
}
|
||||
}};
|
||||
|
||||
@@ -47,8 +47,7 @@ impl BlocksVecs {
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.timestamp
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.total
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.total.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.weight.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -172,5 +172,4 @@ impl Vecs {
|
||||
.chain(self.addrs.par_iter_mut_any())
|
||||
.chain(self.scripts.par_iter_mut_any())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,12 @@ impl OutputsVecs {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn truncate(&mut self, height: Height, txout_index: TxOutIndex, stamp: Stamp) -> Result<()> {
|
||||
pub fn truncate(
|
||||
&mut self,
|
||||
height: Height,
|
||||
txout_index: TxOutIndex,
|
||||
stamp: Stamp,
|
||||
) -> Result<()> {
|
||||
self.first_txout_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.value
|
||||
|
||||
@@ -14,7 +14,10 @@ use vecdb::{
|
||||
use crate::parallel_import;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct ScriptTypeVecs<I: VecIndex + PcoVecValue + Formattable + Serialize + JsonSchema, M: StorageMode = Rw> {
|
||||
pub struct ScriptTypeVecs<
|
||||
I: VecIndex + PcoVecValue + Formattable + Serialize + JsonSchema,
|
||||
M: StorageMode = Rw,
|
||||
> {
|
||||
pub first_index: M::Stored<PcoVec<Height, I>>,
|
||||
pub to_tx_index: M::Stored<PcoVec<I, TxIndex>>,
|
||||
}
|
||||
@@ -49,10 +52,22 @@ impl ScriptsVecs {
|
||||
unknown_output_index_to_tx_index = PcoVec::forced_import(db, "tx_index", version),
|
||||
};
|
||||
Ok(Self {
|
||||
empty: ScriptTypeVecs { first_index: first_empty_output_index, to_tx_index: empty_output_index_to_tx_index },
|
||||
op_return: ScriptTypeVecs { first_index: first_op_return_index, to_tx_index: op_return_index_to_tx_index },
|
||||
p2ms: ScriptTypeVecs { first_index: first_p2ms_output_index, to_tx_index: p2ms_output_index_to_tx_index },
|
||||
unknown: ScriptTypeVecs { first_index: first_unknown_output_index, to_tx_index: unknown_output_index_to_tx_index },
|
||||
empty: ScriptTypeVecs {
|
||||
first_index: first_empty_output_index,
|
||||
to_tx_index: empty_output_index_to_tx_index,
|
||||
},
|
||||
op_return: ScriptTypeVecs {
|
||||
first_index: first_op_return_index,
|
||||
to_tx_index: op_return_index_to_tx_index,
|
||||
},
|
||||
p2ms: ScriptTypeVecs {
|
||||
first_index: first_p2ms_output_index,
|
||||
to_tx_index: p2ms_output_index_to_tx_index,
|
||||
},
|
||||
unknown: ScriptTypeVecs {
|
||||
first_index: first_unknown_output_index,
|
||||
to_tx_index: unknown_output_index_to_tx_index,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -65,21 +80,29 @@ impl ScriptsVecs {
|
||||
unknown_output_index: UnknownOutputIndex,
|
||||
stamp: Stamp,
|
||||
) -> Result<()> {
|
||||
self.empty.first_index
|
||||
self.empty
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.op_return.first_index
|
||||
self.op_return
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.p2ms.first_index
|
||||
self.p2ms
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.unknown.first_index
|
||||
self.unknown
|
||||
.first_index
|
||||
.truncate_if_needed_with_stamp(height, stamp)?;
|
||||
self.empty.to_tx_index
|
||||
self.empty
|
||||
.to_tx_index
|
||||
.truncate_if_needed_with_stamp(empty_output_index, stamp)?;
|
||||
self.op_return.to_tx_index
|
||||
self.op_return
|
||||
.to_tx_index
|
||||
.truncate_if_needed_with_stamp(op_return_index, stamp)?;
|
||||
self.p2ms.to_tx_index
|
||||
self.p2ms
|
||||
.to_tx_index
|
||||
.truncate_if_needed_with_stamp(p2ms_output_index, stamp)?;
|
||||
self.unknown.to_tx_index
|
||||
self.unknown
|
||||
.to_tx_index
|
||||
.truncate_if_needed_with_stamp(unknown_output_index, stamp)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user