From 07618ebe431f09a565253091095cbe355afbe734 Mon Sep 17 00:00:00 2001 From: nym21 Date: Fri, 25 Apr 2025 18:16:23 +0200 Subject: [PATCH] global: renames + refactor + p2a support --- Cargo.lock | 77 +- Cargo.toml | 2 +- crates/brk_computer/src/storage/stores.rs | 37 +- .../storage/vecs/grouped/from_dateindex.rs | 18 +- .../src/storage/vecs/grouped/from_height.rs | 16 +- .../vecs/grouped/from_height_strict.rs | 4 +- .../src/storage/vecs/grouped/from_txindex.rs | 24 +- .../vecs/grouped/value_from_txindex.rs | 10 +- .../brk_computer/src/storage/vecs/indexes.rs | 336 +++-- .../src/storage/vecs/marketprice.rs | 42 +- .../src/storage/vecs/transactions.rs | 74 +- .../src/storage/vecs/vec/eager.rs | 12 +- .../{addressindex.rs => _addressindex.rs} | 30 +- .../src/structs/_addressindexoutputindex.rs | 28 + crates/brk_core/src/structs/_addresstype.rs | 48 + crates/brk_core/src/structs/addressbytes.rs | 203 +-- .../brk_core/src/structs/addressbyteshash.rs | 60 + .../src/structs/addressindextxoutindex.rs | 26 - .../brk_core/src/structs/blockhashprefix.rs | 54 + crates/brk_core/src/structs/compressed.rs | 156 --- crates/brk_core/src/structs/date.rs | 8 +- crates/brk_core/src/structs/dateindex.rs | 20 +- crates/brk_core/src/structs/decadeindex.rs | 26 +- .../brk_core/src/structs/difficultyepoch.rs | 16 +- crates/brk_core/src/structs/halvingepoch.rs | 16 +- .../structs/{txinindex.rs => inputindex.rs} | 34 +- crates/brk_core/src/structs/mod.rs | 34 +- crates/brk_core/src/structs/monthindex.rs | 24 +- .../structs/{txoutindex.rs => outputindex.rs} | 34 +- .../structs/{addresstype.rs => outputtype.rs} | 41 +- ...addresstypeindex.rs => outputtypeindex.rs} | 230 ++-- crates/brk_core/src/structs/quarterindex.rs | 20 +- crates/brk_core/src/structs/stored_u32.rs | 9 + crates/brk_core/src/structs/stored_u64.rs | 14 +- crates/brk_core/src/structs/txidprefix.rs | 60 + crates/brk_core/src/structs/txindex.rs | 44 +- crates/brk_core/src/structs/txversion.rs | 14 +- crates/brk_core/src/structs/weekindex.rs | 22 +- crates/brk_core/src/structs/weight.rs | 17 +- crates/brk_core/src/structs/yearindex.rs | 30 +- crates/brk_core/src/utils/bytes.rs | 12 + crates/brk_core/src/utils/mod.rs | 2 + crates/brk_indexer/examples/main.rs | 2 +- crates/brk_indexer/src/indexes.rs | 146 ++- crates/brk_indexer/src/lib.rs | 359 +++-- crates/brk_indexer/src/stores/mod.rs | 132 +- crates/brk_indexer/src/vecs/mod.rs | 788 +++++------ crates/brk_query/src/index.rs | 28 +- websites/kibo.money/scripts/main.js | 10 +- websites/kibo.money/scripts/table.js | 26 +- .../kibo.money/scripts/vecid-to-indexes.js | 1160 +++++++++++++++-- 51 files changed, 2802 insertions(+), 1833 deletions(-) rename crates/brk_core/src/structs/{addressindex.rs => _addressindex.rs} (66%) create mode 100644 crates/brk_core/src/structs/_addressindexoutputindex.rs create mode 100644 crates/brk_core/src/structs/_addresstype.rs create mode 100644 crates/brk_core/src/structs/addressbyteshash.rs delete mode 100644 crates/brk_core/src/structs/addressindextxoutindex.rs create mode 100644 crates/brk_core/src/structs/blockhashprefix.rs delete mode 100644 crates/brk_core/src/structs/compressed.rs rename crates/brk_core/src/structs/{txinindex.rs => inputindex.rs} (65%) rename crates/brk_core/src/structs/{txoutindex.rs => outputindex.rs} (67%) rename crates/brk_core/src/structs/{addresstype.rs => outputtype.rs} (65%) rename crates/brk_core/src/structs/{addresstypeindex.rs => outputtypeindex.rs} (56%) create mode 100644 crates/brk_core/src/structs/txidprefix.rs create mode 100644 crates/brk_core/src/utils/bytes.rs diff --git a/Cargo.lock b/Cargo.lock index 7470cbbeb..1a060b9b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] diff --git a/Cargo.toml b/Cargo.toml index e25ddeba2..db3bea3fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/crates/brk_computer/src/storage/stores.rs b/crates/brk_computer/src/storage/stores.rs index 3ecae31cd..4e4c6aff7 100644 --- a/crates/brk_computer/src/storage/stores.rs +++ b/crates/brk_computer/src/storage/stores.rs @@ -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, - pub address_to_utxos_spent: Store, + // pub address_to_utxos_received: Store, + // pub address_to_utxos_spent: Store, } impl Stores { - pub fn import(path: &Path, keyspace: &TransactionalKeyspace) -> color_eyre::Result { - 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 { + // 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, }) } } diff --git a/crates/brk_computer/src/storage/vecs/grouped/from_dateindex.rs b/crates/brk_computer/src/storage/vecs/grouped/from_dateindex.rs index e37bbca16..cd9d36070 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/from_dateindex.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/from_dateindex.rs @@ -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 where T: ComputedType + PartialOrd, { - pub dateindex: EagerVec, - pub dateindex_extra: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - pub yearindex: ComputedVecBuilder, - pub decadeindex: ComputedVecBuilder, + pub dateindex: EagerVec, + pub dateindex_extra: ComputedVecBuilder, + pub weekindex: ComputedVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; @@ -79,7 +79,7 @@ where ) -> color_eyre::Result<()> where F: FnMut( - &mut EagerVec, + &mut EagerVec, &mut Indexer, &mut indexes::Vecs, &Indexes, diff --git a/crates/brk_computer/src/storage/vecs/grouped/from_height.rs b/crates/brk_computer/src/storage/vecs/grouped/from_height.rs index 018babb18..e9e474b1d 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/from_height.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/from_height.rs @@ -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>, pub height_extra: ComputedVecBuilder, - pub dateindex: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - pub yearindex: ComputedVecBuilder, + pub dateindex: ComputedVecBuilder, + pub weekindex: ComputedVecBuilder, + pub difficultyepoch: ComputedVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, - pub decadeindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; diff --git a/crates/brk_computer/src/storage/vecs/grouped/from_height_strict.rs b/crates/brk_computer/src/storage/vecs/grouped/from_height_strict.rs index 06275ae5a..dce444fca 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/from_height_strict.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/from_height_strict.rs @@ -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, pub height_extra: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, + pub difficultyepoch: ComputedVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, } diff --git a/crates/brk_computer/src/storage/vecs/grouped/from_txindex.rs b/crates/brk_computer/src/storage/vecs/grouped/from_txindex.rs index 4eef7ab64..3826846d0 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/from_txindex.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/from_txindex.rs @@ -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 where T: ComputedType + PartialOrd, { - pub txindex: Option>, + pub txindex: Option>, pub height: ComputedVecBuilder, - pub dateindex: ComputedVecBuilder, - pub weekindex: ComputedVecBuilder, - pub difficultyepoch: ComputedVecBuilder, - pub monthindex: ComputedVecBuilder, - pub quarterindex: ComputedVecBuilder, - pub yearindex: ComputedVecBuilder, + pub dateindex: ComputedVecBuilder, + pub weekindex: ComputedVecBuilder, + pub difficultyepoch: ComputedVecBuilder, + pub monthindex: ComputedVecBuilder, + pub quarterindex: ComputedVecBuilder, + pub yearindex: ComputedVecBuilder, // TODO: pub halvingepoch: StorableVecGeneator, - pub decadeindex: ComputedVecBuilder, + pub decadeindex: ComputedVecBuilder, } const VERSION: Version = Version::ZERO; @@ -91,7 +91,7 @@ where ) -> color_eyre::Result<()> where F: FnMut( - &mut EagerVec, + &mut EagerVec, &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: Option<&mut StoredVec>, ) -> color_eyre::Result<()> { let txindex = txindex.unwrap_or_else(|| self.txindex.as_mut().unwrap().mut_vec()); diff --git a/crates/brk_computer/src/storage/vecs/grouped/value_from_txindex.rs b/crates/brk_computer/src/storage/vecs/grouped/value_from_txindex.rs index 8f327b984..e55fa24c4 100644 --- a/crates/brk_computer/src/storage/vecs/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/storage/vecs/grouped/value_from_txindex.rs @@ -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, + &mut EagerVec, &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>, + mut txindex: Option<&mut StoredVec>, ) -> 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, ) diff --git a/crates/brk_computer/src/storage/vecs/indexes.rs b/crates/brk_computer/src/storage/vecs/indexes.rs index 7d722ab7c..3bb8ae274 100644 --- a/crates/brk_computer/src/storage/vecs/indexes.rs +++ b/crates/brk_computer/src/storage/vecs/indexes.rs @@ -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, - pub dateindex_to_date: EagerVec, - pub dateindex_to_dateindex: EagerVec, - pub dateindex_to_first_height: EagerVec, - pub dateindex_to_last_height: EagerVec, - pub dateindex_to_monthindex: EagerVec, - pub dateindex_to_timestamp: EagerVec, - pub dateindex_to_weekindex: EagerVec, - pub decadeindex_to_decadeindex: EagerVec, - pub decadeindex_to_first_yearindex: EagerVec, - pub decadeindex_to_last_yearindex: EagerVec, - pub decadeindex_to_timestamp: EagerVec, - pub difficultyepoch_to_difficultyepoch: EagerVec, - pub difficultyepoch_to_first_height: EagerVec, - pub difficultyepoch_to_last_height: EagerVec, - pub difficultyepoch_to_timestamp: EagerVec, - pub emptyindex_to_emptyindex: EagerVec, - pub halvingepoch_to_first_height: EagerVec, - pub halvingepoch_to_halvingepoch: EagerVec, - pub halvingepoch_to_last_height: EagerVec, - pub halvingepoch_to_timestamp: EagerVec, - pub height_to_dateindex: EagerVec, - pub height_to_difficultyepoch: EagerVec, - pub height_to_fixed_date: EagerVec, - pub height_to_fixed_timestamp: EagerVec, - pub height_to_halvingepoch: EagerVec, + pub dateindex_to_date: EagerVec, + pub dateindex_to_dateindex: EagerVec, + pub dateindex_to_first_height: EagerVec, + pub dateindex_to_last_height: EagerVec, + pub dateindex_to_monthindex: EagerVec, + pub dateindex_to_timestamp: EagerVec, + pub dateindex_to_weekindex: EagerVec, + pub decadeindex_to_decadeindex: EagerVec, + pub decadeindex_to_first_yearindex: EagerVec, + pub decadeindex_to_last_yearindex: EagerVec, + pub decadeindex_to_timestamp: EagerVec, + pub difficultyepoch_to_difficultyepoch: EagerVec, + pub difficultyepoch_to_first_height: EagerVec, + pub difficultyepoch_to_last_height: EagerVec, + pub difficultyepoch_to_timestamp: EagerVec, + pub emptyoutputindex_to_emptyoutputindex: EagerVec, + pub halvingepoch_to_first_height: EagerVec, + pub halvingepoch_to_halvingepoch: EagerVec, + pub halvingepoch_to_last_height: EagerVec, + pub halvingepoch_to_timestamp: EagerVec, + pub height_to_date: EagerVec, + pub height_to_date_fixed: EagerVec, + pub height_to_dateindex: EagerVec, + pub height_to_difficultyepoch: EagerVec, + pub height_to_halvingepoch: EagerVec, pub height_to_height: EagerVec, - pub height_to_last_txindex: EagerVec, - pub height_to_real_date: EagerVec, - pub monthindex_to_first_dateindex: EagerVec, - pub monthindex_to_last_dateindex: EagerVec, - pub monthindex_to_monthindex: EagerVec, - pub monthindex_to_quarterindex: EagerVec, - pub monthindex_to_timestamp: EagerVec, - pub monthindex_to_yearindex: EagerVec, - pub multisigindex_to_multisigindex: EagerVec, - pub opreturnindex_to_opreturnindex: EagerVec, - pub p2pk33index_to_p2pk33index: EagerVec, - pub p2pk65index_to_p2pk65index: EagerVec, - pub p2pkhindex_to_p2pkhindex: EagerVec, - pub p2shindex_to_p2shindex: EagerVec, - pub p2trindex_to_p2trindex: EagerVec, - pub p2wpkhindex_to_p2wpkhindex: EagerVec, - pub p2wshindex_to_p2wshindex: EagerVec, - pub pushonlyindex_to_pushonlyindex: EagerVec, - pub quarterindex_to_first_monthindex: EagerVec, - pub quarterindex_to_last_monthindex: EagerVec, - pub quarterindex_to_quarterindex: EagerVec, - pub quarterindex_to_timestamp: EagerVec, - pub txindex_to_last_txinindex: EagerVec, - pub txindex_to_last_txoutindex: EagerVec, - pub txindex_to_txindex: EagerVec, - pub txinindex_to_txinindex: EagerVec, - pub txoutindex_to_txoutindex: EagerVec, - pub unknownindex_to_unknownindex: EagerVec, - pub weekindex_to_first_dateindex: EagerVec, - pub weekindex_to_last_dateindex: EagerVec, - pub weekindex_to_timestamp: EagerVec, - pub weekindex_to_weekindex: EagerVec, - pub yearindex_to_decadeindex: EagerVec, - pub yearindex_to_first_monthindex: EagerVec, - pub yearindex_to_last_monthindex: EagerVec, - pub yearindex_to_timestamp: EagerVec, - pub yearindex_to_yearindex: EagerVec, + pub height_to_last_txindex: EagerVec, + pub height_to_timestamp_fixed: EagerVec, + pub inputindex_to_inputindex: EagerVec, + pub monthindex_to_first_dateindex: EagerVec, + pub monthindex_to_last_dateindex: EagerVec, + pub monthindex_to_monthindex: EagerVec, + pub monthindex_to_quarterindex: EagerVec, + pub monthindex_to_timestamp: EagerVec, + pub monthindex_to_yearindex: EagerVec, + pub opreturnindex_to_opreturnindex: EagerVec, + pub outputindex_to_outputindex: EagerVec, + pub p2aindex_to_p2aindex: EagerVec, + pub p2msindex_to_p2msindex: EagerVec, + pub p2pk33index_to_p2pk33index: EagerVec, + pub p2pk65index_to_p2pk65index: EagerVec, + pub p2pkhindex_to_p2pkhindex: EagerVec, + pub p2shindex_to_p2shindex: EagerVec, + pub p2trindex_to_p2trindex: EagerVec, + pub p2wpkhindex_to_p2wpkhindex: EagerVec, + pub p2wshindex_to_p2wshindex: EagerVec, + pub quarterindex_to_first_monthindex: EagerVec, + pub quarterindex_to_last_monthindex: EagerVec, + pub quarterindex_to_quarterindex: EagerVec, + pub quarterindex_to_timestamp: EagerVec, + pub txindex_to_height: EagerVec, + pub txindex_to_last_inputindex: EagerVec, + pub txindex_to_last_outputindex: EagerVec, + pub txindex_to_txindex: EagerVec, + pub unknownoutputindex_to_unknownoutputindex: EagerVec, + pub weekindex_to_first_dateindex: EagerVec, + pub weekindex_to_last_dateindex: EagerVec, + pub weekindex_to_timestamp: EagerVec, + pub weekindex_to_weekindex: EagerVec, + pub yearindex_to_decadeindex: EagerVec, + pub yearindex_to_first_monthindex: EagerVec, + pub yearindex_to_last_monthindex: EagerVec, + pub yearindex_to_timestamp: EagerVec, + pub yearindex_to_yearindex: EagerVec, } 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 { diff --git a/crates/brk_computer/src/storage/vecs/marketprice.rs b/crates/brk_computer/src/storage/vecs/marketprice.rs index 6530a566e..dd62bc5f4 100644 --- a/crates/brk_computer/src/storage/vecs/marketprice.rs +++ b/crates/brk_computer/src/storage/vecs/marketprice.rs @@ -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>, - pub dateindex_to_high_in_cents: EagerVec>, - pub dateindex_to_low_in_cents: EagerVec>, - pub dateindex_to_ohlc: EagerVec, - pub dateindex_to_ohlc_in_sats: EagerVec, - pub dateindex_to_ohlc_in_cents: EagerVec, - pub dateindex_to_open_in_cents: EagerVec>, + pub dateindex_to_close_in_cents: EagerVec>, + pub dateindex_to_high_in_cents: EagerVec>, + pub dateindex_to_low_in_cents: EagerVec>, + pub dateindex_to_ohlc: EagerVec, + pub dateindex_to_ohlc_in_sats: EagerVec, + pub dateindex_to_ohlc_in_cents: EagerVec, + pub dateindex_to_open_in_cents: EagerVec>, pub height_to_close_in_cents: EagerVec>, pub height_to_high_in_cents: EagerVec>, pub height_to_low_in_cents: EagerVec>, @@ -49,20 +49,20 @@ pub struct Vecs { pub chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict>, pub chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict>, pub chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict>, - pub weekindex_to_ohlc: EagerVec, - pub weekindex_to_ohlc_in_sats: EagerVec, - pub difficultyepoch_to_ohlc: EagerVec, - pub difficultyepoch_to_ohlc_in_sats: EagerVec, - pub monthindex_to_ohlc: EagerVec, - pub monthindex_to_ohlc_in_sats: EagerVec, - pub quarterindex_to_ohlc: EagerVec, - pub quarterindex_to_ohlc_in_sats: EagerVec, - pub yearindex_to_ohlc: EagerVec, - pub yearindex_to_ohlc_in_sats: EagerVec, + pub weekindex_to_ohlc: EagerVec, + pub weekindex_to_ohlc_in_sats: EagerVec, + pub difficultyepoch_to_ohlc: EagerVec, + pub difficultyepoch_to_ohlc_in_sats: EagerVec, + pub monthindex_to_ohlc: EagerVec, + pub monthindex_to_ohlc_in_sats: EagerVec, + pub quarterindex_to_ohlc: EagerVec, + pub quarterindex_to_ohlc_in_sats: EagerVec, + pub yearindex_to_ohlc: EagerVec, + pub yearindex_to_ohlc_in_sats: EagerVec, // pub halvingepoch_to_ohlc: StorableVec, // pub halvingepoch_to_ohlc_in_sats: StorableVec, - pub decadeindex_to_ohlc: EagerVec, - pub decadeindex_to_ohlc_in_sats: EagerVec, + pub decadeindex_to_ohlc: EagerVec, + pub decadeindex_to_ohlc_in_sats: EagerVec, } const VERSION: Version = Version::ZERO; diff --git a/crates/brk_computer/src/storage/vecs/transactions.rs b/crates/brk_computer/src/storage/vecs/transactions.rs index a572b71d7..0b65785d8 100644 --- a/crates/brk_computer/src/storage/vecs/transactions.rs +++ b/crates/brk_computer/src/storage/vecs/transactions.rs @@ -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, pub indexes_to_tx_weight: ComputedVecsFromTxindex, pub txindex_to_input_count: ComputedVecsFromTxindex, - pub txindex_to_is_coinbase: EagerVec, + pub txindex_to_is_coinbase: EagerVec, pub txindex_to_output_count: ComputedVecsFromTxindex, - pub txindex_to_vsize: EagerVec, - pub txindex_to_weight: EagerVec, + pub txindex_to_vsize: EagerVec, + pub txindex_to_weight: EagerVec, /// Value == 0 when Coinbase - pub txinindex_to_value: EagerVec, + pub inputindex_to_value: EagerVec, 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(), ], diff --git a/crates/brk_computer/src/storage/vecs/vec/eager.rs b/crates/brk_computer/src/storage/vecs/vec/eager.rs index 38b52849d..2abafdca0 100644 --- a/crates/brk_computer/src/storage/vecs/vec/eager.rs +++ b/crates/brk_computer/src/storage/vecs/vec/eager.rs @@ -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 { } } -impl EagerVec { +impl EagerVec { pub fn compute_from_bitcoin( &mut self, - max_from: Txindex, - bitcoin: &mut StoredVec, - i_to_height: &mut StoredVec, + max_from: TxIndex, + bitcoin: &mut StoredVec, + i_to_height: &mut StoredVec, price: &mut StoredVec>, exit: &Exit, ) -> Result<()> { @@ -503,7 +503,7 @@ impl EagerVec { 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); diff --git a/crates/brk_core/src/structs/addressindex.rs b/crates/brk_core/src/structs/_addressindex.rs similarity index 66% rename from crates/brk_core/src/structs/addressindex.rs rename to crates/brk_core/src/structs/_addressindex.rs index 74379139b..cdd4b0592 100644 --- a/crates/brk_core/src/structs/addressindex.rs +++ b/crates/brk_core/src/structs/_addressindex.rs @@ -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::(); pub fn increment(&mut self) { @@ -35,56 +35,56 @@ impl Addressindex { } } -impl From for Addressindex { +impl From for AddressIndex { fn from(value: u32) -> Self { Self(value) } } -impl From for Addressindex { +impl From for AddressIndex { fn from(value: u64) -> Self { Self(value as u32) } } -impl From for u64 { - fn from(value: Addressindex) -> Self { +impl From for u64 { + fn from(value: AddressIndex) -> Self { value.0 as u64 } } -impl From for Addressindex { +impl From for AddressIndex { fn from(value: usize) -> Self { Self(value as u32) } } -impl From for usize { - fn from(value: Addressindex) -> Self { +impl From for usize { + fn from(value: AddressIndex) -> Self { value.0 as usize } } -impl TryFrom for Addressindex { +impl TryFrom for AddressIndex { type Error = Error; fn try_from(value: ByteView) -> Result { Ok(Self::read_from_bytes(&value)?) } } -impl From for ByteView { - fn from(value: Addressindex) -> Self { +impl From for ByteView { + fn from(value: AddressIndex) -> Self { Self::new(value.as_bytes()) } } -impl Add for Addressindex { +impl Add for AddressIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u32) } } -impl Add for Addressindex { +impl Add for AddressIndex { type Output = Self; - fn add(self, rhs: Addressindex) -> Self::Output { + fn add(self, rhs: AddressIndex) -> Self::Output { Self(self.0 + rhs.0) } } diff --git a/crates/brk_core/src/structs/_addressindexoutputindex.rs b/crates/brk_core/src/structs/_addressindexoutputindex.rs new file mode 100644 index 000000000..c85062b1f --- /dev/null +++ b/crates/brk_core/src/structs/_addressindexoutputindex.rs @@ -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 for AddressIndexOutputIndex { + type Error = Error; + fn try_from(value: ByteView) -> Result { + Ok(Self::read_from_bytes(&value)?) + } +} +impl From for ByteView { + fn from(value: AddressIndexOutputIndex) -> Self { + Self::new(value.as_bytes()) + } +} diff --git a/crates/brk_core/src/structs/_addresstype.rs b/crates/brk_core/src/structs/_addresstype.rs new file mode 100644 index 000000000..6d0247e9d --- /dev/null +++ b/crates/brk_core/src/structs/_addresstype.rs @@ -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 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!() + } + } + } +} diff --git a/crates/brk_core/src/structs/addressbytes.rs b/crates/brk_core/src/structs/addressbytes.rs index d572b0d3e..cafa0ba60 100644 --- a/crates/brk_core/src/structs/addressbytes.rs +++ b/crates/brk_core/src/structs/addressbytes.rs @@ -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 { - let (script, addresstype) = tuple; + fn try_from(tuple: (&ScriptBuf, OutputType)) -> Result { + 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(&self, serializer: S) -> Result where S: Serializer, @@ -114,22 +119,22 @@ impl Serialize for P2PK65AddressBytes { } } -impl From for Addressbytes { - fn from(value: P2PK65AddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -138,16 +143,16 @@ impl Serialize for P2PK33AddressBytes { } } -impl From for Addressbytes { - fn from(value: P2PK33AddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -170,16 +175,16 @@ impl Serialize for P2PKHAddressBytes { } } -impl From for Addressbytes { - fn from(value: P2PKHAddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -200,16 +205,16 @@ impl Serialize for P2SHAddressBytes { } } -impl From for Addressbytes { - fn from(value: P2SHAddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -226,16 +231,16 @@ impl Serialize for P2WPKHAddressBytes { } } -impl From for Addressbytes { - fn from(value: P2WPKHAddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -252,16 +257,16 @@ impl Serialize for P2WSHAddressBytes { } } -impl From for Addressbytes { - fn from(value: P2WSHAddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result where S: Serializer, @@ -278,12 +283,60 @@ impl Serialize for P2TRAddressBytes { } } -impl From for Addressbytes { - fn from(value: P2TRAddressBytes) -> Self { +impl From 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(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.collect_str(&self.to_string()) + } +} + +impl From 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, diff --git a/crates/brk_core/src/structs/addressbyteshash.rs b/crates/brk_core/src/structs/addressbyteshash.rs new file mode 100644 index 000000000..303f225e8 --- /dev/null +++ b/crates/brk_core/src/structs/addressbyteshash.rs @@ -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 for AddressBytesHash { + type Error = Error; + fn try_from(value: ByteView) -> Result { + Ok(Self::read_from_bytes(&value)?) + } +} + +impl From<&AddressBytesHash> for ByteView { + fn from(value: &AddressBytesHash) -> Self { + Self::new(value.as_bytes()) + } +} + +impl From for ByteView { + fn from(value: AddressBytesHash) -> Self { + Self::from(&value) + } +} diff --git a/crates/brk_core/src/structs/addressindextxoutindex.rs b/crates/brk_core/src/structs/addressindextxoutindex.rs deleted file mode 100644 index d895ca47b..000000000 --- a/crates/brk_core/src/structs/addressindextxoutindex.rs +++ /dev/null @@ -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 for AddressindexTxoutindex { - type Error = Error; - fn try_from(value: ByteView) -> Result { - Ok(Self::read_from_bytes(&value)?) - } -} -impl From for ByteView { - fn from(value: AddressindexTxoutindex) -> Self { - Self::new(value.as_bytes()) - } -} diff --git a/crates/brk_core/src/structs/blockhashprefix.rs b/crates/brk_core/src/structs/blockhashprefix.rs new file mode 100644 index 000000000..345d90a1f --- /dev/null +++ b/crates/brk_core/src/structs/blockhashprefix.rs @@ -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 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 for BlockHashPrefix { + type Error = Error; + fn try_from(value: ByteView) -> Result { + Ok(Self::read_from_bytes(&value)?) + } +} + +impl From<&BlockHashPrefix> for ByteView { + fn from(value: &BlockHashPrefix) -> Self { + Self::new(value.as_bytes()) + } +} + +impl From for ByteView { + fn from(value: BlockHashPrefix) -> Self { + Self::from(&value) + } +} diff --git a/crates/brk_core/src/structs/compressed.rs b/crates/brk_core/src/structs/compressed.rs deleted file mode 100644 index 271a77fea..000000000 --- a/crates/brk_core/src/structs/compressed.rs +++ /dev/null @@ -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 for AddressHash { - type Error = Error; - fn try_from(value: ByteView) -> Result { - Ok(Self::read_from_bytes(&value)?) - } -} -impl From<&AddressHash> for ByteView { - fn from(value: &AddressHash) -> Self { - Self::new(value.as_bytes()) - } -} -impl From 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 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 for BlockHashPrefix { - type Error = Error; - fn try_from(value: ByteView) -> Result { - Ok(Self::read_from_bytes(&value)?) - } -} -impl From<&BlockHashPrefix> for ByteView { - fn from(value: &BlockHashPrefix) -> Self { - Self::new(value.as_bytes()) - } -} -impl From 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 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 for TxidPrefix { - type Error = Error; - fn try_from(value: ByteView) -> Result { - Ok(Self::read_from_bytes(&value)?) - } -} -impl From<&TxidPrefix> for ByteView { - fn from(value: &TxidPrefix) -> Self { - Self::new(value.as_bytes()) - } -} -impl From 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) -} diff --git a/crates/brk_core/src/structs/date.rs b/crates/brk_core/src/structs/date.rs index 1e8c3f81b..a8f252ee3 100644 --- a/crates/brk_core/src/structs/date.rs +++ b/crates/brk_core/src/structs/date.rs @@ -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 for Date { } } -impl From for Date { - fn from(value: Dateindex) -> Self { - if value == Dateindex::default() { +impl From for Date { + fn from(value: DateIndex) -> Self { + if value == DateIndex::default() { Date::INDEX_ZERO } else { Self::from( diff --git a/crates/brk_core/src/structs/dateindex.rs b/crates/brk_core/src/structs/dateindex.rs index dfda5d490..2d248e02a 100644 --- a/crates/brk_core/src/structs/dateindex.rs +++ b/crates/brk_core/src/structs/dateindex.rs @@ -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::(); } -impl From for usize { - fn from(value: Dateindex) -> Self { +impl From for usize { + fn from(value: DateIndex) -> Self { value.0 as usize } } -impl From for Dateindex { +impl From for DateIndex { fn from(value: usize) -> Self { Self(value as u16) } } -impl From for i64 { - fn from(value: Dateindex) -> Self { +impl From for i64 { + fn from(value: DateIndex) -> Self { value.0 as i64 } } -impl Add for Dateindex { +impl Add for DateIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u16) } } -impl TryFrom for Dateindex { +impl TryFrom for DateIndex { type Error = Error; fn try_from(value: Date) -> Result { let value_ = jiff::civil::Date::from(value); @@ -72,7 +72,7 @@ impl TryFrom for Dateindex { } } -impl CheckedSub for Dateindex { +impl CheckedSub for DateIndex { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/decadeindex.rs b/crates/brk_core/src/structs/decadeindex.rs index af36005a1..013e07f2d 100644 --- a/crates/brk_core/src/structs/decadeindex.rs +++ b/crates/brk_core/src/structs/decadeindex.rs @@ -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 for Decadeindex { +impl From for DecadeIndex { fn from(value: u8) -> Self { Self(value) } } -impl From for Decadeindex { +impl From for DecadeIndex { fn from(value: usize) -> Self { Self(value as u8) } } -impl From for usize { - fn from(value: Decadeindex) -> Self { +impl From for usize { + fn from(value: DecadeIndex) -> Self { value.0 as usize } } -impl Add for Decadeindex { +impl Add for DecadeIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,13 +51,13 @@ impl Add for Decadeindex { } } -impl From for Decadeindex { - fn from(value: Dateindex) -> Self { +impl From for DecadeIndex { + fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } -impl From for Decadeindex { +impl From for DecadeIndex { fn from(value: Date) -> Self { let year = value.year(); if year < 2000 { @@ -67,14 +67,14 @@ impl From for Decadeindex { } } -impl CheckedSub for Decadeindex { +impl CheckedSub for DecadeIndex { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } } -impl From for Decadeindex { - fn from(value: Yearindex) -> Self { +impl From for DecadeIndex { + fn from(value: YearIndex) -> Self { let v = usize::from(value); if v == 0 { Self(0) diff --git a/crates/brk_core/src/structs/difficultyepoch.rs b/crates/brk_core/src/structs/difficultyepoch.rs index 9507fc723..f9520847d 100644 --- a/crates/brk_core/src/structs/difficultyepoch.rs +++ b/crates/brk_core/src/structs/difficultyepoch.rs @@ -23,27 +23,27 @@ use super::Height; IntoBytes, KnownLayout, )] -pub struct Difficultyepoch(u16); +pub struct DifficultyEpoch(u16); -impl From for Difficultyepoch { +impl From for DifficultyEpoch { fn from(value: u16) -> Self { Self(value) } } -impl From for Difficultyepoch { +impl From for DifficultyEpoch { fn from(value: usize) -> Self { Self(value as u16) } } -impl From for usize { - fn from(value: Difficultyepoch) -> Self { +impl From for usize { + fn from(value: DifficultyEpoch) -> Self { value.0 as usize } } -impl Add for Difficultyepoch { +impl Add for DifficultyEpoch { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,13 +51,13 @@ impl Add for Difficultyepoch { } } -impl From for Difficultyepoch { +impl From 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.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/halvingepoch.rs b/crates/brk_core/src/structs/halvingepoch.rs index 7c98fc2ef..1c4f2ca0e 100644 --- a/crates/brk_core/src/structs/halvingepoch.rs +++ b/crates/brk_core/src/structs/halvingepoch.rs @@ -23,27 +23,27 @@ use super::Height; IntoBytes, KnownLayout, )] -pub struct Halvingepoch(u8); +pub struct HalvingEpoch(u8); -impl From for Halvingepoch { +impl From for HalvingEpoch { fn from(value: u8) -> Self { Self(value) } } -impl From for Halvingepoch { +impl From for HalvingEpoch { fn from(value: usize) -> Self { Self(value as u8) } } -impl From for usize { - fn from(value: Halvingepoch) -> Self { +impl From for usize { + fn from(value: HalvingEpoch) -> Self { value.0 as usize } } -impl Add for Halvingepoch { +impl Add for HalvingEpoch { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,13 +51,13 @@ impl Add for Halvingepoch { } } -impl From for Halvingepoch { +impl From 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.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/txinindex.rs b/crates/brk_core/src/structs/inputindex.rs similarity index 65% rename from crates/brk_core/src/structs/txinindex.rs rename to crates/brk_core/src/structs/inputindex.rs index 04544d593..c9b98c554 100644 --- a/crates/brk_core/src/structs/txinindex.rs +++ b/crates/brk_core/src/structs/inputindex.rs @@ -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 for Txinindex { +impl Add 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 for Txinindex { +impl Add for InputIndex { type Output = Self; fn add(self, rhs: Vin) -> Self::Output { Self(self.0 + u64::from(rhs)) } } -impl Add for Txinindex { +impl Add for InputIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u64) } } -impl AddAssign for Txinindex { - fn add_assign(&mut self, rhs: Txinindex) { +impl AddAssign for InputIndex { + fn add_assign(&mut self, rhs: InputIndex) { self.0 += rhs.0 } } -impl CheckedSub for Txinindex { +impl CheckedSub for InputIndex { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self::from) } } -impl From for u32 { - fn from(value: Txinindex) -> Self { +impl From for u32 { + fn from(value: InputIndex) -> Self { if value.0 > u32::MAX as u64 { panic!() } @@ -75,24 +75,24 @@ impl From for u32 { } } -impl From for Txinindex { +impl From for InputIndex { fn from(value: u64) -> Self { Self(value) } } -impl From for u64 { - fn from(value: Txinindex) -> Self { +impl From for u64 { + fn from(value: InputIndex) -> Self { value.0 } } -impl From for Txinindex { +impl From for InputIndex { fn from(value: usize) -> Self { Self(value as u64) } } -impl From for usize { - fn from(value: Txinindex) -> Self { +impl From for usize { + fn from(value: InputIndex) -> Self { value.0 as usize } } diff --git a/crates/brk_core/src/structs/mod.rs b/crates/brk_core/src/structs/mod.rs index b5723d8b1..09ca3e141 100644 --- a/crates/brk_core/src/structs/mod.rs +++ b/crates/brk_core/src/structs/mod.rs @@ -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::*; diff --git a/crates/brk_core/src/structs/monthindex.rs b/crates/brk_core/src/structs/monthindex.rs index 892300afe..5bc68e9f8 100644 --- a/crates/brk_core/src/structs/monthindex.rs +++ b/crates/brk_core/src/structs/monthindex.rs @@ -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 for Monthindex { +impl From for MonthIndex { fn from(value: u16) -> Self { Self(value) } } -impl From for Monthindex { +impl From for MonthIndex { fn from(value: usize) -> Self { Self(value as u16) } } -impl From for usize { - fn from(value: Monthindex) -> Self { +impl From for usize { + fn from(value: MonthIndex) -> Self { value.0 as usize } } -impl Add for Monthindex { +impl Add for MonthIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,19 +51,19 @@ impl Add for Monthindex { } } -impl From for Monthindex { - fn from(value: Dateindex) -> Self { +impl From for MonthIndex { + fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } -impl From for Monthindex { +impl From 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.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/txoutindex.rs b/crates/brk_core/src/structs/outputindex.rs similarity index 67% rename from crates/brk_core/src/structs/txoutindex.rs rename to crates/brk_core/src/structs/outputindex.rs index ba4571505..6dabbf294 100644 --- a/crates/brk_core/src/structs/txoutindex.rs +++ b/crates/brk_core/src/structs/outputindex.rs @@ -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 for Txoutindex { +impl Add 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 for Txoutindex { +impl Add for OutputIndex { type Output = Self; fn add(self, rhs: Vout) -> Self::Output { Self(self.0 + u64::from(rhs)) } } -impl Add for Txoutindex { +impl Add for OutputIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u64) } } -impl AddAssign for Txoutindex { - fn add_assign(&mut self, rhs: Txoutindex) { +impl AddAssign for OutputIndex { + fn add_assign(&mut self, rhs: OutputIndex) { self.0 += rhs.0 } } -impl CheckedSub for Txoutindex { +impl CheckedSub for OutputIndex { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self::from) } } -impl From for u32 { - fn from(value: Txoutindex) -> Self { +impl From for u32 { + fn from(value: OutputIndex) -> Self { if value.0 > u32::MAX as u64 { panic!() } @@ -81,24 +81,24 @@ impl From for u32 { } } -impl From for Txoutindex { +impl From for OutputIndex { fn from(value: u64) -> Self { Self(value) } } -impl From for u64 { - fn from(value: Txoutindex) -> Self { +impl From for u64 { + fn from(value: OutputIndex) -> Self { value.0 } } -impl From for Txoutindex { +impl From for OutputIndex { fn from(value: usize) -> Self { Self(value as u64) } } -impl From for usize { - fn from(value: Txoutindex) -> Self { +impl From for usize { + fn from(value: OutputIndex) -> Self { value.0 as usize } } diff --git a/crates/brk_core/src/structs/addresstype.rs b/crates/brk_core/src/structs/outputtype.rs similarity index 65% rename from crates/brk_core/src/structs/addresstype.rs rename to crates/brk_core/src/structs/outputtype.rs index ddbeab956..f6e3d7f6a 100644 --- a/crates/brk_core/src/structs/addresstype.rs +++ b/crates/brk_core/src/structs/outputtype.rs @@ -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 } diff --git a/crates/brk_core/src/structs/addresstypeindex.rs b/crates/brk_core/src/structs/outputtypeindex.rs similarity index 56% rename from crates/brk_core/src/structs/addresstypeindex.rs rename to crates/brk_core/src/structs/outputtypeindex.rs index 3bb31026e..ee569fb23 100644 --- a/crates/brk_core/src/structs/addresstypeindex.rs +++ b/crates/brk_core/src/structs/outputtypeindex.rs @@ -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 for Addresstypeindex { +impl From for OutputTypeIndex { fn from(value: u32) -> Self { Self(value) } } -impl From for Addresstypeindex { +impl From for OutputTypeIndex { fn from(value: u64) -> Self { Self(value as u32) } } -impl From for u64 { - fn from(value: Addresstypeindex) -> Self { +impl From for u64 { + fn from(value: OutputTypeIndex) -> Self { value.0 as u64 } } -impl From for Addresstypeindex { +impl From for OutputTypeIndex { fn from(value: usize) -> Self { Self(value as u32) } } -impl From for usize { - fn from(value: Addresstypeindex) -> Self { +impl From for usize { + fn from(value: OutputTypeIndex) -> Self { value.0 as usize } } -impl Add for Addresstypeindex { +impl Add for OutputTypeIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u32) } } -impl Add for Addresstypeindex { +impl Add 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 for OutputTypeIndex { + type Error = Error; + fn try_from(value: ByteView) -> Result { + Ok(Self::read_from_bytes(&value)?) + } +} +impl From for ByteView { + fn from(value: OutputTypeIndex) -> Self { + Self::new(value.as_bytes()) + } +} #[derive( Debug, @@ -96,23 +110,23 @@ impl Add for Addresstypeindex { KnownLayout, Serialize, )] -pub struct Emptyindex(Addresstypeindex); -impl From for Emptyindex { - fn from(value: Addresstypeindex) -> Self { +pub struct EmptyOutputIndex(OutputTypeIndex); +impl From for EmptyOutputIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: Emptyindex) -> Self { +impl From for usize { + fn from(value: EmptyOutputIndex) -> Self { Self::from(*value) } } -impl From for Emptyindex { +impl From for EmptyOutputIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for Emptyindex { +impl Add for EmptyOutputIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -136,23 +150,23 @@ impl Add for Emptyindex { KnownLayout, Serialize, )] -pub struct Multisigindex(Addresstypeindex); -impl From for Multisigindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2MSIndex(OutputTypeIndex); +impl From for P2MSIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: Multisigindex) -> Self { +impl From for usize { + fn from(value: P2MSIndex) -> Self { Self::from(*value) } } -impl From for Multisigindex { +impl From for P2MSIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for Multisigindex { +impl Add for P2MSIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -176,23 +190,23 @@ impl Add for Multisigindex { KnownLayout, Serialize, )] -pub struct Opreturnindex(Addresstypeindex); -impl From for Opreturnindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2AIndex(OutputTypeIndex); +impl From for P2AIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: Opreturnindex) -> Self { +impl From for usize { + fn from(value: P2AIndex) -> Self { Self::from(*value) } } -impl From for Opreturnindex { +impl From for P2AIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for Opreturnindex { +impl Add for P2AIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -216,23 +230,23 @@ impl Add for Opreturnindex { KnownLayout, Serialize, )] -pub struct Pushonlyindex(Addresstypeindex); -impl From for Pushonlyindex { - fn from(value: Addresstypeindex) -> Self { +pub struct OpReturnIndex(OutputTypeIndex); +impl From for OpReturnIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: Pushonlyindex) -> Self { +impl From for usize { + fn from(value: OpReturnIndex) -> Self { Self::from(*value) } } -impl From for Pushonlyindex { +impl From for OpReturnIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for Pushonlyindex { +impl Add for OpReturnIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -256,23 +270,23 @@ impl Add for Pushonlyindex { KnownLayout, Serialize, )] -pub struct Unknownindex(Addresstypeindex); -impl From for Unknownindex { - fn from(value: Addresstypeindex) -> Self { +pub struct UnknownOutputIndex(OutputTypeIndex); +impl From for UnknownOutputIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: Unknownindex) -> Self { +impl From for usize { + fn from(value: UnknownOutputIndex) -> Self { Self::from(*value) } } -impl From for Unknownindex { +impl From for UnknownOutputIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for Unknownindex { +impl Add for UnknownOutputIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -296,23 +310,23 @@ impl Add for Unknownindex { KnownLayout, Serialize, )] -pub struct P2PK33index(Addresstypeindex); -impl From for P2PK33index { - fn from(value: Addresstypeindex) -> Self { +pub struct P2PK33Index(OutputTypeIndex); +impl From for P2PK33Index { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2PK33index) -> Self { +impl From for usize { + fn from(value: P2PK33Index) -> Self { Self::from(*value) } } -impl From for P2PK33index { +impl From for P2PK33Index { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2PK33index { +impl Add for P2PK33Index { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -336,23 +350,23 @@ impl Add for P2PK33index { KnownLayout, Serialize, )] -pub struct P2PK65index(Addresstypeindex); -impl From for P2PK65index { - fn from(value: Addresstypeindex) -> Self { +pub struct P2PK65Index(OutputTypeIndex); +impl From for P2PK65Index { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2PK65index) -> Self { +impl From for usize { + fn from(value: P2PK65Index) -> Self { Self::from(*value) } } -impl From for P2PK65index { +impl From for P2PK65Index { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2PK65index { +impl Add for P2PK65Index { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -376,23 +390,23 @@ impl Add for P2PK65index { KnownLayout, Serialize, )] -pub struct P2PKHindex(Addresstypeindex); -impl From for P2PKHindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2PKHIndex(OutputTypeIndex); +impl From for P2PKHIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2PKHindex) -> Self { +impl From for usize { + fn from(value: P2PKHIndex) -> Self { Self::from(*value) } } -impl From for P2PKHindex { +impl From for P2PKHIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2PKHindex { +impl Add for P2PKHIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -416,23 +430,23 @@ impl Add for P2PKHindex { KnownLayout, Serialize, )] -pub struct P2SHindex(Addresstypeindex); -impl From for P2SHindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2SHIndex(OutputTypeIndex); +impl From for P2SHIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2SHindex) -> Self { +impl From for usize { + fn from(value: P2SHIndex) -> Self { Self::from(*value) } } -impl From for P2SHindex { +impl From for P2SHIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2SHindex { +impl Add for P2SHIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -456,23 +470,23 @@ impl Add for P2SHindex { KnownLayout, Serialize, )] -pub struct P2TRindex(Addresstypeindex); -impl From for P2TRindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2TRIndex(OutputTypeIndex); +impl From for P2TRIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2TRindex) -> Self { +impl From for usize { + fn from(value: P2TRIndex) -> Self { Self::from(*value) } } -impl From for P2TRindex { +impl From for P2TRIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2TRindex { +impl Add for P2TRIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -496,23 +510,23 @@ impl Add for P2TRindex { KnownLayout, Serialize, )] -pub struct P2WPKHindex(Addresstypeindex); -impl From for P2WPKHindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2WPKHIndex(OutputTypeIndex); +impl From for P2WPKHIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2WPKHindex) -> Self { +impl From for usize { + fn from(value: P2WPKHIndex) -> Self { Self::from(*value) } } -impl From for P2WPKHindex { +impl From for P2WPKHIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2WPKHindex { +impl Add for P2WPKHIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) @@ -536,23 +550,23 @@ impl Add for P2WPKHindex { KnownLayout, Serialize, )] -pub struct P2WSHindex(Addresstypeindex); -impl From for P2WSHindex { - fn from(value: Addresstypeindex) -> Self { +pub struct P2WSHIndex(OutputTypeIndex); +impl From for P2WSHIndex { + fn from(value: OutputTypeIndex) -> Self { Self(value) } } -impl From for usize { - fn from(value: P2WSHindex) -> Self { +impl From for usize { + fn from(value: P2WSHIndex) -> Self { Self::from(*value) } } -impl From for P2WSHindex { +impl From for P2WSHIndex { fn from(value: usize) -> Self { - Self(Addresstypeindex::from(value)) + Self(OutputTypeIndex::from(value)) } } -impl Add for P2WSHindex { +impl Add for P2WSHIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(*self + rhs) diff --git a/crates/brk_core/src/structs/quarterindex.rs b/crates/brk_core/src/structs/quarterindex.rs index e3b2fbb33..e15726878 100644 --- a/crates/brk_core/src/structs/quarterindex.rs +++ b/crates/brk_core/src/structs/quarterindex.rs @@ -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 for Quarterindex { +impl From for QuarterIndex { fn from(value: u16) -> Self { Self(value) } } -impl From for Quarterindex { +impl From for QuarterIndex { fn from(value: usize) -> Self { Self(value as u16) } } -impl From for usize { - fn from(value: Quarterindex) -> Self { +impl From for usize { + fn from(value: QuarterIndex) -> Self { value.0 as usize } } -impl Add for Quarterindex { +impl Add for QuarterIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,13 +51,13 @@ impl Add for Quarterindex { } } -impl From for Quarterindex { - fn from(value: Monthindex) -> Self { +impl From 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.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/stored_u32.rs b/crates/brk_core/src/structs/stored_u32.rs index 8fb595cc9..bebbafb94 100644 --- a/crates/brk_core/src/structs/stored_u32.rs +++ b/crates/brk_core/src/structs/stored_u32.rs @@ -39,6 +39,9 @@ impl From for StoredU32 { impl From 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 for f64 { value.0 as f64 } } + +impl From for usize { + fn from(value: StoredU32) -> Self { + value.0 as usize + } +} diff --git a/crates/brk_core/src/structs/stored_u64.rs b/crates/brk_core/src/structs/stored_u64.rs index 26b52adfa..93c0b2808 100644 --- a/crates/brk_core/src/structs/stored_u64.rs +++ b/crates/brk_core/src/structs/stored_u64.rs @@ -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 for f64 { } } -impl From for StoredU64 { - fn from(value: Txindex) -> Self { +impl From for StoredU64 { + fn from(value: TxIndex) -> Self { Self(*value as u64) } } -impl From for StoredU64 { - fn from(value: Txinindex) -> Self { +impl From for StoredU64 { + fn from(value: InputIndex) -> Self { Self(*value) } } -impl From for StoredU64 { - fn from(value: Txoutindex) -> Self { +impl From for StoredU64 { + fn from(value: OutputIndex) -> Self { Self(*value) } } diff --git a/crates/brk_core/src/structs/txidprefix.rs b/crates/brk_core/src/structs/txidprefix.rs new file mode 100644 index 000000000..9341b0d10 --- /dev/null +++ b/crates/brk_core/src/structs/txidprefix.rs @@ -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 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 for TxidPrefix { + type Error = Error; + fn try_from(value: ByteView) -> Result { + Ok(Self::read_from_bytes(&value)?) + } +} + +impl From<&TxidPrefix> for ByteView { + fn from(value: &TxidPrefix) -> Self { + Self::new(value.as_bytes()) + } +} + +impl From for ByteView { + fn from(value: TxidPrefix) -> Self { + Self::from(&value) + } +} + +impl From<[u8; 8]> for TxidPrefix { + fn from(value: [u8; 8]) -> Self { + Self(value) + } +} diff --git a/crates/brk_core/src/structs/txindex.rs b/crates/brk_core/src/structs/txindex.rs index 43c6c80cd..5ad4c19a1 100644 --- a/crates/brk_core/src/structs/txindex.rs +++ b/crates/brk_core/src/structs/txindex.rs @@ -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 for Txindex { +impl Add 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 for Txindex { +impl Add for TxIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { Self(self.0 + rhs as u32) } } -impl AddAssign for Txindex { - fn add_assign(&mut self, rhs: Txindex) { +impl AddAssign for TxIndex { + fn add_assign(&mut self, rhs: TxIndex) { self.0 += rhs.0 } } -impl CheckedSub for Txindex { - fn checked_sub(self, rhs: Txindex) -> Option { - self.0.checked_sub(rhs.0).map(Txindex::from) +impl CheckedSub for TxIndex { + fn checked_sub(self, rhs: TxIndex) -> Option { + self.0.checked_sub(rhs.0).map(TxIndex::from) } } -impl From for Txindex { +impl From for TxIndex { fn from(value: u32) -> Self { Self(value) } } -impl From for Txindex { +impl From for TxIndex { fn from(value: u64) -> Self { Self(value as u32) } } -impl From for u64 { - fn from(value: Txindex) -> Self { +impl From for u64 { + fn from(value: TxIndex) -> Self { value.0 as u64 } } -impl From for Txindex { +impl From for TxIndex { fn from(value: usize) -> Self { Self(value as u32) } } -impl From for usize { - fn from(value: Txindex) -> Self { +impl From for usize { + fn from(value: TxIndex) -> Self { value.0 as usize } } -impl TryFrom for Txindex { +impl TryFrom for TxIndex { type Error = Error; fn try_from(value: ByteView) -> Result { Ok(Self::read_from_bytes(&value)?) } } -impl From for ByteView { - fn from(value: Txindex) -> Self { +impl From for ByteView { + fn from(value: TxIndex) -> Self { Self::new(value.as_bytes()) } } -impl From for StoredU32 { - fn from(value: Txindex) -> Self { +impl From for StoredU32 { + fn from(value: TxIndex) -> Self { Self::from(value.0) } } diff --git a/crates/brk_core/src/structs/txversion.rs b/crates/brk_core/src/structs/txversion.rs index 8a271f180..ed649eebe 100644 --- a/crates/brk_core/src/structs/txversion.rs +++ b/crates/brk_core/src/structs/txversion.rs @@ -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 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 for bitcoin::transaction::Version { fn from(value: TxVersion) -> Self { - Self(value.0) + Self(value.0 as i32) } } impl From for StoredU8 { fn from(value: TxVersion) -> Self { - Self::from(value.0 as u8) + Self::from(value.0) } } diff --git a/crates/brk_core/src/structs/weekindex.rs b/crates/brk_core/src/structs/weekindex.rs index 0be61847e..dc7250d5a 100644 --- a/crates/brk_core/src/structs/weekindex.rs +++ b/crates/brk_core/src/structs/weekindex.rs @@ -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 for Weekindex { +impl From for WeekIndex { fn from(value: u16) -> Self { Self(value) } } -impl From for Weekindex { +impl From for WeekIndex { fn from(value: usize) -> Self { Self(value as u16) } } -impl From for usize { - fn from(value: Weekindex) -> Self { +impl From for usize { + fn from(value: WeekIndex) -> Self { value.0 as usize } } -impl Add for Weekindex { +impl Add for WeekIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,13 +51,13 @@ impl Add for Weekindex { } } -impl From for Weekindex { - fn from(value: Dateindex) -> Self { +impl From for WeekIndex { + fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } -impl From for Weekindex { +impl From for WeekIndex { fn from(value: Date) -> Self { let date = jiff::civil::Date::from(value).iso_week_date(); @@ -81,7 +81,7 @@ impl From for Weekindex { } } -impl CheckedSub for Weekindex { +impl CheckedSub for WeekIndex { fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } diff --git a/crates/brk_core/src/structs/weight.rs b/crates/brk_core/src/structs/weight.rs index af8e1d312..a4975ea4a 100644 --- a/crates/brk_core/src/structs/weight.rs +++ b/crates/brk_core/src/structs/weight.rs @@ -19,29 +19,36 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; FromBytes, Serialize, )] -pub struct Weight(u64); +pub struct Weight(u32); impl From 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 for bitcoin::Weight { fn from(value: Weight) -> Self { - Self::from_wu(*value) + Self::from_wu(*value as u64) } } impl From for Weight { fn from(value: usize) -> Self { - Self(value as u64) + if value > u32::MAX as usize { + panic!() + } + Self(value as u32) } } impl From for Weight { fn from(value: f64) -> Self { - Self(value as u64) + Self(value as u32) } } diff --git a/crates/brk_core/src/structs/yearindex.rs b/crates/brk_core/src/structs/yearindex.rs index e82ae04da..3c378a9be 100644 --- a/crates/brk_core/src/structs/yearindex.rs +++ b/crates/brk_core/src/structs/yearindex.rs @@ -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 for Yearindex { +impl From for YearIndex { fn from(value: u8) -> Self { Self(value) } } -impl From for Yearindex { +impl From for YearIndex { fn from(value: usize) -> Self { Self(value as u8) } } -impl From for usize { - fn from(value: Yearindex) -> Self { +impl From for usize { + fn from(value: YearIndex) -> Self { value.0 as usize } } -impl Add for Yearindex { +impl Add for YearIndex { type Output = Self; fn add(self, rhs: usize) -> Self::Output { @@ -51,32 +51,32 @@ impl Add for Yearindex { } } -impl From for Yearindex { - fn from(value: Dateindex) -> Self { +impl From for YearIndex { + fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } -impl From for Yearindex { +impl From for YearIndex { fn from(value: Date) -> Self { Self((value.year() - 2009) as u8) } } -impl From for u16 { - fn from(value: Yearindex) -> Self { +impl From 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.0.checked_sub(rhs.0).map(Self) } } -impl From for Yearindex { - fn from(value: Monthindex) -> Self { +impl From for YearIndex { + fn from(value: MonthIndex) -> Self { Self((usize::from(value) / 12) as u8) } } diff --git a/crates/brk_core/src/utils/bytes.rs b/crates/brk_core/src/utils/bytes.rs new file mode 100644 index 000000000..93d5f6450 --- /dev/null +++ b/crates/brk_core/src/utils/bytes.rs @@ -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) +} diff --git a/crates/brk_core/src/utils/mod.rs b/crates/brk_core/src/utils/mod.rs index 04483c47f..d8fc983a2 100644 --- a/crates/brk_core/src/utils/mod.rs +++ b/crates/brk_core/src/utils/mod.rs @@ -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::*; diff --git a/crates/brk_indexer/examples/main.rs b/crates/brk_indexer/examples/main.rs index 5a5ce1285..616932dcd 100644 --- a/crates/brk_indexer/examples/main.rs +++ b/crates/brk_indexer/examples/main.rs @@ -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()?; diff --git a/crates/brk_indexer/src/indexes.rs b/crates/brk_indexer/src/indexes.rs index 1b3d1e315..5db6370ea 100644 --- a/crates/brk_indexer/src/indexes.rs +++ b/crates/brk_indexer/src/indexes.rs @@ -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("")?, diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index affc2d72c..7285336a6 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -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::>(); + 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::>()); - 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::>(); + 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::>()); + + (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, - Option, + OutputType, + brk_core::Result, + Option, &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 = BTreeMap::new(); + let mut already_added_addressbyteshash: BTreeMap = 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 = BTreeMap::default(); + let mut txindex_to_tx_and_txid: BTreeMap = 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)), } diff --git a/crates/brk_indexer/src/stores/mod.rs b/crates/brk_indexer/src/stores/mod.rs index 8fc5ebf00..2c76ccbfa 100644 --- a/crates/brk_indexer/src/stores/mod.rs +++ b/crates/brk_indexer/src/stores/mod.rs @@ -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, - pub blockhash_prefix_to_height: Store, - pub txid_prefix_to_txindex: Store, + pub addressbyteshash_to_outputtypeindex: Store, + pub blockhashprefix_to_height: Store, + pub txidprefix_to_txindex: Store, } 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 { diff --git a/crates/brk_indexer/src/vecs/mod.rs b/crates/brk_indexer/src/vecs/mod.rs index 439d42d7e..27c8ef058 100644 --- a/crates/brk_indexer/src/vecs/mod.rs +++ b/crates/brk_indexer/src/vecs/mod.rs @@ -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, - pub addressindex_to_addresstypeindex: IndexedVec, - pub addressindex_to_height: IndexedVec, - pub emptyindex_to_height: IndexedVec, + pub emptyoutputindex_to_txindex: IndexedVec, pub height_to_blockhash: IndexedVec, pub height_to_difficulty: IndexedVec, - pub height_to_first_addressindex: IndexedVec, - pub height_to_first_emptyindex: IndexedVec, - pub height_to_first_multisigindex: IndexedVec, - pub height_to_first_opreturnindex: IndexedVec, - pub height_to_first_p2pk33index: IndexedVec, - pub height_to_first_p2pk65index: IndexedVec, - pub height_to_first_p2pkhindex: IndexedVec, - pub height_to_first_p2shindex: IndexedVec, - pub height_to_first_p2trindex: IndexedVec, - pub height_to_first_p2wpkhindex: IndexedVec, - pub height_to_first_p2wshindex: IndexedVec, - pub height_to_first_pushonlyindex: IndexedVec, - pub height_to_first_txindex: IndexedVec, - pub height_to_first_txinindex: IndexedVec, - pub height_to_first_txoutindex: IndexedVec, - pub height_to_first_unknownindex: IndexedVec, - pub height_to_total_size: IndexedVec, + pub height_to_first_emptyoutputindex: IndexedVec, + pub height_to_first_inputindex: IndexedVec, + pub height_to_first_opreturnindex: IndexedVec, + pub height_to_first_outputindex: IndexedVec, + pub height_to_first_p2aindex: IndexedVec, + pub height_to_first_p2msindex: IndexedVec, + pub height_to_first_p2pk33index: IndexedVec, + pub height_to_first_p2pk65index: IndexedVec, + pub height_to_first_p2pkhindex: IndexedVec, + pub height_to_first_p2shindex: IndexedVec, + pub height_to_first_p2trindex: IndexedVec, + pub height_to_first_p2wpkhindex: IndexedVec, + pub height_to_first_p2wshindex: IndexedVec, + pub height_to_first_txindex: IndexedVec, + pub height_to_first_unknownoutputindex: IndexedVec, + /// Doesn't guarantee continuity due to possible reorgs pub height_to_timestamp: IndexedVec, + pub height_to_total_size: IndexedVec, pub height_to_weight: IndexedVec, - pub multisigindex_to_height: IndexedVec, - pub opreturnindex_to_height: IndexedVec, - pub p2pk33index_to_height: IndexedVec, - pub p2pk33index_to_p2pk33addressbytes: IndexedVec, - pub p2pk65index_to_height: IndexedVec, - pub p2pk65index_to_p2pk65addressbytes: IndexedVec, - pub p2pkhindex_to_height: IndexedVec, - pub p2pkhindex_to_p2pkhaddressbytes: IndexedVec, - pub p2shindex_to_height: IndexedVec, - pub p2shindex_to_p2shaddressbytes: IndexedVec, - pub p2trindex_to_height: IndexedVec, - pub p2trindex_to_p2traddressbytes: IndexedVec, - pub p2wpkhindex_to_height: IndexedVec, - pub p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec, - pub p2wshindex_to_height: IndexedVec, - pub p2wshindex_to_p2wshaddressbytes: IndexedVec, - pub pushonlyindex_to_height: IndexedVec, - pub txindex_to_base_size: IndexedVec, - pub txindex_to_first_txinindex: IndexedVec, - pub txindex_to_first_txoutindex: IndexedVec, - pub txindex_to_height: IndexedVec, - pub txindex_to_is_explicitly_rbf: IndexedVec, - pub txindex_to_rawlocktime: IndexedVec, - pub txindex_to_total_size: IndexedVec, - pub txindex_to_txid: IndexedVec, - pub txindex_to_txversion: IndexedVec, - pub txinindex_to_height: IndexedVec, - /// If txoutindex == Txoutindex MAX then is it's coinbase - pub txinindex_to_txoutindex: IndexedVec, - pub txoutindex_to_addressindex: IndexedVec, - pub txoutindex_to_height: IndexedVec, - pub txoutindex_to_value: IndexedVec, - pub unknownindex_to_height: IndexedVec, + /// If outputindex == Outputindex::MAX then it's coinbase + pub inputindex_to_outputindex: IndexedVec, + pub opreturnindex_to_txindex: IndexedVec, + pub outputindex_to_outputtype: IndexedVec, + pub outputindex_to_outputtypeindex: IndexedVec, + pub outputindex_to_value: IndexedVec, + pub p2aindex_to_p2abytes: IndexedVec, + pub p2msindex_to_txindex: IndexedVec, + pub p2pk33index_to_p2pk33bytes: IndexedVec, + pub p2pk65index_to_p2pk65bytes: IndexedVec, + pub p2pkhindex_to_p2pkhbytes: IndexedVec, + pub p2shindex_to_p2shbytes: IndexedVec, + pub p2trindex_to_p2trbytes: IndexedVec, + pub p2wpkhindex_to_p2wpkhbytes: IndexedVec, + pub p2wshindex_to_p2wshbytes: IndexedVec, + pub txindex_to_base_size: IndexedVec, + pub txindex_to_first_inputindex: IndexedVec, + pub txindex_to_first_outputindex: IndexedVec, + pub txindex_to_is_explicitly_rbf: IndexedVec, + pub txindex_to_rawlocktime: IndexedVec, + pub txindex_to_total_size: IndexedVec, + pub txindex_to_txid: IndexedVec, + pub txindex_to_txversion: IndexedVec, + pub unknownoutputindex_to_txindex: IndexedVec, } 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> { - 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> { + 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, ] } } diff --git a/crates/brk_query/src/index.rs b/crates/brk_query/src/index.rs index b2398c9dd..fe823c686 100644 --- a/crates/brk_query/src/index.rs +++ b/crates/brk_query/src/index.rs @@ -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, diff --git a/websites/kibo.money/scripts/main.js b/websites/kibo.money/scripts/main.js index d9e380110..abaaaf61b 100644 --- a/websites/kibo.money/scripts/main.js +++ b/websites/kibo.money/scripts/main.js @@ -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): diff --git a/websites/kibo.money/scripts/table.js b/websites/kibo.money/scripts/table.js index f2f762f35..e6f3092f7 100644 --- a/websites/kibo.money/scripts/table.js +++ b/websites/kibo.money/scripts/table.js @@ -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} 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); } } diff --git a/websites/kibo.money/scripts/vecid-to-indexes.js b/websites/kibo.money/scripts/vecid-to-indexes.js index 8db06cf1c..f6e5d34a9 100644 --- a/websites/kibo.money/scripts/vecid-to-indexes.js +++ b/websites/kibo.money/scripts/vecid-to-indexes.js @@ -20,15 +20,15 @@ /** @typedef {15} P2WPKHindex */ /** @typedef {16} P2WSHindex */ /** @typedef {17} Txindex */ -/** @typedef {18} Txinindex */ -/** @typedef {19} Txoutindex */ +/** @typedef {18} Inputindex */ +/** @typedef {19} Outputindex */ /** @typedef {20} Emptyindex */ -/** @typedef {21} Multisigindex */ +/** @typedef {21} P2MSindex */ /** @typedef {22} Opreturnindex */ /** @typedef {23} Pushonlyindex */ /** @typedef {24} Unknownindex */ -/** @typedef {Height | Dateindex | Weekindex | Difficultyepoch | Monthindex | Quarterindex | Yearindex | Decadeindex | Halvingepoch | Addressindex | P2PK33index | P2PK65index | P2PKHindex | P2SHindex | P2TRindex | P2WPKHindex | P2WSHindex | Txindex | Txinindex | Txoutindex | Emptyindex | Multisigindex | Opreturnindex | Pushonlyindex | Unknownindex} Index */ +/** @typedef {Height | Dateindex | Weekindex | Difficultyepoch | Monthindex | Quarterindex | Yearindex | Decadeindex | Halvingepoch | Addressindex | P2PK33index | P2PK65index | P2PKHindex | P2SHindex | P2TRindex | P2WPKHindex | P2WSHindex | Txindex | Inputindex | Outputindex | Emptyindex | P2MSindex | Opreturnindex | Pushonlyindex | Unknownindex} Index */ export function createVecIdToIndexes() { const Height = /** @satisfies {Height} */ (0); @@ -49,117 +49,422 @@ export function createVecIdToIndexes() { const P2WPKHindex = /** @satisfies {P2WPKHindex} */ (15); const P2WSHindex = /** @satisfies {P2WSHindex} */ (16); const Txindex = /** @satisfies {Txindex} */ (17); - const Txinindex = /** @satisfies {Txinindex} */ (18); - const Txoutindex = /** @satisfies {Txoutindex} */ (19); + const Inputindex = /** @satisfies {Inputindex} */ (18); + const Outputindex = /** @satisfies {Outputindex} */ (19); const Emptyindex = /** @satisfies {Emptyindex} */ (20); - const Multisigindex = /** @satisfies {Multisigindex} */ (21); + const P2MSindex = /** @satisfies {P2MSindex} */ (21); const Opreturnindex = /** @satisfies {Opreturnindex} */ (22); const Pushonlyindex = /** @satisfies {Pushonlyindex} */ (23); const Unknownindex = /** @satisfies {Unknownindex} */ (24); return /** @type {const} */ ({ - addressindex: [Addressindex, Txoutindex], - addresstype: [Addressindex], - addresstypeindex: [Addressindex], + addressindex: [Addressindex, Outputindex], + outputtype: [Addressindex], + outputtypeindex: [Addressindex], "base-size": [Txindex], "block-count": [Height], - "block-count-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "block-count-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "block-interval-10p": [Dateindex], "block-interval-25p": [Dateindex], "block-interval-75p": [Dateindex], "block-interval-90p": [Dateindex], - "block-interval-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "block-interval-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "block-interval-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "block-interval-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "block-interval-median": [Dateindex], - "block-interval-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "block-size-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "block-vbytes-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "block-weight-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "block-interval-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "block-size-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "block-vbytes-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "block-weight-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], blockhash: [Height], - close: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + close: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "close-in-cents": [Dateindex, Height], - "close-in-sats": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "close-in-sats": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], coinbase: [Height], "coinbase-10p": [Dateindex], "coinbase-25p": [Dateindex], "coinbase-75p": [Dateindex], "coinbase-90p": [Dateindex], - "coinbase-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "coinbase-in-btc": [Height], "coinbase-in-btc-10p": [Dateindex], "coinbase-in-btc-25p": [Dateindex], "coinbase-in-btc-75p": [Dateindex], "coinbase-in-btc-90p": [Dateindex], - "coinbase-in-btc-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-in-btc-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-in-btc-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-in-btc-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "coinbase-in-btc-median": [Dateindex], - "coinbase-in-btc-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-in-btc-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-in-btc-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-in-btc-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "coinbase-in-usd": [Height], "coinbase-in-usd-10p": [Dateindex], "coinbase-in-usd-25p": [Dateindex], "coinbase-in-usd-75p": [Dateindex], "coinbase-in-usd-90p": [Dateindex], - "coinbase-in-usd-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-in-usd-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-in-usd-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-in-usd-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "coinbase-in-usd-median": [Dateindex], - "coinbase-in-usd-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-in-usd-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-in-usd-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-in-usd-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "coinbase-median": [Dateindex], - "coinbase-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "coinbase-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "coinbase-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "coinbase-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], date: [Dateindex], dateindex: [Dateindex, Height], decadeindex: [Yearindex, Decadeindex], difficulty: [Height], difficultyepoch: [Height, Difficultyepoch], - emptyindex: [Emptyindex], + emptyoutputindex: [Emptyindex], fee: [Txindex], "fee-10p": [Height], "fee-25p": [Height], "fee-75p": [Height], "fee-90p": [Height], - "fee-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "fee-in-btc": [Txindex], "fee-in-btc-10p": [Height], "fee-in-btc-25p": [Height], "fee-in-btc-75p": [Height], "fee-in-btc-90p": [Height], - "fee-in-btc-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-in-btc-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-in-btc-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-in-btc-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "fee-in-btc-median": [Height], - "fee-in-btc-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-in-btc-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-in-btc-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-in-btc-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "fee-in-usd": [Txindex], "fee-in-usd-10p": [Height], "fee-in-usd-25p": [Height], "fee-in-usd-75p": [Height], "fee-in-usd-90p": [Height], - "fee-in-usd-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-in-usd-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-in-usd-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-in-usd-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "fee-in-usd-median": [Height], - "fee-in-usd-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-in-usd-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-in-usd-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-in-usd-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "fee-median": [Height], - "fee-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "fee-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "fee-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "fee-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], feerate: [Txindex], "feerate-10p": [Height], "feerate-25p": [Height], "feerate-75p": [Height], "feerate-90p": [Height], - "feerate-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "feerate-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "feerate-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "feerate-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "feerate-median": [Height], - "feerate-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "feerate-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "first-addressindex": [Height], "first-dateindex": [Weekindex, Monthindex], - "first-emptyindex": [Height], + "first-emptyoutputindex": [Height], "first-height": [Dateindex, Difficultyepoch, Halvingepoch], "first-monthindex": [Quarterindex, Yearindex], - "first-multisigindex": [Height], + "first-p2msindex": [Height], "first-opreturnindex": [Height], "first-p2pk33index": [Height], "first-p2pk65index": [Height], @@ -170,30 +475,120 @@ export function createVecIdToIndexes() { "first-p2wshindex": [Height], "first-pushonlyindex": [Height], "first-txindex": [Height], - "first-txinindex": [Height, Txindex], - "first-txoutindex": [Height, Txindex], + "first-inputindex": [Height, Txindex], + "first-outputindex": [Height, Txindex], "first-unkownindex": [Height], "first-yearindex": [Decadeindex], "fixed-date": [Height], "fixed-timestamp": [Height], halvingepoch: [Height, Halvingepoch], - height: [Addressindex, Height, P2PK33index, P2PK65index, P2PKHindex, P2SHindex, P2TRindex, P2WPKHindex, P2WSHindex, Txindex, Txinindex, Txoutindex, Emptyindex, Multisigindex, Opreturnindex, Pushonlyindex, Unknownindex], - high: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + height: [ + Addressindex, + Height, + P2PK33index, + P2PK65index, + P2PKHindex, + P2SHindex, + P2TRindex, + P2WPKHindex, + P2WSHindex, + Txindex, + Inputindex, + Outputindex, + Emptyindex, + P2MSindex, + Opreturnindex, + Pushonlyindex, + Unknownindex, + ], + high: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "high-in-cents": [Dateindex, Height], - "high-in-sats": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "high-in-sats": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "input-count": [Txindex], "input-count-10p": [Height], "input-count-25p": [Height], "input-count-75p": [Height], "input-count-90p": [Height], - "input-count-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "input-count-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "input-count-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "input-count-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "input-count-median": [Height], - "input-count-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "input-count-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "input-count-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "input-count-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "input-value": [Txindex], - "input-value-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "input-value-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "input-value-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "input-value-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], interval: [Height], "is-coinbase": [Txindex], "is-explicitly-rbf": [Txindex], @@ -201,35 +596,143 @@ export function createVecIdToIndexes() { "last-height": [Dateindex, Difficultyepoch, Halvingepoch], "last-monthindex": [Quarterindex, Yearindex], "last-txindex": [Height], - "last-txinindex": [Txindex], - "last-txoutindex": [Txindex], + "last-inputindex": [Txindex], + "last-outputindex": [Txindex], "last-yearindex": [Decadeindex], locktime: [Txindex], - low: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + low: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "low-in-cents": [Dateindex, Height], - "low-in-sats": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "low-in-sats": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], monthindex: [Dateindex, Monthindex], - multisigindex: [Multisigindex], - ohlc: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + p2msindex: [P2MSindex], + ohlc: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "ohlc-in-cents": [Dateindex, Height], - "ohlc-in-sats": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - open: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "ohlc-in-sats": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + open: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "open-in-cents": [Dateindex, Height], - "open-in-sats": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "open-in-sats": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], opreturnindex: [Opreturnindex], "output-count": [Txindex], "output-count-10p": [Height], "output-count-25p": [Height], "output-count-75p": [Height], "output-count-90p": [Height], - "output-count-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "output-count-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "output-count-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "output-count-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "output-count-median": [Height], - "output-count-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "output-count-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "output-count-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "output-count-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "output-value": [Txindex], - "output-value-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "output-value-sum": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "output-value-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "output-value-sum": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], p2pk33addressbytes: [P2PK33index], p2pk33index: [P2PK33index], p2pk65addressbytes: [P2PK65index], @@ -252,93 +755,498 @@ export function createVecIdToIndexes() { "subsidy-25p": [Dateindex], "subsidy-75p": [Dateindex], "subsidy-90p": [Dateindex], - "subsidy-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "subsidy-in-btc": [Height], "subsidy-in-btc-10p": [Dateindex], "subsidy-in-btc-25p": [Dateindex], "subsidy-in-btc-75p": [Dateindex], "subsidy-in-btc-90p": [Dateindex], - "subsidy-in-btc-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-in-btc-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-in-btc-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-in-btc-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "subsidy-in-btc-median": [Dateindex], - "subsidy-in-btc-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-in-btc-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-in-btc-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-in-btc-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "subsidy-in-usd": [Height], "subsidy-in-usd-10p": [Dateindex], "subsidy-in-usd-25p": [Dateindex], "subsidy-in-usd-75p": [Dateindex], "subsidy-in-usd-90p": [Dateindex], - "subsidy-in-usd-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-in-usd-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-in-usd-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-in-usd-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "subsidy-in-usd-median": [Dateindex], - "subsidy-in-usd-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-in-usd-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-in-usd-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-in-usd-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "subsidy-median": [Dateindex], - "subsidy-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "subsidy-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - timestamp: [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch, Halvingepoch], - "total-block-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-block-size": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-block-vbytes": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-block-weight": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-coinbase": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-coinbase-in-btc": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-coinbase-in-usd": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-fee": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-fee-in-btc": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-fee-in-usd": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-input-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-input-value": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-output-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-output-value": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "subsidy-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "subsidy-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + timestamp: [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + Halvingepoch, + ], + "total-block-count": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-block-size": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-block-vbytes": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-block-weight": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-coinbase": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-coinbase-in-btc": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-coinbase-in-usd": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-fee": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-fee-in-btc": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-fee-in-usd": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-input-count": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-input-value": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-output-count": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-output-value": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "total-size": [Height, Txindex], - "total-subsidy": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-subsidy-in-btc": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-subsidy-in-usd": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-tx-count": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-tx-v1": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-tx-v2": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "total-tx-v3": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "total-subsidy": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-subsidy-in-btc": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-subsidy-in-usd": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-tx-count": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-tx-v1": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-tx-v2": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "total-tx-v3": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-count": [Height], "tx-count-10p": [Dateindex], "tx-count-25p": [Dateindex], "tx-count-75p": [Dateindex], "tx-count-90p": [Dateindex], - "tx-count-average": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "tx-count-max": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-count-average": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "tx-count-max": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-count-median": [Dateindex], - "tx-count-min": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "tx-count-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-count-min": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "tx-count-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-v1": [Height], - "tx-v1-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-v1-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-v2": [Height], - "tx-v2-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-v2-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-v3": [Height], - "tx-v3-sum": [Dateindex, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-v3-sum": [ + Dateindex, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-vsize-10p": [Height], "tx-vsize-25p": [Height], "tx-vsize-75p": [Height], "tx-vsize-90p": [Height], - "tx-vsize-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "tx-vsize-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-vsize-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "tx-vsize-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-vsize-median": [Height], - "tx-vsize-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-vsize-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-weight-10p": [Height], "tx-weight-25p": [Height], "tx-weight-75p": [Height], "tx-weight-90p": [Height], - "tx-weight-average": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], - "tx-weight-max": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-weight-average": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], + "tx-weight-max": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], "tx-weight-median": [Height], - "tx-weight-min": [Dateindex, Height, Weekindex, Monthindex, Quarterindex, Yearindex, Decadeindex, Difficultyepoch], + "tx-weight-min": [ + Dateindex, + Height, + Weekindex, + Monthindex, + Quarterindex, + Yearindex, + Decadeindex, + Difficultyepoch, + ], txid: [Txindex], txindex: [Txindex], - txinindex: [Txinindex], - txoutindex: [Txinindex, Txoutindex], + inputindex: [Inputindex], + outputindex: [Inputindex, Outputindex], txversion: [Txindex], - unknownindex: [Unknownindex], - value: [Txinindex, Txoutindex], + unknownoutputindex: [Unknownindex], + value: [Inputindex, Outputindex], vbytes: [Height], vsize: [Txindex], weekindex: [Dateindex, Weekindex],