mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-13 16:38:36 -07:00
global: renames + refactor + p2a support
This commit is contained in:
@@ -24,7 +24,7 @@ fn main() -> color_eyre::Result<()> {
|
||||
|
||||
let outputs = Path::new("../../_outputs");
|
||||
|
||||
let mut indexer = Indexer::new(outputs, false, false)?;
|
||||
let mut indexer = Indexer::new(outputs, false, true)?;
|
||||
|
||||
indexer.import_stores()?;
|
||||
indexer.import_vecs()?;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use bitcoincore_rpc::Client;
|
||||
use brk_core::{
|
||||
Addressindex, BlockHash, CheckedSub, Emptyindex, Height, Multisigindex, Opreturnindex,
|
||||
P2PK33index, P2PK65index, P2PKHindex, P2SHindex, P2TRindex, P2WPKHindex, P2WSHindex,
|
||||
Pushonlyindex, Txindex, Txinindex, Txoutindex, Unknownindex,
|
||||
BlockHash, CheckedSub, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex,
|
||||
OutputType, OutputTypeIndex, P2AIndex, P2MSIndex, P2PK33Index, P2PK65Index, P2PKHIndex,
|
||||
P2SHIndex, P2TRIndex, P2WPKHIndex, P2WSHIndex, TxIndex, UnknownOutputIndex,
|
||||
};
|
||||
use brk_parser::NUMBER_OF_UNSAFE_BLOCKS;
|
||||
use brk_vec::{Result, StoredIndex, StoredType, Value};
|
||||
@@ -12,46 +12,60 @@ use crate::{IndexedVec, Stores, Vecs};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Indexes {
|
||||
pub addressindex: Addressindex,
|
||||
pub emptyindex: Emptyindex,
|
||||
pub emptyoutputindex: EmptyOutputIndex,
|
||||
pub height: Height,
|
||||
pub multisigindex: Multisigindex,
|
||||
pub opreturnindex: Opreturnindex,
|
||||
pub p2pk33index: P2PK33index,
|
||||
pub p2pk65index: P2PK65index,
|
||||
pub p2pkhindex: P2PKHindex,
|
||||
pub p2shindex: P2SHindex,
|
||||
pub p2trindex: P2TRindex,
|
||||
pub p2wpkhindex: P2WPKHindex,
|
||||
pub p2wshindex: P2WSHindex,
|
||||
pub pushonlyindex: Pushonlyindex,
|
||||
pub txindex: Txindex,
|
||||
pub txinindex: Txinindex,
|
||||
pub txoutindex: Txoutindex,
|
||||
pub unknownindex: Unknownindex,
|
||||
pub opreturnindex: OpReturnIndex,
|
||||
pub p2msindex: P2MSIndex,
|
||||
pub p2pk33index: P2PK33Index,
|
||||
pub p2pk65index: P2PK65Index,
|
||||
pub p2pkhindex: P2PKHIndex,
|
||||
pub p2shindex: P2SHIndex,
|
||||
pub p2trindex: P2TRIndex,
|
||||
pub p2wpkhindex: P2WPKHIndex,
|
||||
pub p2wshindex: P2WSHIndex,
|
||||
pub p2aindex: P2AIndex,
|
||||
pub txindex: TxIndex,
|
||||
pub inputindex: InputIndex,
|
||||
pub outputindex: OutputIndex,
|
||||
pub unknownoutputindex: UnknownOutputIndex,
|
||||
}
|
||||
|
||||
impl Indexes {
|
||||
pub fn outputtypeindex(&self, outputtype: OutputType) -> OutputTypeIndex {
|
||||
match outputtype {
|
||||
OutputType::Empty => *self.emptyoutputindex,
|
||||
OutputType::OpReturn => *self.opreturnindex,
|
||||
OutputType::P2A => *self.p2aindex,
|
||||
OutputType::P2MS => *self.p2msindex,
|
||||
OutputType::P2PK33 => *self.p2pkhindex,
|
||||
OutputType::P2PK65 => *self.p2pk65index,
|
||||
OutputType::P2PKH => *self.p2pkhindex,
|
||||
OutputType::P2SH => *self.p2shindex,
|
||||
OutputType::P2TR => *self.p2trindex,
|
||||
OutputType::P2WPKH => *self.p2wpkhindex,
|
||||
OutputType::P2WSH => *self.p2wshindex,
|
||||
OutputType::Unknown => *self.unknownoutputindex,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_if_needed(&self, vecs: &mut Vecs) -> brk_vec::Result<()> {
|
||||
let height = self.height;
|
||||
vecs.height_to_first_txindex
|
||||
.push_if_needed(height, self.txindex)?;
|
||||
vecs.height_to_first_txinindex
|
||||
.push_if_needed(height, self.txinindex)?;
|
||||
vecs.height_to_first_txoutindex
|
||||
.push_if_needed(height, self.txoutindex)?;
|
||||
vecs.height_to_first_addressindex
|
||||
.push_if_needed(height, self.addressindex)?;
|
||||
vecs.height_to_first_emptyindex
|
||||
.push_if_needed(height, self.emptyindex)?;
|
||||
vecs.height_to_first_multisigindex
|
||||
.push_if_needed(height, self.multisigindex)?;
|
||||
vecs.height_to_first_inputindex
|
||||
.push_if_needed(height, self.inputindex)?;
|
||||
vecs.height_to_first_outputindex
|
||||
.push_if_needed(height, self.outputindex)?;
|
||||
vecs.height_to_first_emptyoutputindex
|
||||
.push_if_needed(height, self.emptyoutputindex)?;
|
||||
vecs.height_to_first_p2msindex
|
||||
.push_if_needed(height, self.p2msindex)?;
|
||||
vecs.height_to_first_opreturnindex
|
||||
.push_if_needed(height, self.opreturnindex)?;
|
||||
vecs.height_to_first_pushonlyindex
|
||||
.push_if_needed(height, self.pushonlyindex)?;
|
||||
vecs.height_to_first_unknownindex
|
||||
.push_if_needed(height, self.unknownindex)?;
|
||||
vecs.height_to_first_p2aindex
|
||||
.push_if_needed(height, self.p2aindex)?;
|
||||
vecs.height_to_first_unknownoutputindex
|
||||
.push_if_needed(height, self.unknownoutputindex)?;
|
||||
vecs.height_to_first_p2pk33index
|
||||
.push_if_needed(height, self.p2pk33index)?;
|
||||
vecs.height_to_first_p2pk65index
|
||||
@@ -106,100 +120,90 @@ impl TryFrom<(&mut Vecs, &Stores, &Client)> for Indexes {
|
||||
.unwrap_or(starting_height);
|
||||
|
||||
Ok(Self {
|
||||
addressindex: *starting_index(
|
||||
&vecs.height_to_first_addressindex,
|
||||
&vecs.addressindex_to_height,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
emptyindex: *starting_index(
|
||||
&vecs.height_to_first_emptyindex,
|
||||
&vecs.emptyindex_to_height,
|
||||
emptyoutputindex: *starting_index(
|
||||
&vecs.height_to_first_emptyoutputindex,
|
||||
&vecs.emptyoutputindex_to_txindex,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
height,
|
||||
multisigindex: *starting_index(
|
||||
&vecs.height_to_first_multisigindex,
|
||||
&vecs.multisigindex_to_height,
|
||||
p2msindex: *starting_index(
|
||||
&vecs.height_to_first_p2msindex,
|
||||
&vecs.p2msindex_to_txindex,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
opreturnindex: *starting_index(
|
||||
&vecs.height_to_first_opreturnindex,
|
||||
&vecs.opreturnindex_to_height,
|
||||
&vecs.opreturnindex_to_txindex,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2pk33index: *starting_index(
|
||||
&vecs.height_to_first_p2pk33index,
|
||||
&vecs.p2pk33index_to_height,
|
||||
&vecs.p2pk33index_to_p2pk33bytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2pk65index: *starting_index(
|
||||
&vecs.height_to_first_p2pk65index,
|
||||
&vecs.p2pk65index_to_height,
|
||||
&vecs.p2pk65index_to_p2pk65bytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2pkhindex: *starting_index(
|
||||
&vecs.height_to_first_p2pkhindex,
|
||||
&vecs.p2pkhindex_to_height,
|
||||
&vecs.p2pkhindex_to_p2pkhbytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2shindex: *starting_index(
|
||||
&vecs.height_to_first_p2shindex,
|
||||
&vecs.p2shindex_to_height,
|
||||
&vecs.p2shindex_to_p2shbytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2trindex: *starting_index(
|
||||
&vecs.height_to_first_p2trindex,
|
||||
&vecs.p2trindex_to_height,
|
||||
&vecs.p2trindex_to_p2trbytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2wpkhindex: *starting_index(
|
||||
&vecs.height_to_first_p2wpkhindex,
|
||||
&vecs.p2wpkhindex_to_height,
|
||||
&vecs.p2wpkhindex_to_p2wpkhbytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
p2wshindex: *starting_index(
|
||||
&vecs.height_to_first_p2wshindex,
|
||||
&vecs.p2wshindex_to_height,
|
||||
&vecs.p2wshindex_to_p2wshbytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
pushonlyindex: *starting_index(
|
||||
&vecs.height_to_first_pushonlyindex,
|
||||
&vecs.pushonlyindex_to_height,
|
||||
p2aindex: *starting_index(
|
||||
&vecs.height_to_first_p2aindex,
|
||||
&vecs.p2aindex_to_p2abytes,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
txindex: *starting_index(
|
||||
&vecs.height_to_first_txindex,
|
||||
&vecs.txindex_to_height,
|
||||
txindex: *starting_index(&vecs.height_to_first_txindex, &vecs.txindex_to_txid, height)?
|
||||
.context("")?,
|
||||
inputindex: *starting_index(
|
||||
&vecs.height_to_first_inputindex,
|
||||
&vecs.inputindex_to_outputindex,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
txinindex: *starting_index(
|
||||
&vecs.height_to_first_txinindex,
|
||||
&vecs.txinindex_to_height,
|
||||
outputindex: *starting_index(
|
||||
&vecs.height_to_first_outputindex,
|
||||
&vecs.outputindex_to_value,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
txoutindex: *starting_index(
|
||||
&vecs.height_to_first_txoutindex,
|
||||
&vecs.txoutindex_to_height,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
unknownindex: *starting_index(
|
||||
&vecs.height_to_first_unknownindex,
|
||||
&vecs.unknownindex_to_height,
|
||||
unknownoutputindex: *starting_index(
|
||||
&vecs.height_to_first_unknownoutputindex,
|
||||
&vecs.unknownoutputindex_to_txindex,
|
||||
height,
|
||||
)?
|
||||
.context("")?,
|
||||
|
||||
@@ -11,8 +11,8 @@ use std::{
|
||||
};
|
||||
|
||||
use brk_core::{
|
||||
AddressHash, Addressbytes, Addressindex, Addresstype, BlockHash, BlockHashPrefix, Height, Sats,
|
||||
Timestamp, Txid, TxidPrefix, Txindex, Txinindex, Txoutindex, Vin, Vout, setrlimit,
|
||||
AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex,
|
||||
OutputType, OutputTypeIndex, Sats, Timestamp, TxIndex, Txid, TxidPrefix, Vin, Vout, setrlimit,
|
||||
};
|
||||
pub use brk_parser::*;
|
||||
|
||||
@@ -21,7 +21,7 @@ use brk_exit::Exit;
|
||||
use brk_vec::Compressed;
|
||||
use color_eyre::eyre::{ContextCompat, eyre};
|
||||
use fjall::TransactionalKeyspace;
|
||||
use log::info;
|
||||
use log::{error, info};
|
||||
use rayon::prelude::*;
|
||||
mod indexes;
|
||||
mod stores;
|
||||
@@ -32,7 +32,7 @@ pub use stores::*;
|
||||
pub use vecs::*;
|
||||
|
||||
const SNAPSHOT_BLOCK_RANGE: usize = 1000;
|
||||
const COLLISIONS_CHECKED_UP_TO: u32 = 893_000;
|
||||
const COLLISIONS_CHECKED_UP_TO: u32 = 0;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Indexer {
|
||||
@@ -150,18 +150,18 @@ impl Indexer {
|
||||
let blockhash_prefix = BlockHashPrefix::from(&blockhash);
|
||||
|
||||
if stores
|
||||
.blockhash_prefix_to_height
|
||||
.blockhashprefix_to_height
|
||||
.get(&blockhash_prefix)?
|
||||
.is_some_and(|prev_height| *prev_height != height)
|
||||
{
|
||||
dbg!(blockhash);
|
||||
error!("BlockHash: {blockhash}");
|
||||
return Err(eyre!("Collision, expect prefix to need be set yet"));
|
||||
}
|
||||
|
||||
idxs.push_if_needed(vecs)?;
|
||||
|
||||
stores
|
||||
.blockhash_prefix_to_height
|
||||
.blockhashprefix_to_height
|
||||
.insert_if_needed(blockhash_prefix, height, height);
|
||||
|
||||
vecs.height_to_blockhash.push_if_needed(height, blockhash)?;
|
||||
@@ -172,29 +172,33 @@ impl Indexer {
|
||||
vecs.height_to_total_size.push_if_needed(height, block.total_size().into())?;
|
||||
vecs.height_to_weight.push_if_needed(height, block.weight().into())?;
|
||||
|
||||
let inputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vin, txin)| (Txindex::from(index), Vin::from(vin), txin, tx))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let (inputs, outputs) = thread::scope(|s| {
|
||||
let inputs_handle = s.spawn(|| block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vin, txin)| (TxIndex::from(index), Vin::from(vin), txin, tx))
|
||||
})
|
||||
.collect::<Vec<_>>());
|
||||
|
||||
let outputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.output
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (Txindex::from(index), Vout::from(vout), txout, tx))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let outputs_handle = s.spawn(|| block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.output
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (TxIndex::from(index), Vout::from(vout), txout, tx))
|
||||
})
|
||||
.collect::<Vec<_>>());
|
||||
|
||||
(inputs_handle.join().unwrap(), outputs_handle.join().unwrap())
|
||||
});
|
||||
|
||||
let tx_len = block.txdata.len();
|
||||
let outputs_len = outputs.len();
|
||||
@@ -203,7 +207,7 @@ impl Indexer {
|
||||
let (
|
||||
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_join_handle,
|
||||
input_source_vec_handle,
|
||||
txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt_handle,
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle,
|
||||
) = thread::scope(|scope| {
|
||||
let txid_prefix_to_txid_and_block_txindex_and_prev_txindex_handle =
|
||||
scope.spawn(|| -> color_eyre::Result<_> {
|
||||
@@ -217,14 +221,14 @@ impl Indexer {
|
||||
let txid_prefix = TxidPrefix::from(&txid);
|
||||
|
||||
let prev_txindex_opt =
|
||||
if check_collisions && stores.txid_prefix_to_txindex.needs(height) {
|
||||
if check_collisions && stores.txidprefix_to_txindex.needs(height) {
|
||||
// Should only find collisions for two txids (duplicates), see below
|
||||
stores.txid_prefix_to_txindex.get(&txid_prefix)?.map(|v| *v)
|
||||
stores.txidprefix_to_txindex.get(&txid_prefix)?.map(|v| *v)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok((txid_prefix, (tx, txid, Txindex::from(index), prev_txindex_opt)))
|
||||
Ok((txid_prefix, (tx, txid, TxIndex::from(index), prev_txindex_opt)))
|
||||
})
|
||||
.try_fold(BTreeMap::new, |mut map, tuple| {
|
||||
let (key, value) = tuple?;
|
||||
@@ -246,19 +250,19 @@ impl Indexer {
|
||||
inputs
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(|(block_txinindex, (block_txindex, vin, txin, tx))| -> color_eyre::Result<(Txinindex, InputSource)> {
|
||||
.map(|(block_inputindex, (block_txindex, vin, txin, tx))| -> color_eyre::Result<(InputIndex, InputSource)> {
|
||||
let txindex = idxs.txindex + block_txindex;
|
||||
let txinindex = idxs.txinindex + Txinindex::from(block_txinindex);
|
||||
let inputindex = idxs.inputindex + InputIndex::from(block_inputindex);
|
||||
|
||||
let outpoint = txin.previous_output;
|
||||
let txid = Txid::from(outpoint.txid);
|
||||
|
||||
if tx.is_coinbase() {
|
||||
return Ok((txinindex, InputSource::SameBlock((tx, txindex, txin, vin))));
|
||||
return Ok((inputindex, InputSource::SameBlock((tx, txindex, txin, vin))));
|
||||
}
|
||||
|
||||
let prev_txindex = if let Some(txindex) = stores
|
||||
.txid_prefix_to_txindex
|
||||
.txidprefix_to_txindex
|
||||
.get(&TxidPrefix::from(&txid))?
|
||||
.map(|v| *v)
|
||||
.and_then(|txindex| {
|
||||
@@ -268,24 +272,24 @@ impl Indexer {
|
||||
txindex
|
||||
} else {
|
||||
// dbg!(indexes.txindex + block_txindex, txindex, txin, vin);
|
||||
return Ok((txinindex, InputSource::SameBlock((tx, txindex, txin, vin))));
|
||||
return Ok((inputindex, InputSource::SameBlock((tx, txindex, txin, vin))));
|
||||
};
|
||||
|
||||
let vout = Vout::from(outpoint.vout);
|
||||
|
||||
let txoutindex = *vecs
|
||||
.txindex_to_first_txoutindex
|
||||
let outputindex = *vecs
|
||||
.txindex_to_first_outputindex
|
||||
.get(prev_txindex)?
|
||||
.context("Expect txoutindex to not be none")
|
||||
.context("Expect outputindex to not be none")
|
||||
.inspect_err(|_| {
|
||||
dbg!(outpoint.txid, prev_txindex, vout);
|
||||
})?
|
||||
+ vout;
|
||||
|
||||
Ok((txinindex, InputSource::PreviousBlock((
|
||||
Ok((inputindex, InputSource::PreviousBlock((
|
||||
vin,
|
||||
txindex,
|
||||
txoutindex,
|
||||
outputindex,
|
||||
))))
|
||||
})
|
||||
.try_fold(BTreeMap::new, |mut map, tuple| -> color_eyre::Result<_> {
|
||||
@@ -304,71 +308,58 @@ impl Indexer {
|
||||
})
|
||||
});
|
||||
|
||||
let txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt_handle = scope.spawn(|| {
|
||||
let outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle = scope.spawn(|| {
|
||||
outputs
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(
|
||||
#[allow(clippy::type_complexity)]
|
||||
|(block_txoutindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
|
||||
Txoutindex,
|
||||
|(block_outputindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
|
||||
OutputIndex,
|
||||
(
|
||||
&TxOut,
|
||||
Txindex,
|
||||
TxIndex,
|
||||
Vout,
|
||||
Addresstype,
|
||||
brk_core::Result<Addressbytes>,
|
||||
Option<Addressindex>,
|
||||
OutputType,
|
||||
brk_core::Result<AddressBytes>,
|
||||
Option<OutputTypeIndex>,
|
||||
&Transaction,
|
||||
),
|
||||
)> {
|
||||
let txindex = idxs.txindex + block_txindex;
|
||||
let txoutindex = idxs.txoutindex + Txoutindex::from(block_txoutindex);
|
||||
let outputindex = idxs.outputindex + OutputIndex::from(block_outputindex);
|
||||
|
||||
let script = &txout.script_pubkey;
|
||||
|
||||
let addresstype = Addresstype::from(script);
|
||||
let outputtype = OutputType::from(script);
|
||||
|
||||
let addressbytes_res =
|
||||
Addressbytes::try_from((script, addresstype)).inspect_err(|_| {
|
||||
let address_bytes_res =
|
||||
AddressBytes::try_from((script, outputtype)).inspect_err(|_| {
|
||||
// dbg!(&txout, height, txi, &tx.compute_txid());
|
||||
});
|
||||
|
||||
let addressindex_opt = addressbytes_res.as_ref().ok().and_then(|addressbytes| {
|
||||
let outputtypeindex_opt = address_bytes_res.as_ref().ok().and_then(|addressbytes| {
|
||||
stores
|
||||
.addresshash_to_addressindex
|
||||
.get(&AddressHash::from((addressbytes, addresstype)))
|
||||
.addressbyteshash_to_outputtypeindex
|
||||
.get(&AddressBytesHash::from((addressbytes, outputtype)))
|
||||
.unwrap()
|
||||
.map(|v| *v)
|
||||
// Checking if not in the future
|
||||
.and_then(|addressindex_local| {
|
||||
(addressindex_local < idxs.addressindex).then_some(addressindex_local)
|
||||
.and_then(|outputtypeindex_local| {
|
||||
(outputtypeindex_local < idxs.outputtypeindex(outputtype)).then_some(outputtypeindex_local)
|
||||
})
|
||||
});
|
||||
|
||||
if let Some(Some(addressindex)) = check_collisions.then_some(addressindex_opt) {
|
||||
let addressbytes = addressbytes_res.as_ref().unwrap();
|
||||
|
||||
let prev_addresstype = *vecs
|
||||
.addressindex_to_addresstype
|
||||
.get(addressindex)?
|
||||
.context("Expect to have address type")?;
|
||||
|
||||
let addresstypeindex = *vecs
|
||||
.addressindex_to_addresstypeindex
|
||||
.get(addressindex)?
|
||||
.context("Expect to have address type index")?;
|
||||
if let Some(Some(outputtypeindex)) = check_collisions.then_some(outputtypeindex_opt) {
|
||||
let addressbytes = address_bytes_res.as_ref().unwrap();
|
||||
|
||||
let prev_addressbytes_opt =
|
||||
vecs.get_addressbytes(prev_addresstype, addresstypeindex)?;
|
||||
|
||||
vecs.get_addressbytes(outputtype, outputtypeindex)?;
|
||||
let prev_addressbytes =
|
||||
prev_addressbytes_opt.as_ref().context("Expect to have addressbytes")?;
|
||||
|
||||
if (vecs.addressindex_to_addresstype.hasnt(addressindex)?
|
||||
&& addresstype != prev_addresstype)
|
||||
|| (stores.addresshash_to_addressindex.needs(height)
|
||||
&& prev_addressbytes != addressbytes)
|
||||
if stores.addressbyteshash_to_outputtypeindex.needs(height)
|
||||
&& prev_addressbytes != addressbytes
|
||||
{
|
||||
let txid = tx.compute_txid();
|
||||
dbg!(
|
||||
@@ -376,30 +367,28 @@ impl Indexer {
|
||||
txid,
|
||||
vout,
|
||||
block_txindex,
|
||||
addresstype,
|
||||
prev_addresstype,
|
||||
outputtype,
|
||||
prev_addressbytes,
|
||||
addressbytes,
|
||||
idxs.addressindex,
|
||||
addressindex,
|
||||
addresstypeindex,
|
||||
&idxs,
|
||||
outputtypeindex,
|
||||
outputtypeindex,
|
||||
txout,
|
||||
AddressHash::from((addressbytes, addresstype)),
|
||||
AddressHash::from((prev_addressbytes, prev_addresstype))
|
||||
AddressBytesHash::from((addressbytes, outputtype)),
|
||||
);
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
Ok((
|
||||
txoutindex,
|
||||
outputindex,
|
||||
(
|
||||
txout,
|
||||
txindex,
|
||||
vout,
|
||||
addresstype,
|
||||
addressbytes_res,
|
||||
addressindex_opt,
|
||||
outputtype,
|
||||
address_bytes_res,
|
||||
outputtypeindex_opt,
|
||||
tx,
|
||||
),
|
||||
))
|
||||
@@ -424,7 +413,7 @@ impl Indexer {
|
||||
(
|
||||
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_handle.join(),
|
||||
input_source_vec_handle.join(),
|
||||
txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt_handle.join(),
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle.join(),
|
||||
)
|
||||
});
|
||||
|
||||
@@ -439,158 +428,139 @@ impl Indexer {
|
||||
.ok()
|
||||
.context("Export input_source_vec_handle to join")??;
|
||||
|
||||
let txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt =
|
||||
txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt_handle
|
||||
let outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt =
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle
|
||||
.ok()
|
||||
.context(
|
||||
"Expect txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt_handle to join",
|
||||
"Expect outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle to join",
|
||||
)??;
|
||||
|
||||
let mut new_txindexvout_to_txoutindex: BTreeMap<
|
||||
(Txindex, Vout),
|
||||
Txoutindex,
|
||||
let mut new_txindexvout_to_outputindex: BTreeMap<
|
||||
(TxIndex, Vout),
|
||||
OutputIndex,
|
||||
> = BTreeMap::new();
|
||||
|
||||
let mut already_added_addresshash: BTreeMap<AddressHash, Addressindex> = BTreeMap::new();
|
||||
let mut already_added_addressbyteshash: BTreeMap<AddressBytesHash, OutputTypeIndex> = BTreeMap::new();
|
||||
|
||||
txoutindex_to_txout_addresstype_addressbytes_res_addressindex_opt
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt
|
||||
.into_iter()
|
||||
.try_for_each(
|
||||
|(
|
||||
txoutindex,
|
||||
(txout, txindex, vout, addresstype, addressbytes_res, addressindex_opt, _tx),
|
||||
outputindex,
|
||||
(txout, txindex, vout, outputtype, addressbytes_res, outputtypeindex_opt, _tx),
|
||||
)|
|
||||
-> color_eyre::Result<()> {
|
||||
let sats = Sats::from(txout.value);
|
||||
|
||||
if vout.is_zero() {
|
||||
vecs.txindex_to_first_txoutindex.push_if_needed(txindex, txoutindex)?;
|
||||
vecs.txindex_to_first_outputindex.push_if_needed(txindex, outputindex)?;
|
||||
}
|
||||
|
||||
vecs.txoutindex_to_value.push_if_needed(txoutindex, sats)?;
|
||||
vecs.outputindex_to_value.push_if_needed(outputindex, sats)?;
|
||||
|
||||
vecs.txoutindex_to_height
|
||||
.push_if_needed(txoutindex, height)?;
|
||||
vecs.outputindex_to_outputtype
|
||||
.push_if_needed(outputindex, outputtype)?;
|
||||
|
||||
let mut addressindex = idxs.addressindex;
|
||||
let mut addressbyteshash = None;
|
||||
|
||||
let mut addresshash = None;
|
||||
let outputtypeindex;
|
||||
|
||||
if let Some(addressindex_local) = addressindex_opt.or_else(|| {
|
||||
if let Some(outputtypeindex_local) = outputtypeindex_opt.or_else(|| {
|
||||
addressbytes_res.as_ref().ok().and_then(|addressbytes| {
|
||||
// Check if address was first seen before in this iterator
|
||||
// Example: https://mempool.space/address/046a0765b5865641ce08dd39690aade26dfbf5511430ca428a3089261361cef170e3929a68aee3d8d4848b0c5111b0a37b82b86ad559fd2a745b44d8e8d9dfdc0c
|
||||
addresshash.replace(AddressHash::from((addressbytes, addresstype)));
|
||||
already_added_addresshash
|
||||
.get(addresshash.as_ref().unwrap())
|
||||
addressbyteshash.replace(AddressBytesHash::from((addressbytes, outputtype)));
|
||||
already_added_addressbyteshash
|
||||
.get(addressbyteshash.as_ref().unwrap())
|
||||
.cloned()
|
||||
})
|
||||
}) {
|
||||
addressindex = addressindex_local;
|
||||
outputtypeindex = outputtypeindex_local;
|
||||
} else {
|
||||
idxs.addressindex.increment();
|
||||
|
||||
let addresstypeindex = match addresstype {
|
||||
Addresstype::Empty => {
|
||||
vecs.emptyindex_to_height
|
||||
.push_if_needed(idxs.emptyindex, height)?;
|
||||
idxs.emptyindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::Multisig => {
|
||||
vecs.multisigindex_to_height.push_if_needed(idxs.multisigindex, height)?;
|
||||
idxs.multisigindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::OpReturn => {
|
||||
vecs.opreturnindex_to_height.push_if_needed(idxs.opreturnindex, height)?;
|
||||
idxs.opreturnindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::PushOnly => {
|
||||
vecs.pushonlyindex_to_height.push_if_needed(idxs.pushonlyindex, height)?;
|
||||
idxs.pushonlyindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::Unknown => {
|
||||
vecs.unknownindex_to_height.push_if_needed(idxs.unknownindex, height)?;
|
||||
idxs.unknownindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2PK65 => {
|
||||
vecs.p2pk65index_to_height.push_if_needed(idxs.p2pk65index, height)?;
|
||||
outputtypeindex = match outputtype {
|
||||
OutputType::P2PK65 => {
|
||||
idxs.p2pk65index.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2PK33 => {
|
||||
vecs.p2pk33index_to_height.push_if_needed(idxs.p2pk33index, height)?;
|
||||
OutputType::P2PK33 => {
|
||||
idxs.p2pk33index.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2PKH => {
|
||||
vecs.p2pkhindex_to_height.push_if_needed(idxs.p2pkhindex, height)?;
|
||||
OutputType::P2PKH => {
|
||||
idxs.p2pkhindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2SH => {
|
||||
vecs.p2shindex_to_height.push_if_needed(idxs.p2shindex, height)?;
|
||||
OutputType::P2MS => {
|
||||
vecs.p2msindex_to_txindex.push_if_needed(idxs.p2msindex, txindex)?;
|
||||
idxs.p2msindex.copy_then_increment()
|
||||
},
|
||||
OutputType::P2SH => {
|
||||
idxs.p2shindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2WPKH => {
|
||||
vecs.p2wpkhindex_to_height.push_if_needed(idxs.p2wpkhindex, height)?;
|
||||
OutputType::OpReturn => {
|
||||
vecs.opreturnindex_to_txindex.push_if_needed(idxs.opreturnindex, txindex)?;
|
||||
idxs.opreturnindex.copy_then_increment()
|
||||
},
|
||||
OutputType::P2WPKH => {
|
||||
idxs.p2wpkhindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2WSH => {
|
||||
vecs.p2wshindex_to_height.push_if_needed(idxs.p2wshindex, height)?;
|
||||
OutputType::P2WSH => {
|
||||
idxs.p2wshindex.copy_then_increment()
|
||||
},
|
||||
Addresstype::P2TR => {
|
||||
vecs.p2trindex_to_height.push_if_needed(idxs.p2trindex, height)?;
|
||||
OutputType::P2TR => {
|
||||
idxs.p2trindex.copy_then_increment()
|
||||
},
|
||||
OutputType::P2A => {
|
||||
idxs.p2aindex.copy_then_increment()
|
||||
},
|
||||
OutputType::Empty => {
|
||||
vecs.emptyoutputindex_to_txindex
|
||||
.push_if_needed(idxs.emptyoutputindex, txindex)?;
|
||||
idxs.emptyoutputindex.copy_then_increment()
|
||||
},
|
||||
OutputType::Unknown => {
|
||||
vecs.unknownoutputindex_to_txindex.push_if_needed(idxs.unknownoutputindex, txindex)?;
|
||||
idxs.unknownoutputindex.copy_then_increment()
|
||||
},
|
||||
};
|
||||
|
||||
vecs.addressindex_to_addresstype
|
||||
.push_if_needed(addressindex, addresstype)?;
|
||||
|
||||
vecs.addressindex_to_addresstypeindex
|
||||
.push_if_needed(addressindex, addresstypeindex)?;
|
||||
|
||||
vecs.addressindex_to_height
|
||||
.push_if_needed(addressindex, height)?;
|
||||
|
||||
if let Ok(addressbytes) = addressbytes_res {
|
||||
let addresshash = addresshash.unwrap();
|
||||
let addressbyteshash = addressbyteshash.unwrap();
|
||||
|
||||
already_added_addresshash
|
||||
.insert(addresshash, addressindex);
|
||||
already_added_addressbyteshash
|
||||
.insert(addressbyteshash, outputtypeindex);
|
||||
|
||||
stores.addresshash_to_addressindex.insert_if_needed(
|
||||
addresshash,
|
||||
addressindex,
|
||||
stores.addressbyteshash_to_outputtypeindex.insert_if_needed(
|
||||
addressbyteshash,
|
||||
outputtypeindex,
|
||||
height,
|
||||
);
|
||||
|
||||
vecs.push_addressbytes_if_needed(addresstypeindex, addressbytes)?;
|
||||
vecs.push_bytes_if_needed(outputtypeindex, addressbytes)?;
|
||||
}
|
||||
}
|
||||
|
||||
new_txindexvout_to_txoutindex
|
||||
.insert((txindex, vout), txoutindex);
|
||||
vecs.outputindex_to_outputtypeindex
|
||||
.push_if_needed(outputindex, outputtypeindex)?;
|
||||
|
||||
vecs.txoutindex_to_addressindex
|
||||
.push_if_needed(txoutindex, addressindex)?;
|
||||
new_txindexvout_to_outputindex
|
||||
.insert((txindex, vout), outputindex);
|
||||
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
drop(already_added_addresshash);
|
||||
drop(already_added_addressbyteshash);
|
||||
|
||||
input_source_vec
|
||||
.into_iter()
|
||||
.map(
|
||||
#[allow(clippy::type_complexity)]
|
||||
|(txinindex, input_source)| -> color_eyre::Result<(
|
||||
Txinindex, Vin, Txindex, Txoutindex
|
||||
|(inputindex, input_source)| -> color_eyre::Result<(
|
||||
InputIndex, Vin, TxIndex, OutputIndex
|
||||
)> {
|
||||
match input_source {
|
||||
InputSource::PreviousBlock((vin, txindex, txoutindex)) => Ok((txinindex, vin, txindex, txoutindex)),
|
||||
InputSource::PreviousBlock((vin, txindex, outputindex)) => Ok((inputindex, vin, txindex, outputindex)),
|
||||
InputSource::SameBlock((tx, txindex, txin, vin)) => {
|
||||
if tx.is_coinbase() {
|
||||
return Ok((txinindex, vin, txindex, Txoutindex::COINBASE));
|
||||
return Ok((inputindex, vin, txindex, OutputIndex::COINBASE));
|
||||
}
|
||||
|
||||
let outpoint = txin.previous_output;
|
||||
@@ -606,37 +576,33 @@ impl Indexer {
|
||||
.2;
|
||||
let prev_txindex = idxs.txindex + block_txindex;
|
||||
|
||||
let prev_txoutindex = new_txindexvout_to_txoutindex
|
||||
let prev_outputindex = new_txindexvout_to_outputindex
|
||||
.remove(&(prev_txindex, vout))
|
||||
.context("should have found addressindex from same block")
|
||||
.inspect_err(|_| {
|
||||
dbg!(&new_txindexvout_to_txoutindex, txin, prev_txindex, vout, txid);
|
||||
dbg!(&new_txindexvout_to_outputindex, txin, prev_txindex, vout, txid);
|
||||
})?;
|
||||
|
||||
Ok((txinindex, vin, txindex, prev_txoutindex))
|
||||
Ok((inputindex, vin, txindex, prev_outputindex))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.try_for_each(|res| -> color_eyre::Result<()> {
|
||||
let (txinindex, vin, txindex, txoutindex) = res?;
|
||||
let (inputindex, vin, txindex, outputindex) = res?;
|
||||
|
||||
if vin.is_zero() {
|
||||
vecs.txindex_to_first_txinindex.push_if_needed(txindex, txinindex)?;
|
||||
vecs.txindex_to_first_inputindex.push_if_needed(txindex, inputindex)?;
|
||||
}
|
||||
|
||||
vecs.txinindex_to_txoutindex.push_if_needed(txinindex, txoutindex)?;
|
||||
|
||||
vecs.txinindex_to_height
|
||||
.push_if_needed(txinindex, height)?;
|
||||
|
||||
vecs.inputindex_to_outputindex.push_if_needed(inputindex, outputindex)?;
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
drop(new_txindexvout_to_txoutindex);
|
||||
drop(new_txindexvout_to_outputindex);
|
||||
|
||||
let mut txindex_to_tx_and_txid: BTreeMap<Txindex, (&Transaction, Txid)> = BTreeMap::default();
|
||||
let mut txindex_to_tx_and_txid: BTreeMap<TxIndex, (&Transaction, Txid)> = BTreeMap::default();
|
||||
|
||||
txid_prefix_to_txid_and_block_txindex_and_prev_txindex
|
||||
.into_iter()
|
||||
@@ -649,7 +615,7 @@ impl Indexer {
|
||||
match prev_txindex_opt {
|
||||
None => {
|
||||
stores
|
||||
.txid_prefix_to_txindex
|
||||
.txidprefix_to_txindex
|
||||
.insert_if_needed(txid_prefix, txindex, height);
|
||||
}
|
||||
Some(prev_txindex) => {
|
||||
@@ -659,7 +625,7 @@ impl Indexer {
|
||||
}
|
||||
|
||||
if !check_collisions {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let len = vecs.txindex_to_txid.len();
|
||||
@@ -690,9 +656,7 @@ impl Indexer {
|
||||
let is_dup = only_known_dup_txids.contains(prev_txid);
|
||||
|
||||
if !is_dup {
|
||||
let prev_height =
|
||||
vecs.txindex_to_height.get(prev_txindex)?.expect("To have height");
|
||||
dbg!(height, txindex, prev_height, prev_txid, prev_txindex);
|
||||
dbg!(height, txindex, prev_txid, prev_txindex);
|
||||
return Err(eyre!("Expect none"));
|
||||
}
|
||||
}
|
||||
@@ -707,17 +671,16 @@ impl Indexer {
|
||||
.try_for_each(|(txindex, (tx, txid))| -> color_eyre::Result<()> {
|
||||
vecs.txindex_to_txversion.push_if_needed(txindex, tx.version.into())?;
|
||||
vecs.txindex_to_txid.push_if_needed(txindex, txid)?;
|
||||
vecs.txindex_to_height.push_if_needed(txindex, height)?;
|
||||
vecs.txindex_to_rawlocktime.push_if_needed(txindex, tx.lock_time.into())?;
|
||||
vecs.txindex_to_base_size.push_if_needed(txindex, tx.base_size())?;
|
||||
vecs.txindex_to_total_size.push_if_needed(txindex, tx.total_size())?;
|
||||
vecs.txindex_to_base_size.push_if_needed(txindex, tx.base_size().into())?;
|
||||
vecs.txindex_to_total_size.push_if_needed(txindex, tx.total_size().into())?;
|
||||
vecs.txindex_to_is_explicitly_rbf.push_if_needed(txindex, tx.is_explicitly_rbf())?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
idxs.txindex += Txindex::from(tx_len);
|
||||
idxs.txinindex += Txinindex::from(inputs_len);
|
||||
idxs.txoutindex += Txoutindex::from(outputs_len);
|
||||
idxs.txindex += TxIndex::from(tx_len);
|
||||
idxs.inputindex += InputIndex::from(inputs_len);
|
||||
idxs.outputindex += OutputIndex::from(outputs_len);
|
||||
|
||||
export_if_needed(stores, vecs, height, false, exit)?;
|
||||
|
||||
@@ -755,6 +718,6 @@ impl Indexer {
|
||||
|
||||
#[derive(Debug)]
|
||||
enum InputSource<'a> {
|
||||
PreviousBlock((Vin, Txindex, Txoutindex)),
|
||||
SameBlock((&'a Transaction, Txindex, &'a TxIn, Vin)),
|
||||
PreviousBlock((Vin, TxIndex, OutputIndex)),
|
||||
SameBlock((&'a Transaction, TxIndex, &'a TxIn, Vin)),
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::{fs, path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
AddressHash, Addressbytes, Addressindex, Addresstype, BlockHashPrefix, Height, TxidPrefix,
|
||||
Txindex,
|
||||
AddressBytes, AddressBytesHash, BlockHashPrefix, Height, OutputType, OutputTypeIndex, TxIndex,
|
||||
TxidPrefix,
|
||||
};
|
||||
use brk_vec::{Value, Version};
|
||||
use fjall::{PersistMode, TransactionalKeyspace};
|
||||
@@ -20,9 +20,9 @@ use super::Vecs;
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
pub keyspace: TransactionalKeyspace,
|
||||
pub addresshash_to_addressindex: Store<AddressHash, Addressindex>,
|
||||
pub blockhash_prefix_to_height: Store<BlockHashPrefix, Height>,
|
||||
pub txid_prefix_to_txindex: Store<TxidPrefix, Txindex>,
|
||||
pub addressbyteshash_to_outputtypeindex: Store<AddressBytesHash, OutputTypeIndex>,
|
||||
pub blockhashprefix_to_height: Store<BlockHashPrefix, Height>,
|
||||
pub txidprefix_to_txindex: Store<TxidPrefix, TxIndex>,
|
||||
}
|
||||
|
||||
impl Stores {
|
||||
@@ -38,36 +38,38 @@ impl Stores {
|
||||
};
|
||||
|
||||
thread::scope(|scope| {
|
||||
let addresshash_to_addressindex = scope.spawn(|| {
|
||||
let addressbyteshash_to_outputtypeindex = scope.spawn(|| {
|
||||
Store::import(
|
||||
keyspace.clone(),
|
||||
path,
|
||||
"addresshash_to_addressindex",
|
||||
"addressbyteshash_to_outputtypeindex",
|
||||
Version::ZERO,
|
||||
)
|
||||
});
|
||||
let blockhash_prefix_to_height = scope.spawn(|| {
|
||||
let blockhashprefix_to_height = scope.spawn(|| {
|
||||
Store::import(
|
||||
keyspace.clone(),
|
||||
path,
|
||||
"blockhash_prefix_to_height",
|
||||
"blockhashprefix_to_height",
|
||||
Version::ZERO,
|
||||
)
|
||||
});
|
||||
let txid_prefix_to_txindex = scope.spawn(|| {
|
||||
let txidprefix_to_txindex = scope.spawn(|| {
|
||||
Store::import(
|
||||
keyspace.clone(),
|
||||
path,
|
||||
"txid_prefix_to_txindex",
|
||||
"txidprefix_to_txindex",
|
||||
Version::ZERO,
|
||||
)
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
keyspace: keyspace.clone(),
|
||||
addresshash_to_addressindex: addresshash_to_addressindex.join().unwrap()?,
|
||||
blockhash_prefix_to_height: blockhash_prefix_to_height.join().unwrap()?,
|
||||
txid_prefix_to_txindex: txid_prefix_to_txindex.join().unwrap()?,
|
||||
addressbyteshash_to_outputtypeindex: addressbyteshash_to_outputtypeindex
|
||||
.join()
|
||||
.unwrap()?,
|
||||
blockhashprefix_to_height: blockhashprefix_to_height.join().unwrap()?,
|
||||
txidprefix_to_txindex: txidprefix_to_txindex.join().unwrap()?,
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -77,24 +79,24 @@ impl Stores {
|
||||
vecs: &mut Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
) -> color_eyre::Result<()> {
|
||||
if self.addresshash_to_addressindex.is_empty()
|
||||
&& self.blockhash_prefix_to_height.is_empty()
|
||||
&& self.txid_prefix_to_txindex.is_empty()
|
||||
if self.addressbyteshash_to_outputtypeindex.is_empty()
|
||||
&& self.blockhashprefix_to_height.is_empty()
|
||||
&& self.txidprefix_to_txindex.is_empty()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
vecs.height_to_blockhash
|
||||
.iter_from(starting_indexes.height, |(_, blockhash, ..)| {
|
||||
let blockhash_prefix = BlockHashPrefix::from(blockhash);
|
||||
self.blockhash_prefix_to_height.remove(blockhash_prefix);
|
||||
let blockhashprefix = BlockHashPrefix::from(blockhash);
|
||||
self.blockhashprefix_to_height.remove(blockhashprefix);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
vecs.txindex_to_txid
|
||||
.iter_from(starting_indexes.txindex, |(_txindex, txid, ..)| {
|
||||
let txid_prefix = TxidPrefix::from(txid);
|
||||
self.txid_prefix_to_txindex.remove(txid_prefix);
|
||||
let txidprefix = TxidPrefix::from(txid);
|
||||
self.txidprefix_to_txindex.remove(txidprefix);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -104,13 +106,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2pk65index_to_p2pk65addressbytes
|
||||
.p2pk65index_to_p2pk65bytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2PK65));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PK65));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -121,13 +123,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2pk33index_to_p2pk33addressbytes
|
||||
.p2pk33index_to_p2pk33bytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2PK33));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PK33));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -138,13 +140,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2pkhindex_to_p2pkhaddressbytes
|
||||
.p2pkhindex_to_p2pkhbytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2PKH));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PKH));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -155,13 +157,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2shindex_to_p2shaddressbytes
|
||||
.p2shindex_to_p2shbytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2SH));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2SH));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -172,13 +174,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2trindex_to_p2traddressbytes
|
||||
.p2trindex_to_p2trbytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2TR));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2TR));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -189,13 +191,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2wpkhindex_to_p2wpkhaddressbytes
|
||||
.p2wpkhindex_to_p2wpkhbytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2WPKH));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2WPKH));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -206,13 +208,13 @@ impl Stores {
|
||||
{
|
||||
let mut index = index.into_inner();
|
||||
while let Some(typedbytes) = vecs
|
||||
.p2wshindex_to_p2wshaddressbytes
|
||||
.p2wshindex_to_p2wshbytes
|
||||
.get(index)?
|
||||
.map(Value::into_inner)
|
||||
{
|
||||
let bytes = Addressbytes::from(typedbytes);
|
||||
let hash = AddressHash::from((&bytes, Addresstype::P2WSH));
|
||||
self.addresshash_to_addressindex.remove(hash);
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2WSH));
|
||||
self.addressbyteshash_to_outputtypeindex.remove(hash);
|
||||
index.increment();
|
||||
}
|
||||
}
|
||||
@@ -224,9 +226,9 @@ impl Stores {
|
||||
|
||||
pub fn starting_height(&self) -> Height {
|
||||
[
|
||||
self.addresshash_to_addressindex.height(),
|
||||
self.blockhash_prefix_to_height.height(),
|
||||
self.txid_prefix_to_txindex.height(),
|
||||
self.addressbyteshash_to_outputtypeindex.height(),
|
||||
self.blockhashprefix_to_height.height(),
|
||||
self.txidprefix_to_txindex.height(),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|height| height.map(Height::incremented).unwrap_or_default())
|
||||
@@ -236,16 +238,18 @@ impl Stores {
|
||||
|
||||
pub fn commit(&mut self, height: Height) -> fjall::Result<()> {
|
||||
thread::scope(|scope| -> fjall::Result<()> {
|
||||
let addresshash_to_addressindex_commit_handle =
|
||||
scope.spawn(|| self.addresshash_to_addressindex.commit(height));
|
||||
let blockhash_prefix_to_height_commit_handle =
|
||||
scope.spawn(|| self.blockhash_prefix_to_height.commit(height));
|
||||
let txid_prefix_to_txindex_commit_handle =
|
||||
scope.spawn(|| self.txid_prefix_to_txindex.commit(height));
|
||||
let addressbyteshash_to_outputtypeindex_commit_handle =
|
||||
scope.spawn(|| self.addressbyteshash_to_outputtypeindex.commit(height));
|
||||
let blockhashprefix_to_height_commit_handle =
|
||||
scope.spawn(|| self.blockhashprefix_to_height.commit(height));
|
||||
let txidprefix_to_txindex_commit_handle =
|
||||
scope.spawn(|| self.txidprefix_to_txindex.commit(height));
|
||||
|
||||
addresshash_to_addressindex_commit_handle.join().unwrap()?;
|
||||
blockhash_prefix_to_height_commit_handle.join().unwrap()?;
|
||||
txid_prefix_to_txindex_commit_handle.join().unwrap()?;
|
||||
addressbyteshash_to_outputtypeindex_commit_handle
|
||||
.join()
|
||||
.unwrap()?;
|
||||
blockhashprefix_to_height_commit_handle.join().unwrap()?;
|
||||
txidprefix_to_txindex_commit_handle.join().unwrap()?;
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
@@ -254,9 +258,9 @@ impl Stores {
|
||||
}
|
||||
|
||||
pub fn rotate_memtables(&self) {
|
||||
self.addresshash_to_addressindex.rotate_memtable();
|
||||
self.blockhash_prefix_to_height.rotate_memtable();
|
||||
self.txid_prefix_to_txindex.rotate_memtable();
|
||||
self.addressbyteshash_to_outputtypeindex.rotate_memtable();
|
||||
self.blockhashprefix_to_height.rotate_memtable();
|
||||
self.txidprefix_to_txindex.rotate_memtable();
|
||||
}
|
||||
|
||||
fn open_keyspace(path: &Path) -> fjall::Result<TransactionalKeyspace> {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{
|
||||
Addressbytes, Addressindex, Addresstype, Addresstypeindex, BlockHash, Emptyindex, Height,
|
||||
Multisigindex, Opreturnindex, P2PK33AddressBytes, P2PK33index, P2PK65AddressBytes, P2PK65index,
|
||||
P2PKHAddressBytes, P2PKHindex, P2SHAddressBytes, P2SHindex, P2TRAddressBytes, P2TRindex,
|
||||
P2WPKHAddressBytes, P2WPKHindex, P2WSHAddressBytes, P2WSHindex, Pushonlyindex, RawLockTime,
|
||||
Sats, StoredUsize, Timestamp, TxVersion, Txid, Txindex, Txinindex, Txoutindex, Unknownindex,
|
||||
Weight,
|
||||
AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex,
|
||||
OutputType, OutputTypeIndex, P2ABytes, P2AIndex, P2MSIndex, P2PK33Bytes, P2PK33Index,
|
||||
P2PK65Bytes, P2PK65Index, P2PKHBytes, P2PKHIndex, P2SHBytes, P2SHIndex, P2TRBytes, P2TRIndex,
|
||||
P2WPKHBytes, P2WPKHIndex, P2WSHBytes, P2WSHIndex, RawLockTime, Sats, StoredU32, StoredUsize,
|
||||
Timestamp, TxIndex, TxVersion, Txid, UnknownOutputIndex, Weight,
|
||||
};
|
||||
use brk_vec::{AnyStoredVec, Compressed, Result, Version};
|
||||
use rayon::prelude::*;
|
||||
@@ -19,64 +18,52 @@ pub use base::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub addressindex_to_addresstype: IndexedVec<Addressindex, Addresstype>,
|
||||
pub addressindex_to_addresstypeindex: IndexedVec<Addressindex, Addresstypeindex>,
|
||||
pub addressindex_to_height: IndexedVec<Addressindex, Height>,
|
||||
pub emptyindex_to_height: IndexedVec<Emptyindex, Height>,
|
||||
pub emptyoutputindex_to_txindex: IndexedVec<EmptyOutputIndex, TxIndex>,
|
||||
pub height_to_blockhash: IndexedVec<Height, BlockHash>,
|
||||
pub height_to_difficulty: IndexedVec<Height, f64>,
|
||||
pub height_to_first_addressindex: IndexedVec<Height, Addressindex>,
|
||||
pub height_to_first_emptyindex: IndexedVec<Height, Emptyindex>,
|
||||
pub height_to_first_multisigindex: IndexedVec<Height, Multisigindex>,
|
||||
pub height_to_first_opreturnindex: IndexedVec<Height, Opreturnindex>,
|
||||
pub height_to_first_p2pk33index: IndexedVec<Height, P2PK33index>,
|
||||
pub height_to_first_p2pk65index: IndexedVec<Height, P2PK65index>,
|
||||
pub height_to_first_p2pkhindex: IndexedVec<Height, P2PKHindex>,
|
||||
pub height_to_first_p2shindex: IndexedVec<Height, P2SHindex>,
|
||||
pub height_to_first_p2trindex: IndexedVec<Height, P2TRindex>,
|
||||
pub height_to_first_p2wpkhindex: IndexedVec<Height, P2WPKHindex>,
|
||||
pub height_to_first_p2wshindex: IndexedVec<Height, P2WSHindex>,
|
||||
pub height_to_first_pushonlyindex: IndexedVec<Height, Pushonlyindex>,
|
||||
pub height_to_first_txindex: IndexedVec<Height, Txindex>,
|
||||
pub height_to_first_txinindex: IndexedVec<Height, Txinindex>,
|
||||
pub height_to_first_txoutindex: IndexedVec<Height, Txoutindex>,
|
||||
pub height_to_first_unknownindex: IndexedVec<Height, Unknownindex>,
|
||||
pub height_to_total_size: IndexedVec<Height, StoredUsize>,
|
||||
pub height_to_first_emptyoutputindex: IndexedVec<Height, EmptyOutputIndex>,
|
||||
pub height_to_first_inputindex: IndexedVec<Height, InputIndex>,
|
||||
pub height_to_first_opreturnindex: IndexedVec<Height, OpReturnIndex>,
|
||||
pub height_to_first_outputindex: IndexedVec<Height, OutputIndex>,
|
||||
pub height_to_first_p2aindex: IndexedVec<Height, P2AIndex>,
|
||||
pub height_to_first_p2msindex: IndexedVec<Height, P2MSIndex>,
|
||||
pub height_to_first_p2pk33index: IndexedVec<Height, P2PK33Index>,
|
||||
pub height_to_first_p2pk65index: IndexedVec<Height, P2PK65Index>,
|
||||
pub height_to_first_p2pkhindex: IndexedVec<Height, P2PKHIndex>,
|
||||
pub height_to_first_p2shindex: IndexedVec<Height, P2SHIndex>,
|
||||
pub height_to_first_p2trindex: IndexedVec<Height, P2TRIndex>,
|
||||
pub height_to_first_p2wpkhindex: IndexedVec<Height, P2WPKHIndex>,
|
||||
pub height_to_first_p2wshindex: IndexedVec<Height, P2WSHIndex>,
|
||||
pub height_to_first_txindex: IndexedVec<Height, TxIndex>,
|
||||
pub height_to_first_unknownoutputindex: IndexedVec<Height, UnknownOutputIndex>,
|
||||
/// Doesn't guarantee continuity due to possible reorgs
|
||||
pub height_to_timestamp: IndexedVec<Height, Timestamp>,
|
||||
pub height_to_total_size: IndexedVec<Height, StoredUsize>,
|
||||
pub height_to_weight: IndexedVec<Height, Weight>,
|
||||
pub multisigindex_to_height: IndexedVec<Multisigindex, Height>,
|
||||
pub opreturnindex_to_height: IndexedVec<Opreturnindex, Height>,
|
||||
pub p2pk33index_to_height: IndexedVec<P2PK33index, Height>,
|
||||
pub p2pk33index_to_p2pk33addressbytes: IndexedVec<P2PK33index, P2PK33AddressBytes>,
|
||||
pub p2pk65index_to_height: IndexedVec<P2PK65index, Height>,
|
||||
pub p2pk65index_to_p2pk65addressbytes: IndexedVec<P2PK65index, P2PK65AddressBytes>,
|
||||
pub p2pkhindex_to_height: IndexedVec<P2PKHindex, Height>,
|
||||
pub p2pkhindex_to_p2pkhaddressbytes: IndexedVec<P2PKHindex, P2PKHAddressBytes>,
|
||||
pub p2shindex_to_height: IndexedVec<P2SHindex, Height>,
|
||||
pub p2shindex_to_p2shaddressbytes: IndexedVec<P2SHindex, P2SHAddressBytes>,
|
||||
pub p2trindex_to_height: IndexedVec<P2TRindex, Height>,
|
||||
pub p2trindex_to_p2traddressbytes: IndexedVec<P2TRindex, P2TRAddressBytes>,
|
||||
pub p2wpkhindex_to_height: IndexedVec<P2WPKHindex, Height>,
|
||||
pub p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec<P2WPKHindex, P2WPKHAddressBytes>,
|
||||
pub p2wshindex_to_height: IndexedVec<P2WSHindex, Height>,
|
||||
pub p2wshindex_to_p2wshaddressbytes: IndexedVec<P2WSHindex, P2WSHAddressBytes>,
|
||||
pub pushonlyindex_to_height: IndexedVec<Pushonlyindex, Height>,
|
||||
pub txindex_to_base_size: IndexedVec<Txindex, usize>,
|
||||
pub txindex_to_first_txinindex: IndexedVec<Txindex, Txinindex>,
|
||||
pub txindex_to_first_txoutindex: IndexedVec<Txindex, Txoutindex>,
|
||||
pub txindex_to_height: IndexedVec<Txindex, Height>,
|
||||
pub txindex_to_is_explicitly_rbf: IndexedVec<Txindex, bool>,
|
||||
pub txindex_to_rawlocktime: IndexedVec<Txindex, RawLockTime>,
|
||||
pub txindex_to_total_size: IndexedVec<Txindex, usize>,
|
||||
pub txindex_to_txid: IndexedVec<Txindex, Txid>,
|
||||
pub txindex_to_txversion: IndexedVec<Txindex, TxVersion>,
|
||||
pub txinindex_to_height: IndexedVec<Txinindex, Height>,
|
||||
/// If txoutindex == Txoutindex MAX then is it's coinbase
|
||||
pub txinindex_to_txoutindex: IndexedVec<Txinindex, Txoutindex>,
|
||||
pub txoutindex_to_addressindex: IndexedVec<Txoutindex, Addressindex>,
|
||||
pub txoutindex_to_height: IndexedVec<Txoutindex, Height>,
|
||||
pub txoutindex_to_value: IndexedVec<Txoutindex, Sats>,
|
||||
pub unknownindex_to_height: IndexedVec<Unknownindex, Height>,
|
||||
/// If outputindex == Outputindex::MAX then it's coinbase
|
||||
pub inputindex_to_outputindex: IndexedVec<InputIndex, OutputIndex>,
|
||||
pub opreturnindex_to_txindex: IndexedVec<OpReturnIndex, TxIndex>,
|
||||
pub outputindex_to_outputtype: IndexedVec<OutputIndex, OutputType>,
|
||||
pub outputindex_to_outputtypeindex: IndexedVec<OutputIndex, OutputTypeIndex>,
|
||||
pub outputindex_to_value: IndexedVec<OutputIndex, Sats>,
|
||||
pub p2aindex_to_p2abytes: IndexedVec<P2AIndex, P2ABytes>,
|
||||
pub p2msindex_to_txindex: IndexedVec<P2MSIndex, TxIndex>,
|
||||
pub p2pk33index_to_p2pk33bytes: IndexedVec<P2PK33Index, P2PK33Bytes>,
|
||||
pub p2pk65index_to_p2pk65bytes: IndexedVec<P2PK65Index, P2PK65Bytes>,
|
||||
pub p2pkhindex_to_p2pkhbytes: IndexedVec<P2PKHIndex, P2PKHBytes>,
|
||||
pub p2shindex_to_p2shbytes: IndexedVec<P2SHIndex, P2SHBytes>,
|
||||
pub p2trindex_to_p2trbytes: IndexedVec<P2TRIndex, P2TRBytes>,
|
||||
pub p2wpkhindex_to_p2wpkhbytes: IndexedVec<P2WPKHIndex, P2WPKHBytes>,
|
||||
pub p2wshindex_to_p2wshbytes: IndexedVec<P2WSHIndex, P2WSHBytes>,
|
||||
pub txindex_to_base_size: IndexedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_first_inputindex: IndexedVec<TxIndex, InputIndex>,
|
||||
pub txindex_to_first_outputindex: IndexedVec<TxIndex, OutputIndex>,
|
||||
pub txindex_to_is_explicitly_rbf: IndexedVec<TxIndex, bool>,
|
||||
pub txindex_to_rawlocktime: IndexedVec<TxIndex, RawLockTime>,
|
||||
pub txindex_to_total_size: IndexedVec<TxIndex, StoredU32>,
|
||||
pub txindex_to_txid: IndexedVec<TxIndex, Txid>,
|
||||
pub txindex_to_txversion: IndexedVec<TxIndex, TxVersion>,
|
||||
pub unknownoutputindex_to_txindex: IndexedVec<UnknownOutputIndex, TxIndex>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -84,43 +71,28 @@ impl Vecs {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
Ok(Self {
|
||||
addressindex_to_addresstype: IndexedVec::forced_import(
|
||||
&path.join("addressindex_to_addresstype"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
addressindex_to_addresstypeindex: IndexedVec::forced_import(
|
||||
&path.join("addressindex_to_addresstypeindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
addressindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("addressindex_to_height"),
|
||||
emptyoutputindex_to_txindex: IndexedVec::forced_import(
|
||||
&path.join("emptyoutputindex_to_txindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_blockhash: IndexedVec::forced_import(
|
||||
&path.join("height_to_blockhash"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_difficulty: IndexedVec::forced_import(
|
||||
&path.join("height_to_difficulty"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_addressindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_addressindex"),
|
||||
height_to_first_emptyoutputindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_emptyoutputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_emptyindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_emptyindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_multisigindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_multisigindex"),
|
||||
height_to_first_inputindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_inputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
@@ -129,28 +101,18 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_pushonlyindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_pushonlyindex"),
|
||||
height_to_first_outputindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_outputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_txindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_txindex"),
|
||||
height_to_first_p2aindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_p2aindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_txinindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_txinindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_txoutindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_txoutindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_unknownindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_unkownindex"),
|
||||
height_to_first_p2msindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_p2msindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
@@ -189,8 +151,13 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_total_size: IndexedVec::forced_import(
|
||||
&path.join("height_to_total_size"),
|
||||
height_to_first_txindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_txindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_first_unknownoutputindex: IndexedVec::forced_import(
|
||||
&path.join("height_to_first_unknownoutputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
@@ -199,78 +166,98 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_total_size: IndexedVec::forced_import(
|
||||
&path.join("height_to_total_size"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_weight: IndexedVec::forced_import(
|
||||
&path.join("height_to_weight"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk33index_to_p2pk33addressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2pk33index_to_p2pk33addressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2pk65index_to_p2pk65addressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2pk65index_to_p2pk65addressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2pkhindex_to_p2pkhaddressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2pkhindex_to_p2pkhaddressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2shindex_to_p2shaddressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2shindex_to_p2shaddressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2trindex_to_p2traddressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2trindex_to_p2traddressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2wpkhindex_to_p2wpkhaddressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
p2wshindex_to_p2wshaddressbytes: IndexedVec::forced_import(
|
||||
&path.join("p2wshindex_to_p2wshaddressbytes"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
txindex_to_first_txinindex: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_first_txinindex"),
|
||||
inputindex_to_outputindex: IndexedVec::forced_import(
|
||||
&path.join("inputindex_to_outputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_first_txoutindex: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_first_txoutindex"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
)?,
|
||||
txindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_height"),
|
||||
opreturnindex_to_txindex: IndexedVec::forced_import(
|
||||
&path.join("opreturnindex_to_txindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_rawlocktime: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_locktime"),
|
||||
outputindex_to_outputtype: IndexedVec::forced_import(
|
||||
&path.join("outputindex_to_outputtype"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_txid: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_txid"),
|
||||
outputindex_to_outputtypeindex: IndexedVec::forced_import(
|
||||
&path.join("outputindex_to_outputtypeindex"),
|
||||
Version::ZERO,
|
||||
Compressed::NO,
|
||||
compressed,
|
||||
)?,
|
||||
outputindex_to_value: IndexedVec::forced_import(
|
||||
&path.join("outputindex_to_value"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2aindex_to_p2abytes: IndexedVec::forced_import(
|
||||
&path.join("p2aindex_to_p2abytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2msindex_to_txindex: IndexedVec::forced_import(
|
||||
&path.join("p2msindex_to_txindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk33index_to_p2pk33bytes: IndexedVec::forced_import(
|
||||
&path.join("p2pk33index_to_p2pk33bytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk65index_to_p2pk65bytes: IndexedVec::forced_import(
|
||||
&path.join("p2pk65index_to_p2pk65bytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pkhindex_to_p2pkhbytes: IndexedVec::forced_import(
|
||||
&path.join("p2pkhindex_to_p2pkhbytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2shindex_to_p2shbytes: IndexedVec::forced_import(
|
||||
&path.join("p2shindex_to_p2shbytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2trindex_to_p2trbytes: IndexedVec::forced_import(
|
||||
&path.join("p2trindex_to_p2trbytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2wpkhindex_to_p2wpkhbytes: IndexedVec::forced_import(
|
||||
&path.join("p2wpkhindex_to_p2wpkhbytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2wshindex_to_p2wshbytes: IndexedVec::forced_import(
|
||||
&path.join("p2wshindex_to_p2wshbytes"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_base_size: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_base_size"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_total_size: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_total_size"),
|
||||
txindex_to_first_inputindex: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_first_inputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_first_outputindex: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_first_outputindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
@@ -279,93 +266,28 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_rawlocktime: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_rawlocktime"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_total_size: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_total_size"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_txid: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_txid"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_txversion: IndexedVec::forced_import(
|
||||
&path.join("txindex_to_txversion"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txinindex_to_txoutindex: IndexedVec::forced_import(
|
||||
&path.join("txinindex_to_txoutindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txoutindex_to_addressindex: IndexedVec::forced_import(
|
||||
&path.join("txoutindex_to_addressindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txoutindex_to_value: IndexedVec::forced_import(
|
||||
&path.join("txoutindex_to_value"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
emptyindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("emptyindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
multisigindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("multisigindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
opreturnindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("opreturnindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
pushonlyindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("pushonlyindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txinindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("txinindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txoutindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("txoutindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
unknownindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("unknownindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk33index_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2pk33index_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk65index_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2pk65index_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pkhindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2pkhindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2shindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2shindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2trindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2trindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2wpkhindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2wpkhindex_to_height"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2wshindex_to_height: IndexedVec::forced_import(
|
||||
&path.join("p2wshindex_to_height"),
|
||||
unknownoutputindex_to_txindex: IndexedVec::forced_import(
|
||||
&path.join("unknownoutputindex_to_txindex"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
@@ -376,8 +298,13 @@ impl Vecs {
|
||||
let saved_height = starting_indexes.height.decremented().unwrap_or_default();
|
||||
|
||||
let &Indexes {
|
||||
addressindex,
|
||||
emptyoutputindex,
|
||||
height,
|
||||
inputindex,
|
||||
opreturnindex,
|
||||
outputindex,
|
||||
p2aindex,
|
||||
p2msindex,
|
||||
p2pk33index,
|
||||
p2pk65index,
|
||||
p2pkhindex,
|
||||
@@ -386,23 +313,27 @@ impl Vecs {
|
||||
p2wpkhindex,
|
||||
p2wshindex,
|
||||
txindex,
|
||||
txinindex,
|
||||
txoutindex,
|
||||
unknownindex,
|
||||
pushonlyindex,
|
||||
opreturnindex,
|
||||
multisigindex,
|
||||
emptyindex,
|
||||
unknownoutputindex,
|
||||
} = starting_indexes;
|
||||
|
||||
self.height_to_first_addressindex
|
||||
self.emptyoutputindex_to_txindex
|
||||
.truncate_if_needed(emptyoutputindex, saved_height)?;
|
||||
self.height_to_blockhash
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_emptyindex
|
||||
self.height_to_difficulty
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_multisigindex
|
||||
self.height_to_first_emptyoutputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_inputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_opreturnindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_outputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_p2aindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_p2msindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_p2pk33index
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_p2pk65index
|
||||
@@ -417,180 +348,139 @@ impl Vecs {
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_p2wshindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_pushonlyindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_txindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_txinindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_txoutindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_first_unknownindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
|
||||
self.height_to_blockhash
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_difficulty
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_total_size
|
||||
self.height_to_first_unknownoutputindex
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_timestamp
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_total_size
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
self.height_to_weight
|
||||
.truncate_if_needed(height, saved_height)?;
|
||||
|
||||
self.addressindex_to_addresstype
|
||||
.truncate_if_needed(addressindex, saved_height)?;
|
||||
self.addressindex_to_addresstypeindex
|
||||
.truncate_if_needed(addressindex, saved_height)?;
|
||||
self.addressindex_to_height
|
||||
.truncate_if_needed(addressindex, saved_height)?;
|
||||
|
||||
self.p2pk33index_to_p2pk33addressbytes
|
||||
self.inputindex_to_outputindex
|
||||
.truncate_if_needed(inputindex, saved_height)?;
|
||||
self.opreturnindex_to_txindex
|
||||
.truncate_if_needed(opreturnindex, saved_height)?;
|
||||
self.outputindex_to_outputtype
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
self.outputindex_to_outputtypeindex
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
self.outputindex_to_value
|
||||
.truncate_if_needed(outputindex, saved_height)?;
|
||||
self.p2aindex_to_p2abytes
|
||||
.truncate_if_needed(p2aindex, saved_height)?;
|
||||
self.p2msindex_to_txindex
|
||||
.truncate_if_needed(p2msindex, saved_height)?;
|
||||
self.p2pk33index_to_p2pk33bytes
|
||||
.truncate_if_needed(p2pk33index, saved_height)?;
|
||||
self.p2pk65index_to_p2pk65addressbytes
|
||||
self.p2pk65index_to_p2pk65bytes
|
||||
.truncate_if_needed(p2pk65index, saved_height)?;
|
||||
self.p2pkhindex_to_p2pkhaddressbytes
|
||||
self.p2pkhindex_to_p2pkhbytes
|
||||
.truncate_if_needed(p2pkhindex, saved_height)?;
|
||||
self.p2shindex_to_p2shaddressbytes
|
||||
self.p2shindex_to_p2shbytes
|
||||
.truncate_if_needed(p2shindex, saved_height)?;
|
||||
self.p2trindex_to_p2traddressbytes
|
||||
self.p2trindex_to_p2trbytes
|
||||
.truncate_if_needed(p2trindex, saved_height)?;
|
||||
self.p2wpkhindex_to_p2wpkhaddressbytes
|
||||
self.p2wpkhindex_to_p2wpkhbytes
|
||||
.truncate_if_needed(p2wpkhindex, saved_height)?;
|
||||
self.p2wshindex_to_p2wshaddressbytes
|
||||
self.p2wshindex_to_p2wshbytes
|
||||
.truncate_if_needed(p2wshindex, saved_height)?;
|
||||
|
||||
self.txindex_to_first_txinindex
|
||||
self.txindex_to_base_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_first_txoutindex
|
||||
self.txindex_to_first_inputindex
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_height
|
||||
self.txindex_to_first_outputindex
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_is_explicitly_rbf
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_rawlocktime
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_total_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_txid
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_txversion
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_base_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_total_size
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
self.txindex_to_is_explicitly_rbf
|
||||
.truncate_if_needed(txindex, saved_height)?;
|
||||
|
||||
self.txinindex_to_txoutindex
|
||||
.truncate_if_needed(txinindex, saved_height)?;
|
||||
|
||||
self.txoutindex_to_addressindex
|
||||
.truncate_if_needed(txoutindex, saved_height)?;
|
||||
self.txoutindex_to_value
|
||||
.truncate_if_needed(txoutindex, saved_height)?;
|
||||
|
||||
self.emptyindex_to_height
|
||||
.truncate_if_needed(emptyindex, saved_height)?;
|
||||
self.multisigindex_to_height
|
||||
.truncate_if_needed(multisigindex, saved_height)?;
|
||||
self.opreturnindex_to_height
|
||||
.truncate_if_needed(opreturnindex, saved_height)?;
|
||||
self.pushonlyindex_to_height
|
||||
.truncate_if_needed(pushonlyindex, saved_height)?;
|
||||
self.txinindex_to_height
|
||||
.truncate_if_needed(txinindex, saved_height)?;
|
||||
self.txoutindex_to_height
|
||||
.truncate_if_needed(txoutindex, saved_height)?;
|
||||
self.unknownindex_to_height
|
||||
.truncate_if_needed(unknownindex, saved_height)?;
|
||||
self.p2pk33index_to_height
|
||||
.truncate_if_needed(p2pk33index, saved_height)?;
|
||||
self.p2pk65index_to_height
|
||||
.truncate_if_needed(p2pk65index, saved_height)?;
|
||||
self.p2pkhindex_to_height
|
||||
.truncate_if_needed(p2pkhindex, saved_height)?;
|
||||
self.p2shindex_to_height
|
||||
.truncate_if_needed(p2shindex, saved_height)?;
|
||||
self.p2trindex_to_height
|
||||
.truncate_if_needed(p2trindex, saved_height)?;
|
||||
self.p2wpkhindex_to_height
|
||||
.truncate_if_needed(p2wpkhindex, saved_height)?;
|
||||
self.p2wshindex_to_height
|
||||
.truncate_if_needed(p2wshindex, saved_height)?;
|
||||
self.unknownoutputindex_to_txindex
|
||||
.truncate_if_needed(unknownoutputindex, saved_height)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_addressbytes(
|
||||
&self,
|
||||
addresstype: Addresstype,
|
||||
addresstypeindex: Addresstypeindex,
|
||||
) -> brk_vec::Result<Option<Addressbytes>> {
|
||||
Ok(match addresstype {
|
||||
Addresstype::P2PK65 => self
|
||||
.p2pk65index_to_p2pk65addressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2PK33 => self
|
||||
.p2pk33index_to_p2pk33addressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2PKH => self
|
||||
.p2pkhindex_to_p2pkhaddressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2SH => self
|
||||
.p2shindex_to_p2shaddressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2WPKH => self
|
||||
.p2wpkhindex_to_p2wpkhaddressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2WSH => self
|
||||
.p2wshindex_to_p2wshaddressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
Addresstype::P2TR => self
|
||||
.p2trindex_to_p2traddressbytes
|
||||
.get(addresstypeindex.into())?
|
||||
// .map(|v| Addressbytes::from(v.clone())),
|
||||
.map(|v| Addressbytes::from(v.into_inner())),
|
||||
_ => unreachable!(),
|
||||
outputtype: OutputType,
|
||||
outputtypeindex: OutputTypeIndex,
|
||||
) -> brk_vec::Result<Option<AddressBytes>> {
|
||||
Ok(match outputtype {
|
||||
OutputType::P2PK65 => self
|
||||
.p2pk65index_to_p2pk65bytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2PK33 => self
|
||||
.p2pk33index_to_p2pk33bytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2PKH => self
|
||||
.p2pkhindex_to_p2pkhbytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2SH => self
|
||||
.p2shindex_to_p2shbytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2WPKH => self
|
||||
.p2wpkhindex_to_p2wpkhbytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2WSH => self
|
||||
.p2wshindex_to_p2wshbytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2TR => self
|
||||
.p2trindex_to_p2trbytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::P2A => self
|
||||
.p2aindex_to_p2abytes
|
||||
.get(outputtypeindex.into())?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
|
||||
unreachable!()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn push_addressbytes_if_needed(
|
||||
pub fn push_bytes_if_needed(
|
||||
&mut self,
|
||||
index: Addresstypeindex,
|
||||
addressbytes: Addressbytes,
|
||||
index: OutputTypeIndex,
|
||||
bytes: AddressBytes,
|
||||
) -> brk_vec::Result<()> {
|
||||
match addressbytes {
|
||||
Addressbytes::P2PK65(bytes) => self
|
||||
.p2pk65index_to_p2pk65addressbytes
|
||||
match bytes {
|
||||
AddressBytes::P2PK65(bytes) => self
|
||||
.p2pk65index_to_p2pk65bytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2PK33(bytes) => self
|
||||
.p2pk33index_to_p2pk33addressbytes
|
||||
AddressBytes::P2PK33(bytes) => self
|
||||
.p2pk33index_to_p2pk33bytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2PKH(bytes) => self
|
||||
.p2pkhindex_to_p2pkhaddressbytes
|
||||
AddressBytes::P2PKH(bytes) => self
|
||||
.p2pkhindex_to_p2pkhbytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2SH(bytes) => self
|
||||
.p2shindex_to_p2shaddressbytes
|
||||
AddressBytes::P2SH(bytes) => self
|
||||
.p2shindex_to_p2shbytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2WPKH(bytes) => self
|
||||
.p2wpkhindex_to_p2wpkhaddressbytes
|
||||
AddressBytes::P2WPKH(bytes) => self
|
||||
.p2wpkhindex_to_p2wpkhbytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2WSH(bytes) => self
|
||||
.p2wshindex_to_p2wshaddressbytes
|
||||
AddressBytes::P2WSH(bytes) => self
|
||||
.p2wshindex_to_p2wshbytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
Addressbytes::P2TR(bytes) => self
|
||||
.p2trindex_to_p2traddressbytes
|
||||
AddressBytes::P2TR(bytes) => self
|
||||
.p2trindex_to_p2trbytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
AddressBytes::P2A(bytes) => self
|
||||
.p2aindex_to_p2abytes
|
||||
.push_if_needed(index.into(), bytes),
|
||||
}
|
||||
}
|
||||
@@ -611,20 +501,15 @@ impl Vecs {
|
||||
|
||||
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStoredVec> {
|
||||
vec![
|
||||
self.addressindex_to_addresstype.any_vec(),
|
||||
self.addressindex_to_addresstypeindex.any_vec(),
|
||||
self.addressindex_to_height.any_vec(),
|
||||
self.emptyoutputindex_to_txindex.any_vec(),
|
||||
self.height_to_blockhash.any_vec(),
|
||||
self.height_to_difficulty.any_vec(),
|
||||
self.height_to_first_addressindex.any_vec(),
|
||||
self.height_to_first_emptyindex.any_vec(),
|
||||
self.height_to_first_multisigindex.any_vec(),
|
||||
self.height_to_first_emptyoutputindex.any_vec(),
|
||||
self.height_to_first_inputindex.any_vec(),
|
||||
self.height_to_first_opreturnindex.any_vec(),
|
||||
self.height_to_first_pushonlyindex.any_vec(),
|
||||
self.height_to_first_txindex.any_vec(),
|
||||
self.height_to_first_txinindex.any_vec(),
|
||||
self.height_to_first_txoutindex.any_vec(),
|
||||
self.height_to_first_unknownindex.any_vec(),
|
||||
self.height_to_first_outputindex.any_vec(),
|
||||
self.height_to_first_p2aindex.any_vec(),
|
||||
self.height_to_first_p2msindex.any_vec(),
|
||||
self.height_to_first_p2pk33index.any_vec(),
|
||||
self.height_to_first_p2pk65index.any_vec(),
|
||||
self.height_to_first_p2pkhindex.any_vec(),
|
||||
@@ -632,61 +517,48 @@ impl Vecs {
|
||||
self.height_to_first_p2trindex.any_vec(),
|
||||
self.height_to_first_p2wpkhindex.any_vec(),
|
||||
self.height_to_first_p2wshindex.any_vec(),
|
||||
self.height_to_total_size.any_vec(),
|
||||
self.height_to_first_txindex.any_vec(),
|
||||
self.height_to_first_unknownoutputindex.any_vec(),
|
||||
self.height_to_timestamp.any_vec(),
|
||||
self.height_to_total_size.any_vec(),
|
||||
self.height_to_weight.any_vec(),
|
||||
self.p2pk33index_to_p2pk33addressbytes.any_vec(),
|
||||
self.p2pk65index_to_p2pk65addressbytes.any_vec(),
|
||||
self.p2pkhindex_to_p2pkhaddressbytes.any_vec(),
|
||||
self.p2shindex_to_p2shaddressbytes.any_vec(),
|
||||
self.p2trindex_to_p2traddressbytes.any_vec(),
|
||||
self.p2wpkhindex_to_p2wpkhaddressbytes.any_vec(),
|
||||
self.p2wshindex_to_p2wshaddressbytes.any_vec(),
|
||||
self.txindex_to_first_txinindex.any_vec(),
|
||||
self.txindex_to_first_txoutindex.any_vec(),
|
||||
self.txindex_to_height.any_vec(),
|
||||
self.txindex_to_rawlocktime.any_vec(),
|
||||
self.txindex_to_txid.any_vec(),
|
||||
self.inputindex_to_outputindex.any_vec(),
|
||||
self.opreturnindex_to_txindex.any_vec(),
|
||||
self.outputindex_to_outputtype.any_vec(),
|
||||
self.outputindex_to_outputtypeindex.any_vec(),
|
||||
self.outputindex_to_value.any_vec(),
|
||||
self.p2aindex_to_p2abytes.any_vec(),
|
||||
self.p2msindex_to_txindex.any_vec(),
|
||||
self.p2pk33index_to_p2pk33bytes.any_vec(),
|
||||
self.p2pk65index_to_p2pk65bytes.any_vec(),
|
||||
self.p2pkhindex_to_p2pkhbytes.any_vec(),
|
||||
self.p2shindex_to_p2shbytes.any_vec(),
|
||||
self.p2trindex_to_p2trbytes.any_vec(),
|
||||
self.p2wpkhindex_to_p2wpkhbytes.any_vec(),
|
||||
self.p2wshindex_to_p2wshbytes.any_vec(),
|
||||
self.txindex_to_base_size.any_vec(),
|
||||
self.txindex_to_total_size.any_vec(),
|
||||
self.txindex_to_first_inputindex.any_vec(),
|
||||
self.txindex_to_first_outputindex.any_vec(),
|
||||
self.txindex_to_is_explicitly_rbf.any_vec(),
|
||||
self.txindex_to_rawlocktime.any_vec(),
|
||||
self.txindex_to_total_size.any_vec(),
|
||||
self.txindex_to_txid.any_vec(),
|
||||
self.txindex_to_txversion.any_vec(),
|
||||
self.txinindex_to_txoutindex.any_vec(),
|
||||
self.txoutindex_to_addressindex.any_vec(),
|
||||
self.txoutindex_to_value.any_vec(),
|
||||
self.emptyindex_to_height.any_vec(),
|
||||
self.multisigindex_to_height.any_vec(),
|
||||
self.opreturnindex_to_height.any_vec(),
|
||||
self.pushonlyindex_to_height.any_vec(),
|
||||
self.txinindex_to_height.any_vec(),
|
||||
self.txoutindex_to_height.any_vec(),
|
||||
self.unknownindex_to_height.any_vec(),
|
||||
self.p2pk33index_to_height.any_vec(),
|
||||
self.p2pk65index_to_height.any_vec(),
|
||||
self.p2pkhindex_to_height.any_vec(),
|
||||
self.p2shindex_to_height.any_vec(),
|
||||
self.p2trindex_to_height.any_vec(),
|
||||
self.p2wpkhindex_to_height.any_vec(),
|
||||
self.p2wshindex_to_height.any_vec(),
|
||||
self.unknownoutputindex_to_txindex.any_vec(),
|
||||
]
|
||||
}
|
||||
|
||||
fn as_mut_any_vecs(&mut self) -> Vec<&mut dyn AnyIndexedVec> {
|
||||
vec![
|
||||
&mut self.addressindex_to_addresstype,
|
||||
&mut self.addressindex_to_addresstypeindex,
|
||||
&mut self.addressindex_to_height,
|
||||
&mut self.emptyoutputindex_to_txindex,
|
||||
&mut self.height_to_blockhash,
|
||||
&mut self.height_to_difficulty,
|
||||
&mut self.height_to_first_addressindex,
|
||||
&mut self.height_to_first_emptyindex,
|
||||
&mut self.height_to_first_multisigindex,
|
||||
&mut self.height_to_first_emptyoutputindex,
|
||||
&mut self.height_to_first_inputindex,
|
||||
&mut self.height_to_first_opreturnindex,
|
||||
&mut self.height_to_first_pushonlyindex,
|
||||
&mut self.height_to_first_txindex,
|
||||
&mut self.height_to_first_txinindex,
|
||||
&mut self.height_to_first_txoutindex,
|
||||
&mut self.height_to_first_unknownindex,
|
||||
&mut self.height_to_first_outputindex,
|
||||
&mut self.height_to_first_p2aindex,
|
||||
&mut self.height_to_first_p2msindex,
|
||||
&mut self.height_to_first_p2pk33index,
|
||||
&mut self.height_to_first_p2pk65index,
|
||||
&mut self.height_to_first_p2pkhindex,
|
||||
@@ -694,42 +566,34 @@ impl Vecs {
|
||||
&mut self.height_to_first_p2trindex,
|
||||
&mut self.height_to_first_p2wpkhindex,
|
||||
&mut self.height_to_first_p2wshindex,
|
||||
&mut self.height_to_total_size,
|
||||
&mut self.height_to_first_txindex,
|
||||
&mut self.height_to_first_unknownoutputindex,
|
||||
&mut self.height_to_timestamp,
|
||||
&mut self.height_to_total_size,
|
||||
&mut self.height_to_weight,
|
||||
&mut self.p2pk33index_to_p2pk33addressbytes,
|
||||
&mut self.p2pk65index_to_p2pk65addressbytes,
|
||||
&mut self.p2pkhindex_to_p2pkhaddressbytes,
|
||||
&mut self.p2shindex_to_p2shaddressbytes,
|
||||
&mut self.p2trindex_to_p2traddressbytes,
|
||||
&mut self.p2wpkhindex_to_p2wpkhaddressbytes,
|
||||
&mut self.p2wshindex_to_p2wshaddressbytes,
|
||||
&mut self.txindex_to_first_txinindex,
|
||||
&mut self.txindex_to_first_txoutindex,
|
||||
&mut self.txindex_to_height,
|
||||
&mut self.txindex_to_rawlocktime,
|
||||
&mut self.txindex_to_txid,
|
||||
&mut self.inputindex_to_outputindex,
|
||||
&mut self.opreturnindex_to_txindex,
|
||||
&mut self.outputindex_to_outputtype,
|
||||
&mut self.outputindex_to_outputtypeindex,
|
||||
&mut self.outputindex_to_value,
|
||||
&mut self.p2aindex_to_p2abytes,
|
||||
&mut self.p2msindex_to_txindex,
|
||||
&mut self.p2pk33index_to_p2pk33bytes,
|
||||
&mut self.p2pk65index_to_p2pk65bytes,
|
||||
&mut self.p2pkhindex_to_p2pkhbytes,
|
||||
&mut self.p2shindex_to_p2shbytes,
|
||||
&mut self.p2trindex_to_p2trbytes,
|
||||
&mut self.p2wpkhindex_to_p2wpkhbytes,
|
||||
&mut self.p2wshindex_to_p2wshbytes,
|
||||
&mut self.txindex_to_base_size,
|
||||
&mut self.txindex_to_total_size,
|
||||
&mut self.txindex_to_first_inputindex,
|
||||
&mut self.txindex_to_first_outputindex,
|
||||
&mut self.txindex_to_is_explicitly_rbf,
|
||||
&mut self.txindex_to_rawlocktime,
|
||||
&mut self.txindex_to_total_size,
|
||||
&mut self.txindex_to_txid,
|
||||
&mut self.txindex_to_txversion,
|
||||
&mut self.txinindex_to_txoutindex,
|
||||
&mut self.txoutindex_to_addressindex,
|
||||
&mut self.txoutindex_to_value,
|
||||
&mut self.emptyindex_to_height,
|
||||
&mut self.multisigindex_to_height,
|
||||
&mut self.opreturnindex_to_height,
|
||||
&mut self.pushonlyindex_to_height,
|
||||
&mut self.txinindex_to_height,
|
||||
&mut self.txoutindex_to_height,
|
||||
&mut self.unknownindex_to_height,
|
||||
&mut self.p2pk33index_to_height,
|
||||
&mut self.p2pk65index_to_height,
|
||||
&mut self.p2pkhindex_to_height,
|
||||
&mut self.p2shindex_to_height,
|
||||
&mut self.p2trindex_to_height,
|
||||
&mut self.p2wpkhindex_to_height,
|
||||
&mut self.p2wshindex_to_height,
|
||||
&mut self.unknownoutputindex_to_txindex,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user