global: renames + refactor + p2a support

This commit is contained in:
nym21
2025-04-25 18:16:23 +02:00
parent 1492834d1e
commit 07618ebe43
51 changed files with 2802 additions and 1833 deletions

77
Cargo.lock generated
View File

@@ -34,6 +34,19 @@ dependencies = [
"cpufeatures",
]
[[package]]
name = "ahash"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
dependencies = [
"cfg-if",
"getrandom 0.2.16",
"once_cell",
"version_check",
"zerocopy 0.7.35",
]
[[package]]
name = "aho-corasick"
version = "1.1.3"
@@ -440,7 +453,7 @@ dependencies = [
"rlimit",
"serde",
"serde_bytes",
"zerocopy",
"zerocopy 0.8.24",
]
[[package]]
@@ -481,7 +494,7 @@ dependencies = [
"fjall",
"log",
"rayon",
"zerocopy",
"zerocopy 0.8.24",
]
[[package]]
@@ -506,7 +519,7 @@ dependencies = [
"rayon",
"serde",
"serde_json",
"zerocopy",
"zerocopy 0.8.24",
]
[[package]]
@@ -561,7 +574,7 @@ dependencies = [
"rayon",
"serde",
"serde_json",
"zerocopy",
"zerocopy 0.8.24",
"zstd",
]
@@ -649,9 +662,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.19"
version = "1.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362"
checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a"
dependencies = [
"jobserver",
"libc",
@@ -2134,12 +2147,12 @@ dependencies = [
[[package]]
name = "papergrid"
version = "0.14.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b915f831b85d984193fdc3d3611505871dc139b2534530fa01c1a6a6707b6723"
checksum = "30268a8d20c2c0d126b2b6610ab405f16517f6ba9f244d8c59ac2c512a8a1ce7"
dependencies = [
"ahash",
"bytecount",
"fnv",
"unicode-width",
]
@@ -2299,7 +2312,7 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
"zerocopy 0.8.24",
]
[[package]]
@@ -2820,19 +2833,20 @@ checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
name = "tabled"
version = "0.18.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "121d8171ee5687a4978d1b244f7d99c43e7385a272185a2f1e1fa4dc0979d444"
checksum = "228d124371171cd39f0f454b58f73ddebeeef3cef3207a82ffea1c29465aea43"
dependencies = [
"papergrid",
"tabled_derive",
"testing_table",
]
[[package]]
name = "tabled_derive"
version = "0.10.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52d9946811baad81710ec921809e2af67ad77719418673b2a3794932d57b7538"
checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846"
dependencies = [
"heck",
"proc-macro-error2",
@@ -2854,6 +2868,15 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "testing_table"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f8daae29995a24f65619e19d8d31dea5b389f3d853d8bf297bbf607cd0014cc"
dependencies = [
"unicode-width",
]
[[package]]
name = "textwrap"
version = "0.16.2"
@@ -3409,9 +3432,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.6"
version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10"
checksum = "6cb8234a863ea0e8cd7284fcdd4f145233eb00fee02bbdd9861aec44e6477bc5"
dependencies = [
"memchr",
]
@@ -3440,13 +3463,33 @@ dependencies = [
"lzma-sys",
]
[[package]]
name = "zerocopy"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0"
dependencies = [
"zerocopy-derive 0.7.35",
]
[[package]]
name = "zerocopy"
version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879"
dependencies = [
"zerocopy-derive",
"zerocopy-derive 0.8.24",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.100",
]
[[package]]

View File

@@ -41,7 +41,7 @@ minreq = { version = "2.13.4", features = ["https", "serde_json"] }
rayon = "1.10.0"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = { version = "1.0.140", features = ["float_roundtrip"] }
tabled = "0.18.0"
tabled = "0.19.0"
zerocopy = { version = "0.8.24", features = ["derive"] }
[workspace.metadata.release]

View File

@@ -1,34 +1,31 @@
use std::path::Path;
use brk_core::{AddressindexTxoutindex, Unit};
use brk_indexer::Store;
use brk_vec::Version;
use fjall::TransactionalKeyspace;
#[derive(Clone)]
pub struct Stores {
pub address_to_utxos_received: Store<AddressindexTxoutindex, Unit>,
pub address_to_utxos_spent: Store<AddressindexTxoutindex, Unit>,
// pub address_to_utxos_received: Store<AddressIndexOutputIndex, Unit>,
// pub address_to_utxos_spent: Store<AddressIndexOutputIndex, Unit>,
}
impl Stores {
pub fn import(path: &Path, keyspace: &TransactionalKeyspace) -> color_eyre::Result<Self> {
let address_to_utxos_received = Store::import(
keyspace.clone(),
path,
"address_to_utxos_received",
Version::ZERO,
)?;
let address_to_utxos_spent = Store::import(
keyspace.clone(),
path,
"address_to_utxos_spent",
Version::ZERO,
)?;
pub fn import(_: &Path, _: &TransactionalKeyspace) -> color_eyre::Result<Self> {
// let address_to_utxos_received = Store::import(
// keyspace.clone(),
// path,
// "address_to_utxos_received",
// Version::ZERO,
// )?;
// let address_to_utxos_spent = Store::import(
// keyspace.clone(),
// path,
// "address_to_utxos_spent",
// Version::ZERO,
// )?;
Ok(Self {
address_to_utxos_received,
address_to_utxos_spent,
// address_to_utxos_received,
// address_to_utxos_spent,
})
}
}

View File

@@ -1,6 +1,6 @@
use std::path::Path;
use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex};
use brk_core::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStoredVec, Compressed, Result, Version};
@@ -14,13 +14,13 @@ pub struct ComputedVecsFromDateindex<T>
where
T: ComputedType + PartialOrd,
{
pub dateindex: EagerVec<Dateindex, T>,
pub dateindex_extra: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
pub dateindex: EagerVec<DateIndex, T>,
pub dateindex_extra: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
pub yearindex: ComputedVecBuilder<YearIndex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
}
const VERSION: Version = Version::ZERO;
@@ -79,7 +79,7 @@ where
) -> color_eyre::Result<()>
where
F: FnMut(
&mut EagerVec<Dateindex, T>,
&mut EagerVec<DateIndex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,

View File

@@ -1,7 +1,7 @@
use std::path::Path;
use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex,
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
@@ -18,14 +18,14 @@ where
{
pub height: Option<EagerVec<Height, T>>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
pub yearindex: ComputedVecBuilder<YearIndex, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
}
const VERSION: Version = Version::ZERO;

View File

@@ -1,6 +1,6 @@
use std::path::Path;
use brk_core::{Difficultyepoch, Height};
use brk_core::{DifficultyEpoch, Height};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStoredVec, Compressed, Result, Version};
@@ -16,7 +16,7 @@ where
{
pub height: EagerVec<Height, T>,
pub height_extra: ComputedVecBuilder<Height, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
}

View File

@@ -1,8 +1,8 @@
use std::path::Path;
use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Txindex, Weekindex,
Yearindex,
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, TxIndex, WeekIndex,
YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
@@ -17,16 +17,16 @@ pub struct ComputedVecsFromTxindex<T>
where
T: ComputedType + PartialOrd,
{
pub txindex: Option<EagerVec<Txindex, T>>,
pub txindex: Option<EagerVec<TxIndex, T>>,
pub height: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
pub dateindex: ComputedVecBuilder<DateIndex, T>,
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
pub yearindex: ComputedVecBuilder<YearIndex, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
}
const VERSION: Version = Version::ZERO;
@@ -91,7 +91,7 @@ where
) -> color_eyre::Result<()>
where
F: FnMut(
&mut EagerVec<Txindex, T>,
&mut EagerVec<TxIndex, T>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
@@ -117,7 +117,7 @@ where
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
txindex: Option<&mut StoredVec<Txindex, T>>,
txindex: Option<&mut StoredVec<TxIndex, T>>,
) -> color_eyre::Result<()> {
let txindex = txindex.unwrap_or_else(|| self.txindex.as_mut().unwrap().mut_vec());

View File

@@ -1,6 +1,6 @@
use std::path::Path;
use brk_core::{Bitcoin, Dollars, Sats, Txindex};
use brk_core::{Bitcoin, Dollars, Sats, TxIndex};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStoredVec, Compressed, Result, StoredVec, Version};
@@ -73,7 +73,7 @@ impl ComputedValueVecsFromTxindex {
) -> color_eyre::Result<()>
where
F: FnMut(
&mut EagerVec<Txindex, Sats>,
&mut EagerVec<TxIndex, Sats>,
&mut Indexer,
&mut indexes::Vecs,
&Indexes,
@@ -100,7 +100,7 @@ impl ComputedValueVecsFromTxindex {
marketprices: &mut Option<&mut marketprice::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
mut txindex: Option<&mut StoredVec<Txindex, Sats>>,
mut txindex: Option<&mut StoredVec<TxIndex, Sats>>,
) -> color_eyre::Result<()> {
if let Some(txindex) = txindex.as_mut() {
self.sats
@@ -136,11 +136,11 @@ impl ComputedValueVecsFromTxindex {
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
|v, _, indexes, starting_indexes, exit| {
v.compute_from_bitcoin(
starting_indexes.txindex,
txindex,
indexer.mut_vecs().txindex_to_height.mut_vec(),
indexes.txindex_to_height.mut_vec(),
price,
exit,
)

View File

@@ -1,10 +1,10 @@
use std::{fs, ops::Deref, path::Path};
use brk_core::{
Addressindex, Date, Dateindex, Decadeindex, Difficultyepoch, Emptyindex, Halvingepoch, Height,
Monthindex, Multisigindex, Opreturnindex, P2PK33index, P2PK65index, P2PKHindex, P2SHindex,
P2TRindex, P2WPKHindex, P2WSHindex, Pushonlyindex, Quarterindex, Timestamp, Txindex, Txinindex,
Txoutindex, Unknownindex, Weekindex, Yearindex,
Date, DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height,
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AIndex, P2MSIndex, P2PK33Index,
P2PK65Index, P2PKHIndex, P2SHIndex, P2TRIndex, P2WPKHIndex, P2WSHIndex, QuarterIndex,
Timestamp, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
@@ -14,70 +14,70 @@ use super::EagerVec;
#[derive(Clone)]
pub struct Vecs {
pub addressindex_to_addressindex: EagerVec<Addressindex, Addressindex>,
pub dateindex_to_date: EagerVec<Dateindex, Date>,
pub dateindex_to_dateindex: EagerVec<Dateindex, Dateindex>,
pub dateindex_to_first_height: EagerVec<Dateindex, Height>,
pub dateindex_to_last_height: EagerVec<Dateindex, Height>,
pub dateindex_to_monthindex: EagerVec<Dateindex, Monthindex>,
pub dateindex_to_timestamp: EagerVec<Dateindex, Timestamp>,
pub dateindex_to_weekindex: EagerVec<Dateindex, Weekindex>,
pub decadeindex_to_decadeindex: EagerVec<Decadeindex, Decadeindex>,
pub decadeindex_to_first_yearindex: EagerVec<Decadeindex, Yearindex>,
pub decadeindex_to_last_yearindex: EagerVec<Decadeindex, Yearindex>,
pub decadeindex_to_timestamp: EagerVec<Decadeindex, Timestamp>,
pub difficultyepoch_to_difficultyepoch: EagerVec<Difficultyepoch, Difficultyepoch>,
pub difficultyepoch_to_first_height: EagerVec<Difficultyepoch, Height>,
pub difficultyepoch_to_last_height: EagerVec<Difficultyepoch, Height>,
pub difficultyepoch_to_timestamp: EagerVec<Difficultyepoch, Timestamp>,
pub emptyindex_to_emptyindex: EagerVec<Emptyindex, Emptyindex>,
pub halvingepoch_to_first_height: EagerVec<Halvingepoch, Height>,
pub halvingepoch_to_halvingepoch: EagerVec<Halvingepoch, Halvingepoch>,
pub halvingepoch_to_last_height: EagerVec<Halvingepoch, Height>,
pub halvingepoch_to_timestamp: EagerVec<Halvingepoch, Timestamp>,
pub height_to_dateindex: EagerVec<Height, Dateindex>,
pub height_to_difficultyepoch: EagerVec<Height, Difficultyepoch>,
pub height_to_fixed_date: EagerVec<Height, Date>,
pub height_to_fixed_timestamp: EagerVec<Height, Timestamp>,
pub height_to_halvingepoch: EagerVec<Height, Halvingepoch>,
pub dateindex_to_date: EagerVec<DateIndex, Date>,
pub dateindex_to_dateindex: EagerVec<DateIndex, DateIndex>,
pub dateindex_to_first_height: EagerVec<DateIndex, Height>,
pub dateindex_to_last_height: EagerVec<DateIndex, Height>,
pub dateindex_to_monthindex: EagerVec<DateIndex, MonthIndex>,
pub dateindex_to_timestamp: EagerVec<DateIndex, Timestamp>,
pub dateindex_to_weekindex: EagerVec<DateIndex, WeekIndex>,
pub decadeindex_to_decadeindex: EagerVec<DecadeIndex, DecadeIndex>,
pub decadeindex_to_first_yearindex: EagerVec<DecadeIndex, YearIndex>,
pub decadeindex_to_last_yearindex: EagerVec<DecadeIndex, YearIndex>,
pub decadeindex_to_timestamp: EagerVec<DecadeIndex, Timestamp>,
pub difficultyepoch_to_difficultyepoch: EagerVec<DifficultyEpoch, DifficultyEpoch>,
pub difficultyepoch_to_first_height: EagerVec<DifficultyEpoch, Height>,
pub difficultyepoch_to_last_height: EagerVec<DifficultyEpoch, Height>,
pub difficultyepoch_to_timestamp: EagerVec<DifficultyEpoch, Timestamp>,
pub emptyoutputindex_to_emptyoutputindex: EagerVec<EmptyOutputIndex, EmptyOutputIndex>,
pub halvingepoch_to_first_height: EagerVec<HalvingEpoch, Height>,
pub halvingepoch_to_halvingepoch: EagerVec<HalvingEpoch, HalvingEpoch>,
pub halvingepoch_to_last_height: EagerVec<HalvingEpoch, Height>,
pub halvingepoch_to_timestamp: EagerVec<HalvingEpoch, Timestamp>,
pub height_to_date: EagerVec<Height, Date>,
pub height_to_date_fixed: EagerVec<Height, Date>,
pub height_to_dateindex: EagerVec<Height, DateIndex>,
pub height_to_difficultyepoch: EagerVec<Height, DifficultyEpoch>,
pub height_to_halvingepoch: EagerVec<Height, HalvingEpoch>,
pub height_to_height: EagerVec<Height, Height>,
pub height_to_last_txindex: EagerVec<Height, Txindex>,
pub height_to_real_date: EagerVec<Height, Date>,
pub monthindex_to_first_dateindex: EagerVec<Monthindex, Dateindex>,
pub monthindex_to_last_dateindex: EagerVec<Monthindex, Dateindex>,
pub monthindex_to_monthindex: EagerVec<Monthindex, Monthindex>,
pub monthindex_to_quarterindex: EagerVec<Monthindex, Quarterindex>,
pub monthindex_to_timestamp: EagerVec<Monthindex, Timestamp>,
pub monthindex_to_yearindex: EagerVec<Monthindex, Yearindex>,
pub multisigindex_to_multisigindex: EagerVec<Multisigindex, Multisigindex>,
pub opreturnindex_to_opreturnindex: EagerVec<Opreturnindex, Opreturnindex>,
pub p2pk33index_to_p2pk33index: EagerVec<P2PK33index, P2PK33index>,
pub p2pk65index_to_p2pk65index: EagerVec<P2PK65index, P2PK65index>,
pub p2pkhindex_to_p2pkhindex: EagerVec<P2PKHindex, P2PKHindex>,
pub p2shindex_to_p2shindex: EagerVec<P2SHindex, P2SHindex>,
pub p2trindex_to_p2trindex: EagerVec<P2TRindex, P2TRindex>,
pub p2wpkhindex_to_p2wpkhindex: EagerVec<P2WPKHindex, P2WPKHindex>,
pub p2wshindex_to_p2wshindex: EagerVec<P2WSHindex, P2WSHindex>,
pub pushonlyindex_to_pushonlyindex: EagerVec<Pushonlyindex, Pushonlyindex>,
pub quarterindex_to_first_monthindex: EagerVec<Quarterindex, Monthindex>,
pub quarterindex_to_last_monthindex: EagerVec<Quarterindex, Monthindex>,
pub quarterindex_to_quarterindex: EagerVec<Quarterindex, Quarterindex>,
pub quarterindex_to_timestamp: EagerVec<Quarterindex, Timestamp>,
pub txindex_to_last_txinindex: EagerVec<Txindex, Txinindex>,
pub txindex_to_last_txoutindex: EagerVec<Txindex, Txoutindex>,
pub txindex_to_txindex: EagerVec<Txindex, Txindex>,
pub txinindex_to_txinindex: EagerVec<Txinindex, Txinindex>,
pub txoutindex_to_txoutindex: EagerVec<Txoutindex, Txoutindex>,
pub unknownindex_to_unknownindex: EagerVec<Unknownindex, Unknownindex>,
pub weekindex_to_first_dateindex: EagerVec<Weekindex, Dateindex>,
pub weekindex_to_last_dateindex: EagerVec<Weekindex, Dateindex>,
pub weekindex_to_timestamp: EagerVec<Weekindex, Timestamp>,
pub weekindex_to_weekindex: EagerVec<Weekindex, Weekindex>,
pub yearindex_to_decadeindex: EagerVec<Yearindex, Decadeindex>,
pub yearindex_to_first_monthindex: EagerVec<Yearindex, Monthindex>,
pub yearindex_to_last_monthindex: EagerVec<Yearindex, Monthindex>,
pub yearindex_to_timestamp: EagerVec<Yearindex, Timestamp>,
pub yearindex_to_yearindex: EagerVec<Yearindex, Yearindex>,
pub height_to_last_txindex: EagerVec<Height, TxIndex>,
pub height_to_timestamp_fixed: EagerVec<Height, Timestamp>,
pub inputindex_to_inputindex: EagerVec<InputIndex, InputIndex>,
pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>,
pub monthindex_to_last_dateindex: EagerVec<MonthIndex, DateIndex>,
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>,
pub monthindex_to_timestamp: EagerVec<MonthIndex, Timestamp>,
pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>,
pub opreturnindex_to_opreturnindex: EagerVec<OpReturnIndex, OpReturnIndex>,
pub outputindex_to_outputindex: EagerVec<OutputIndex, OutputIndex>,
pub p2aindex_to_p2aindex: EagerVec<P2AIndex, P2AIndex>,
pub p2msindex_to_p2msindex: EagerVec<P2MSIndex, P2MSIndex>,
pub p2pk33index_to_p2pk33index: EagerVec<P2PK33Index, P2PK33Index>,
pub p2pk65index_to_p2pk65index: EagerVec<P2PK65Index, P2PK65Index>,
pub p2pkhindex_to_p2pkhindex: EagerVec<P2PKHIndex, P2PKHIndex>,
pub p2shindex_to_p2shindex: EagerVec<P2SHIndex, P2SHIndex>,
pub p2trindex_to_p2trindex: EagerVec<P2TRIndex, P2TRIndex>,
pub p2wpkhindex_to_p2wpkhindex: EagerVec<P2WPKHIndex, P2WPKHIndex>,
pub p2wshindex_to_p2wshindex: EagerVec<P2WSHIndex, P2WSHIndex>,
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
pub quarterindex_to_last_monthindex: EagerVec<QuarterIndex, MonthIndex>,
pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>,
pub quarterindex_to_timestamp: EagerVec<QuarterIndex, Timestamp>,
pub txindex_to_height: EagerVec<TxIndex, Height>,
pub txindex_to_last_inputindex: EagerVec<TxIndex, InputIndex>,
pub txindex_to_last_outputindex: EagerVec<TxIndex, OutputIndex>,
pub txindex_to_txindex: EagerVec<TxIndex, TxIndex>,
pub unknownoutputindex_to_unknownoutputindex: EagerVec<UnknownOutputIndex, UnknownOutputIndex>,
pub weekindex_to_first_dateindex: EagerVec<WeekIndex, DateIndex>,
pub weekindex_to_last_dateindex: EagerVec<WeekIndex, DateIndex>,
pub weekindex_to_timestamp: EagerVec<WeekIndex, Timestamp>,
pub weekindex_to_weekindex: EagerVec<WeekIndex, WeekIndex>,
pub yearindex_to_decadeindex: EagerVec<YearIndex, DecadeIndex>,
pub yearindex_to_first_monthindex: EagerVec<YearIndex, MonthIndex>,
pub yearindex_to_last_monthindex: EagerVec<YearIndex, MonthIndex>,
pub yearindex_to_timestamp: EagerVec<YearIndex, Timestamp>,
pub yearindex_to_yearindex: EagerVec<YearIndex, YearIndex>,
}
impl Vecs {
@@ -105,13 +105,13 @@ impl Vecs {
Version::ZERO,
compressed,
)?,
height_to_real_date: EagerVec::forced_import(
&path.join("height_to_real_date"),
height_to_date: EagerVec::forced_import(
&path.join("height_to_date"),
Version::ZERO,
compressed,
)?,
height_to_fixed_date: EagerVec::forced_import(
&path.join("height_to_fixed_date"),
height_to_date_fixed: EagerVec::forced_import(
&path.join("height_to_date_fixed"),
Version::ZERO,
compressed,
)?,
@@ -130,13 +130,18 @@ impl Vecs {
Version::ZERO,
compressed,
)?,
txindex_to_last_txinindex: EagerVec::forced_import(
&path.join("txindex_to_last_txinindex"),
txindex_to_height: EagerVec::forced_import(
&path.join("txindex_to_height"),
Version::ZERO,
compressed,
)?,
txindex_to_last_txoutindex: EagerVec::forced_import(
&path.join("txindex_to_last_txoutindex"),
txindex_to_last_inputindex: EagerVec::forced_import(
&path.join("txindex_to_last_inputindex"),
Version::ZERO,
compressed,
)?,
txindex_to_last_outputindex: EagerVec::forced_import(
&path.join("txindex_to_last_outputindex"),
Version::ZERO,
compressed,
)?,
@@ -295,8 +300,8 @@ impl Vecs {
Version::ZERO,
compressed,
)?,
height_to_fixed_timestamp: EagerVec::forced_import(
&path.join("height_to_fixed_timestamp"),
height_to_timestamp_fixed: EagerVec::forced_import(
&path.join("height_to_timestamp_fixed"),
Version::ZERO,
compressed,
)?,
@@ -365,18 +370,18 @@ impl Vecs {
Version::ZERO,
compressed,
)?,
txinindex_to_txinindex: EagerVec::forced_import(
&path.join("txinindex_to_txinindex"),
inputindex_to_inputindex: EagerVec::forced_import(
&path.join("inputindex_to_inputindex"),
Version::ZERO,
compressed,
)?,
emptyindex_to_emptyindex: EagerVec::forced_import(
&path.join("emptyindex_to_emptyindex"),
emptyoutputindex_to_emptyoutputindex: EagerVec::forced_import(
&path.join("emptyoutputindex_to_emptyoutputindex"),
Version::ZERO,
compressed,
)?,
multisigindex_to_multisigindex: EagerVec::forced_import(
&path.join("multisigindex_to_multisigindex"),
p2msindex_to_p2msindex: EagerVec::forced_import(
&path.join("p2msindex_to_p2msindex"),
Version::ZERO,
compressed,
)?,
@@ -385,23 +390,18 @@ impl Vecs {
Version::ZERO,
compressed,
)?,
pushonlyindex_to_pushonlyindex: EagerVec::forced_import(
&path.join("pushonlyindex_to_pushonlyindex"),
p2aindex_to_p2aindex: EagerVec::forced_import(
&path.join("p2aindex_to_p2aindex"),
Version::ZERO,
compressed,
)?,
unknownindex_to_unknownindex: EagerVec::forced_import(
&path.join("unknownindex_to_unknownindex"),
unknownoutputindex_to_unknownoutputindex: EagerVec::forced_import(
&path.join("unknownoutputindex_to_unknownoutputindex"),
Version::ZERO,
compressed,
)?,
addressindex_to_addressindex: EagerVec::forced_import(
&path.join("addressindex_to_addressindex"),
Version::ZERO,
compressed,
)?,
txoutindex_to_txoutindex: EagerVec::forced_import(
&path.join("txoutindex_to_txoutindex"),
outputindex_to_outputindex: EagerVec::forced_import(
&path.join("outputindex_to_outputindex"),
Version::ZERO,
compressed,
)?,
@@ -418,8 +418,8 @@ impl Vecs {
let height_count = indexer_vecs.height_to_total_size.len();
let txindexes_count = indexer_vecs.txindex_to_txid.len();
let txinindexes_count = indexer_vecs.txinindex_to_txoutindex.len();
let txoutindexes_count = indexer_vecs.txoutindex_to_addressindex.len();
let inputindexes_count = indexer_vecs.inputindex_to_outputindex.len();
let outputindexes_count = indexer_vecs.outputindex_to_value.len();
self.height_to_height.compute_range(
starting_indexes.height,
@@ -428,14 +428,14 @@ impl Vecs {
exit,
)?;
self.height_to_real_date.compute_transform(
self.height_to_date.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(),
|(h, t, ..)| (h, Date::from(t)),
exit,
)?;
self.height_to_fixed_timestamp.compute_transform(
self.height_to_timestamp_fixed.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(),
|(h, timestamp, s, ..)| {
@@ -448,9 +448,9 @@ impl Vecs {
exit,
)?;
self.height_to_fixed_date.compute_transform(
self.height_to_date_fixed.compute_transform(
starting_indexes.height,
self.height_to_fixed_timestamp.mut_vec(),
self.height_to_timestamp_fixed.mut_vec(),
|(h, t, ..)| (h, Date::from(t)),
exit,
)?;
@@ -464,8 +464,8 @@ impl Vecs {
self.height_to_dateindex.compute_transform(
starting_indexes.height,
self.height_to_fixed_date.mut_vec(),
|(h, d, ..)| (h, Dateindex::try_from(d).unwrap()),
self.height_to_date_fixed.mut_vec(),
|(h, d, ..)| (h, DateIndex::try_from(d).unwrap()),
exit,
)?;
@@ -516,19 +516,19 @@ impl Vecs {
exit,
)?;
self.txindex_to_last_txinindex
self.txindex_to_last_inputindex
.compute_last_index_from_first(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txinindex.mut_vec(),
txinindexes_count,
indexer_vecs.txindex_to_first_inputindex.mut_vec(),
inputindexes_count,
exit,
)?;
self.txindex_to_last_txoutindex
self.txindex_to_last_outputindex
.compute_last_index_from_first(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txoutindex.mut_vec(),
txoutindexes_count,
indexer_vecs.txindex_to_first_outputindex.mut_vec(),
outputindexes_count,
exit,
)?;
@@ -549,7 +549,7 @@ impl Vecs {
self.dateindex_to_weekindex.compute_range(
starting_dateindex,
self.dateindex_to_dateindex.mut_vec(),
|di| (di, Weekindex::from(di)),
|di| (di, WeekIndex::from(di)),
exit,
)?;
@@ -592,7 +592,7 @@ impl Vecs {
self.dateindex_to_monthindex.compute_range(
starting_dateindex,
self.dateindex_to_dateindex.mut_vec(),
|di| (di, Monthindex::from(di)),
|di| (di, MonthIndex::from(di)),
exit,
)?;
@@ -637,7 +637,7 @@ impl Vecs {
self.monthindex_to_quarterindex.compute_range(
starting_monthindex,
self.monthindex_to_monthindex.mut_vec(),
|mi| (mi, Quarterindex::from(mi)),
|mi| (mi, QuarterIndex::from(mi)),
exit,
)?;
@@ -682,7 +682,7 @@ impl Vecs {
self.monthindex_to_yearindex.compute_range(
starting_monthindex,
self.monthindex_to_monthindex.mut_vec(),
|i| (i, Yearindex::from(i)),
|i| (i, YearIndex::from(i)),
exit,
)?;
@@ -727,7 +727,7 @@ impl Vecs {
self.yearindex_to_decadeindex.compute_range(
starting_yearindex,
self.yearindex_to_yearindex.mut_vec(),
|i| (i, Decadeindex::from(i)),
|i| (i, DecadeIndex::from(i)),
exit,
)?;
@@ -770,7 +770,7 @@ impl Vecs {
self.height_to_difficultyepoch.compute_range(
starting_indexes.height,
self.height_to_height.mut_vec(),
|h| (h, Difficultyepoch::from(h)),
|h| (h, DifficultyEpoch::from(h)),
exit,
)?;
@@ -818,7 +818,7 @@ impl Vecs {
self.height_to_halvingepoch.compute_range(
starting_indexes.height,
self.height_to_height.mut_vec(),
|h| (h, Halvingepoch::from(h)),
|h| (h, HalvingEpoch::from(h)),
exit,
)?;
@@ -858,102 +858,97 @@ impl Vecs {
// ---
self.addressindex_to_addressindex.compute_range(
starting_indexes.addressindex,
indexer_vecs.addressindex_to_height.mut_vec(),
|i| (i, i),
exit,
)?;
self.txoutindex_to_txoutindex.compute_range(
starting_indexes.txoutindex,
indexer_vecs.txoutindex_to_height.mut_vec(),
self.outputindex_to_outputindex.compute_range(
starting_indexes.outputindex,
indexer_vecs.outputindex_to_value.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2pk33index_to_p2pk33index.compute_range(
starting_indexes.p2pk33index,
indexer_vecs.p2pk33index_to_height.mut_vec(),
indexer_vecs.p2pk33index_to_p2pk33bytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2pk65index_to_p2pk65index.compute_range(
starting_indexes.p2pk65index,
indexer_vecs.p2pk65index_to_height.mut_vec(),
indexer_vecs.p2pk65index_to_p2pk65bytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2pkhindex_to_p2pkhindex.compute_range(
starting_indexes.p2pkhindex,
indexer_vecs.p2pkhindex_to_height.mut_vec(),
indexer_vecs.p2pkhindex_to_p2pkhbytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2shindex_to_p2shindex.compute_range(
starting_indexes.p2shindex,
indexer_vecs.p2shindex_to_height.mut_vec(),
indexer_vecs.p2shindex_to_p2shbytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2trindex_to_p2trindex.compute_range(
starting_indexes.p2trindex,
indexer_vecs.p2trindex_to_height.mut_vec(),
indexer_vecs.p2trindex_to_p2trbytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2wpkhindex_to_p2wpkhindex.compute_range(
starting_indexes.p2wpkhindex,
indexer_vecs.p2wpkhindex_to_height.mut_vec(),
indexer_vecs.p2wpkhindex_to_p2wpkhbytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.p2wshindex_to_p2wshindex.compute_range(
starting_indexes.p2wshindex,
indexer_vecs.p2wshindex_to_height.mut_vec(),
indexer_vecs.p2wshindex_to_p2wshbytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.txindex_to_txindex.compute_range(
starting_indexes.txindex,
indexer_vecs.txindex_to_height.mut_vec(),
self.txindex_to_height.mut_vec(),
|i| (i, i),
exit,
)?;
self.txinindex_to_txinindex.compute_range(
starting_indexes.txinindex,
indexer_vecs.txinindex_to_height.mut_vec(),
self.inputindex_to_inputindex.compute_range(
starting_indexes.inputindex,
indexer_vecs.inputindex_to_outputindex.mut_vec(),
|i| (i, i),
exit,
)?;
self.emptyindex_to_emptyindex.compute_range(
starting_indexes.emptyindex,
indexer_vecs.emptyindex_to_height.mut_vec(),
self.emptyoutputindex_to_emptyoutputindex.compute_range(
starting_indexes.emptyoutputindex,
indexer_vecs.emptyoutputindex_to_txindex.mut_vec(),
|i| (i, i),
exit,
)?;
self.multisigindex_to_multisigindex.compute_range(
starting_indexes.multisigindex,
indexer_vecs.multisigindex_to_height.mut_vec(),
self.p2msindex_to_p2msindex.compute_range(
starting_indexes.p2msindex,
indexer_vecs.p2msindex_to_txindex.mut_vec(),
|i| (i, i),
exit,
)?;
self.opreturnindex_to_opreturnindex.compute_range(
starting_indexes.opreturnindex,
indexer_vecs.opreturnindex_to_height.mut_vec(),
indexer_vecs.opreturnindex_to_txindex.mut_vec(),
|i| (i, i),
exit,
)?;
self.pushonlyindex_to_pushonlyindex.compute_range(
starting_indexes.pushonlyindex,
indexer_vecs.pushonlyindex_to_height.mut_vec(),
|i| (i, i),
exit,
)?;
self.unknownindex_to_unknownindex.compute_range(
starting_indexes.unknownindex,
indexer_vecs.unknownindex_to_height.mut_vec(),
self.p2aindex_to_p2aindex.compute_range(
starting_indexes.p2aindex,
indexer_vecs.p2aindex_to_p2abytes.mut_vec(),
|i| (i, i),
exit,
)?;
self.unknownoutputindex_to_unknownoutputindex
.compute_range(
starting_indexes.unknownoutputindex,
indexer_vecs.unknownoutputindex_to_txindex.mut_vec(),
|i| (i, i),
exit,
)?;
Ok(Indexes {
indexes: starting_indexes,
@@ -975,12 +970,12 @@ impl Vecs {
self.dateindex_to_first_height.any_vec(),
self.dateindex_to_last_height.any_vec(),
self.height_to_dateindex.any_vec(),
self.height_to_fixed_date.any_vec(),
self.height_to_date_fixed.any_vec(),
self.height_to_height.any_vec(),
self.height_to_last_txindex.any_vec(),
self.height_to_real_date.any_vec(),
self.txindex_to_last_txinindex.any_vec(),
self.txindex_to_last_txoutindex.any_vec(),
self.height_to_date.any_vec(),
self.txindex_to_last_inputindex.any_vec(),
self.txindex_to_last_outputindex.any_vec(),
self.difficultyepoch_to_first_height.any_vec(),
self.difficultyepoch_to_last_height.any_vec(),
self.halvingepoch_to_first_height.any_vec(),
@@ -1012,7 +1007,7 @@ impl Vecs {
self.monthindex_to_timestamp.any_vec(),
self.weekindex_to_timestamp.any_vec(),
self.yearindex_to_timestamp.any_vec(),
self.height_to_fixed_timestamp.any_vec(),
self.height_to_timestamp_fixed.any_vec(),
self.monthindex_to_quarterindex.any_vec(),
self.quarterindex_to_first_monthindex.any_vec(),
self.quarterindex_to_last_monthindex.any_vec(),
@@ -1026,28 +1021,27 @@ impl Vecs {
self.p2wpkhindex_to_p2wpkhindex.any_vec(),
self.p2wshindex_to_p2wshindex.any_vec(),
self.txindex_to_txindex.any_vec(),
self.txinindex_to_txinindex.any_vec(),
self.emptyindex_to_emptyindex.any_vec(),
self.multisigindex_to_multisigindex.any_vec(),
self.inputindex_to_inputindex.any_vec(),
self.emptyoutputindex_to_emptyoutputindex.any_vec(),
self.p2msindex_to_p2msindex.any_vec(),
self.opreturnindex_to_opreturnindex.any_vec(),
self.pushonlyindex_to_pushonlyindex.any_vec(),
self.unknownindex_to_unknownindex.any_vec(),
self.addressindex_to_addressindex.any_vec(),
self.txoutindex_to_txoutindex.any_vec(),
self.p2aindex_to_p2aindex.any_vec(),
self.unknownoutputindex_to_unknownoutputindex.any_vec(),
self.outputindex_to_outputindex.any_vec(),
]
}
}
pub struct Indexes {
indexes: brk_indexer::Indexes,
pub dateindex: Dateindex,
pub weekindex: Weekindex,
pub monthindex: Monthindex,
pub quarterindex: Quarterindex,
pub yearindex: Yearindex,
pub decadeindex: Decadeindex,
pub difficultyepoch: Difficultyepoch,
pub halvingepoch: Halvingepoch,
pub dateindex: DateIndex,
pub weekindex: WeekIndex,
pub monthindex: MonthIndex,
pub quarterindex: QuarterIndex,
pub yearindex: YearIndex,
pub decadeindex: DecadeIndex,
pub difficultyepoch: DifficultyEpoch,
pub halvingepoch: HalvingEpoch,
}
impl Deref for Indexes {

View File

@@ -1,8 +1,8 @@
use std::{fs, path::Path};
use brk_core::{
Cents, Close, Dateindex, Decadeindex, Difficultyepoch, Dollars, Height, High, Low, Monthindex,
OHLCCents, OHLCDollars, OHLCSats, Open, Quarterindex, Sats, Weekindex, Yearindex,
Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex,
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
@@ -19,13 +19,13 @@ use super::{
#[derive(Clone)]
pub struct Vecs {
pub dateindex_to_close_in_cents: EagerVec<Dateindex, Close<Cents>>,
pub dateindex_to_high_in_cents: EagerVec<Dateindex, High<Cents>>,
pub dateindex_to_low_in_cents: EagerVec<Dateindex, Low<Cents>>,
pub dateindex_to_ohlc: EagerVec<Dateindex, OHLCDollars>,
pub dateindex_to_ohlc_in_sats: EagerVec<Dateindex, OHLCSats>,
pub dateindex_to_ohlc_in_cents: EagerVec<Dateindex, OHLCCents>,
pub dateindex_to_open_in_cents: EagerVec<Dateindex, Open<Cents>>,
pub dateindex_to_close_in_cents: EagerVec<DateIndex, Close<Cents>>,
pub dateindex_to_high_in_cents: EagerVec<DateIndex, High<Cents>>,
pub dateindex_to_low_in_cents: EagerVec<DateIndex, Low<Cents>>,
pub dateindex_to_ohlc: EagerVec<DateIndex, OHLCDollars>,
pub dateindex_to_ohlc_in_sats: EagerVec<DateIndex, OHLCSats>,
pub dateindex_to_ohlc_in_cents: EagerVec<DateIndex, OHLCCents>,
pub dateindex_to_open_in_cents: EagerVec<DateIndex, Open<Cents>>,
pub height_to_close_in_cents: EagerVec<Height, Close<Cents>>,
pub height_to_high_in_cents: EagerVec<Height, High<Cents>>,
pub height_to_low_in_cents: EagerVec<Height, Low<Cents>>,
@@ -49,20 +49,20 @@ pub struct Vecs {
pub chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict<High<Sats>>,
pub chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict<Low<Sats>>,
pub chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict<Close<Sats>>,
pub weekindex_to_ohlc: EagerVec<Weekindex, OHLCDollars>,
pub weekindex_to_ohlc_in_sats: EagerVec<Weekindex, OHLCSats>,
pub difficultyepoch_to_ohlc: EagerVec<Difficultyepoch, OHLCDollars>,
pub difficultyepoch_to_ohlc_in_sats: EagerVec<Difficultyepoch, OHLCSats>,
pub monthindex_to_ohlc: EagerVec<Monthindex, OHLCDollars>,
pub monthindex_to_ohlc_in_sats: EagerVec<Monthindex, OHLCSats>,
pub quarterindex_to_ohlc: EagerVec<Quarterindex, OHLCDollars>,
pub quarterindex_to_ohlc_in_sats: EagerVec<Quarterindex, OHLCSats>,
pub yearindex_to_ohlc: EagerVec<Yearindex, OHLCDollars>,
pub yearindex_to_ohlc_in_sats: EagerVec<Yearindex, OHLCSats>,
pub weekindex_to_ohlc: EagerVec<WeekIndex, OHLCDollars>,
pub weekindex_to_ohlc_in_sats: EagerVec<WeekIndex, OHLCSats>,
pub difficultyepoch_to_ohlc: EagerVec<DifficultyEpoch, OHLCDollars>,
pub difficultyepoch_to_ohlc_in_sats: EagerVec<DifficultyEpoch, OHLCSats>,
pub monthindex_to_ohlc: EagerVec<MonthIndex, OHLCDollars>,
pub monthindex_to_ohlc_in_sats: EagerVec<MonthIndex, OHLCSats>,
pub quarterindex_to_ohlc: EagerVec<QuarterIndex, OHLCDollars>,
pub quarterindex_to_ohlc_in_sats: EagerVec<QuarterIndex, OHLCSats>,
pub yearindex_to_ohlc: EagerVec<YearIndex, OHLCDollars>,
pub yearindex_to_ohlc_in_sats: EagerVec<YearIndex, OHLCSats>,
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
// pub halvingepoch_to_ohlc_in_sats: StorableVec<Halvingepoch, OHLCSats>,
pub decadeindex_to_ohlc: EagerVec<Decadeindex, OHLCDollars>,
pub decadeindex_to_ohlc_in_sats: EagerVec<Decadeindex, OHLCSats>,
pub decadeindex_to_ohlc: EagerVec<DecadeIndex, OHLCDollars>,
pub decadeindex_to_ohlc_in_sats: EagerVec<DecadeIndex, OHLCSats>,
}
const VERSION: Version = Version::ZERO;

View File

@@ -1,8 +1,8 @@
use std::{fs, path::Path};
use brk_core::{
CheckedSub, Feerate, Sats, StoredU32, StoredU64, StoredUsize, TxVersion, Txindex, Txinindex,
Txoutindex, Weight,
CheckedSub, Feerate, InputIndex, OutputIndex, Sats, StoredU32, StoredU64, StoredUsize, TxIndex,
TxVersion, Weight,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
@@ -34,12 +34,12 @@ pub struct Vecs {
pub indexes_to_tx_vsize: ComputedVecsFromTxindex<StoredUsize>,
pub indexes_to_tx_weight: ComputedVecsFromTxindex<Weight>,
pub txindex_to_input_count: ComputedVecsFromTxindex<StoredU64>,
pub txindex_to_is_coinbase: EagerVec<Txindex, bool>,
pub txindex_to_is_coinbase: EagerVec<TxIndex, bool>,
pub txindex_to_output_count: ComputedVecsFromTxindex<StoredU64>,
pub txindex_to_vsize: EagerVec<Txindex, StoredUsize>,
pub txindex_to_weight: EagerVec<Txindex, Weight>,
pub txindex_to_vsize: EagerVec<TxIndex, StoredUsize>,
pub txindex_to_weight: EagerVec<TxIndex, Weight>,
/// Value == 0 when Coinbase
pub txinindex_to_value: EagerVec<Txinindex, Sats>,
pub inputindex_to_value: EagerVec<InputIndex, Sats>,
pub indexes_to_subsidy: ComputedValueVecsFromHeight,
pub indexes_to_coinbase: ComputedValueVecsFromHeight,
}
@@ -98,8 +98,8 @@ impl Vecs {
.add_sum()
.add_total(),
)?,
txinindex_to_value: EagerVec::forced_import(
&path.join("txinindex_to_value"),
inputindex_to_value: EagerVec::forced_import(
&path.join("inputindex_to_value"),
Version::ZERO,
compressed,
)?,
@@ -268,8 +268,8 @@ impl Vecs {
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
indexer.mut_vecs().txindex_to_first_inputindex.mut_vec(),
indexes.txindex_to_last_inputindex.mut_vec(),
exit,
)
},
@@ -283,8 +283,8 @@ impl Vecs {
|v, indexer, indexes, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
indexer.mut_vecs().txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
indexer.mut_vecs().txindex_to_first_outputindex.mut_vec(),
indexes.txindex_to_last_outputindex.mut_vec(),
exit,
)
},
@@ -322,7 +322,7 @@ impl Vecs {
self.txindex_to_is_coinbase.compute_is_first_ordered(
starting_indexes.txindex,
indexer_vecs.txindex_to_height.mut_vec(),
indexes.txindex_to_height.mut_vec(),
indexer_vecs.height_to_first_txindex.mut_vec(),
exit,
)?;
@@ -337,7 +337,7 @@ impl Vecs {
.double_unwrap_cached_get(txindex);
// This is the exact definition of a weight unit, as defined by BIP-141 (quote above).
let wu = base_size * 3 + total_size;
let wu = usize::from(base_size) * 3 + usize::from(total_size);
let weight = Weight::from(bitcoin::Weight::from_wu_usize(wu));
(txindex, weight)
@@ -356,23 +356,23 @@ impl Vecs {
exit,
)?;
self.txinindex_to_value.compute_transform(
starting_indexes.txinindex,
indexer_vecs.txinindex_to_txoutindex.mut_vec(),
|(txinindex, txoutindex, slf, other)| {
let value = if txoutindex == Txoutindex::COINBASE {
self.inputindex_to_value.compute_transform(
starting_indexes.inputindex,
indexer_vecs.inputindex_to_outputindex.mut_vec(),
|(inputindex, outputindex, slf, other)| {
let value = if outputindex == OutputIndex::COINBASE {
Sats::ZERO
} else if let Some(value) = indexer_vecs
.txoutindex_to_value
.outputindex_to_value
.mut_vec()
.unwrap_cached_get(txoutindex)
.unwrap_cached_get(outputindex)
{
value
} else {
dbg!(txinindex, txoutindex, slf.len(), other.len());
dbg!(inputindex, outputindex, slf.len(), other.len());
panic!()
};
(txinindex, value)
(inputindex, value)
},
exit,
)?;
@@ -386,9 +386,9 @@ impl Vecs {
let indexer_vecs = indexer.mut_vecs();
vec.compute_sum_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txoutindex.mut_vec(),
indexes.txindex_to_last_txoutindex.mut_vec(),
indexer_vecs.txoutindex_to_value.mut_vec(),
indexer_vecs.txindex_to_first_outputindex.mut_vec(),
indexes.txindex_to_last_outputindex.mut_vec(),
indexer_vecs.outputindex_to_value.mut_vec(),
exit,
)
},
@@ -403,9 +403,9 @@ impl Vecs {
let indexer_vecs = indexer.mut_vecs();
vec.compute_sum_from_indexes(
starting_indexes.txindex,
indexer_vecs.txindex_to_first_txinindex.mut_vec(),
indexes.txindex_to_last_txinindex.mut_vec(),
self.txinindex_to_value.mut_vec(),
indexer_vecs.txindex_to_first_inputindex.mut_vec(),
indexes.txindex_to_last_inputindex.mut_vec(),
self.inputindex_to_value.mut_vec(),
exit,
)
},
@@ -495,20 +495,20 @@ impl Vecs {
starting_indexes.height,
indexer_vecs.height_to_first_txindex.mut_vec(),
|(height, txindex, ..)| {
let first_txoutindex = indexer_vecs
.txindex_to_first_txoutindex
let first_outputindex = indexer_vecs
.txindex_to_first_outputindex
.double_unwrap_cached_get(txindex)
.unwrap_to_usize();
let last_txoutindex = indexes
.txindex_to_last_txoutindex
let last_outputindex = indexes
.txindex_to_last_outputindex
.mut_vec()
.double_unwrap_cached_get(txindex)
.unwrap_to_usize();
let mut sats = Sats::ZERO;
(first_txoutindex..=last_txoutindex).for_each(|txoutindex| {
(first_outputindex..=last_outputindex).for_each(|outputindex| {
sats += indexer_vecs
.txoutindex_to_value
.double_unwrap_cached_get(Txoutindex::from(txoutindex));
.outputindex_to_value
.double_unwrap_cached_get(OutputIndex::from(outputindex));
});
(height, sats)
},
@@ -554,7 +554,7 @@ impl Vecs {
[
vec![
self.txindex_to_is_coinbase.any_vec(),
self.txinindex_to_value.any_vec(),
self.inputindex_to_value.any_vec(),
self.txindex_to_weight.any_vec(),
self.txindex_to_vsize.any_vec(),
],

View File

@@ -6,7 +6,7 @@ use std::{
path::{Path, PathBuf},
};
use brk_core::{Bitcoin, CheckedSub, Close, Dollars, Height, Sats, Txindex};
use brk_core::{Bitcoin, CheckedSub, Close, Dollars, Height, Sats, TxIndex};
use brk_exit::Exit;
use brk_vec::{
Compressed, DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, StoredVec, Version,
@@ -490,12 +490,12 @@ impl EagerVec<Height, Dollars> {
}
}
impl EagerVec<Txindex, Dollars> {
impl EagerVec<TxIndex, Dollars> {
pub fn compute_from_bitcoin(
&mut self,
max_from: Txindex,
bitcoin: &mut StoredVec<Txindex, Bitcoin>,
i_to_height: &mut StoredVec<Txindex, Height>,
max_from: TxIndex,
bitcoin: &mut StoredVec<TxIndex, Bitcoin>,
i_to_height: &mut StoredVec<TxIndex, Height>,
price: &mut StoredVec<Height, Close<Dollars>>,
exit: &Exit,
) -> Result<()> {
@@ -503,7 +503,7 @@ impl EagerVec<Txindex, Dollars> {
Version::ZERO + self.version() + bitcoin.version(),
)?;
let index = max_from.min(Txindex::from(self.len()));
let index = max_from.min(TxIndex::from(self.len()));
bitcoin.iter_from(index, |(i, bitcoin, ..)| {
let height = i_to_height.double_unwrap_cached_get(i);
let dollars = price.double_unwrap_cached_get(height);

View File

@@ -21,9 +21,9 @@ use crate::Error;
KnownLayout,
Serialize,
)]
pub struct Addressindex(u32);
pub struct AddressIndex(u32);
impl Addressindex {
impl AddressIndex {
pub const BYTES: usize = size_of::<Self>();
pub fn increment(&mut self) {
@@ -35,56 +35,56 @@ impl Addressindex {
}
}
impl From<u32> for Addressindex {
impl From<u32> for AddressIndex {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<u64> for Addressindex {
impl From<u64> for AddressIndex {
fn from(value: u64) -> Self {
Self(value as u32)
}
}
impl From<Addressindex> for u64 {
fn from(value: Addressindex) -> Self {
impl From<AddressIndex> for u64 {
fn from(value: AddressIndex) -> Self {
value.0 as u64
}
}
impl From<usize> for Addressindex {
impl From<usize> for AddressIndex {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl From<Addressindex> for usize {
fn from(value: Addressindex) -> Self {
impl From<AddressIndex> for usize {
fn from(value: AddressIndex) -> Self {
value.0 as usize
}
}
impl TryFrom<ByteView> for Addressindex {
impl TryFrom<ByteView> for AddressIndex {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<Addressindex> for ByteView {
fn from(value: Addressindex) -> Self {
impl From<AddressIndex> for ByteView {
fn from(value: AddressIndex) -> Self {
Self::new(value.as_bytes())
}
}
impl Add<usize> for Addressindex {
impl Add<usize> for AddressIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u32)
}
}
impl Add<Addressindex> for Addressindex {
impl Add<AddressIndex> for AddressIndex {
type Output = Self;
fn add(self, rhs: Addressindex) -> Self::Output {
fn add(self, rhs: AddressIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}

View File

@@ -0,0 +1,28 @@
use byteview::ByteView;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use super::{AddressIndex, Outputindex};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Immutable, IntoBytes, KnownLayout, FromBytes,
)]
#[repr(C)]
pub struct AddressIndexOutputIndex {
addressindex: AddressIndex,
_padding: u32,
outputindex: Outputindex,
}
impl TryFrom<ByteView> for AddressIndexOutputIndex {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<AddressIndexOutputIndex> for ByteView {
fn from(value: AddressIndexOutputIndex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,48 @@
use serde::Serialize;
use zerocopy::{Immutable, IntoBytes, KnownLayout, TryFromBytes};
use super::OutputType;
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
TryFromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
#[repr(u8)]
pub enum AddressType {
P2PK65,
P2PK33,
P2PKH,
P2SH,
P2WPKH,
P2WSH,
P2TR,
P2A,
}
impl From<OutputType> for AddressType {
fn from(value: OutputType) -> Self {
match value {
OutputType::P2A => Self::P2A,
OutputType::P2PK33 => Self::P2PK33,
OutputType::P2PK65 => Self::P2PK65,
OutputType::P2PKH => Self::P2PKH,
OutputType::P2SH => Self::P2SH,
OutputType::P2TR => Self::P2TR,
OutputType::P2WPKH => Self::P2WPKH,
OutputType::P2WSH => Self::P2WSH,
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
unreachable!()
}
}
}
}

View File

@@ -12,40 +12,42 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use super::Addresstype;
use super::OutputType;
#[derive(Debug, PartialEq, Eq)]
pub enum Addressbytes {
P2PK65(P2PK65AddressBytes),
P2PK33(P2PK33AddressBytes),
P2PKH(P2PKHAddressBytes),
P2SH(P2SHAddressBytes),
P2WPKH(P2WPKHAddressBytes),
P2WSH(P2WSHAddressBytes),
P2TR(P2TRAddressBytes),
pub enum AddressBytes {
P2PK65(P2PK65Bytes),
P2PK33(P2PK33Bytes),
P2PKH(P2PKHBytes),
P2SH(P2SHBytes),
P2WPKH(P2WPKHBytes),
P2WSH(P2WSHBytes),
P2TR(P2TRBytes),
P2A(P2ABytes),
}
impl Addressbytes {
impl AddressBytes {
pub fn as_slice(&self) -> &[u8] {
match self {
Addressbytes::P2PK65(bytes) => &bytes[..],
Addressbytes::P2PK33(bytes) => &bytes[..],
Addressbytes::P2PKH(bytes) => &bytes[..],
Addressbytes::P2SH(bytes) => &bytes[..],
Addressbytes::P2WPKH(bytes) => &bytes[..],
Addressbytes::P2WSH(bytes) => &bytes[..],
Addressbytes::P2TR(bytes) => &bytes[..],
AddressBytes::P2PK65(bytes) => &bytes[..],
AddressBytes::P2PK33(bytes) => &bytes[..],
AddressBytes::P2PKH(bytes) => &bytes[..],
AddressBytes::P2SH(bytes) => &bytes[..],
AddressBytes::P2WPKH(bytes) => &bytes[..],
AddressBytes::P2WSH(bytes) => &bytes[..],
AddressBytes::P2TR(bytes) => &bytes[..],
AddressBytes::P2A(bytes) => &bytes[..],
}
}
}
impl TryFrom<(&ScriptBuf, Addresstype)> for Addressbytes {
impl TryFrom<(&ScriptBuf, OutputType)> for AddressBytes {
type Error = Error;
fn try_from(tuple: (&ScriptBuf, Addresstype)) -> Result<Self, Self::Error> {
let (script, addresstype) = tuple;
fn try_from(tuple: (&ScriptBuf, OutputType)) -> Result<Self, Self::Error> {
let (script, outputtype) = tuple;
match addresstype {
Addresstype::P2PK65 => {
match outputtype {
OutputType::P2PK65 => {
let bytes = script.as_bytes();
let bytes = match bytes.len() {
67 => &bytes[1..66],
@@ -54,9 +56,9 @@ impl TryFrom<(&ScriptBuf, Addresstype)> for Addressbytes {
return Err(Error::WrongLength);
}
};
Ok(Self::P2PK65(P2PK65AddressBytes(U8x65::from(bytes))))
Ok(Self::P2PK65(P2PK65Bytes(U8x65::from(bytes))))
}
Addresstype::P2PK33 => {
OutputType::P2PK33 => {
let bytes = script.as_bytes();
let bytes = match bytes.len() {
35 => &bytes[1..34],
@@ -65,47 +67,50 @@ impl TryFrom<(&ScriptBuf, Addresstype)> for Addressbytes {
return Err(Error::WrongLength);
}
};
Ok(Self::P2PK33(P2PK33AddressBytes(U8x33::from(bytes))))
Ok(Self::P2PK33(P2PK33Bytes(U8x33::from(bytes))))
}
Addresstype::P2PKH => {
OutputType::P2PKH => {
let bytes = &script.as_bytes()[3..23];
Ok(Self::P2PKH(P2PKHAddressBytes(U8x20::from(bytes))))
Ok(Self::P2PKH(P2PKHBytes(U8x20::from(bytes))))
}
Addresstype::P2SH => {
OutputType::P2SH => {
let bytes = &script.as_bytes()[2..22];
Ok(Self::P2SH(P2SHAddressBytes(U8x20::from(bytes))))
Ok(Self::P2SH(P2SHBytes(U8x20::from(bytes))))
}
Addresstype::P2WPKH => {
OutputType::P2WPKH => {
let bytes = &script.as_bytes()[2..];
Ok(Self::P2WPKH(P2WPKHAddressBytes(U8x20::from(bytes))))
Ok(Self::P2WPKH(P2WPKHBytes(U8x20::from(bytes))))
}
Addresstype::P2WSH => {
OutputType::P2WSH => {
let bytes = &script.as_bytes()[2..];
Ok(Self::P2WSH(P2WSHAddressBytes(U8x32::from(bytes))))
Ok(Self::P2WSH(P2WSHBytes(U8x32::from(bytes))))
}
Addresstype::P2TR => {
OutputType::P2TR => {
let bytes = &script.as_bytes()[2..];
Ok(Self::P2TR(P2TRAddressBytes(U8x32::from(bytes))))
Ok(Self::P2TR(P2TRBytes(U8x32::from(bytes))))
}
Addresstype::Multisig => Err(Error::WrongAddressType),
Addresstype::PushOnly => Err(Error::WrongAddressType),
Addresstype::Unknown => Err(Error::WrongAddressType),
Addresstype::Empty => Err(Error::WrongAddressType),
Addresstype::OpReturn => Err(Error::WrongAddressType),
OutputType::P2A => {
let bytes = &script.as_bytes()[2..];
Ok(Self::P2A(P2ABytes(U8x2::from(bytes))))
}
OutputType::P2MS => Err(Error::WrongAddressType),
OutputType::Unknown => Err(Error::WrongAddressType),
OutputType::Empty => Err(Error::WrongAddressType),
OutputType::OpReturn => Err(Error::WrongAddressType),
}
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2PK65AddressBytes(U8x65);
pub struct P2PK65Bytes(U8x65);
impl fmt::Display for P2PK65AddressBytes {
impl fmt::Display for P2PK65Bytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_hex_string(Case::Lower))
}
}
impl Serialize for P2PK65AddressBytes {
impl Serialize for P2PK65Bytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -114,22 +119,22 @@ impl Serialize for P2PK65AddressBytes {
}
}
impl From<P2PK65AddressBytes> for Addressbytes {
fn from(value: P2PK65AddressBytes) -> Self {
impl From<P2PK65Bytes> for AddressBytes {
fn from(value: P2PK65Bytes) -> Self {
Self::P2PK65(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2PK33AddressBytes(U8x33);
pub struct P2PK33Bytes(U8x33);
impl fmt::Display for P2PK33AddressBytes {
impl fmt::Display for P2PK33Bytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_hex_string(Case::Lower))
}
}
impl Serialize for P2PK33AddressBytes {
impl Serialize for P2PK33Bytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -138,16 +143,16 @@ impl Serialize for P2PK33AddressBytes {
}
}
impl From<P2PK33AddressBytes> for Addressbytes {
fn from(value: P2PK33AddressBytes) -> Self {
impl From<P2PK33Bytes> for AddressBytes {
fn from(value: P2PK33Bytes) -> Self {
Self::P2PK33(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2PKHAddressBytes(U8x20);
pub struct P2PKHBytes(U8x20);
impl fmt::Display for P2PKHAddressBytes {
impl fmt::Display for P2PKHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new()
.push_opcode(opcodes::all::OP_DUP)
@@ -161,7 +166,7 @@ impl fmt::Display for P2PKHAddressBytes {
}
}
impl Serialize for P2PKHAddressBytes {
impl Serialize for P2PKHBytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -170,16 +175,16 @@ impl Serialize for P2PKHAddressBytes {
}
}
impl From<P2PKHAddressBytes> for Addressbytes {
fn from(value: P2PKHAddressBytes) -> Self {
impl From<P2PKHBytes> for AddressBytes {
fn from(value: P2PKHBytes) -> Self {
Self::P2PKH(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2SHAddressBytes(U8x20);
pub struct P2SHBytes(U8x20);
impl fmt::Display for P2SHAddressBytes {
impl fmt::Display for P2SHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new()
.push_opcode(opcodes::all::OP_HASH160)
@@ -191,7 +196,7 @@ impl fmt::Display for P2SHAddressBytes {
}
}
impl Serialize for P2SHAddressBytes {
impl Serialize for P2SHBytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -200,16 +205,16 @@ impl Serialize for P2SHAddressBytes {
}
}
impl From<P2SHAddressBytes> for Addressbytes {
fn from(value: P2SHAddressBytes) -> Self {
impl From<P2SHBytes> for AddressBytes {
fn from(value: P2SHBytes) -> Self {
Self::P2SH(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2WPKHAddressBytes(U8x20);
pub struct P2WPKHBytes(U8x20);
impl fmt::Display for P2WPKHAddressBytes {
impl fmt::Display for P2WPKHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(0).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
@@ -217,7 +222,7 @@ impl fmt::Display for P2WPKHAddressBytes {
}
}
impl Serialize for P2WPKHAddressBytes {
impl Serialize for P2WPKHBytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -226,16 +231,16 @@ impl Serialize for P2WPKHAddressBytes {
}
}
impl From<P2WPKHAddressBytes> for Addressbytes {
fn from(value: P2WPKHAddressBytes) -> Self {
impl From<P2WPKHBytes> for AddressBytes {
fn from(value: P2WPKHBytes) -> Self {
Self::P2WPKH(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2WSHAddressBytes(U8x32);
pub struct P2WSHBytes(U8x32);
impl fmt::Display for P2WSHAddressBytes {
impl fmt::Display for P2WSHBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(0).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
@@ -243,7 +248,7 @@ impl fmt::Display for P2WSHAddressBytes {
}
}
impl Serialize for P2WSHAddressBytes {
impl Serialize for P2WSHBytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -252,16 +257,16 @@ impl Serialize for P2WSHAddressBytes {
}
}
impl From<P2WSHAddressBytes> for Addressbytes {
fn from(value: P2WSHAddressBytes) -> Self {
impl From<P2WSHBytes> for AddressBytes {
fn from(value: P2WSHBytes) -> Self {
Self::P2WSH(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2TRAddressBytes(U8x32);
pub struct P2TRBytes(U8x32);
impl fmt::Display for P2TRAddressBytes {
impl fmt::Display for P2TRBytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(1).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
@@ -269,7 +274,7 @@ impl fmt::Display for P2TRAddressBytes {
}
}
impl Serialize for P2TRAddressBytes {
impl Serialize for P2TRBytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@@ -278,12 +283,60 @@ impl Serialize for P2TRAddressBytes {
}
}
impl From<P2TRAddressBytes> for Addressbytes {
fn from(value: P2TRAddressBytes) -> Self {
impl From<P2TRBytes> for AddressBytes {
fn from(value: P2TRBytes) -> Self {
Self::P2TR(value)
}
}
#[derive(Debug, Clone, Deref, PartialEq, Eq, Immutable, IntoBytes, KnownLayout, FromBytes)]
pub struct P2ABytes(U8x2);
impl fmt::Display for P2ABytes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let script = Builder::new().push_int(1).push_slice(*self.0).into_script();
let address = Address::from_script(&script, Network::Bitcoin).unwrap();
write!(f, "{}", address)
}
}
impl Serialize for P2ABytes {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(&self.to_string())
}
}
impl From<P2ABytes> for AddressBytes {
fn from(value: P2ABytes) -> Self {
Self::P2A(value)
}
}
#[derive(
Debug,
Clone,
Deref,
DerefMut,
PartialEq,
Eq,
Immutable,
IntoBytes,
KnownLayout,
FromBytes,
Serialize,
)]
pub struct U8x2([u8; 2]);
impl From<&[u8]> for U8x2 {
fn from(slice: &[u8]) -> Self {
let mut arr = [0; 2];
arr.copy_from_slice(slice);
Self(arr)
}
}
#[derive(
Debug,
Clone,

View File

@@ -0,0 +1,60 @@
use std::hash::Hasher;
use byteview::ByteView;
use derive_deref::Deref;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use super::{AddressBytes, OutputType};
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct AddressBytesHash([u8; 8]);
impl From<(&AddressBytes, OutputType)> for AddressBytesHash {
fn from((address_bytes, outputtype): (&AddressBytes, OutputType)) -> Self {
let mut hasher = rapidhash::RapidHasher::default();
hasher.write(address_bytes.as_slice());
let mut slice = hasher.finish().to_le_bytes();
slice[0] = slice[0].wrapping_add(outputtype as u8);
Self(slice)
}
}
impl From<[u8; 8]> for AddressBytesHash {
fn from(value: [u8; 8]) -> Self {
Self(value)
}
}
impl TryFrom<ByteView> for AddressBytesHash {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&AddressBytesHash> for ByteView {
fn from(value: &AddressBytesHash) -> Self {
Self::new(value.as_bytes())
}
}
impl From<AddressBytesHash> for ByteView {
fn from(value: AddressBytesHash) -> Self {
Self::from(&value)
}
}

View File

@@ -1,26 +0,0 @@
use byteview::ByteView;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use super::{Addressindex, Txoutindex};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Immutable, IntoBytes, KnownLayout, FromBytes)]
#[repr(C)]
pub struct AddressindexTxoutindex {
addressindex: Addressindex,
_padding: u32,
txoutindex: Txoutindex,
}
impl TryFrom<ByteView> for AddressindexTxoutindex {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<AddressindexTxoutindex> for ByteView {
fn from(value: AddressindexTxoutindex) -> Self {
Self::new(value.as_bytes())
}
}

View File

@@ -0,0 +1,54 @@
use byteview::ByteView;
use derive_deref::Deref;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{Error, copy_first_8bytes};
use super::BlockHash;
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct BlockHashPrefix([u8; 8]);
impl From<BlockHash> for BlockHashPrefix {
fn from(value: BlockHash) -> Self {
Self::from(&value)
}
}
impl From<&BlockHash> for BlockHashPrefix {
fn from(value: &BlockHash) -> Self {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<ByteView> for BlockHashPrefix {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&BlockHashPrefix> for ByteView {
fn from(value: &BlockHashPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<BlockHashPrefix> for ByteView {
fn from(value: BlockHashPrefix) -> Self {
Self::from(&value)
}
}

View File

@@ -1,156 +0,0 @@
use std::hash::Hasher;
use byteview::ByteView;
use derive_deref::Deref;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
use super::{Addressbytes, Addresstype, BlockHash, Txid};
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct AddressHash([u8; 8]);
impl From<(&Addressbytes, Addresstype)> for AddressHash {
fn from((addressbytes, addresstype): (&Addressbytes, Addresstype)) -> Self {
let mut hasher = rapidhash::RapidHasher::default();
hasher.write(addressbytes.as_slice());
let mut slice = hasher.finish().to_le_bytes();
slice[0] = slice[0].wrapping_add(addresstype as u8);
Self(slice)
}
}
impl From<[u8; 8]> for AddressHash {
fn from(value: [u8; 8]) -> Self {
Self(value)
}
}
impl TryFrom<ByteView> for AddressHash {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&AddressHash> for ByteView {
fn from(value: &AddressHash) -> Self {
Self::new(value.as_bytes())
}
}
impl From<AddressHash> for ByteView {
fn from(value: AddressHash) -> Self {
Self::from(&value)
}
}
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct BlockHashPrefix([u8; 8]);
impl From<BlockHash> for BlockHashPrefix {
fn from(value: BlockHash) -> Self {
Self::from(&value)
}
}
impl From<&BlockHash> for BlockHashPrefix {
fn from(value: &BlockHash) -> Self {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<ByteView> for BlockHashPrefix {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&BlockHashPrefix> for ByteView {
fn from(value: &BlockHashPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<BlockHashPrefix> for ByteView {
fn from(value: BlockHashPrefix) -> Self {
Self::from(&value)
}
}
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct TxidPrefix([u8; 8]);
impl From<Txid> for TxidPrefix {
fn from(value: Txid) -> Self {
Self::from(&value)
}
}
impl From<&Txid> for TxidPrefix {
fn from(value: &Txid) -> Self {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<ByteView> for TxidPrefix {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&TxidPrefix> for ByteView {
fn from(value: &TxidPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<TxidPrefix> for ByteView {
fn from(value: TxidPrefix) -> Self {
Self::from(&value)
}
}
impl From<[u8; 8]> for TxidPrefix {
fn from(value: [u8; 8]) -> Self {
Self(value)
}
}
fn copy_first_8bytes(slice: &[u8]) -> Result<[u8; 8], ()> {
let mut buf: [u8; 8] = [0; 8];
let buf_len = buf.len();
if slice.len() < buf_len {
return Err(());
}
slice.iter().take(buf_len).enumerate().for_each(|(i, r)| {
buf[i] = *r;
});
Ok(buf)
}

View File

@@ -2,7 +2,7 @@ use jiff::{Span, civil::Date as Date_, tz::TimeZone};
use serde::{Serialize, Serializer};
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::{Dateindex, Timestamp};
use super::{DateIndex, Timestamp};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, FromBytes, Immutable, IntoBytes, KnownLayout,
@@ -58,9 +58,9 @@ impl From<Timestamp> for Date {
}
}
impl From<Dateindex> for Date {
fn from(value: Dateindex) -> Self {
if value == Dateindex::default() {
impl From<DateIndex> for Date {
fn from(value: DateIndex) -> Self {
if value == DateIndex::default() {
Date::INDEX_ZERO
} else {
Self::from(

View File

@@ -23,38 +23,38 @@ use super::Date;
KnownLayout,
Serialize,
)]
pub struct Dateindex(u16);
pub struct DateIndex(u16);
impl Dateindex {
impl DateIndex {
pub const BYTES: usize = size_of::<Self>();
}
impl From<Dateindex> for usize {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for usize {
fn from(value: DateIndex) -> Self {
value.0 as usize
}
}
impl From<usize> for Dateindex {
impl From<usize> for DateIndex {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<Dateindex> for i64 {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for i64 {
fn from(value: DateIndex) -> Self {
value.0 as i64
}
}
impl Add<usize> for Dateindex {
impl Add<usize> for DateIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u16)
}
}
impl TryFrom<Date> for Dateindex {
impl TryFrom<Date> for DateIndex {
type Error = Error;
fn try_from(value: Date) -> Result<Self, Self::Error> {
let value_ = jiff::civil::Date::from(value);
@@ -72,7 +72,7 @@ impl TryFrom<Date> for Dateindex {
}
}
impl CheckedSub for Dateindex {
impl CheckedSub for DateIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -5,7 +5,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Date, Dateindex, Yearindex};
use super::{Date, DateIndex, YearIndex};
#[derive(
Debug,
@@ -23,27 +23,27 @@ use super::{Date, Dateindex, Yearindex};
IntoBytes,
KnownLayout,
)]
pub struct Decadeindex(u8);
pub struct DecadeIndex(u8);
impl From<u8> for Decadeindex {
impl From<u8> for DecadeIndex {
fn from(value: u8) -> Self {
Self(value)
}
}
impl From<usize> for Decadeindex {
impl From<usize> for DecadeIndex {
fn from(value: usize) -> Self {
Self(value as u8)
}
}
impl From<Decadeindex> for usize {
fn from(value: Decadeindex) -> Self {
impl From<DecadeIndex> for usize {
fn from(value: DecadeIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Decadeindex {
impl Add<usize> for DecadeIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,13 +51,13 @@ impl Add<usize> for Decadeindex {
}
}
impl From<Dateindex> for Decadeindex {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for DecadeIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
}
}
impl From<Date> for Decadeindex {
impl From<Date> for DecadeIndex {
fn from(value: Date) -> Self {
let year = value.year();
if year < 2000 {
@@ -67,14 +67,14 @@ impl From<Date> for Decadeindex {
}
}
impl CheckedSub for Decadeindex {
impl CheckedSub for DecadeIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl From<Yearindex> for Decadeindex {
fn from(value: Yearindex) -> Self {
impl From<YearIndex> for DecadeIndex {
fn from(value: YearIndex) -> Self {
let v = usize::from(value);
if v == 0 {
Self(0)

View File

@@ -23,27 +23,27 @@ use super::Height;
IntoBytes,
KnownLayout,
)]
pub struct Difficultyepoch(u16);
pub struct DifficultyEpoch(u16);
impl From<u16> for Difficultyepoch {
impl From<u16> for DifficultyEpoch {
fn from(value: u16) -> Self {
Self(value)
}
}
impl From<usize> for Difficultyepoch {
impl From<usize> for DifficultyEpoch {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<Difficultyepoch> for usize {
fn from(value: Difficultyepoch) -> Self {
impl From<DifficultyEpoch> for usize {
fn from(value: DifficultyEpoch) -> Self {
value.0 as usize
}
}
impl Add<usize> for Difficultyepoch {
impl Add<usize> for DifficultyEpoch {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,13 +51,13 @@ impl Add<usize> for Difficultyepoch {
}
}
impl From<Height> for Difficultyepoch {
impl From<Height> for DifficultyEpoch {
fn from(value: Height) -> Self {
Self((u32::from(value) / 2016) as u16)
}
}
impl CheckedSub for Difficultyepoch {
impl CheckedSub for DifficultyEpoch {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -23,27 +23,27 @@ use super::Height;
IntoBytes,
KnownLayout,
)]
pub struct Halvingepoch(u8);
pub struct HalvingEpoch(u8);
impl From<u8> for Halvingepoch {
impl From<u8> for HalvingEpoch {
fn from(value: u8) -> Self {
Self(value)
}
}
impl From<usize> for Halvingepoch {
impl From<usize> for HalvingEpoch {
fn from(value: usize) -> Self {
Self(value as u8)
}
}
impl From<Halvingepoch> for usize {
fn from(value: Halvingepoch) -> Self {
impl From<HalvingEpoch> for usize {
fn from(value: HalvingEpoch) -> Self {
value.0 as usize
}
}
impl Add<usize> for Halvingepoch {
impl Add<usize> for HalvingEpoch {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,13 +51,13 @@ impl Add<usize> for Halvingepoch {
}
}
impl From<Height> for Halvingepoch {
impl From<Height> for HalvingEpoch {
fn from(value: Height) -> Self {
Self((u32::from(value) / 210_000) as u8)
}
}
impl CheckedSub for Halvingepoch {
impl CheckedSub for HalvingEpoch {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -25,49 +25,49 @@ use super::Vin;
KnownLayout,
Serialize,
)]
pub struct Txinindex(u64);
pub struct InputIndex(u64);
impl Txinindex {
impl InputIndex {
pub fn incremented(self) -> Self {
Self(*self + 1)
}
}
impl Add<Txinindex> for Txinindex {
impl Add<InputIndex> for InputIndex {
type Output = Self;
fn add(self, rhs: Txinindex) -> Self::Output {
fn add(self, rhs: InputIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Add<Vin> for Txinindex {
impl Add<Vin> for InputIndex {
type Output = Self;
fn add(self, rhs: Vin) -> Self::Output {
Self(self.0 + u64::from(rhs))
}
}
impl Add<usize> for Txinindex {
impl Add<usize> for InputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u64)
}
}
impl AddAssign<Txinindex> for Txinindex {
fn add_assign(&mut self, rhs: Txinindex) {
impl AddAssign<InputIndex> for InputIndex {
fn add_assign(&mut self, rhs: InputIndex) {
self.0 += rhs.0
}
}
impl CheckedSub<Txinindex> for Txinindex {
impl CheckedSub<InputIndex> for InputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self::from)
}
}
impl From<Txinindex> for u32 {
fn from(value: Txinindex) -> Self {
impl From<InputIndex> for u32 {
fn from(value: InputIndex) -> Self {
if value.0 > u32::MAX as u64 {
panic!()
}
@@ -75,24 +75,24 @@ impl From<Txinindex> for u32 {
}
}
impl From<u64> for Txinindex {
impl From<u64> for InputIndex {
fn from(value: u64) -> Self {
Self(value)
}
}
impl From<Txinindex> for u64 {
fn from(value: Txinindex) -> Self {
impl From<InputIndex> for u64 {
fn from(value: InputIndex) -> Self {
value.0
}
}
impl From<usize> for Txinindex {
impl From<usize> for InputIndex {
fn from(value: usize) -> Self {
Self(value as u64)
}
}
impl From<Txinindex> for usize {
fn from(value: Txinindex) -> Self {
impl From<InputIndex> for usize {
fn from(value: InputIndex) -> Self {
value.0 as usize
}
}

View File

@@ -1,12 +1,12 @@
mod addressbytes;
mod addressindex;
mod addressindextxoutindex;
mod addresstype;
mod addresstypeindex;
mod addressbyteshash;
// mod addressindex;
// mod addressindexoutputindex;
// mod addresstype;
mod bitcoin;
mod blockhash;
mod blockhashprefix;
mod cents;
mod compressed;
mod date;
mod dateindex;
mod decadeindex;
@@ -15,8 +15,12 @@ mod dollars;
mod feerate;
mod halvingepoch;
mod height;
mod inputindex;
mod monthindex;
mod ohlc;
mod outputindex;
mod outputtype;
mod outputtypeindex;
mod quarterindex;
mod rawlocktime;
mod sats;
@@ -26,9 +30,8 @@ mod stored_u8;
mod stored_usize;
mod timestamp;
mod txid;
mod txidprefix;
mod txindex;
mod txinindex;
mod txoutindex;
mod txversion;
mod unit;
mod vin;
@@ -38,14 +41,14 @@ mod weight;
mod yearindex;
pub use addressbytes::*;
pub use addressindex::*;
pub use addressindextxoutindex::*;
pub use addresstype::*;
pub use addresstypeindex::*;
pub use addressbyteshash::*;
// pub use addressindex::*;
// pub use addressindexoutputindex::*;
// pub use addresstype::*;
pub use bitcoin::*;
pub use blockhash::*;
pub use blockhashprefix::*;
pub use cents::*;
pub use compressed::*;
pub use date::*;
pub use dateindex::*;
pub use decadeindex::*;
@@ -54,8 +57,12 @@ pub use dollars::*;
pub use feerate::*;
pub use halvingepoch::*;
pub use height::*;
pub use inputindex::*;
pub use monthindex::*;
pub use ohlc::*;
pub use outputindex::*;
pub use outputtype::*;
pub use outputtypeindex::*;
pub use quarterindex::*;
pub use rawlocktime::*;
pub use sats::*;
@@ -65,9 +72,8 @@ pub use stored_u64::*;
pub use stored_usize::*;
pub use timestamp::*;
pub use txid::*;
pub use txidprefix::*;
pub use txindex::*;
pub use txinindex::*;
pub use txoutindex::*;
pub use txversion::*;
pub use unit::*;
pub use vin::*;

View File

@@ -5,7 +5,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Date, Dateindex, Yearindex};
use super::{Date, DateIndex, YearIndex};
#[derive(
Debug,
@@ -23,27 +23,27 @@ use super::{Date, Dateindex, Yearindex};
IntoBytes,
KnownLayout,
)]
pub struct Monthindex(u16);
pub struct MonthIndex(u16);
impl From<u16> for Monthindex {
impl From<u16> for MonthIndex {
fn from(value: u16) -> Self {
Self(value)
}
}
impl From<usize> for Monthindex {
impl From<usize> for MonthIndex {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<Monthindex> for usize {
fn from(value: Monthindex) -> Self {
impl From<MonthIndex> for usize {
fn from(value: MonthIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Monthindex {
impl Add<usize> for MonthIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,19 +51,19 @@ impl Add<usize> for Monthindex {
}
}
impl From<Dateindex> for Monthindex {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for MonthIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
}
}
impl From<Date> for Monthindex {
impl From<Date> for MonthIndex {
fn from(value: Date) -> Self {
Self(u16::from(Yearindex::from(value)) * 12 + value.month() as u16 - 1)
Self(u16::from(YearIndex::from(value)) * 12 + value.month() as u16 - 1)
}
}
impl CheckedSub for Monthindex {
impl CheckedSub for MonthIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -25,9 +25,9 @@ use super::Vout;
KnownLayout,
Serialize,
)]
pub struct Txoutindex(u64);
pub struct OutputIndex(u64);
impl Txoutindex {
impl OutputIndex {
pub const COINBASE: Self = Self(u64::MAX);
pub fn incremented(self) -> Self {
@@ -39,41 +39,41 @@ impl Txoutindex {
}
}
impl Add<Txoutindex> for Txoutindex {
impl Add<OutputIndex> for OutputIndex {
type Output = Self;
fn add(self, rhs: Txoutindex) -> Self::Output {
fn add(self, rhs: OutputIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Add<Vout> for Txoutindex {
impl Add<Vout> for OutputIndex {
type Output = Self;
fn add(self, rhs: Vout) -> Self::Output {
Self(self.0 + u64::from(rhs))
}
}
impl Add<usize> for Txoutindex {
impl Add<usize> for OutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u64)
}
}
impl AddAssign<Txoutindex> for Txoutindex {
fn add_assign(&mut self, rhs: Txoutindex) {
impl AddAssign<OutputIndex> for OutputIndex {
fn add_assign(&mut self, rhs: OutputIndex) {
self.0 += rhs.0
}
}
impl CheckedSub<Txoutindex> for Txoutindex {
impl CheckedSub<OutputIndex> for OutputIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self::from)
}
}
impl From<Txoutindex> for u32 {
fn from(value: Txoutindex) -> Self {
impl From<OutputIndex> for u32 {
fn from(value: OutputIndex) -> Self {
if value.0 > u32::MAX as u64 {
panic!()
}
@@ -81,24 +81,24 @@ impl From<Txoutindex> for u32 {
}
}
impl From<u64> for Txoutindex {
impl From<u64> for OutputIndex {
fn from(value: u64) -> Self {
Self(value)
}
}
impl From<Txoutindex> for u64 {
fn from(value: Txoutindex) -> Self {
impl From<OutputIndex> for u64 {
fn from(value: OutputIndex) -> Self {
value.0
}
}
impl From<usize> for Txoutindex {
impl From<usize> for OutputIndex {
fn from(value: usize) -> Self {
Self(value as u64)
}
}
impl From<Txoutindex> for usize {
fn from(value: Txoutindex) -> Self {
impl From<OutputIndex> for usize {
fn from(value: OutputIndex) -> Self {
value.0 as usize
}
}

View File

@@ -1,27 +1,38 @@
use bitcoin::ScriptBuf;
use bitcoin::{ScriptBuf, opcodes::all::OP_PUSHBYTES_2};
use serde::Serialize;
use zerocopy::{Immutable, IntoBytes, KnownLayout, TryFromBytes};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, TryFromBytes, Immutable, IntoBytes, KnownLayout, Serialize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
TryFromBytes,
Immutable,
IntoBytes,
KnownLayout,
Serialize,
)]
#[repr(u8)]
pub enum Addresstype {
pub enum OutputType {
P2PK65,
P2PK33,
P2PKH,
P2MS,
P2SH,
OpReturn,
P2WPKH,
P2WSH,
P2TR,
Multisig = 251,
PushOnly = 252,
OpReturn = 253,
P2A,
Empty = 254,
Unknown = 255,
}
impl From<&ScriptBuf> for Addresstype {
impl From<&ScriptBuf> for OutputType {
fn from(script: &ScriptBuf) -> Self {
if script.is_p2pk() {
let bytes = script.as_bytes();
@@ -36,22 +47,26 @@ impl From<&ScriptBuf> for Addresstype {
}
} else if script.is_p2pkh() {
Self::P2PKH
} else if script.is_multisig() {
Self::P2MS
} else if script.is_p2sh() {
Self::P2SH
} else if script.is_op_return() {
Self::OpReturn
} else if script.is_p2wpkh() {
Self::P2WPKH
} else if script.is_p2wsh() {
Self::P2WSH
} else if script.is_p2tr() {
Self::P2TR
} else if script.witness_version() == Some(bitcoin::WitnessVersion::V1)
&& script.len() == 4
&& script.as_bytes()[1] == OP_PUSHBYTES_2.to_u8()
&& script.as_bytes()[2..4] == [78, 115]
{
Self::P2A
} else if script.is_empty() {
Self::Empty
} else if script.is_op_return() {
Self::OpReturn
} else if script.is_push_only() {
Self::PushOnly
} else if script.is_multisig() {
Self::Multisig
} else {
Self::Unknown
}

View File

@@ -1,9 +1,12 @@
use std::ops::Add;
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::Error;
#[derive(
Debug,
PartialEq,
@@ -19,9 +22,9 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
KnownLayout,
Serialize,
)]
pub struct Addresstypeindex(u32);
pub struct OutputTypeIndex(u32);
impl Addresstypeindex {
impl OutputTypeIndex {
pub fn increment(&mut self) {
self.0 += 1;
}
@@ -37,47 +40,58 @@ impl Addresstypeindex {
}
}
impl From<u32> for Addresstypeindex {
impl From<u32> for OutputTypeIndex {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<u64> for Addresstypeindex {
impl From<u64> for OutputTypeIndex {
fn from(value: u64) -> Self {
Self(value as u32)
}
}
impl From<Addresstypeindex> for u64 {
fn from(value: Addresstypeindex) -> Self {
impl From<OutputTypeIndex> for u64 {
fn from(value: OutputTypeIndex) -> Self {
value.0 as u64
}
}
impl From<usize> for Addresstypeindex {
impl From<usize> for OutputTypeIndex {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl From<Addresstypeindex> for usize {
fn from(value: Addresstypeindex) -> Self {
impl From<OutputTypeIndex> for usize {
fn from(value: OutputTypeIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Addresstypeindex {
impl Add<usize> for OutputTypeIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u32)
}
}
impl Add<Addresstypeindex> for Addresstypeindex {
impl Add<OutputTypeIndex> for OutputTypeIndex {
type Output = Self;
fn add(self, rhs: Addresstypeindex) -> Self::Output {
fn add(self, rhs: OutputTypeIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl TryFrom<ByteView> for OutputTypeIndex {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<OutputTypeIndex> for ByteView {
fn from(value: OutputTypeIndex) -> Self {
Self::new(value.as_bytes())
}
}
#[derive(
Debug,
@@ -96,23 +110,23 @@ impl Add<Addresstypeindex> for Addresstypeindex {
KnownLayout,
Serialize,
)]
pub struct Emptyindex(Addresstypeindex);
impl From<Addresstypeindex> for Emptyindex {
fn from(value: Addresstypeindex) -> Self {
pub struct EmptyOutputIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for EmptyOutputIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<Emptyindex> for usize {
fn from(value: Emptyindex) -> Self {
impl From<EmptyOutputIndex> for usize {
fn from(value: EmptyOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for Emptyindex {
impl From<usize> for EmptyOutputIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for Emptyindex {
impl Add<usize> for EmptyOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -136,23 +150,23 @@ impl Add<usize> for Emptyindex {
KnownLayout,
Serialize,
)]
pub struct Multisigindex(Addresstypeindex);
impl From<Addresstypeindex> for Multisigindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2MSIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2MSIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<Multisigindex> for usize {
fn from(value: Multisigindex) -> Self {
impl From<P2MSIndex> for usize {
fn from(value: P2MSIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for Multisigindex {
impl From<usize> for P2MSIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for Multisigindex {
impl Add<usize> for P2MSIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -176,23 +190,23 @@ impl Add<usize> for Multisigindex {
KnownLayout,
Serialize,
)]
pub struct Opreturnindex(Addresstypeindex);
impl From<Addresstypeindex> for Opreturnindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2AIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2AIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<Opreturnindex> for usize {
fn from(value: Opreturnindex) -> Self {
impl From<P2AIndex> for usize {
fn from(value: P2AIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for Opreturnindex {
impl From<usize> for P2AIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for Opreturnindex {
impl Add<usize> for P2AIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -216,23 +230,23 @@ impl Add<usize> for Opreturnindex {
KnownLayout,
Serialize,
)]
pub struct Pushonlyindex(Addresstypeindex);
impl From<Addresstypeindex> for Pushonlyindex {
fn from(value: Addresstypeindex) -> Self {
pub struct OpReturnIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for OpReturnIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<Pushonlyindex> for usize {
fn from(value: Pushonlyindex) -> Self {
impl From<OpReturnIndex> for usize {
fn from(value: OpReturnIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for Pushonlyindex {
impl From<usize> for OpReturnIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for Pushonlyindex {
impl Add<usize> for OpReturnIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -256,23 +270,23 @@ impl Add<usize> for Pushonlyindex {
KnownLayout,
Serialize,
)]
pub struct Unknownindex(Addresstypeindex);
impl From<Addresstypeindex> for Unknownindex {
fn from(value: Addresstypeindex) -> Self {
pub struct UnknownOutputIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for UnknownOutputIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<Unknownindex> for usize {
fn from(value: Unknownindex) -> Self {
impl From<UnknownOutputIndex> for usize {
fn from(value: UnknownOutputIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for Unknownindex {
impl From<usize> for UnknownOutputIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for Unknownindex {
impl Add<usize> for UnknownOutputIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -296,23 +310,23 @@ impl Add<usize> for Unknownindex {
KnownLayout,
Serialize,
)]
pub struct P2PK33index(Addresstypeindex);
impl From<Addresstypeindex> for P2PK33index {
fn from(value: Addresstypeindex) -> Self {
pub struct P2PK33Index(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PK33Index {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK33index> for usize {
fn from(value: P2PK33index) -> Self {
impl From<P2PK33Index> for usize {
fn from(value: P2PK33Index) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK33index {
impl From<usize> for P2PK33Index {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PK33index {
impl Add<usize> for P2PK33Index {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -336,23 +350,23 @@ impl Add<usize> for P2PK33index {
KnownLayout,
Serialize,
)]
pub struct P2PK65index(Addresstypeindex);
impl From<Addresstypeindex> for P2PK65index {
fn from(value: Addresstypeindex) -> Self {
pub struct P2PK65Index(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PK65Index {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PK65index> for usize {
fn from(value: P2PK65index) -> Self {
impl From<P2PK65Index> for usize {
fn from(value: P2PK65Index) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PK65index {
impl From<usize> for P2PK65Index {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PK65index {
impl Add<usize> for P2PK65Index {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -376,23 +390,23 @@ impl Add<usize> for P2PK65index {
KnownLayout,
Serialize,
)]
pub struct P2PKHindex(Addresstypeindex);
impl From<Addresstypeindex> for P2PKHindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2PKHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2PKHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2PKHindex> for usize {
fn from(value: P2PKHindex) -> Self {
impl From<P2PKHIndex> for usize {
fn from(value: P2PKHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2PKHindex {
impl From<usize> for P2PKHIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2PKHindex {
impl Add<usize> for P2PKHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -416,23 +430,23 @@ impl Add<usize> for P2PKHindex {
KnownLayout,
Serialize,
)]
pub struct P2SHindex(Addresstypeindex);
impl From<Addresstypeindex> for P2SHindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2SHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2SHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2SHindex> for usize {
fn from(value: P2SHindex) -> Self {
impl From<P2SHIndex> for usize {
fn from(value: P2SHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2SHindex {
impl From<usize> for P2SHIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2SHindex {
impl Add<usize> for P2SHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -456,23 +470,23 @@ impl Add<usize> for P2SHindex {
KnownLayout,
Serialize,
)]
pub struct P2TRindex(Addresstypeindex);
impl From<Addresstypeindex> for P2TRindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2TRIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2TRIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2TRindex> for usize {
fn from(value: P2TRindex) -> Self {
impl From<P2TRIndex> for usize {
fn from(value: P2TRIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2TRindex {
impl From<usize> for P2TRIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2TRindex {
impl Add<usize> for P2TRIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -496,23 +510,23 @@ impl Add<usize> for P2TRindex {
KnownLayout,
Serialize,
)]
pub struct P2WPKHindex(Addresstypeindex);
impl From<Addresstypeindex> for P2WPKHindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2WPKHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2WPKHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2WPKHindex> for usize {
fn from(value: P2WPKHindex) -> Self {
impl From<P2WPKHIndex> for usize {
fn from(value: P2WPKHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WPKHindex {
impl From<usize> for P2WPKHIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2WPKHindex {
impl Add<usize> for P2WPKHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)
@@ -536,23 +550,23 @@ impl Add<usize> for P2WPKHindex {
KnownLayout,
Serialize,
)]
pub struct P2WSHindex(Addresstypeindex);
impl From<Addresstypeindex> for P2WSHindex {
fn from(value: Addresstypeindex) -> Self {
pub struct P2WSHIndex(OutputTypeIndex);
impl From<OutputTypeIndex> for P2WSHIndex {
fn from(value: OutputTypeIndex) -> Self {
Self(value)
}
}
impl From<P2WSHindex> for usize {
fn from(value: P2WSHindex) -> Self {
impl From<P2WSHIndex> for usize {
fn from(value: P2WSHIndex) -> Self {
Self::from(*value)
}
}
impl From<usize> for P2WSHindex {
impl From<usize> for P2WSHIndex {
fn from(value: usize) -> Self {
Self(Addresstypeindex::from(value))
Self(OutputTypeIndex::from(value))
}
}
impl Add<usize> for P2WSHindex {
impl Add<usize> for P2WSHIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(*self + rhs)

View File

@@ -5,7 +5,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::Monthindex;
use super::MonthIndex;
#[derive(
Debug,
@@ -23,27 +23,27 @@ use super::Monthindex;
IntoBytes,
KnownLayout,
)]
pub struct Quarterindex(u16);
pub struct QuarterIndex(u16);
impl From<u16> for Quarterindex {
impl From<u16> for QuarterIndex {
fn from(value: u16) -> Self {
Self(value)
}
}
impl From<usize> for Quarterindex {
impl From<usize> for QuarterIndex {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<Quarterindex> for usize {
fn from(value: Quarterindex) -> Self {
impl From<QuarterIndex> for usize {
fn from(value: QuarterIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Quarterindex {
impl Add<usize> for QuarterIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,13 +51,13 @@ impl Add<usize> for Quarterindex {
}
}
impl From<Monthindex> for Quarterindex {
fn from(value: Monthindex) -> Self {
impl From<MonthIndex> for QuarterIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 3) as u16)
}
}
impl CheckedSub for Quarterindex {
impl CheckedSub for QuarterIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -39,6 +39,9 @@ impl From<u32> for StoredU32 {
impl From<usize> for StoredU32 {
fn from(value: usize) -> Self {
if value > u32::MAX as usize {
panic!("usize too big (value = {value})")
}
Self(value as u32)
}
}
@@ -77,3 +80,9 @@ impl From<StoredU32> for f64 {
value.0 as f64
}
}
impl From<StoredU32> for usize {
fn from(value: StoredU32) -> Self {
value.0 as usize
}
}

View File

@@ -6,7 +6,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Txindex, Txinindex, Txoutindex};
use super::{InputIndex, OutputIndex, TxIndex};
#[derive(
Debug,
@@ -80,20 +80,20 @@ impl From<StoredU64> for f64 {
}
}
impl From<Txindex> for StoredU64 {
fn from(value: Txindex) -> Self {
impl From<TxIndex> for StoredU64 {
fn from(value: TxIndex) -> Self {
Self(*value as u64)
}
}
impl From<Txinindex> for StoredU64 {
fn from(value: Txinindex) -> Self {
impl From<InputIndex> for StoredU64 {
fn from(value: InputIndex) -> Self {
Self(*value)
}
}
impl From<Txoutindex> for StoredU64 {
fn from(value: Txoutindex) -> Self {
impl From<OutputIndex> for StoredU64 {
fn from(value: OutputIndex) -> Self {
Self(*value)
}
}

View File

@@ -0,0 +1,60 @@
use byteview::ByteView;
use derive_deref::Deref;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{Error, copy_first_8bytes};
use super::Txid;
#[derive(
Debug,
Deref,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
FromBytes,
Immutable,
IntoBytes,
KnownLayout,
)]
pub struct TxidPrefix([u8; 8]);
impl From<Txid> for TxidPrefix {
fn from(value: Txid) -> Self {
Self::from(&value)
}
}
impl From<&Txid> for TxidPrefix {
fn from(value: &Txid) -> Self {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<ByteView> for TxidPrefix {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&TxidPrefix> for ByteView {
fn from(value: &TxidPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<TxidPrefix> for ByteView {
fn from(value: TxidPrefix) -> Self {
Self::from(&value)
}
}
impl From<[u8; 8]> for TxidPrefix {
fn from(value: [u8; 8]) -> Self {
Self(value)
}
}

View File

@@ -26,82 +26,82 @@ use super::StoredU32;
KnownLayout,
Serialize,
)]
pub struct Txindex(u32);
pub struct TxIndex(u32);
impl Txindex {
impl TxIndex {
pub fn incremented(self) -> Self {
Self(*self + 1)
}
}
impl Add<Txindex> for Txindex {
impl Add<TxIndex> for TxIndex {
type Output = Self;
fn add(self, rhs: Txindex) -> Self::Output {
fn add(self, rhs: TxIndex) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Add<usize> for Txindex {
impl Add<usize> for TxIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
Self(self.0 + rhs as u32)
}
}
impl AddAssign<Txindex> for Txindex {
fn add_assign(&mut self, rhs: Txindex) {
impl AddAssign<TxIndex> for TxIndex {
fn add_assign(&mut self, rhs: TxIndex) {
self.0 += rhs.0
}
}
impl CheckedSub<Txindex> for Txindex {
fn checked_sub(self, rhs: Txindex) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Txindex::from)
impl CheckedSub<TxIndex> for TxIndex {
fn checked_sub(self, rhs: TxIndex) -> Option<Self> {
self.0.checked_sub(rhs.0).map(TxIndex::from)
}
}
impl From<u32> for Txindex {
impl From<u32> for TxIndex {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<u64> for Txindex {
impl From<u64> for TxIndex {
fn from(value: u64) -> Self {
Self(value as u32)
}
}
impl From<Txindex> for u64 {
fn from(value: Txindex) -> Self {
impl From<TxIndex> for u64 {
fn from(value: TxIndex) -> Self {
value.0 as u64
}
}
impl From<usize> for Txindex {
impl From<usize> for TxIndex {
fn from(value: usize) -> Self {
Self(value as u32)
}
}
impl From<Txindex> for usize {
fn from(value: Txindex) -> Self {
impl From<TxIndex> for usize {
fn from(value: TxIndex) -> Self {
value.0 as usize
}
}
impl TryFrom<ByteView> for Txindex {
impl TryFrom<ByteView> for TxIndex {
type Error = Error;
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<Txindex> for ByteView {
fn from(value: Txindex) -> Self {
impl From<TxIndex> for ByteView {
fn from(value: TxIndex) -> Self {
Self::new(value.as_bytes())
}
}
impl From<Txindex> for StoredU32 {
fn from(value: Txindex) -> Self {
impl From<TxIndex> for StoredU32 {
fn from(value: TxIndex) -> Self {
Self::from(value.0)
}
}

View File

@@ -19,28 +19,34 @@ use super::StoredU8;
FromBytes,
Serialize,
)]
pub struct TxVersion(i32);
pub struct TxVersion(u8);
impl TxVersion {
pub const ONE: Self = Self(1);
pub const TWO: Self = Self(2);
pub const THREE: Self = Self(3);
pub const NON_STANDARD: Self = Self(u8::MAX);
}
impl From<bitcoin::transaction::Version> for TxVersion {
fn from(value: bitcoin::transaction::Version) -> Self {
Self(value.0)
match value.0 {
1 => Self::ONE,
2 => Self::TWO,
3 => Self::THREE,
_ => Self::NON_STANDARD,
}
}
}
impl From<TxVersion> for bitcoin::transaction::Version {
fn from(value: TxVersion) -> Self {
Self(value.0)
Self(value.0 as i32)
}
}
impl From<TxVersion> for StoredU8 {
fn from(value: TxVersion) -> Self {
Self::from(value.0 as u8)
Self::from(value.0)
}
}

View File

@@ -5,7 +5,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Date, Dateindex};
use super::{Date, DateIndex};
#[derive(
Debug,
@@ -23,27 +23,27 @@ use super::{Date, Dateindex};
IntoBytes,
KnownLayout,
)]
pub struct Weekindex(u16);
pub struct WeekIndex(u16);
impl From<u16> for Weekindex {
impl From<u16> for WeekIndex {
fn from(value: u16) -> Self {
Self(value)
}
}
impl From<usize> for Weekindex {
impl From<usize> for WeekIndex {
fn from(value: usize) -> Self {
Self(value as u16)
}
}
impl From<Weekindex> for usize {
fn from(value: Weekindex) -> Self {
impl From<WeekIndex> for usize {
fn from(value: WeekIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Weekindex {
impl Add<usize> for WeekIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,13 +51,13 @@ impl Add<usize> for Weekindex {
}
}
impl From<Dateindex> for Weekindex {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for WeekIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
}
}
impl From<Date> for Weekindex {
impl From<Date> for WeekIndex {
fn from(value: Date) -> Self {
let date = jiff::civil::Date::from(value).iso_week_date();
@@ -81,7 +81,7 @@ impl From<Date> for Weekindex {
}
}
impl CheckedSub for Weekindex {
impl CheckedSub for WeekIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}

View File

@@ -19,29 +19,36 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
FromBytes,
Serialize,
)]
pub struct Weight(u64);
pub struct Weight(u32);
impl From<bitcoin::Weight> for Weight {
fn from(value: bitcoin::Weight) -> Self {
Self(value.to_wu())
let wu = value.to_wu();
if wu > u32::MAX as u64 {
unreachable!("wu is too big, shouldn't happen")
}
Self(wu as u32)
}
}
impl From<Weight> for bitcoin::Weight {
fn from(value: Weight) -> Self {
Self::from_wu(*value)
Self::from_wu(*value as u64)
}
}
impl From<usize> for Weight {
fn from(value: usize) -> Self {
Self(value as u64)
if value > u32::MAX as usize {
panic!()
}
Self(value as u32)
}
}
impl From<f64> for Weight {
fn from(value: f64) -> Self {
Self(value as u64)
Self(value as u32)
}
}

View File

@@ -5,7 +5,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use super::{Date, Dateindex, Monthindex};
use super::{Date, DateIndex, MonthIndex};
#[derive(
Debug,
@@ -23,27 +23,27 @@ use super::{Date, Dateindex, Monthindex};
IntoBytes,
KnownLayout,
)]
pub struct Yearindex(u8);
pub struct YearIndex(u8);
impl From<u8> for Yearindex {
impl From<u8> for YearIndex {
fn from(value: u8) -> Self {
Self(value)
}
}
impl From<usize> for Yearindex {
impl From<usize> for YearIndex {
fn from(value: usize) -> Self {
Self(value as u8)
}
}
impl From<Yearindex> for usize {
fn from(value: Yearindex) -> Self {
impl From<YearIndex> for usize {
fn from(value: YearIndex) -> Self {
value.0 as usize
}
}
impl Add<usize> for Yearindex {
impl Add<usize> for YearIndex {
type Output = Self;
fn add(self, rhs: usize) -> Self::Output {
@@ -51,32 +51,32 @@ impl Add<usize> for Yearindex {
}
}
impl From<Dateindex> for Yearindex {
fn from(value: Dateindex) -> Self {
impl From<DateIndex> for YearIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))
}
}
impl From<Date> for Yearindex {
impl From<Date> for YearIndex {
fn from(value: Date) -> Self {
Self((value.year() - 2009) as u8)
}
}
impl From<Yearindex> for u16 {
fn from(value: Yearindex) -> Self {
impl From<YearIndex> for u16 {
fn from(value: YearIndex) -> Self {
value.0 as u16
}
}
impl CheckedSub for Yearindex {
impl CheckedSub for YearIndex {
fn checked_sub(self, rhs: Self) -> Option<Self> {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl From<Monthindex> for Yearindex {
fn from(value: Monthindex) -> Self {
impl From<MonthIndex> for YearIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 12) as u8)
}
}

View File

@@ -0,0 +1,12 @@
#[allow(clippy::result_unit_err)]
pub fn copy_first_8bytes(slice: &[u8]) -> Result<[u8; 8], ()> {
let mut buf: [u8; 8] = [0; 8];
let buf_len = buf.len();
if slice.len() < buf_len {
return Err(());
}
slice.iter().take(buf_len).enumerate().for_each(|(i, r)| {
buf[i] = *r;
});
Ok(buf)
}

View File

@@ -1,8 +1,10 @@
mod bytes;
mod checked_sub;
mod paths;
mod pause;
mod rlimit;
pub use bytes::*;
pub use checked_sub::*;
pub use paths::*;
pub use pause::*;

View File

@@ -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()?;

View File

@@ -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("")?,

View File

@@ -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)),
}

View File

@@ -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> {

View File

@@ -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,
]
}
}

View File

@@ -15,8 +15,8 @@ pub enum Index {
P2WPKHindex,
P2WSHindex,
Txindex,
Txinindex,
Txoutindex,
Inputindex,
Outputindex,
Weekindex,
Monthindex,
Quarterindex,
@@ -25,7 +25,7 @@ pub enum Index {
Difficultyepoch,
Halvingepoch,
Emptyindex,
Multisigindex,
P2MSindex,
Opreturnindex,
Pushonlyindex,
Unknownindex,
@@ -52,10 +52,10 @@ impl Index {
Self::P2WPKHindex,
Self::P2WSHindex,
Self::Txindex,
Self::Txinindex,
Self::Txoutindex,
Self::Inputindex,
Self::Outputindex,
Self::Emptyindex,
Self::Multisigindex,
Self::P2MSindex,
Self::Opreturnindex,
Self::Pushonlyindex,
Self::Unknownindex,
@@ -75,8 +75,8 @@ impl Index {
Self::Decadeindex => &["decade", "decadeindex"],
Self::Halvingepoch => &["h", "halving", "halvingepoch"],
Self::Txindex => &["tx", "txindex"],
Self::Txinindex => &["txin", "txinindex"],
Self::Txoutindex => &["txout", "txoutindex"],
Self::Inputindex => &["txin", "inputindex"],
Self::Outputindex => &["txout", "outputindex"],
Self::Addressindex => &["a", "address", "addressindex"],
Self::P2PK33index => &["p2pk33", "p2pk33index"],
Self::P2PK65index => &["p2pk65", "p2pk65index"],
@@ -85,11 +85,11 @@ impl Index {
Self::P2TRindex => &["p2tr", "p2trindex"],
Self::P2WPKHindex => &["p2wpkh", "p2wpkhindex"],
Self::P2WSHindex => &["p2wsh", "p2wshindex"],
Self::Emptyindex => &["empty", "emptyindex"],
Self::Multisigindex => &["multisig", "multisigindex"],
Self::Emptyindex => &["empty", "emptyoutputindex"],
Self::P2MSindex => &["multisig", "p2msindex"],
Self::Opreturnindex => &["opreturn", "opreturnindex"],
Self::Pushonlyindex => &["pushonly", "pushonlyindex"],
Self::Unknownindex => &["unknown", "unknownindex"],
Self::Unknownindex => &["unknown", "unknownoutputindex"],
}
}
@@ -120,8 +120,8 @@ impl TryFrom<&str> for Index {
v if (Self::Dateindex).possible_values().contains(&v) => Self::Dateindex,
v if (Self::Height).possible_values().contains(&v) => Self::Height,
v if (Self::Txindex).possible_values().contains(&v) => Self::Txindex,
v if (Self::Txinindex).possible_values().contains(&v) => Self::Txinindex,
v if (Self::Txoutindex).possible_values().contains(&v) => Self::Txoutindex,
v if (Self::Inputindex).possible_values().contains(&v) => Self::Inputindex,
v if (Self::Outputindex).possible_values().contains(&v) => Self::Outputindex,
v if (Self::Addressindex).possible_values().contains(&v) => Self::Addressindex,
v if (Self::P2PK33index).possible_values().contains(&v) => Self::P2PK33index,
v if (Self::P2PK65index).possible_values().contains(&v) => Self::P2PK65index,
@@ -139,7 +139,7 @@ impl TryFrom<&str> for Index {
v if (Self::Quarterindex).possible_values().contains(&v) => Self::Quarterindex,
v if (Self::Quarterindex).possible_values().contains(&v) => Self::Quarterindex,
v if (Self::Emptyindex).possible_values().contains(&v) => Self::Emptyindex,
v if (Self::Multisigindex).possible_values().contains(&v) => Self::Multisigindex,
v if (Self::P2MSindex).possible_values().contains(&v) => Self::P2MSindex,
v if (Self::Opreturnindex).possible_values().contains(&v) => Self::Opreturnindex,
v if (Self::Pushonlyindex).possible_values().contains(&v) => Self::Pushonlyindex,
v if (Self::Unknownindex).possible_values().contains(&v) => Self::Unknownindex,

View File

@@ -9,7 +9,7 @@
* @import {Signal, Signals} from "../packages/solid-signals/types";
* @import { getOwner as GetOwner, onCleanup as OnCleanup, Owner } from "../packages/solid-signals/v0.2.4-treeshaked/types/core/owner"
* @import { createEffect as CreateEffect, Accessor, Setter, createMemo as CreateMemo } from "../packages/solid-signals/v0.2.4-treeshaked/types/signals";
* @import {Addressindex, Dateindex, Decadeindex, Difficultyepoch, Index, Halvingepoch, Height, Monthindex, P2PK33index, P2PK65index, P2PKHindex, P2SHindex, P2TRindex, P2WPKHindex, P2WSHindex, Txindex, Txinindex, Txoutindex, VecId, Weekindex, Yearindex, VecIdToIndexes, Quarterindex, Emptyindex, Multisigindex, Opreturnindex, Pushonlyindex, Unknownindex} from "./vecid-to-indexes"
* @import {Addressindex, Dateindex, Decadeindex, Difficultyepoch, Index, Halvingepoch, Height, Monthindex, P2PK33index, P2PK65index, P2PKHindex, P2SHindex, P2TRindex, P2WPKHindex, P2WSHindex, Txindex, Inputindex, Outputindex, VecId, Weekindex, Yearindex, VecIdToIndexes, Quarterindex, Emptyindex, P2MSindex, Opreturnindex, Pushonlyindex, Unknownindex} from "./vecid-to-indexes"
*/
/**
@@ -1188,10 +1188,10 @@ function createUtils() {
return "P2WSHindex";
case /** @satisfies {Txindex} */ (17):
return "Txindex";
case /** @satisfies {Txinindex} */ (18):
return "Txinindex";
case /** @satisfies {Txoutindex} */ (19):
return "Txoutindex";
case /** @satisfies {Inputindex} */ (18):
return "Inputindex";
case /** @satisfies {Outputindex} */ (19):
return "Outputindex";
case /** @satisfies {Weekindex} */ (2):
return "Weekindex";
case /** @satisfies {Monthindex} */ (4):

View File

@@ -414,13 +414,13 @@ function createSerializedIndexes() {
/** @satisfies {VecId} */ ("p2wpkhindex"),
/** @satisfies {VecId} */ ("p2wshindex"),
/** @satisfies {VecId} */ ("txindex"),
/** @satisfies {VecId} */ ("txinindex"),
/** @satisfies {VecId} */ ("txoutindex"),
/** @satisfies {VecId} */ ("emptyindex"),
/** @satisfies {VecId} */ ("multisigindex"),
/** @satisfies {VecId} */ ("inputindex"),
/** @satisfies {VecId} */ ("outputindex"),
/** @satisfies {VecId} */ ("emptyoutputindex"),
/** @satisfies {VecId} */ ("p2msindex"),
/** @satisfies {VecId} */ ("opreturnindex"),
/** @satisfies {VecId} */ ("pushonlyindex"),
/** @satisfies {VecId} */ ("unknownindex"),
/** @satisfies {VecId} */ ("unknownoutputindex"),
]);
}
/** @typedef {ReturnType<typeof createSerializedIndexes>} SerializedIndexes */
@@ -468,19 +468,19 @@ function serializedIndexToIndex(serializedIndex) {
return /** @satisfies {P2WSHindex} */ (16);
case "txindex":
return /** @satisfies {Txindex} */ (17);
case "txinindex":
return /** @satisfies {Txinindex} */ (18);
case "txoutindex":
return /** @satisfies {Txoutindex} */ (19);
case "emptyindex":
case "inputindex":
return /** @satisfies {Inputindex} */ (18);
case "outputindex":
return /** @satisfies {Outputindex} */ (19);
case "emptyoutputindex":
return /** @satisfies {Emptyindex} */ (20);
case "multisigindex":
return /** @satisfies {Multisigindex} */ (21);
case "p2msindex":
return /** @satisfies {P2MSindex} */ (21);
case "opreturnindex":
return /** @satisfies {Opreturnindex} */ (22);
case "pushonlyindex":
return /** @satisfies {Pushonlyindex} */ (23);
case "unknownindex":
case "unknownoutputindex":
return /** @satisfies {Unknownindex} */ (24);
}
}

File diff suppressed because it is too large Load Diff