global: snapshot

This commit is contained in:
nym21
2025-09-03 18:17:25 +02:00
parent 1c2afd14dd
commit 3359dfcc29
55 changed files with 3213 additions and 2769 deletions

1
.gitignore vendored
View File

@@ -5,6 +5,7 @@
target
websites/dist
vecid-to-indexes.js
/ids.txt
# Copies
*\ copy*

123
Cargo.lock generated
View File

@@ -451,9 +451,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.9.3"
version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
dependencies = [
"serde",
]
@@ -608,6 +608,7 @@ dependencies = [
"brk_indexer",
"brk_structs",
"derive_deref",
"nucleo-matcher",
"schemars 1.0.4",
"serde",
"serde_json",
@@ -703,7 +704,7 @@ dependencies = [
"anyhow",
"append-only-vec",
"arcstr",
"bitflags 2.9.3",
"bitflags 2.9.4",
"brk_rolldown_common",
"brk_rolldown_debug",
"brk_rolldown_ecmascript",
@@ -752,7 +753,7 @@ checksum = "23cd66173b33436aaec126f64e8f1d0938539d2eb934e88c633cf6181f7e4c53"
dependencies = [
"anyhow",
"arcstr",
"bitflags 2.9.3",
"bitflags 2.9.4",
"brk_rolldown_ecmascript",
"brk_rolldown_error",
"brk_rolldown_fs",
@@ -834,7 +835,7 @@ checksum = "9fd007c612609bcf46e3dca4f9f3c79d16dc1f0bdf7cd0047bfe752fbc6fbecc"
dependencies = [
"anyhow",
"arcstr",
"bitflags 2.9.3",
"bitflags 2.9.4",
"brk_rolldown_utils",
"derive_more",
"heck",
@@ -865,7 +866,7 @@ dependencies = [
"anyhow",
"arcstr",
"async-trait",
"bitflags 2.9.3",
"bitflags 2.9.4",
"brk_rolldown_common",
"brk_rolldown_debug",
"brk_rolldown_ecmascript",
@@ -1144,10 +1145,11 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.34"
version = "1.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc"
checksum = "590f9024a68a8c40351881787f1934dc11afd69090f5edb6831464694d836ea3"
dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex",
@@ -1193,18 +1195,18 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.46"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57"
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.46"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41"
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
dependencies = [
"anstream",
"anstyle",
@@ -1214,9 +1216,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.45"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6"
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
dependencies = [
"heck",
"proc-macro2",
@@ -1551,9 +1553,9 @@ dependencies = [
[[package]]
name = "deranged"
version = "0.4.0"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
checksum = "d630bccd429a5bb5a64b5e94f693bfc48c9f8566418fda4c494cc94f911f87cc"
dependencies = [
"powerfmt",
"serde",
@@ -1764,6 +1766,12 @@ dependencies = [
"windows-sys 0.60.2",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e178e4fba8a2726903f6ba98a6d221e76f9c12c650d5dc0e6afdc50677b49650"
[[package]]
name = "fixedbitset"
version = "0.5.7"
@@ -2285,7 +2293,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"inotify-sys",
"libc",
]
@@ -2314,7 +2322,7 @@ version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"cfg-if",
"libc",
]
@@ -2460,16 +2468,16 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"libc",
"redox_syscall",
]
[[package]]
name = "libz-rs-sys"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "172a788537a2221661b480fee8dc5f96c580eb34fa88764d3205dc356c7e4221"
checksum = "840db8cf39d9ec4dd794376f38acc40d0fc65eec2a8f484f7fd375b84602becd"
dependencies = [
"zlib-rs",
]
@@ -2609,7 +2617,7 @@ version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"cfg-if",
"cfg_aliases",
"libc",
@@ -2636,7 +2644,7 @@ version = "8.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"fsevent-sys",
"inotify",
"kqueue",
@@ -2663,6 +2671,16 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "nucleo-matcher"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf33f538733d1a5a3494b836ba913207f14d9d4a1d3cd67030c5061bdd2cac85"
dependencies = [
"memchr",
"unicode-segmentation",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
@@ -2816,7 +2834,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "989b81258ce151e23adee6f1393f7c0fb7e10e3a6c6c001f71bbaff4081c72a4"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"oxc_allocator",
"oxc_ast_macros",
"oxc_data_structures",
@@ -2857,7 +2875,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5361ef66f38635d9671596d83abf44bcdbc3e39dbff303f3517828b86ad60e8f"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"itertools",
"nonmax",
"oxc_index",
@@ -2872,7 +2890,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde8fc6f7337632fce3e9e51c150f57fb0ef234524c6947f63e8009e1ea613cf"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"cow-utils",
"dragonbox_ecma",
"nonmax",
@@ -2950,7 +2968,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83d8c311d64fa0bf8cab1bde3f7760cd828e71ed483ca0878799f1f72542cb4d"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"oxc_allocator",
"oxc_ast",
"oxc_ast_visit",
@@ -3005,7 +3023,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70253728183a5a92d1ba964d9952201e0269ebd07c4917c4553283d564225bab"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"cow-utils",
"memchr",
"num-bigint",
@@ -3028,7 +3046,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de5bb2ed6646bb7815126e0f36787c349e13561fed2c05f95b27a1f82dd066c4"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"oxc_allocator",
"oxc_ast_macros",
"oxc_diagnostics",
@@ -3113,7 +3131,7 @@ version = "0.81.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72d9d80d47d2eee5c1e6dbcdf1841b42afc4f1cd1f63701fc346162616dac52f"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"cow-utils",
"dragonbox_ecma",
"nonmax",
@@ -3621,7 +3639,7 @@ version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
]
[[package]]
@@ -3735,7 +3753,7 @@ version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [
"bitflags 2.9.3",
"bitflags 2.9.4",
"errno",
"libc",
"linux-raw-sys",
@@ -3884,9 +3902,9 @@ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
[[package]]
name = "seqdb"
version = "0.2.5"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54ab988c96efa9d275ca2b12bf2d3c6adec993b8e82ea31a88c984abdaa14fa"
checksum = "ade192d6f8a1e58c43428c8e194016124f20744f75cb14e2fcc0c79309fe4f91"
dependencies = [
"libc",
"log",
@@ -4290,12 +4308,11 @@ dependencies = [
[[package]]
name = "time"
version = "0.3.41"
version = "0.3.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
checksum = "83bde6f1ec10e72d583d91623c939f623002284ef622b87de38cfd546cbf2031"
dependencies = [
"deranged",
"itoa",
"num-conv",
"powerfmt",
"serde",
@@ -4305,15 +4322,15 @@ dependencies = [
[[package]]
name = "time-core"
version = "0.1.4"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
[[package]]
name = "time-macros"
version = "0.2.22"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3"
dependencies = [
"num-conv",
"time-core",
@@ -4444,7 +4461,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
dependencies = [
"async-compression",
"bitflags 2.9.3",
"bitflags 2.9.4",
"bytes",
"futures-core",
"http",
@@ -4616,6 +4633,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-segmentation"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-width"
version = "0.2.1"
@@ -4672,9 +4695,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.18.0"
version = "1.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be"
checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2"
dependencies = [
"getrandom 0.3.3",
"js-sys",
@@ -4712,9 +4735,9 @@ checksum = "8f54a172d0620933a27a4360d3db3e2ae0dd6cceae9730751a036bbf182c4b23"
[[package]]
name = "vecdb"
version = "0.2.5"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5c4ec34c376be3a41435eeb7672d0ea0e9c1d60c5d1d90218912588f91abea"
checksum = "5c3e103eeb634851690d815a886ba8fe1ab21d2f520d915c411979bc76de8419"
dependencies = [
"ctrlc",
"log",
@@ -4732,9 +4755,9 @@ dependencies = [
[[package]]
name = "vecdb_derive"
version = "0.2.5"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "778c4874c05822465e28cae6a7dead593a73124ec80afb85b85adae5ac883368"
checksum = "6bdf71ae8eeaf2f187cee599e8e34a49bf6fd0536977bd009d94be35e3801754"
dependencies = [
"quote",
"syn 2.0.106",
@@ -5224,9 +5247,9 @@ dependencies = [
[[package]]
name = "zlib-rs"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626bd9fa9734751fc50d6060752170984d7053f5a39061f524cda68023d4db8a"
checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2"
[[package]]
name = "zopfli"

View File

@@ -53,7 +53,7 @@ serde_derive = "1.0.219"
serde_json = { version = "1.0.143", features = ["float_roundtrip"] }
tokio = { version = "1.47.1", features = ["rt-multi-thread"] }
# vecdb = { path = "../seqdb/crates/vecdb", features = ["derive"]}
vecdb = { version = "0.2.5", features = ["derive"]}
vecdb = { version = "0.2.9", features = ["derive"]}
zerocopy = "0.8.26"
zerocopy-derive = "0.8.26"

View File

@@ -17,7 +17,7 @@
<a href="https://deps.rs/crate/brk">
<img src="https://deps.rs/crate/brk/latest/status.svg" alt="Dependency status">
</a>
<a href="https://discord.gg/HaR3wpH3nr">
<a href="https://discord.gg/WACpShCB7M">
<img src="https://img.shields.io/discord/1350431684562124850?label=discord" alt="Discord" />
</a>
<a href="https://primal.net/p/nprofile1qqsfw5dacngjlahye34krvgz7u0yghhjgk7gxzl5ptm9v6n2y3sn03sqxu2e6">
@@ -92,7 +92,3 @@ Heartfelt thanks go out to every donor on [Nostr](https://primal.net/p/npub1jagm
## Donate
[`bc1q09 8zsm89 m7kgyz e338vf ejhpdt 92ua9p 3peuve`](bitcoin:bc1q098zsm89m7kgyze338vfejhpdt92ua9p3peuve)
[`lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhkxmmww3jkuar8d35kgetj8yuq363hv4`](lightning:lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhkxmmww3jkuar8d35kgetj8yuq363hv4)
[Geyser Fund](https://geyser.fund/project/brk)

View File

@@ -20,8 +20,8 @@ brk_logger = { workspace = true }
brk_parser = { workspace = true }
brk_server = { workspace = true }
vecdb = { workspace = true }
clap = { version = "4.5.46", features = ["string"] }
clap_derive = "4.5.45"
clap = { version = "4.5.47", features = ["string"] }
clap_derive = "4.5.47"
color-eyre = "0.6.5"
log = { workspace = true }
minreq = { workspace = true }

View File

@@ -288,7 +288,7 @@ impl Vecs {
let txindex_to_fee_rate =
EagerVec::forced_import_compressed(&db, "fee_rate", version + VERSION + Version::ZERO)?;
Ok(Self {
let this = Self {
height_to_interval: EagerVec::forced_import_compressed(
&db,
"interval",
@@ -804,7 +804,16 @@ impl Vecs {
txindex_to_weight,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

View File

@@ -43,7 +43,7 @@ pub struct Vecs {
pub indexes_to_cointime_price: ComputedVecsFromHeight<Dollars>,
pub indexes_to_cointime_cap: ComputedVecsFromHeight<Dollars>,
pub indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex,
// pub indexes_to_thermo_cap_relative_to_investor_cap: ComputedValueVecsFromHeight,
// pub indexes_to_thermo_cap_rel_to_investor_cap: ComputedValueVecsFromHeight,
}
impl Vecs {
@@ -58,7 +58,7 @@ impl Vecs {
let compute_dollars = price.is_some();
Ok(Self {
let this = Self {
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
&db,
"coinblocks_created",
@@ -247,7 +247,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
#[allow(clippy::too_many_arguments)]
@@ -597,7 +606,7 @@ impl Vecs {
// The price taken won't be correct for time based indexes
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
indexes_to_coinblocks_destroyed.height.as_ref().unwrap(),
exit,
)?;
@@ -613,7 +622,7 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
self.indexes_to_coinblocks_created.height.as_ref().unwrap(),
exit,
)?;
@@ -629,7 +638,7 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
self.indexes_to_coinblocks_stored.height.as_ref().unwrap(),
exit,
)?;

View File

@@ -38,7 +38,7 @@ impl Vecs {
pub fn forced_import(parent: &Path, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
let db = Database::open(&parent.join("constants"))?;
Ok(Self {
let this = Self {
constant_0: ComputedVecsFromHeight::forced_import(
&db,
"constant_0",
@@ -145,7 +145,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

View File

@@ -16,30 +16,39 @@ pub struct Vecs {
db: Database,
fetcher: Fetcher,
pub dateindex_to_ohlc_in_cents: RawVec<DateIndex, OHLCCents>,
pub height_to_ohlc_in_cents: RawVec<Height, OHLCCents>,
pub dateindex_to_price_ohlc_in_cents: RawVec<DateIndex, OHLCCents>,
pub height_to_price_ohlc_in_cents: RawVec<Height, OHLCCents>,
}
impl Vecs {
pub fn forced_import(parent: &Path, fetcher: Fetcher, version: Version) -> Result<Self> {
let db = Database::open(&parent.join("fetched"))?;
Ok(Self {
let this = Self {
fetcher,
dateindex_to_ohlc_in_cents: RawVec::forced_import(
dateindex_to_price_ohlc_in_cents: RawVec::forced_import(
&db,
"ohlc_in_cents",
"price_ohlc_in_cents",
version + Version::ZERO,
)?,
height_to_ohlc_in_cents: RawVec::forced_import(
height_to_price_ohlc_in_cents: RawVec::forced_import(
&db,
"ohlc_in_cents",
"price_ohlc_in_cents",
version + Version::ZERO,
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(
@@ -64,12 +73,12 @@ impl Vecs {
let height_to_timestamp = &indexer.vecs.height_to_timestamp;
let index = starting_indexes
.height
.min(Height::from(self.height_to_ohlc_in_cents.len()));
.min(Height::from(self.height_to_price_ohlc_in_cents.len()));
height_to_timestamp
.iter_at(index)
.try_for_each(|(i, v)| -> Result<()> {
let v = v.into_owned();
self.height_to_ohlc_in_cents.forced_push_at(
self.height_to_price_ohlc_in_cents.forced_push_at(
i,
self.fetcher
.get_height(
@@ -84,11 +93,11 @@ impl Vecs {
)?;
Ok(())
})?;
self.height_to_ohlc_in_cents.safe_flush(exit)?;
self.height_to_price_ohlc_in_cents.safe_flush(exit)?;
let index = starting_indexes
.dateindex
.min(DateIndex::from(self.dateindex_to_ohlc_in_cents.len()));
.min(DateIndex::from(self.dateindex_to_price_ohlc_in_cents.len()));
let mut prev = None;
indexes
.dateindex_to_date
@@ -98,7 +107,7 @@ impl Vecs {
if prev.is_none() {
let i = i.unwrap_to_usize();
prev.replace(if i > 0 {
self.dateindex_to_ohlc_in_cents
self.dateindex_to_price_ohlc_in_cents
.into_iter()
.unwrap_get_inner_(i - 1)
} else {
@@ -106,7 +115,8 @@ impl Vecs {
});
}
let ohlc = if i.unwrap_to_usize() + 100 >= self.dateindex_to_ohlc_in_cents.len()
let ohlc = if i.unwrap_to_usize() + 100
>= self.dateindex_to_price_ohlc_in_cents.len()
&& let Ok(mut ohlc) = self.fetcher.get_date(d)
{
let prev_open = *prev.as_ref().unwrap().close;
@@ -120,20 +130,20 @@ impl Vecs {
prev.replace(ohlc.clone());
self.dateindex_to_ohlc_in_cents
self.dateindex_to_price_ohlc_in_cents
.forced_push_at(i, ohlc, exit)?;
Ok(())
})?;
self.dateindex_to_ohlc_in_cents.safe_flush(exit)?;
self.dateindex_to_price_ohlc_in_cents.safe_flush(exit)?;
Ok(())
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
vec![
&self.dateindex_to_ohlc_in_cents as &dyn AnyCollectableVec,
&self.height_to_ohlc_in_cents,
&self.dateindex_to_price_ohlc_in_cents as &dyn AnyCollectableVec,
&self.height_to_price_ohlc_in_cents,
]
}
}

View File

@@ -144,7 +144,7 @@ where
Box::new(
EagerVec::forced_import(
db,
&suffix("cum"),
&suffix("cumulative"),
version + VERSION + Version::ZERO,
format,
)

View File

@@ -197,7 +197,7 @@ where
}),
cumulative: options.cumulative.then(|| {
Box::new(LazyVecFrom2::init(
&suffix("cum"),
&suffix("cumulative"),
version + VERSION + Version::ZERO,
source_extra.cumulative.as_ref().unwrap().boxed_clone(),
len_source.clone(),

View File

@@ -447,7 +447,7 @@ impl ComputedVecsFromTxindex<Dollars> {
let starting_index = self.height.starting_index(starting_indexes.height);
let mut close_iter = price.chainindexes_to_close.height.into_iter();
let mut close_iter = price.chainindexes_to_price_close.height.into_iter();
(starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len())
.map(Height::from)

View File

@@ -22,18 +22,18 @@ pub struct ComputedRatioVecsFromDateIndex {
pub ratio: ComputedVecsFromDateIndex<StoredF32>,
pub ratio_1w_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_1m_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p99: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p98: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p95: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p5: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p2: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p1: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p99_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p98_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p95_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p5_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p2_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p1_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct99: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct98: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct95: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct5: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct2: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct1: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct99_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct98_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct95_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct5_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct2_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct1_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
pub ratio_4y_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
@@ -141,10 +141,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p99: extended.then(|| {
ratio_pct99: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p99"),
&format!("{name}_ratio_pct99"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -152,10 +152,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p98: extended.then(|| {
ratio_pct98: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p98"),
&format!("{name}_ratio_pct98"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -163,10 +163,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p95: extended.then(|| {
ratio_pct95: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p95"),
&format!("{name}_ratio_pct95"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -174,10 +174,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p5: extended.then(|| {
ratio_pct5: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p5"),
&format!("{name}_ratio_pct5"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -185,10 +185,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p2: extended.then(|| {
ratio_pct2: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p2"),
&format!("{name}_ratio_pct2"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -196,10 +196,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p1: extended.then(|| {
ratio_pct1: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p1"),
&format!("{name}_ratio_pct1"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -207,10 +207,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p99_as_price: extended.then(|| {
ratio_pct99_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p99_as_price"),
&format!("{name}_ratio_pct99_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -218,10 +218,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p98_as_price: extended.then(|| {
ratio_pct98_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p98_as_price"),
&format!("{name}_ratio_pct98_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -229,10 +229,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p95_as_price: extended.then(|| {
ratio_pct95_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p95_as_price"),
&format!("{name}_ratio_pct95_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -240,10 +240,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p5_as_price: extended.then(|| {
ratio_pct5_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p5_as_price"),
&format!("{name}_ratio_pct5_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -251,10 +251,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p2_as_price: extended.then(|| {
ratio_pct2_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p2_as_price"),
&format!("{name}_ratio_pct2_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -262,10 +262,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p1_as_price: extended.then(|| {
ratio_pct1_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p1_as_price"),
&format!("{name}_ratio_pct1_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -322,7 +322,7 @@ impl ComputedRatioVecsFromDateIndex {
exit: &Exit,
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let closes = price.timeindexes_to_close.dateindex.as_ref().unwrap();
let closes = price.timeindexes_to_price_close.dateindex.as_ref().unwrap();
let price = price_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
@@ -423,42 +423,42 @@ impl ComputedRatioVecsFromDateIndex {
.iter_at(starting_dateindex)
.try_for_each(|(index, ratio)| -> Result<()> {
if index < min_ratio_date {
self.ratio_p5
self.ratio_pct5
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p2
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p1
self.ratio_pct1
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p95
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p98
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p99
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
@@ -470,42 +470,42 @@ impl ComputedRatioVecsFromDateIndex {
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
sorted.insert(pos, ratio);
self.ratio_p1
self.ratio_pct1
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.01), exit)?;
self.ratio_p2
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.02), exit)?;
self.ratio_p5
self.ratio_pct5
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.05), exit)?;
self.ratio_p95
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.95), exit)?;
self.ratio_p98
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.98), exit)?;
self.ratio_p99
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
@@ -521,32 +521,32 @@ impl ComputedRatioVecsFromDateIndex {
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
self.ratio_p1.as_mut().unwrap().compute_rest(
self.ratio_pct1.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p2.as_mut().unwrap().compute_rest(
self.ratio_pct2.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p5.as_mut().unwrap().compute_rest(
self.ratio_pct5.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p95.as_mut().unwrap().compute_rest(
self.ratio_pct95.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p98.as_mut().unwrap().compute_rest(
self.ratio_pct98.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p99.as_mut().unwrap().compute_rest(
self.ratio_pct99.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
@@ -556,14 +556,14 @@ impl ComputedRatioVecsFromDateIndex {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
});
self.ratio_p99_as_price.as_mut().unwrap().compute_all(
self.ratio_pct99_in_usd.as_mut().unwrap().compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
let mut iter = self
.ratio_p99
.ratio_pct99
.as_ref()
.unwrap()
.dateindex
@@ -583,10 +583,10 @@ impl ComputedRatioVecsFromDateIndex {
},
)?;
let compute_as_price =
|as_price: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
let compute_in_usd =
|in_usd: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
source: Option<&ComputedVecsFromDateIndex<StoredF32>>| {
as_price.unwrap().compute_all(
in_usd.unwrap().compute_all(
indexer,
indexes,
starting_indexes,
@@ -607,12 +607,12 @@ impl ComputedRatioVecsFromDateIndex {
)
};
compute_as_price(self.ratio_p1_as_price.as_mut(), self.ratio_p1.as_ref())?;
compute_as_price(self.ratio_p2_as_price.as_mut(), self.ratio_p2.as_ref())?;
compute_as_price(self.ratio_p5_as_price.as_mut(), self.ratio_p5.as_ref())?;
compute_as_price(self.ratio_p95_as_price.as_mut(), self.ratio_p95.as_ref())?;
compute_as_price(self.ratio_p98_as_price.as_mut(), self.ratio_p98.as_ref())?;
compute_as_price(self.ratio_p99_as_price.as_mut(), self.ratio_p99.as_ref())?;
compute_in_usd(self.ratio_pct1_in_usd.as_mut(), self.ratio_pct1.as_ref())?;
compute_in_usd(self.ratio_pct2_in_usd.as_mut(), self.ratio_pct2.as_ref())?;
compute_in_usd(self.ratio_pct5_in_usd.as_mut(), self.ratio_pct5.as_ref())?;
compute_in_usd(self.ratio_pct95_in_usd.as_mut(), self.ratio_pct95.as_ref())?;
compute_in_usd(self.ratio_pct98_in_usd.as_mut(), self.ratio_pct98.as_ref())?;
compute_in_usd(self.ratio_pct99_in_usd.as_mut(), self.ratio_pct99.as_ref())?;
self.ratio_sd.as_mut().unwrap().compute_all(
indexer,
@@ -652,22 +652,22 @@ impl ComputedRatioVecsFromDateIndex {
fn mut_ratio_vecs(&mut self) -> Vec<&mut EagerVec<DateIndex, StoredF32>> {
[
self.ratio_p1
self.ratio_pct1
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p2
self.ratio_pct2
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p5
self.ratio_pct5
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p95
self.ratio_pct95
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p98
self.ratio_pct98
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p99
self.ratio_pct99
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
]
@@ -686,22 +686,22 @@ impl ComputedRatioVecsFromDateIndex {
self.ratio_1y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_2y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_4y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p1.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p2.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p5.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p95.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p98.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p99.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p1_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p2_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p5_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p95_as_price
self.ratio_pct1.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct2.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct5.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct95.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct98.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct99.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct1_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct2_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct5_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct95_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.ratio_p98_as_price
self.ratio_pct98_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.ratio_p99_as_price
self.ratio_pct99_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
]

View File

@@ -16,7 +16,7 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
pub sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub sd: ComputedVecsFromDateIndex<StoredF32>,
pub _0sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub _0sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p0_5sd: ComputedVecsFromDateIndex<StoredF32>,
pub p1sd: ComputedVecsFromDateIndex<StoredF32>,
pub p1_5sd: ComputedVecsFromDateIndex<StoredF32>,
@@ -29,18 +29,18 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
pub m2sd: ComputedVecsFromDateIndex<StoredF32>,
pub m2_5sd: ComputedVecsFromDateIndex<StoredF32>,
pub m3sd: ComputedVecsFromDateIndex<StoredF32>,
pub p0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub zscore: ComputedVecsFromDateIndex<StoredF32>,
}
@@ -175,105 +175,105 @@ impl ComputedStandardDeviationVecsFromDateIndex {
indexes,
options,
)?,
_0sd_as_price: ComputedVecsFromDateIndex::forced_import(
_0sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_0sd_as_price"),
&format!("{name}_0sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p0_5sd_as_price"),
&format!("{name}_p0_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
p1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p1sd_as_price"),
&format!("{name}_p1sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p1_5sd_as_price"),
&format!("{name}_p1_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
p2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p2sd_as_price"),
&format!("{name}_p2sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p2_5sd_as_price"),
&format!("{name}_p2_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
p3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p3sd_as_price"),
&format!("{name}_p3sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m0_5sd_as_price"),
&format!("{name}_m0_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
m1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m1sd_as_price"),
&format!("{name}_m1sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m1_5sd_as_price"),
&format!("{name}_m1_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
m2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m2sd_as_price"),
&format!("{name}_m2sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m2_5sd_as_price"),
&format!("{name}_m2_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
m3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m3sd_as_price"),
&format!("{name}_m3sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -297,7 +297,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
starting_indexes: &Indexes,
exit: &Exit,
source: &impl CollectableVec<DateIndex, StoredF32>,
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let min_date = DateIndex::try_from(Date::MIN_RATIO).unwrap();
@@ -326,7 +326,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
exit,
sma_opt,
source,
source_as_price,
source_in_usd,
)
}
@@ -339,7 +339,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
exit: &Exit,
sma_opt: Option<&impl AnyIterableVec<DateIndex, StoredF32>>,
source: &impl CollectableVec<DateIndex, StoredF32>,
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let sma = sma_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.sma.as_ref().unwrap().dateindex)
@@ -571,14 +571,14 @@ impl ComputedStandardDeviationVecsFromDateIndex {
},
)?;
let Some(price) = source_as_price else {
let Some(price) = source_in_usd else {
return Ok(());
};
let compute_as_price =
|as_price: &mut ComputedVecsFromDateIndex<Dollars>,
let compute_in_usd =
|in_usd: &mut ComputedVecsFromDateIndex<Dollars>,
mut iter: BoxedVecIterator<DateIndex, StoredF32>| {
as_price.compute_all(
in_usd.compute_all(
indexer,
indexes,
starting_indexes,
@@ -598,53 +598,53 @@ impl ComputedStandardDeviationVecsFromDateIndex {
)
};
compute_as_price(&mut self._0sd_as_price, sma.iter())?;
compute_as_price(
&mut self.p0_5sd_as_price,
compute_in_usd(&mut self._0sd_in_usd, sma.iter())?;
compute_in_usd(
&mut self.p0_5sd_in_usd,
self.p0_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p1sd_as_price,
compute_in_usd(
&mut self.p1sd_in_usd,
self.p1sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p1_5sd_as_price,
compute_in_usd(
&mut self.p1_5sd_in_usd,
self.p1_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p2sd_as_price,
compute_in_usd(
&mut self.p2sd_in_usd,
self.p2sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p2_5sd_as_price,
compute_in_usd(
&mut self.p2_5sd_in_usd,
self.p2_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p3sd_as_price,
compute_in_usd(
&mut self.p3sd_in_usd,
self.p3sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m0_5sd_as_price,
compute_in_usd(
&mut self.m0_5sd_in_usd,
self.m0_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m1sd_as_price,
compute_in_usd(
&mut self.m1sd_in_usd,
self.m1sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m1_5sd_as_price,
compute_in_usd(
&mut self.m1_5sd_in_usd,
self.m1_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m2sd_as_price,
compute_in_usd(
&mut self.m2sd_in_usd,
self.m2sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m2_5sd_as_price,
compute_in_usd(
&mut self.m2_5sd_in_usd,
self.m2_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m3sd_as_price,
compute_in_usd(
&mut self.m3sd_in_usd,
self.m3sd.dateindex.as_ref().unwrap().iter(),
)?;
@@ -685,19 +685,19 @@ impl ComputedStandardDeviationVecsFromDateIndex {
self.m2sd.vecs(),
self.m2_5sd.vecs(),
self.m3sd.vecs(),
self._0sd_as_price.vecs(),
self.p0_5sd_as_price.vecs(),
self.p1sd_as_price.vecs(),
self.p1_5sd_as_price.vecs(),
self.p2sd_as_price.vecs(),
self.p2_5sd_as_price.vecs(),
self.p3sd_as_price.vecs(),
self.m0_5sd_as_price.vecs(),
self.m1sd_as_price.vecs(),
self.m1_5sd_as_price.vecs(),
self.m2sd_as_price.vecs(),
self.m2_5sd_as_price.vecs(),
self.m3sd_as_price.vecs(),
self._0sd_in_usd.vecs(),
self.p0_5sd_in_usd.vecs(),
self.p1sd_in_usd.vecs(),
self.p1_5sd_in_usd.vecs(),
self.p2sd_in_usd.vecs(),
self.p2_5sd_in_usd.vecs(),
self.p3sd_in_usd.vecs(),
self.m0_5sd_in_usd.vecs(),
self.m1sd_in_usd.vecs(),
self.m1_5sd_in_usd.vecs(),
self.m2sd_in_usd.vecs(),
self.m2_5sd_in_usd.vecs(),
self.m3sd_in_usd.vecs(),
self.zscore.vecs(),
]
.into_iter()

View File

@@ -138,10 +138,10 @@ impl ComputedValueVecsFromDateIndex {
}
let dateindex_to_bitcoin = self.bitcoin.dateindex.as_ref().unwrap();
let dateindex_to_close = price
let dateindex_to_price_close = price
.as_ref()
.unwrap()
.timeindexes_to_close
.timeindexes_to_price_close
.dateindex
.as_ref()
.unwrap();
@@ -156,7 +156,7 @@ impl ComputedValueVecsFromDateIndex {
v.compute_from_bitcoin(
starting_indexes.dateindex,
dateindex_to_bitcoin,
dateindex_to_close,
dateindex_to_price_close,
exit,
)
},

View File

@@ -139,7 +139,7 @@ impl ComputedValueVecsFromHeight {
}
let height_to_bitcoin = self.bitcoin.height.as_ref().unwrap();
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
if let Some(dollars) = self.dollars.as_mut() {
dollars.compute_all(
@@ -151,7 +151,7 @@ impl ComputedValueVecsFromHeight {
v.compute_from_bitcoin(
starting_indexes.height,
height_to_bitcoin,
height_to_close,
height_to_price_close,
exit,
)
},

View File

@@ -78,23 +78,25 @@ impl ComputedValueVecsFromTxindex {
version + VERSION,
bitcoin_txindex.boxed_clone(),
indexes.txindex_to_height.boxed_clone(),
price.chainindexes_to_close.height.boxed_clone(),
price.chainindexes_to_price_close.height.boxed_clone(),
|txindex: TxIndex,
txindex_to_btc_iter,
txindex_to_in_btc_iter,
txindex_to_height_iter,
height_to_close_iter| {
height_to_price_close_iter| {
let txindex = txindex.unwrap_to_usize();
txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| {
let btc = value.into_owned();
txindex_to_height_iter
.next_at(txindex)
.and_then(|(_, value)| {
let height = value.into_owned();
height_to_close_iter
.next_at(height.unwrap_to_usize())
.map(|(_, close)| *close.into_owned() * btc)
})
})
txindex_to_in_btc_iter
.next_at(txindex)
.and_then(|(_, value)| {
let btc = value.into_owned();
txindex_to_height_iter
.next_at(txindex)
.and_then(|(_, value)| {
let height = value.into_owned();
height_to_price_close_iter
.next_at(height.unwrap_to_usize())
.map(|(_, close)| *close.into_owned() * btc)
})
})
},
)
});

View File

@@ -102,13 +102,13 @@ impl ComputedHeightValueVecs {
}
let height_to_bitcoin = &self.bitcoin;
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
if let Some(dollars) = self.dollars.as_mut() {
dollars.compute_from_bitcoin(
starting_indexes.height,
height_to_bitcoin,
height_to_close,
height_to_price_close,
exit,
)?;
}

View File

@@ -236,7 +236,7 @@ impl Vecs {
|index, _| Some(index),
);
Ok(Self {
let this = Self {
emptyoutputindex_to_emptyoutputindex,
inputindex_to_inputindex,
opreturnindex_to_opreturnindex,
@@ -472,7 +472,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -29,8 +29,8 @@ pub struct Vecs {
pub inner: common::Vecs,
pub height_to_address_count: EagerVec<Height, StoredU64>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
pub height_to_addr_count: EagerVec<Height, StoredU64>,
pub indexes_to_addr_count: ComputedVecsFromHeight<StoredU64>,
}
impl Vecs {
@@ -43,7 +43,7 @@ impl Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
states_path: Option<&Path>,
compute_relative_to_all: bool,
compute_rel_to_all: bool,
) -> Result<Self> {
let compute_dollars = price.is_some();
@@ -58,15 +58,15 @@ impl Vecs {
compute_dollars,
)
}),
height_to_address_count: EagerVec::forced_import(
height_to_addr_count: EagerVec::forced_import(
db,
&suffix("address_count"),
&suffix("addr_count"),
version + VERSION + Version::ZERO,
format,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_addr_count: ComputedVecsFromHeight::forced_import(
db,
&suffix("address_count"),
&suffix("addr_count"),
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -80,7 +80,7 @@ impl Vecs {
indexes,
price,
false,
compute_relative_to_all,
compute_rel_to_all,
false,
)?,
})
@@ -90,7 +90,7 @@ impl Vecs {
impl DynCohortVecs for Vecs {
fn min_height_vecs_len(&self) -> usize {
[
self.height_to_address_count.len(),
self.height_to_addr_count.len(),
self.inner.min_height_vecs_len(),
]
.into_iter()
@@ -110,8 +110,8 @@ impl DynCohortVecs for Vecs {
self.starting_height = Some(starting_height);
if let Some(prev_height) = starting_height.decremented() {
self.state.as_mut().unwrap().address_count = *self
.height_to_address_count
self.state.as_mut().unwrap().addr_count = *self
.height_to_addr_count
.into_iter()
.unwrap_get_inner(prev_height);
}
@@ -120,9 +120,9 @@ impl DynCohortVecs for Vecs {
}
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
self.height_to_address_count
self.height_to_addr_count
.validate_computed_version_or_reset(
base_version + self.height_to_address_count.inner_version(),
base_version + self.height_to_addr_count.inner_version(),
)?;
self.inner.validate_computed_versions(base_version)
@@ -133,9 +133,9 @@ impl DynCohortVecs for Vecs {
return Ok(());
}
self.height_to_address_count.forced_push_at(
self.height_to_addr_count.forced_push_at(
height,
self.state.as_ref().unwrap().address_count.into(),
self.state.as_ref().unwrap().addr_count.into(),
exit,
)?;
@@ -162,7 +162,7 @@ impl DynCohortVecs for Vecs {
}
fn safe_flush_stateful_vecs(&mut self, height: Height, exit: &Exit) -> Result<()> {
self.height_to_address_count.safe_flush(exit)?;
self.height_to_addr_count.safe_flush(exit)?;
self.inner
.safe_flush_stateful_vecs(height, exit, &mut self.state.as_mut().unwrap().inner)
@@ -177,11 +177,11 @@ impl DynCohortVecs for Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_address_count.compute_rest(
self.indexes_to_addr_count.compute_rest(
indexes,
starting_indexes,
exit,
Some(&self.height_to_address_count),
Some(&self.height_to_addr_count),
)?;
self.inner
@@ -191,8 +191,8 @@ impl DynCohortVecs for Vecs {
fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
[
self.inner.vecs(),
self.indexes_to_address_count.vecs(),
vec![&self.height_to_address_count],
self.indexes_to_addr_count.vecs(),
vec![&self.height_to_addr_count],
]
.concat()
}
@@ -205,11 +205,11 @@ impl CohortVecs for Vecs {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
self.height_to_address_count.compute_sum_of_others(
self.height_to_addr_count.compute_sum_of_others(
starting_indexes.height,
others
.iter()
.map(|v| &v.height_to_address_count)
.map(|v| &v.height_to_addr_count)
.collect::<Vec<_>>()
.as_slice(),
exit,

File diff suppressed because it is too large Load Diff

View File

@@ -73,20 +73,24 @@ pub struct Vecs {
pub height_to_unspendable_supply: EagerVec<Height, Sats>,
pub height_to_opreturn_supply: EagerVec<Height, Sats>,
pub addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount,
// ---
// Computed
// ---
pub addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount,
pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight,
pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_empty_address_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_addr_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_empty_addr_count: ComputedVecsFromHeight<StoredU64>,
pub height_to_market_cap: Option<LazyVecFrom1<Height, Dollars, Height, Dollars>>,
pub indexes_to_market_cap: Option<ComputedVecsFromDateIndex<Dollars>>,
pub loadedaddressindex_to_loadedaddressindex:
LazyVecFrom1<LoadedAddressIndex, LoadedAddressIndex, LoadedAddressIndex, LoadedAddressData>,
pub emptyaddressindex_to_emptyaddressindex:
LazyVecFrom1<EmptyAddressIndex, EmptyAddressIndex, EmptyAddressIndex, EmptyAddressData>,
}
const SAVED_STAMPED_CHANGES: u16 = 10;
@@ -111,7 +115,28 @@ impl Vecs {
let utxo_cohorts =
utxo_cohorts::Vecs::forced_import(&db, version, format, indexes, price, &states_path)?;
Ok(Self {
let loadedaddressindex_to_loadedaddressdata = RawVec::forced_import_with(
ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?;
let emptyaddressindex_to_emptyaddressdata = RawVec::forced_import_with(
ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?;
let loadedaddressindex_to_loadedaddressindex = LazyVecFrom1::init(
"loadedaddressindex",
version + VERSION + Version::ZERO,
loadedaddressindex_to_loadedaddressdata.boxed_clone(),
|index, _| Some(index),
);
let emptyaddressindex_to_emptyaddressindex = LazyVecFrom1::init(
"emptyaddressindex",
version + VERSION + Version::ZERO,
emptyaddressindex_to_emptyaddressdata.boxed_clone(),
|index, _| Some(index),
);
let this = Self {
chain_state: RawVec::forced_import_with(
ImportOptions::new(&db, "chain", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
@@ -145,17 +170,17 @@ impl Vecs {
compute_dollars,
indexes,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_addr_count: ComputedVecsFromHeight::forced_import(
&db,
"address_count",
"addr_count",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_empty_addr_count: ComputedVecsFromHeight::forced_import(
&db,
"empty_address_count",
"empty_addr_count",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -192,99 +217,99 @@ impl Vecs {
)
.unwrap()
}),
addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from(
addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import_compressed(
&db,
"p2pk65_address_count",
"p2pk65_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pk33: EagerVec::forced_import_compressed(
&db,
"p2pk33_address_count",
"p2pk33_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pkh: EagerVec::forced_import_compressed(
&db,
"p2pkh_address_count",
"p2pkh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2sh: EagerVec::forced_import_compressed(
&db,
"p2sh_address_count",
"p2sh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wpkh: EagerVec::forced_import_compressed(
&db,
"p2wpkh_address_count",
"p2wpkh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wsh: EagerVec::forced_import_compressed(
&db,
"p2wsh_address_count",
"p2wsh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2tr: EagerVec::forced_import_compressed(
&db,
"p2tr_address_count",
"p2tr_addr_count",
version + VERSION + Version::ZERO,
)?,
p2a: EagerVec::forced_import_compressed(
&db,
"p2a_address_count",
"p2a_addr_count",
version + VERSION + Version::ZERO,
)?,
},
),
addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount::from(
addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import_compressed(
&db,
"p2pk65_empty_address_count",
"p2pk65_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pk33: EagerVec::forced_import_compressed(
&db,
"p2pk33_empty_address_count",
"p2pk33_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pkh: EagerVec::forced_import_compressed(
&db,
"p2pkh_empty_address_count",
"p2pkh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2sh: EagerVec::forced_import_compressed(
&db,
"p2sh_empty_address_count",
"p2sh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wpkh: EagerVec::forced_import_compressed(
&db,
"p2wpkh_empty_address_count",
"p2wpkh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wsh: EagerVec::forced_import_compressed(
&db,
"p2wsh_empty_address_count",
"p2wsh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2tr: EagerVec::forced_import_compressed(
&db,
"p2tr_empty_address_count",
"p2tr_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2a: EagerVec::forced_import_compressed(
&db,
"p2a_empty_address_count",
"p2a_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
},
),
addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount::from(
addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
&db,
"p2pk65_address_count",
"p2pk65_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -292,7 +317,7 @@ impl Vecs {
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
&db,
"p2pk33_address_count",
"p2pk33_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -300,7 +325,7 @@ impl Vecs {
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
&db,
"p2pkh_address_count",
"p2pkh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -308,7 +333,7 @@ impl Vecs {
)?,
p2sh: ComputedVecsFromHeight::forced_import(
&db,
"p2sh_address_count",
"p2sh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -316,7 +341,7 @@ impl Vecs {
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
&db,
"p2wpkh_address_count",
"p2wpkh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -324,7 +349,7 @@ impl Vecs {
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
&db,
"p2wsh_address_count",
"p2wsh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -332,7 +357,7 @@ impl Vecs {
)?,
p2tr: ComputedVecsFromHeight::forced_import(
&db,
"p2tr_address_count",
"p2tr_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -340,7 +365,7 @@ impl Vecs {
)?,
p2a: ComputedVecsFromHeight::forced_import(
&db,
"p2a_address_count",
"p2a_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -348,11 +373,11 @@ impl Vecs {
)?,
},
),
addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount::from(
addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
&db,
"p2pk65_empty_address_count",
"p2pk65_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -360,7 +385,7 @@ impl Vecs {
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
&db,
"p2pk33_empty_address_count",
"p2pk33_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -368,7 +393,7 @@ impl Vecs {
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
&db,
"p2pkh_empty_address_count",
"p2pkh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -376,7 +401,7 @@ impl Vecs {
)?,
p2sh: ComputedVecsFromHeight::forced_import(
&db,
"p2sh_empty_address_count",
"p2sh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -384,7 +409,7 @@ impl Vecs {
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
&db,
"p2wpkh_empty_address_count",
"p2wpkh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -392,7 +417,7 @@ impl Vecs {
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
&db,
"p2wsh_empty_address_count",
"p2wsh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -400,7 +425,7 @@ impl Vecs {
)?,
p2tr: ComputedVecsFromHeight::forced_import(
&db,
"p2tr_empty_address_count",
"p2tr_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -408,7 +433,7 @@ impl Vecs {
)?,
p2a: ComputedVecsFromHeight::forced_import(
&db,
"p2a_empty_address_count",
"p2a_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -459,17 +484,22 @@ impl Vecs {
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
loadedaddressindex_to_loadedaddressdata: RawVec::forced_import_with(
ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
emptyaddressindex_to_emptyaddressdata: RawVec::forced_import_with(
ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
loadedaddressindex_to_loadedaddressdata,
emptyaddressindex_to_emptyaddressdata,
loadedaddressindex_to_loadedaddressindex,
emptyaddressindex_to_emptyaddressindex,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
#[allow(clippy::too_many_arguments)]
@@ -524,17 +554,17 @@ impl Vecs {
.height
.as_ref()
.unwrap();
let height_to_close = price
let height_to_price_close = price
.as_ref()
.map(|price| &price.chainindexes_to_close.height);
let dateindex_to_close = price
.map(|price| &price.chainindexes_to_price_close.height);
let dateindex_to_price_close = price
.as_ref()
.map(|price| price.timeindexes_to_close.dateindex.as_ref().unwrap());
.map(|price| price.timeindexes_to_price_close.dateindex.as_ref().unwrap());
let height_to_date_fixed = &indexes.height_to_date_fixed;
let dateindex_to_first_height = &indexes.dateindex_to_first_height;
let dateindex_to_height_count = &indexes.dateindex_to_height_count;
let mut height_to_close_iter = height_to_close.as_ref().map(|v| v.into_iter());
let mut height_to_price_close_iter = height_to_price_close.as_ref().map(|v| v.into_iter());
let mut height_to_timestamp_fixed_iter = height_to_timestamp_fixed.into_iter();
let base_version = Version::ZERO
@@ -558,10 +588,10 @@ impl Vecs {
+ outputindex_to_outputtype.version()
+ outputindex_to_typeindex.version()
+ height_to_unclaimed_rewards.version()
+ height_to_close
+ height_to_price_close
.as_ref()
.map_or(Version::ZERO, |v| v.version())
+ dateindex_to_close
+ dateindex_to_price_close
.as_ref()
.map_or(Version::ZERO, |v| v.version())
+ height_to_date_fixed.version()
@@ -657,12 +687,14 @@ impl Vecs {
.rollback_before(starting_height.into())?,
]
.into_iter()
.enumerate()
.map(|(i, s)| {
let h = Height::from(s).incremented();
dbg!((i, s, h));
h
})
// .enumerate()
// .map(|(i, s)| {
// let h = Height::from(s).incremented();
// // dbg!((i, s, h));
// h
// })
.map(Height::from)
.map(Height::incremented)
.collect::<BTreeSet<Height>>();
if set.len() == 1 {
@@ -709,7 +741,7 @@ impl Vecs {
.map(|(height, supply)| {
let height = Height::from(height);
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let price = height_to_close_iter
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
BlockState {
@@ -780,13 +812,14 @@ impl Vecs {
let mut height_to_output_count_iter = height_to_output_count.into_iter();
let mut height_to_input_count_iter = height_to_input_count.into_iter();
let mut height_to_unclaimed_rewards_iter = height_to_unclaimed_rewards.into_iter();
let mut dateindex_to_close_iter = dateindex_to_close.as_ref().map(|v| v.into_iter());
let mut dateindex_to_price_close_iter =
dateindex_to_price_close.as_ref().map(|v| v.into_iter());
let mut height_to_date_fixed_iter = height_to_date_fixed.into_iter();
let mut dateindex_to_first_height_iter = dateindex_to_first_height.into_iter();
let mut dateindex_to_height_count_iter = dateindex_to_height_count.into_iter();
let height_to_close_vec =
height_to_close.map(|height_to_close| height_to_close.collect().unwrap());
let height_to_price_close_vec = height_to_price_close
.map(|height_to_price_close| height_to_price_close.collect().unwrap());
let height_to_timestamp_fixed_vec = height_to_timestamp_fixed.collect().unwrap();
let outputindex_range_to_height = RangeMap::from(height_to_first_outputindex);
@@ -805,12 +838,12 @@ impl Vecs {
} else {
Sats::ZERO
};
let mut addresstype_to_address_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_address_count,
let mut addresstype_to_addr_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_addr_count,
starting_height,
));
let mut addresstype_to_empty_address_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_empty_address_count,
let mut addresstype_to_empty_addr_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_empty_addr_count,
starting_height,
));
@@ -855,7 +888,7 @@ impl Vecs {
.for_each(|(_, v)| v.state.as_mut().unwrap().reset_single_iteration_values());
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let price = height_to_close_iter
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
let first_outputindex = height_to_first_outputindex_iter
@@ -1123,8 +1156,8 @@ impl Vecs {
&mut addresstype_to_typeindex_to_loadedaddressdata,
&mut addresstype_to_typeindex_to_emptyaddressdata,
price,
&mut addresstype_to_address_count,
&mut addresstype_to_empty_address_count,
&mut addresstype_to_addr_count,
&mut addresstype_to_empty_addr_count,
&mut stored_or_new_addresstype_to_typeindex_to_addressdatawithsource,
);
@@ -1134,9 +1167,9 @@ impl Vecs {
&mut addresstype_to_typeindex_to_loadedaddressdata,
&mut addresstype_to_typeindex_to_emptyaddressdata,
price,
&mut addresstype_to_address_count,
&mut addresstype_to_empty_address_count,
height_to_close_vec.as_ref(),
&mut addresstype_to_addr_count,
&mut addresstype_to_empty_addr_count,
height_to_price_close_vec.as_ref(),
&height_to_timestamp_fixed_vec,
height,
timestamp,
@@ -1195,14 +1228,14 @@ impl Vecs {
self.height_to_opreturn_supply
.forced_push_at(height, opreturn_supply, exit)?;
self.addresstype_to_height_to_address_count.forced_push_at(
self.addresstype_to_height_to_addr_count.forced_push_at(
height,
&addresstype_to_address_count,
&addresstype_to_addr_count,
exit,
)?;
self.addresstype_to_height_to_empty_address_count
.forced_push_at(height, &addresstype_to_empty_address_count, exit)?;
self.addresstype_to_height_to_empty_addr_count
.forced_push_at(height, &addresstype_to_empty_addr_count, exit)?;
let date = height_to_date_fixed_iter.unwrap_get_inner(height);
let dateindex = DateIndex::try_from(date).unwrap();
@@ -1213,7 +1246,7 @@ impl Vecs {
let is_date_last_height = date_first_height
+ Height::from(date_height_count).decremented().unwrap()
== height;
let date_price = dateindex_to_close_iter
let date_price = dateindex_to_price_close_iter
.as_mut()
.map(|v| is_date_last_height.then(|| *v.unwrap_get_inner(dateindex)));
@@ -1276,7 +1309,7 @@ impl Vecs {
info!("Computing rest part 1...");
self.indexes_to_address_count.compute_all(
self.indexes_to_addr_count.compute_all(
indexer,
indexes,
starting_indexes,
@@ -1285,7 +1318,7 @@ impl Vecs {
v.compute_sum_of_others(
starting_indexes.height,
&self
.addresstype_to_height_to_address_count
.addresstype_to_height_to_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v)
@@ -1296,7 +1329,7 @@ impl Vecs {
},
)?;
self.indexes_to_empty_address_count.compute_all(
self.indexes_to_empty_addr_count.compute_all(
indexer,
indexes,
starting_indexes,
@@ -1305,7 +1338,7 @@ impl Vecs {
v.compute_sum_of_others(
starting_indexes.height,
&self
.addresstype_to_height_to_empty_address_count
.addresstype_to_height_to_empty_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v)
@@ -1333,18 +1366,18 @@ impl Vecs {
Some(&self.height_to_opreturn_supply),
)?;
self.addresstype_to_indexes_to_address_count.compute(
self.addresstype_to_indexes_to_addr_count.compute(
indexes,
starting_indexes,
exit,
&self.addresstype_to_height_to_address_count,
&self.addresstype_to_height_to_addr_count,
)?;
self.addresstype_to_indexes_to_empty_address_count.compute(
self.addresstype_to_indexes_to_empty_addr_count.compute(
indexes,
starting_indexes,
exit,
&self.addresstype_to_height_to_empty_address_count,
&self.addresstype_to_height_to_empty_addr_count,
)?;
self.utxo_cohorts
@@ -1643,11 +1676,11 @@ impl Vecs {
.try_for_each(|(_, v)| v.safe_flush_stateful_vecs(height, exit))?;
self.height_to_unspendable_supply.safe_flush(exit)?;
self.height_to_opreturn_supply.safe_flush(exit)?;
self.addresstype_to_height_to_address_count
self.addresstype_to_height_to_addr_count
.as_mut_vec()
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
self.addresstype_to_height_to_empty_address_count
self.addresstype_to_height_to_empty_addr_count
.as_mut_vec()
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
@@ -1845,19 +1878,19 @@ impl Vecs {
.collect::<Vec<_>>(),
self.indexes_to_unspendable_supply.vecs(),
self.indexes_to_opreturn_supply.vecs(),
self.indexes_to_address_count.vecs(),
self.indexes_to_empty_address_count.vecs(),
self.addresstype_to_indexes_to_address_count.vecs(),
self.indexes_to_addr_count.vecs(),
self.indexes_to_empty_addr_count.vecs(),
self.addresstype_to_indexes_to_addr_count.vecs(),
self.indexes_to_market_cap
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.addresstype_to_indexes_to_empty_address_count.vecs(),
self.addresstype_to_height_to_address_count
self.addresstype_to_indexes_to_empty_addr_count.vecs(),
self.addresstype_to_height_to_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v as &dyn AnyCollectableVec)
.collect::<Vec<_>>(),
self.addresstype_to_height_to_empty_address_count
self.addresstype_to_height_to_empty_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v as &dyn AnyCollectableVec)
@@ -1868,6 +1901,19 @@ impl Vecs {
vec![
&self.height_to_unspendable_supply,
&self.height_to_opreturn_supply,
&self.chain_state,
&self.p2pk33addressindex_to_anyaddressindex,
&self.p2pk65addressindex_to_anyaddressindex,
&self.p2pkhaddressindex_to_anyaddressindex,
&self.p2shaddressindex_to_anyaddressindex,
&self.p2traddressindex_to_anyaddressindex,
&self.p2wpkhaddressindex_to_anyaddressindex,
&self.p2wshaddressindex_to_anyaddressindex,
&self.p2aaddressindex_to_anyaddressindex,
&self.loadedaddressindex_to_loadedaddressdata,
&self.emptyaddressindex_to_emptyaddressdata,
&self.loadedaddressindex_to_loadedaddressindex,
&self.emptyaddressindex_to_emptyaddressindex,
],
]
.into_iter()
@@ -1888,8 +1934,8 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
addresstype_to_addr_count: &mut ByAddressType<u64>,
addresstype_to_empty_addr_count: &mut ByAddressType<u64>,
stored_or_new_addresstype_to_typeindex_to_addressdatawithsource: &mut AddressTypeToTypeIndexTree<
WithAddressDataSource<LoadedAddressData>,
>,
@@ -1926,9 +1972,9 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
});
if is_new || from_any_empty {
(*addresstype_to_address_count.get_mut(_type).unwrap()) += 1;
(*addresstype_to_addr_count.get_mut(_type).unwrap()) += 1;
if from_any_empty {
(*addresstype_to_empty_address_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) -= 1;
}
}
@@ -1988,9 +2034,9 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
height_to_close_vec: Option<&Vec<brk_structs::Close<Dollars>>>,
addresstype_to_addr_count: &mut ByAddressType<u64>,
addresstype_to_empty_addr_count: &mut ByAddressType<u64>,
height_to_price_close_vec: Option<&Vec<brk_structs::Close<Dollars>>>,
height_to_timestamp_fixed_vec: &[Timestamp],
height: Height,
timestamp: Timestamp,
@@ -1999,7 +2045,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
>,
) -> Result<()> {
self.0.into_iter().try_for_each(|(prev_height, mut v)| {
let prev_price = height_to_close_vec
let prev_price = height_to_price_close_vec
.as_ref()
.map(|v| **v.get(prev_height.unwrap_to_usize()).unwrap());
@@ -2039,7 +2085,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
let amount = prev_amount.checked_sub(value).unwrap();
let will_be_empty = addressdata.outputs_len - 1 == 0;
let will_be_empty = addressdata.utxos - 1 == 0;
if will_be_empty
|| vecs.amount_range.get_mut(amount).0.clone()
@@ -2060,8 +2106,8 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
unreachable!()
}
(*addresstype_to_address_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_address_count.get_mut(_type).unwrap()) += 1;
(*addresstype_to_addr_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) += 1;
let addressdata =
typeindex_to_loadedaddressdata.remove(&type_index).unwrap();

View File

@@ -33,7 +33,7 @@ impl Vecs {
price: Option<&price::Vecs>,
states_path: Option<&Path>,
extended: bool,
compute_relative_to_all: bool,
compute_rel_to_all: bool,
compute_adjusted: bool,
) -> Result<Self> {
let compute_dollars = price.is_some();
@@ -57,7 +57,7 @@ impl Vecs {
indexes,
price,
extended,
compute_relative_to_all,
compute_rel_to_all,
compute_adjusted,
)?,
})

View File

@@ -49,7 +49,7 @@ impl Vecs {
term: ByTerm {
short: utxo_cohort::Vecs::forced_import(
db,
Some("short_term_holders"),
Some("sth"),
format,
version + VERSION + Version::ZERO,
indexes,
@@ -61,7 +61,7 @@ impl Vecs {
)?,
long: utxo_cohort::Vecs::forced_import(
db,
Some("long_term_holders"),
Some("lth"),
format,
version + VERSION + Version::ZERO,
indexes,

View File

@@ -9,14 +9,14 @@ use super::CohortState;
#[derive(Clone)]
pub struct AddressCohortState {
pub address_count: u64,
pub addr_count: u64,
pub inner: CohortState,
}
impl AddressCohortState {
pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self {
Self {
address_count: 0,
addr_count: 0,
inner: CohortState::new(path, name, compute_dollars),
}
}
@@ -44,14 +44,14 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| addressdata.realized_price());
let prev_supply_state = SupplyState {
utxos: addressdata.outputs_len as u64,
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
};
addressdata.send(value, prev_price)?;
let supply_state = SupplyState {
utxos: addressdata.outputs_len as u64,
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
};
@@ -79,14 +79,14 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| address_data.realized_price());
let prev_supply_state = SupplyState {
utxos: address_data.outputs_len as u64,
utxos: address_data.utxos as u64,
value: address_data.amount(),
};
address_data.receive(value, price);
let supply_state = SupplyState {
utxos: address_data.outputs_len as u64,
utxos: address_data.utxos as u64,
value: address_data.amount(),
};
@@ -99,7 +99,7 @@ impl AddressCohortState {
}
pub fn add(&mut self, addressdata: &LoadedAddressData) {
self.address_count += 1;
self.addr_count += 1;
self.inner.increment_(
&addressdata.into(),
addressdata.realized_cap,
@@ -108,7 +108,7 @@ impl AddressCohortState {
}
pub fn subtract(&mut self, addressdata: &LoadedAddressData) {
self.address_count = self.address_count.checked_sub(1).unwrap();
self.addr_count = self.addr_count.checked_sub(1).unwrap();
self.inner.decrement_(
&addressdata.into(),
addressdata.realized_cap,

View File

@@ -283,7 +283,7 @@ impl CohortState {
}
}
Ordering::Equal => {
state.supply_even += sats;
state.supply_breakeven += sats;
}
}
};

View File

@@ -43,7 +43,7 @@ impl SubAssign<&SupplyState> for SupplyState {
impl From<&LoadedAddressData> for SupplyState {
fn from(value: &LoadedAddressData) -> Self {
Self {
utxos: value.outputs_len as u64,
utxos: value.utxos as u64,
value: value.amount(),
}
}

View File

@@ -3,7 +3,7 @@ use brk_structs::{Dollars, Sats};
#[derive(Debug, Default, Clone)]
pub struct UnrealizedState {
pub supply_in_profit: Sats,
pub supply_even: Sats,
pub supply_breakeven: Sats,
pub supply_in_loss: Sats,
pub unrealized_profit: Dollars,
pub unrealized_loss: Dollars,
@@ -12,7 +12,7 @@ pub struct UnrealizedState {
impl UnrealizedState {
pub const NAN: Self = Self {
supply_in_profit: Sats::ZERO,
supply_even: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::NAN,
unrealized_loss: Dollars::NAN,
@@ -20,7 +20,7 @@ impl UnrealizedState {
pub const ZERO: Self = Self {
supply_in_profit: Sats::ZERO,
supply_even: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::ZERO,
unrealized_loss: Dollars::ZERO,

View File

@@ -22,7 +22,7 @@ fn main() -> Result<()> {
let blocks_dir = bitcoin_dir.join("blocks");
let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk");
fs::create_dir_all(outputs_dir)?;
fs::create_dir_all(&outputs_dir)?;
// let outputs_dir = Path::new("/Volumes/WD_BLACK1/brk");
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
@@ -35,9 +35,9 @@ fn main() -> Result<()> {
let parser = Parser::new(blocks_dir, Some(outputs_dir.to_path_buf()), rpc);
fs::create_dir_all(outputs_dir)?;
fs::create_dir_all(&outputs_dir)?;
let mut indexer = Indexer::forced_import(outputs_dir)?;
let mut indexer = Indexer::forced_import(&outputs_dir)?;
loop {
let i = Instant::now();

View File

@@ -5,7 +5,7 @@ use std::{collections::BTreeMap, path::Path, str::FromStr, thread, time::Instant
use bitcoin::{Transaction, TxIn, TxOut};
use brk_error::{Error, Result};
use brk_parser::Parser;
use brk_parser::{BlockExtended, Parser};
use brk_store::AnyStore;
use brk_structs::{
AddressBytes, AddressBytesHash, BlockHash, BlockHashPrefix, Height, InputIndex, OutputIndex,
@@ -14,7 +14,7 @@ use brk_structs::{
};
use log::{error, info};
use rayon::prelude::*;
use vecdb::{AnyVec, Database, Exit, GenericStoredVec, PAGE_SIZE, Reader, VecIterator};
use vecdb::{AnyVec, Exit, GenericStoredVec, Reader, VecIterator};
mod indexes;
mod stores;
mod vecs;
@@ -29,7 +29,6 @@ const VERSION: Version = Version::ONE;
#[derive(Clone)]
pub struct Indexer {
pub db: Database,
pub vecs: Vecs,
pub stores: Stores,
}
@@ -38,18 +37,15 @@ impl Indexer {
pub fn forced_import(outputs_dir: &Path) -> Result<Self> {
info!("Importing indexer...");
let db = Database::open(&outputs_dir.join("indexed/vecs"))?;
db.set_min_len(PAGE_SIZE * 50_000_000)?;
info!("Opened database");
let path = outputs_dir.join("indexed");
let vecs = Vecs::forced_import(&db, VERSION + Version::ZERO)?;
let vecs = Vecs::forced_import(&path, VERSION + Version::ZERO)?;
info!("Imported vecs");
let stores =
Stores::forced_import(&outputs_dir.join("indexed/stores"), VERSION + Version::ZERO)?;
let stores = Stores::forced_import(&path, VERSION + Version::ZERO)?;
info!("Imported stores");
Ok(Self { vecs, stores, db })
Ok(Self { vecs, stores })
}
pub fn index(
@@ -59,16 +55,9 @@ impl Indexer {
exit: &Exit,
check_collisions: bool,
) -> Result<Indexes> {
let db = self.db.clone();
// dbg!(self.db.regions().id_to_index());
// dbg!(self.db.layout());
let starting_indexes = Indexes::try_from((&mut self.vecs, &self.stores, rpc))
.unwrap_or_else(|_report| Indexes::default());
// dbg!(&starting_indexes);
let lock = exit.lock();
self.stores
.rollback_if_needed(&mut self.vecs, &starting_indexes)?;
@@ -108,7 +97,6 @@ impl Indexer {
vecs.flush(height)?;
info!("Flushed vecs in {}s", i.elapsed().as_secs());
let i = Instant::now();
db.flush()?;
info!("Flushed db in {}s", i.elapsed().as_secs());
Ok(())
};
@@ -210,6 +198,10 @@ impl Indexer {
.blockhashprefix_to_height
.insert_if_needed(blockhash_prefix, height, height);
stores
.height_to_coinbase_tag
.insert_if_needed( height, block.coinbase_tag().into(), height);
vecs.height_to_blockhash.push_if_needed(height, blockhash)?;
vecs.height_to_difficulty
.push_if_needed(height, block.header.difficulty_float().into())?;
@@ -797,7 +789,7 @@ impl Indexer {
}
let i = Instant::now();
db.punch_holes()?;
self.vecs.punch_holes()?;
info!("Punched holes in db in {}s", i.elapsed().as_secs());
Ok(starting_indexes)

View File

@@ -4,11 +4,12 @@ use brk_error::Result;
use brk_store::{AnyStore, Store};
use brk_structs::{
AddressBytes, AddressBytesHash, BlockHashPrefix, ByAddressType, Height, OutputIndex,
OutputType, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit, Version,
OutputType, StoredString, TxIndex, TxidPrefix, TypeIndex, TypeIndexWithOutputindex, Unit,
Version,
};
use fjall::{PersistMode, TransactionalKeyspace};
use rayon::prelude::*;
use vecdb::VecIterator;
use vecdb::{AnyVec, StoredIndex, VecIterator};
use crate::Indexes;
@@ -20,6 +21,7 @@ pub struct Stores {
pub addressbyteshash_to_typeindex: Store<AddressBytesHash, TypeIndex>,
pub blockhashprefix_to_height: Store<BlockHashPrefix, Height>,
pub height_to_coinbase_tag: Store<Height, StoredString>,
pub txidprefix_to_txindex: Store<TxidPrefix, TxIndex>,
pub addresstype_to_typeindex_with_outputindex:
ByAddressType<Store<TypeIndexWithOutputindex, Unit>>,
@@ -28,14 +30,16 @@ pub struct Stores {
const VERSION: Version = Version::ZERO;
impl Stores {
pub fn forced_import(path: &Path, version: Version) -> Result<Self> {
fs::create_dir_all(path)?;
pub fn forced_import(parent: &Path, version: Version) -> Result<Self> {
let path = parent.join("stores");
let keyspace = match brk_store::open_keyspace(path) {
fs::create_dir_all(&path)?;
let keyspace = match brk_store::open_keyspace(&path) {
Ok(keyspace) => keyspace,
Err(_) => {
fs::remove_dir_all(path)?;
return Self::forced_import(path, version);
fs::remove_dir_all(&path)?;
return Self::forced_import(&path, version);
}
};
@@ -43,7 +47,7 @@ impl Stores {
let addressbyteshash_to_typeindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"addressbyteshash_to_typeindex",
version + VERSION + Version::ZERO,
None,
@@ -52,7 +56,7 @@ impl Stores {
let blockhashprefix_to_height = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"blockhashprefix_to_height",
version + VERSION + Version::ZERO,
None,
@@ -61,7 +65,7 @@ impl Stores {
let txidprefix_to_txindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"txidprefix_to_txindex",
version + VERSION + Version::ZERO,
None,
@@ -70,7 +74,7 @@ impl Stores {
let p2aaddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2aaddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -79,7 +83,7 @@ impl Stores {
let p2pk33addressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2pk33addressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -88,7 +92,7 @@ impl Stores {
let p2pk65addressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2pk65addressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -97,7 +101,7 @@ impl Stores {
let p2pkhaddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2pkhaddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -106,7 +110,7 @@ impl Stores {
let p2shaddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2shaddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -115,7 +119,7 @@ impl Stores {
let p2traddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2traddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -124,7 +128,7 @@ impl Stores {
let p2wpkhaddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2wpkhaddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
@@ -133,16 +137,25 @@ impl Stores {
let p2wshaddressindex_with_outputindex = scope.spawn(|| {
Store::import(
&keyspace,
path,
&path,
"p2wshaddressindex_with_outputindex",
version + VERSION + Version::ZERO,
Some(false),
)
});
let height_to_coinbase_tag = Store::import(
&keyspace,
&path,
"height_to_coinbase_tag",
version + VERSION + Version::ZERO,
None,
)?;
Ok(Self {
keyspace: keyspace.clone(),
height_to_coinbase_tag,
addressbyteshash_to_typeindex: addressbyteshash_to_typeindex.join().unwrap()?,
blockhashprefix_to_height: blockhashprefix_to_height.join().unwrap()?,
txidprefix_to_txindex: txidprefix_to_txindex.join().unwrap()?,
@@ -182,11 +195,9 @@ impl Stores {
.map_err(|e| e.into())
}
fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 11] {
fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 12] {
[
&self.addressbyteshash_to_typeindex,
&self.blockhashprefix_to_height,
&self.txidprefix_to_txindex,
&self.addresstype_to_typeindex_with_outputindex.p2a,
&self.addresstype_to_typeindex_with_outputindex.p2pk33,
&self.addresstype_to_typeindex_with_outputindex.p2pk65,
@@ -195,14 +206,15 @@ impl Stores {
&self.addresstype_to_typeindex_with_outputindex.p2tr,
&self.addresstype_to_typeindex_with_outputindex.p2wpkh,
&self.addresstype_to_typeindex_with_outputindex.p2wsh,
&self.blockhashprefix_to_height,
&self.height_to_coinbase_tag,
&self.txidprefix_to_txindex,
]
}
fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 11] {
fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 12] {
[
&mut self.addressbyteshash_to_typeindex,
&mut self.blockhashprefix_to_height,
&mut self.txidprefix_to_txindex,
&mut self.addresstype_to_typeindex_with_outputindex.p2a,
&mut self.addresstype_to_typeindex_with_outputindex.p2pk33,
&mut self.addresstype_to_typeindex_with_outputindex.p2pk65,
@@ -211,6 +223,9 @@ impl Stores {
&mut self.addresstype_to_typeindex_with_outputindex.p2tr,
&mut self.addresstype_to_typeindex_with_outputindex.p2wpkh,
&mut self.addresstype_to_typeindex_with_outputindex.p2wsh,
&mut self.blockhashprefix_to_height,
&mut self.height_to_coinbase_tag,
&mut self.txidprefix_to_txindex,
]
}
@@ -222,6 +237,7 @@ impl Stores {
if self.addressbyteshash_to_typeindex.is_empty()?
&& self.blockhashprefix_to_height.is_empty()?
&& self.txidprefix_to_txindex.is_empty()?
&& self.height_to_coinbase_tag.is_empty()?
&& self
.addresstype_to_typeindex_with_outputindex
.p2a
@@ -266,6 +282,12 @@ impl Stores {
self.blockhashprefix_to_height.remove(blockhashprefix);
});
(starting_indexes.height.unwrap_to_usize()..vecs.height_to_blockhash.len())
.map(Height::from)
.for_each(|h| {
self.height_to_coinbase_tag.remove(h);
});
if let Some(mut index) = vecs
.height_to_first_p2pk65addressindex
.iter()

View File

@@ -1,3 +1,5 @@
use std::path::Path;
use brk_error::Result;
use brk_structs::{
AddressBytes, BlockHash, EmptyOutputIndex, Height, InputIndex, OpReturnIndex, OutputIndex,
@@ -9,7 +11,8 @@ use brk_structs::{
};
use rayon::prelude::*;
use vecdb::{
AnyCollectableVec, AnyStoredVec, CompressedVec, Database, GenericStoredVec, RawVec, Stamp,
AnyCollectableVec, AnyStoredVec, CompressedVec, Database, GenericStoredVec, PAGE_SIZE, RawVec,
Stamp,
};
use crate::Indexes;
@@ -18,6 +21,8 @@ const VERSION: Version = Version::ZERO;
#[derive(Clone)]
pub struct Vecs {
db: Database,
pub emptyoutputindex_to_txindex: CompressedVec<EmptyOutputIndex, TxIndex>,
pub height_to_blockhash: RawVec<Height, BlockHash>,
pub height_to_difficulty: CompressedVec<Height, StoredF64>,
@@ -67,225 +72,240 @@ pub struct Vecs {
}
impl Vecs {
pub fn forced_import(db: &Database, version: Version) -> Result<Self> {
Ok(Self {
pub fn forced_import(parent: &Path, version: Version) -> Result<Self> {
let db = Database::open(&parent.join("vecs"))?;
db.set_min_len(PAGE_SIZE * 50_000_000)?;
let this = Self {
emptyoutputindex_to_txindex: CompressedVec::forced_import(
db,
&db,
"txindex",
version + VERSION + Version::ZERO,
)?,
height_to_blockhash: RawVec::forced_import(
db,
&db,
"blockhash",
version + VERSION + Version::ZERO,
)?,
height_to_difficulty: CompressedVec::forced_import(
db,
&db,
"difficulty",
version + VERSION + Version::ZERO,
)?,
height_to_first_emptyoutputindex: CompressedVec::forced_import(
db,
&db,
"first_emptyoutputindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_inputindex: CompressedVec::forced_import(
db,
&db,
"first_inputindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_opreturnindex: CompressedVec::forced_import(
db,
&db,
"first_opreturnindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_outputindex: CompressedVec::forced_import(
db,
&db,
"first_outputindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2aaddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2aaddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2msoutputindex: CompressedVec::forced_import(
db,
&db,
"first_p2msoutputindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2pk33addressindex: CompressedVec::forced_import(
db,
&db,
"first_p2pk33addressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2pk65addressindex: CompressedVec::forced_import(
db,
&db,
"first_p2pk65addressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2pkhaddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2pkhaddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2shaddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2shaddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2traddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2traddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2wpkhaddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2wpkhaddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_p2wshaddressindex: CompressedVec::forced_import(
db,
&db,
"first_p2wshaddressindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_txindex: CompressedVec::forced_import(
db,
&db,
"first_txindex",
version + VERSION + Version::ZERO,
)?,
height_to_first_unknownoutputindex: CompressedVec::forced_import(
db,
&db,
"first_unknownoutputindex",
version + VERSION + Version::ZERO,
)?,
height_to_timestamp: CompressedVec::forced_import(
db,
&db,
"timestamp",
version + VERSION + Version::ZERO,
)?,
height_to_total_size: CompressedVec::forced_import(
db,
&db,
"total_size",
version + VERSION + Version::ZERO,
)?,
height_to_weight: CompressedVec::forced_import(
db,
&db,
"weight",
version + VERSION + Version::ZERO,
)?,
inputindex_to_outputindex: RawVec::forced_import(
db,
&db,
"outputindex",
version + VERSION + Version::ZERO,
)?,
opreturnindex_to_txindex: CompressedVec::forced_import(
db,
&db,
"txindex",
version + VERSION + Version::ZERO,
)?,
outputindex_to_outputtype: RawVec::forced_import(
db,
&db,
"outputtype",
version + VERSION + Version::ZERO,
)?,
outputindex_to_typeindex: RawVec::forced_import(
db,
&db,
"typeindex",
version + VERSION + Version::ZERO,
)?,
outputindex_to_value: RawVec::forced_import(
db,
&db,
"value",
version + VERSION + Version::ZERO,
)?,
p2aaddressindex_to_p2abytes: RawVec::forced_import(
db,
&db,
"p2abytes",
version + VERSION + Version::ZERO,
)?,
p2msoutputindex_to_txindex: CompressedVec::forced_import(
db,
&db,
"txindex",
version + VERSION + Version::ZERO,
)?,
p2pk33addressindex_to_p2pk33bytes: RawVec::forced_import(
db,
&db,
"p2pk33bytes",
version + VERSION + Version::ZERO,
)?,
p2pk65addressindex_to_p2pk65bytes: RawVec::forced_import(
db,
&db,
"p2pk65bytes",
version + VERSION + Version::ZERO,
)?,
p2pkhaddressindex_to_p2pkhbytes: RawVec::forced_import(
db,
&db,
"p2pkhbytes",
version + VERSION + Version::ZERO,
)?,
p2shaddressindex_to_p2shbytes: RawVec::forced_import(
db,
&db,
"p2shbytes",
version + VERSION + Version::ZERO,
)?,
p2traddressindex_to_p2trbytes: RawVec::forced_import(
db,
&db,
"p2trbytes",
version + VERSION + Version::ZERO,
)?,
p2wpkhaddressindex_to_p2wpkhbytes: RawVec::forced_import(
db,
&db,
"p2wpkhbytes",
version + VERSION + Version::ZERO,
)?,
p2wshaddressindex_to_p2wshbytes: RawVec::forced_import(
db,
&db,
"p2wshbytes",
version + VERSION + Version::ZERO,
)?,
txindex_to_base_size: CompressedVec::forced_import(
db,
&db,
"base_size",
version + VERSION + Version::ZERO,
)?,
txindex_to_first_inputindex: CompressedVec::forced_import(
db,
&db,
"first_inputindex",
version + VERSION + Version::ZERO,
)?,
txindex_to_first_outputindex: CompressedVec::forced_import(
db,
&db,
"first_outputindex",
version + VERSION + Version::ZERO,
)?,
txindex_to_is_explicitly_rbf: CompressedVec::forced_import(
db,
&db,
"is_explicitly_rbf",
version + VERSION + Version::ZERO,
)?,
txindex_to_rawlocktime: CompressedVec::forced_import(
db,
&db,
"rawlocktime",
version + VERSION + Version::ZERO,
)?,
txindex_to_total_size: CompressedVec::forced_import(
db,
&db,
"total_size",
version + VERSION + Version::ZERO,
)?,
txindex_to_txid: RawVec::forced_import(db, "txid", version + VERSION + Version::ZERO)?,
txindex_to_txid: RawVec::forced_import(&db, "txid", version + VERSION + Version::ZERO)?,
txindex_to_txversion: CompressedVec::forced_import(
db,
&db,
"txversion",
version + VERSION + Version::ZERO,
)?,
unknownoutputindex_to_txindex: CompressedVec::forced_import(
db,
&db,
"txindex",
version + VERSION + Version::ZERO,
)?,
})
db,
};
// self.db.retain_regions(
// this.vecs()
// .into_iter()
// .flat_map(|v| v.region_names())
// .collect(),
// )?;
Ok(this)
}
pub fn rollback_if_needed(&mut self, starting_indexes: &Indexes) -> Result<()> {
@@ -438,6 +458,7 @@ impl Vecs {
self.mut_vecs()
.into_par_iter()
.try_for_each(|vec| vec.stamped_flush(Stamp::from(height)))?;
self.db.flush()?;
Ok(())
}
@@ -452,6 +473,11 @@ impl Vecs {
.unwrap()
}
pub fn punch_holes(&self) -> Result<()> {
self.db.punch_holes()?;
Ok(())
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
vec![
&self.emptyoutputindex_to_txindex,

View File

@@ -21,3 +21,4 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_with = "3.14.0"
tabled = "0.20.0"
nucleo-matcher = "0.3.1"

View File

@@ -2,11 +2,11 @@ use std::fmt::{self, Debug};
use brk_error::Error;
use brk_structs::{
DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex,
MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex,
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex,
P2WSHAddressIndex, Printable, QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex,
WeekIndex, YearIndex,
DateIndex, DecadeIndex, DifficultyEpoch, EmptyAddressIndex, EmptyOutputIndex, HalvingEpoch,
Height, InputIndex, LoadedAddressIndex, MonthIndex, OpReturnIndex, OutputIndex,
P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex,
P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, Printable,
QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -63,10 +63,14 @@ pub enum Index {
WeekIndex,
#[schemars(description = "Year index")]
YearIndex,
#[schemars(description = "Loaded Address Index")]
LoadedAddressIndex,
#[schemars(description = "Empty Address Index")]
EmptyAddressIndex,
}
impl Index {
pub fn all() -> [Self; 25] {
pub fn all() -> [Self; 27] {
[
Self::DateIndex,
Self::DecadeIndex,
@@ -93,6 +97,8 @@ impl Index {
Self::UnknownOutputIndex,
Self::WeekIndex,
Self::YearIndex,
Self::LoadedAddressIndex,
Self::EmptyAddressIndex,
]
}
@@ -123,6 +129,8 @@ impl Index {
Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(),
Self::WeekIndex => WeekIndex::to_possible_strings(),
Self::YearIndex => YearIndex::to_possible_strings(),
Self::LoadedAddressIndex => LoadedAddressIndex::to_possible_strings(),
Self::EmptyAddressIndex => EmptyAddressIndex::to_possible_strings(),
}
}
@@ -186,6 +194,12 @@ impl TryFrom<&str> for Index {
v if (Self::UnknownOutputIndex).possible_values().contains(&v) => {
Self::UnknownOutputIndex
}
v if (Self::LoadedAddressIndex).possible_values().contains(&v) => {
Self::LoadedAddressIndex
}
v if (Self::EmptyAddressIndex).possible_values().contains(&v) => {
Self::EmptyAddressIndex
}
_ => return Err(Error::Str("Bad index")),
})
}

View File

@@ -3,9 +3,13 @@
use std::collections::BTreeMap;
use brk_computer::Computer;
use brk_error::Result;
use brk_error::{Error, Result};
use brk_indexer::Indexer;
use brk_structs::Height;
use nucleo_matcher::{
Config, Matcher,
pattern::{Atom, AtomKind, CaseMatching, Normalization, Pattern},
};
use tabled::settings::Style;
use vecdb::{AnyCollectableVec, AnyStoredVec};
@@ -53,38 +57,65 @@ impl<'a> Interface<'a> {
Height::from(self.indexer.vecs.height_to_blockhash.stamp())
}
pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> {
let tuples = params
.ids
.iter()
.flat_map(|s| {
s.to_lowercase()
.replace("-", "_")
.split_whitespace()
.flat_map(|s| {
s.split(',')
.flat_map(|s| s.split('+').map(|s| s.to_string()))
})
.collect::<Vec<_>>()
})
.map(|mut id| {
let mut res = self.vecs.id_to_index_to_vec.get(id.as_str());
if res.is_none()
&& let Ok(index) = Index::try_from(id.as_str())
{
id = index.possible_values().last().unwrap().to_string();
res = self.vecs.id_to_index_to_vec.get(id.as_str())
}
(id, res)
})
.filter(|(_, opt)| opt.is_some())
.map(|(id, vec)| (id, vec.unwrap()))
.collect::<Vec<_>>();
pub fn search(&self, params: &Params) -> Result<Vec<(String, &&dyn AnyCollectableVec)>> {
let ids_to_vec = self
.vecs
.index_to_id_to_vec
.get(&params.index)
.ok_or(Error::String(format!(
"Index \"{}\" isn't a valid index",
params.index
)))?;
tuples
.iter()
.flat_map(|(str, i_to_v)| i_to_v.get(&params.index).map(|vec| (str.to_owned(), vec)))
.collect::<Vec<_>>()
let maybe_ids = params.ids.iter().flat_map(|s| {
s.to_lowercase()
.replace("-", "_")
.split_whitespace()
.flat_map(|s| {
s.split(',')
.flat_map(|s| s.split('+').map(|s| s.to_string()))
})
.collect::<Vec<_>>()
});
maybe_ids
.map(|id| {
let vec = ids_to_vec.get(id.as_str()).ok_or_else(|| {
let mut message = format!(
"No vec named \"{}\" indexed by \"{}\" found.\n",
// tell if id found in another index
id,
params.index
);
let mut matcher = Matcher::new(Config::DEFAULT);
let matches = Pattern::new(
id.as_str(),
CaseMatching::Ignore,
Normalization::Smart,
AtomKind::Fuzzy,
)
.match_list(ids_to_vec.keys(), &mut matcher)
.into_iter()
.take(10)
.map(|(s, _)| s)
.collect::<Vec<_>>();
if !matches.is_empty() {
message +=
&format!("\nMaybe you meant one of the following: {matches:#?} ?\n");
}
if let Some(index_to_vec) = self.id_to_index_to_vec().get(id.as_str()) {
message += &format!("\nBut there is a vec named {id} which supports the following indexes: {:#?}\n", index_to_vec.keys());
}
Error::String(message)
});
vec.map(|vec| (id, vec))
})
.collect::<Result<Vec<_>>>()
}
pub fn format(
@@ -183,7 +214,7 @@ impl<'a> Interface<'a> {
}
pub fn search_and_format(&self, params: Params) -> Result<Output> {
self.format(self.search(&params), &params.rest)
self.format(self.search(&params)?, &params.rest)
}
pub fn id_to_index_to_vec(&self) -> &BTreeMap<&str, IndexToVec<'_>> {

View File

@@ -1,6 +1,5 @@
use std::path::Path;
use bitcoin::{Block, consensus::serde::hex, script::Instruction};
use bitcoincore_rpc::{Auth, Client, Result};
use brk_parser::Parser;
use brk_structs::Height;
@@ -28,14 +27,9 @@ fn main() -> Result<()> {
.parse(start, end)
.iter()
.for_each(|(height, _block, hash)| {
println!("{height}: {}", _block.get_coinbase_message());
println!("{height}: {}", hash);
});
println!(
"391487: {}",
parser.get(Height::new(391487)).get_coinbase_message()
);
let block_0 = parser.get(Height::new(0));
println!(
@@ -50,8 +44,6 @@ fn main() -> Result<()> {
.script_pubkey
);
println!("{}", block_0.get_coinbase_message());
let block_158251 = parser.get(Height::new(158251));
println!(
"{}",
@@ -64,7 +56,6 @@ fn main() -> Result<()> {
.unwrap()
.script_pubkey
);
println!("{}", block_158251.get_coinbase_message());
let block_840_000 = parser.get(Height::new(840_004));
@@ -80,27 +71,7 @@ fn main() -> Result<()> {
.value
);
println!("{}", block_840_000.get_coinbase_message());
dbg!(i.elapsed());
Ok(())
}
pub trait BlockExtended {
fn get_coinbase_message(&self) -> String;
}
impl BlockExtended for Block {
fn get_coinbase_message(&self) -> String {
let Some(input) = self.txdata.first().and_then(|tx| tx.input.first()) else {
return String::new();
};
let bytes = input.script_sig.as_bytes();
String::from_utf8_lossy(bytes)
.chars()
.filter(|&c| c != '\u{FFFD}' && (c >= ' ' || c == '\n' || c == '\r' || c == '\t'))
.take(1_024)
.collect()
}
}

View File

@@ -0,0 +1,19 @@
use bitcoin::Block;
pub trait BlockExtended {
fn coinbase_tag(&self) -> String;
}
impl BlockExtended for Block {
fn coinbase_tag(&self) -> String {
let Some(input) = self.txdata.first().and_then(|tx| tx.input.first()) else {
return String::new();
};
let bytes = input.script_sig.as_bytes();
String::from_utf8_lossy(bytes)
.chars()
.filter(|&c| c != '\u{FFFD}' && (c >= ' ' || c == '\n' || c == '\r' || c == '\t'))
.take(1_024)
.collect()
}
}

View File

@@ -14,6 +14,7 @@ mod blk_index_to_blk_path;
mod blk_index_to_blk_recap;
mod blk_metadata;
mod blk_recap;
mod block;
mod block_state;
mod error;
mod utils;
@@ -22,6 +23,7 @@ mod xor_index;
use blk_index_to_blk_recap::*;
use blk_metadata::*;
pub use block::*;
use block_state::*;
pub use error::*;
use utils::*;

View File

@@ -16,7 +16,7 @@ use crate::{HeaderMapExtended, ResponseExtended};
use super::AppState;
const MAX_WEIGHT: usize = 320_000;
const MAX_WEIGHT: usize = 65 * 10_000;
pub async fn handler(
uri: Uri,
@@ -43,7 +43,7 @@ fn req_to_response_res(
interface, cache, ..
}: AppState,
) -> Result<Response> {
let vecs = interface.search(&params);
let vecs = interface.search(&params)?;
if vecs.is_empty() {
return Ok(Json(vec![] as Vec<usize>).into_response());
@@ -61,9 +61,9 @@ fn req_to_response_res(
.sum::<usize>();
if weight > MAX_WEIGHT {
return Err(Error::Str(
"Request is too heavy, max weight is {MAX_WEIGHT} bytes",
));
return Err(Error::String(format!(
"Request is too heavy, max weight is {MAX_WEIGHT} bytes"
)));
}
// TODO: height should be from vec, but good enough for now

View File

@@ -106,16 +106,6 @@ impl ApiRoutes for Router<AppState> {
},
),
)
.route(
"/health",
get(|| async {
Json(serde_json::json!({
"status": "healthy",
"service": "brk-server",
"timestamp": jiff::Timestamp::now().to_string()
}))
}),
)
.route(
"/api",
get(|| async {
@@ -124,9 +114,5 @@ impl ApiRoutes for Router<AppState> {
)
}),
)
.route(
"/discord",
get(|| async { Redirect::temporary("https://discord.com/invite/HaR3wpH3nr") }),
)
}
}

View File

@@ -11,6 +11,7 @@ use axum::{
body::{Body, Bytes},
http::{Request, Response, StatusCode, Uri},
middleware::Next,
response::Redirect,
routing::get,
serve,
};
@@ -47,7 +48,7 @@ impl Server {
Self(AppState {
interface: Box::leak(Box::new(interface)),
path: files_path,
cache: Arc::new(Cache::new(10_000)),
cache: Arc::new(Cache::new(5_000)),
})
}
@@ -98,6 +99,33 @@ impl Server {
.add_files_routes(state.path.as_ref())
.add_mcp_routes(state.interface, mcp)
.route("/version", get(Json(VERSION)))
.route(
"/health",
get(Json(serde_json::json!({
"status": "healthy",
"service": "brk-server",
"timestamp": jiff::Timestamp::now().to_string()
}))),
)
.route(
"/discord",
get(Redirect::temporary("https://discord.gg/WACpShCB7M")),
)
.route("/crates", get(Redirect::temporary("https://crates.io/crates/brk")))
.route(
"/status",
get(Redirect::temporary("https://status.bitview.space")),
)
.route("/github", get(Redirect::temporary("https://github.com/bitcoinresearchkit/brk")))
.route(
"/cli",
get(Redirect::temporary("https://crates.io/crates/brk_cli")),
)
.route(
"/hosting",
get(Redirect::temporary("https://github.com/bitcoinresearchkit/brk?tab=readme-ov-file#hosting-as-a-service")),
)
.route("/nostr", get(Redirect::temporary("https://primal.net/p/npub1jagmm3x39lmwfnrtvxcs9ac7g300y3dusv9lgzhk2e4x5frpxlrqa73v44")))
.with_state(state)
.layer(compression_layer)
.layer(response_uri_layer)

View File

@@ -1,8 +1,8 @@
use std::ops::Add;
use vecdb::{CheckedSub, Printable};
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::TypeIndex;
@@ -22,6 +22,7 @@ use crate::TypeIndex;
IntoBytes,
KnownLayout,
Serialize,
StoredCompressed,
)]
pub struct EmptyAddressIndex(TypeIndex);

View File

@@ -227,13 +227,19 @@ impl TryFrom<&std::path::Path> for Height {
}
impl From<ByteView> for Height {
fn from(value: byteview::ByteView) -> Self {
fn from(value: ByteView) -> Self {
Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap()))
}
}
impl From<Height> for ByteView {
fn from(value: Height) -> Self {
Self::from(&value)
}
}
impl From<&Height> for ByteView {
fn from(value: &Height) -> Self {
Self::new(&value.0.to_be_bytes())
}
}

View File

@@ -11,7 +11,8 @@ pub struct LoadedAddressData {
pub sent: Sats,
pub received: Sats,
pub realized_cap: Dollars,
pub outputs_len: u32,
pub utxos: u32,
#[serde(skip)]
padding: u32,
}
@@ -41,12 +42,12 @@ impl LoadedAddressData {
#[inline]
pub fn has_0_utxos(&self) -> bool {
self.outputs_len == 0
self.utxos == 0
}
pub fn receive(&mut self, amount: Sats, price: Option<Dollars>) {
self.received += amount;
self.outputs_len += 1;
self.utxos += 1;
if let Some(price) = price {
let added = price * amount;
self.realized_cap += added;
@@ -62,7 +63,7 @@ impl LoadedAddressData {
return Err(Error::Str("Previous_amount smaller than sent amount"));
}
self.sent += amount;
self.outputs_len -= 1;
self.utxos -= 1;
if let Some(previous_price) = previous_price {
let subtracted = previous_price * amount;
let realized_cap = self.realized_cap.checked_sub(subtracted).unwrap();
@@ -94,7 +95,7 @@ impl From<&EmptyAddressData> for LoadedAddressData {
sent: value.transfered,
received: value.transfered,
realized_cap: Dollars::ZERO,
outputs_len: 0,
utxos: 0,
padding: 0,
}
}

View File

@@ -2,7 +2,7 @@ use std::ops::Add;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::{CheckedSub, Printable};
use vecdb::{CheckedSub, Printable, StoredCompressed};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::TypeIndex;
@@ -22,6 +22,7 @@ use crate::TypeIndex;
IntoBytes,
KnownLayout,
Serialize,
StoredCompressed,
)]
pub struct LoadedAddressIndex(TypeIndex);

View File

@@ -43,6 +43,7 @@ mod stored_bool;
mod stored_f32;
mod stored_f64;
mod stored_i16;
mod stored_string;
mod stored_u16;
mod stored_u32;
mod stored_u64;
@@ -105,6 +106,7 @@ pub use stored_bool::*;
pub use stored_f32::*;
pub use stored_f64::*;
pub use stored_i16::*;
pub use stored_string::*;
pub use stored_u8::*;
pub use stored_u16::*;
pub use stored_u32::*;

View File

@@ -0,0 +1,56 @@
use byteview::ByteView;
use derive_deref::Deref;
use serde::Serialize;
use vecdb::Printable;
#[derive(Default, Debug, Deref, Clone, Serialize)]
pub struct StoredString(String);
impl StoredString {
pub fn new(string: String) -> Self {
Self(string)
}
pub fn as_str(&self) -> &str {
self
}
pub fn as_string(&self) -> &String {
self
}
}
impl From<String> for StoredString {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<ByteView> for StoredString {
fn from(value: ByteView) -> Self {
let bytes = &*value;
Self(String::from_utf8_lossy(bytes).into_owned())
}
}
impl From<StoredString> for ByteView {
fn from(value: StoredString) -> Self {
Self::from(&value)
}
}
impl From<&StoredString> for ByteView {
fn from(value: &StoredString) -> Self {
Self::new(value.as_bytes())
}
}
impl Printable for StoredString {
fn to_string() -> &'static str {
"string"
}
fn to_possible_strings() -> &'static [&'static str] {
&["string"]
}
}

View File

@@ -141,7 +141,7 @@ export function init({
if (!t) return;
from.set(t.from);
to.set(t.to);
}),
}, 250),
);
elements.charts.append(fieldset);
@@ -241,7 +241,7 @@ export function init({
break;
}
case /** @satisfies {DateIndex} */ (0): {
iseries.update(latest);
iseries.update(last);
break;
}
default: {
@@ -277,7 +277,7 @@ export function init({
iseries.update(last);
} else {
latest.time = time;
iseries.update(latest);
iseries.update(last);
}
}
}
@@ -329,29 +329,32 @@ export function init({
/** @type {Series | undefined} */
let series;
console.log({ topUnit, topSeriesType });
switch (topUnit) {
case "USD": {
switch (topSeriesType) {
case null:
case CANDLE: {
series = chart.addCandlestickSeries({
vecId: "ohlc",
vecId: "price_ohlc",
name: "Price",
unit: topUnit,
setDataCallback: printLatest,
order: 0,
});
break;
}
case LINE: {
series = chart.addLineSeries({
vecId: "close",
vecId: "price_close",
name: "Price",
unit: topUnit,
color: colors.default,
setDataCallback: printLatest,
options: {
priceLineVisible: true,
lastValueVisible: true,
},
order: 0,
});
@@ -361,6 +364,7 @@ export function init({
}
case "Sats": {
switch (topSeriesType) {
case null:
case CANDLE: {
series = chart.addCandlestickSeries({
vecId: "ohlc_in_sats",
@@ -381,6 +385,7 @@ export function init({
setDataCallback: printLatest,
options: {
priceLineVisible: true,
lastValueVisible: true,
},
order: 0,
});
@@ -395,7 +400,6 @@ export function init({
seriesListTop[0]?.remove();
seriesListTop[0] = series;
// setDataCallback insimport("./options").tead of hasData
signals.createEffect(
() => ({
latest: webSockets.kraken1dCandle.latest(),

View File

@@ -6,7 +6,7 @@
* @import * as _ from "../packages/leeoniya-ufuzzy/1.0.19/dist/uFuzzy.d.ts"
* @import { SerializedChartableIndex } from "./chart";
* @import { Signal, Signals, Accessor } from "../packages/solidjs-signals/wrapper";
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex } from "./vecid-to-indexes"
* @import { DateIndex, DecadeIndex, DifficultyEpoch, Index, HalvingEpoch, Height, MonthIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2MSOutputIndex, P2AAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, InputIndex, OutputIndex, VecId, WeekIndex, SemesterIndex, YearIndex, VecIdToIndexes, QuarterIndex, EmptyOutputIndex, OpReturnIndex, UnknownOutputIndex, EmptyAddressIndex, LoadedAddressIndex } from "./vecid-to-indexes"
*/
/**
@@ -50,6 +50,8 @@
* "%pnl" |
* "constant" |
* "vB" |
* "block" |
* "address data" |
* "sd" |
* "Epoch" |
* "Height" |
@@ -721,12 +723,25 @@ function createUtils() {
/** @type {Unit | undefined} */
let unit;
/**
* @param {Unit} u
*/
function setUnit(u) {
if (unit)
throw Error(
`Can't assign "${u}" to unit, "${unit}" is already assigned to "${id}"`,
);
unit = u;
}
if (
(!unit || thoroughUnitCheck) &&
(id.includes("in_sats") ||
(id.endsWith("supply") &&
!(id.endsWith("circulating_supply") || id.endsWith("_own_supply"))) ||
id.endsWith("supply_even") ||
id.endsWith("supply_half") ||
id.endsWith("supply_breakeven") ||
id.endsWith("supply_in_profit") ||
id.endsWith("supply_in_loss") ||
id.endsWith("stack") ||
@@ -743,43 +758,50 @@ function createUtils() {
id.endsWith("dominance")
)))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Sats";
setUnit("Sats");
}
if ((!unit || thoroughUnitCheck) && id.includes("in_btc")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "BTC";
setUnit("BTC");
}
if ((!unit || thoroughUnitCheck) && id === "chain") {
setUnit("block");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "high" ||
id === "ohlc" ||
id === "low" ||
id === "close" ||
id === "open" ||
(id === "emptyaddressdata" || id === "loadedaddressdata")
) {
setUnit("address data");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "price_high" ||
id === "price_ohlc" ||
id === "price_low" ||
id === "price_close" ||
id === "price_open" ||
id === "price_ath" ||
id === "market_cap" ||
id.includes("_usd") ||
id.includes("cointime_value") ||
id.startsWith("price") ||
id.endsWith("_ago") ||
id.endsWith("price_paid") ||
id.endsWith("price") ||
(id.endsWith("_cap") && !id.includes("relative_to")) ||
id.endsWith("_price") ||
(id.endsWith("_cap") && !id.includes("rel_to")) ||
id.endsWith("value_created") ||
id.endsWith("value_destroyed") ||
((id.includes("realized") || id.includes("true_market_mean")) &&
!id.includes("ratio") &&
!id.includes("relative_to")) ||
!id.includes("rel_to")) ||
((id.endsWith("sma") || id.includes("sma_x") || id.endsWith("ema")) &&
!id.includes("ratio") &&
!id.includes("sopr") &&
!id.includes("hash_rate")) ||
id === "ath")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "USD";
setUnit("USD");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("cents")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Cents";
setUnit("Cents");
}
if (
((!unit || thoroughUnitCheck) &&
@@ -788,33 +810,32 @@ function createUtils() {
(id.endsWith("sma") ||
id.endsWith("ema") ||
id.endsWith("zscore"))) ||
id.includes("sopr") ||
id.endsWith("_5sd") ||
id.endsWith("1sd") ||
id.endsWith("2sd") ||
id.endsWith("3sd") ||
id.endsWith("p1") ||
id.endsWith("p2") ||
id.endsWith("p5") ||
id.endsWith("p95") ||
id.endsWith("p98") ||
id.endsWith("p99"))) ||
id.endsWith("pct1") ||
id.endsWith("pct2") ||
id.endsWith("pct5") ||
id.endsWith("pct95") ||
id.endsWith("pct98") ||
id.endsWith("pct99"))) ||
id.includes("liveliness") ||
id.includes("vaultedness") ||
id == "puell_multiple"
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Ratio";
setUnit("Ratio");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "drawdown" ||
(id === "price_drawdown" ||
id.endsWith("oscillator") ||
id.endsWith("dominance") ||
id.endsWith("returns") ||
id.endsWith("cagr"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "percentage";
setUnit("percentage");
}
if (
(!unit || thoroughUnitCheck) &&
@@ -823,43 +844,35 @@ function createUtils() {
id.startsWith("block_count") ||
(id.includes("tx_v") && !id.includes("vsize")))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Count";
setUnit("Count");
}
if (
(!unit || thoroughUnitCheck) &&
(id.startsWith("hash_rate") || id.endsWith("as_hash"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "H/s";
setUnit("H/s");
}
if ((!unit || thoroughUnitCheck) && id.includes("fee_rate")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "sat/vB";
setUnit("sat/vB");
}
if ((!unit || thoroughUnitCheck) && id.startsWith("is_")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Bool";
setUnit("Bool");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("type")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Type";
setUnit("Type");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "interval" || id.startsWith("block_interval"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "secs";
setUnit("secs");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("locktime")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Locktime";
setUnit("Locktime");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("version")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Version";
setUnit("Version");
}
if (
(!unit || thoroughUnitCheck) &&
@@ -869,132 +882,101 @@ function createUtils() {
id.endsWith("total_size") ||
id.includes("block_size"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Bytes";
setUnit("Bytes");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("_sd")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "sd";
setUnit("sd");
}
if (
(!unit || thoroughUnitCheck) &&
(id.includes("vsize") || id.includes("vbytes"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "vB";
setUnit("vB");
}
if ((!unit || thoroughUnitCheck) && id.includes("weight")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "WU";
setUnit("WU");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("index")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Index";
setUnit("Index");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "date" || id === "date_fixed")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Date";
setUnit("Date");
}
if (
(!unit || thoroughUnitCheck) &&
(id === "timestamp" || id === "timestamp_fixed")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Timestamp";
setUnit("Timestamp");
}
if ((!unit || thoroughUnitCheck) && id.includes("coinblocks")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "coinblocks";
setUnit("coinblocks");
}
if ((!unit || thoroughUnitCheck) && id.includes("coindays")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "coindays";
setUnit("coindays");
}
if ((!unit || thoroughUnitCheck) && id.includes("satblocks")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "satblocks";
setUnit("satblocks");
}
if ((!unit || thoroughUnitCheck) && id.includes("satdays")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "satdays";
setUnit("satdays");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("height")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Height";
setUnit("Height");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("relative_to_market_cap")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%mcap";
if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_market_cap")) {
setUnit("%mcap");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_own_market_cap")) {
setUnit("%cmcap");
}
if (
(!unit || thoroughUnitCheck) &&
id.endsWith("relative_to_own_market_cap")
id.endsWith("rel_to_own_unrealized_total_pnl")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%cmcap";
setUnit("%cp+l");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_realized_cap")) {
setUnit("%rcap");
}
if (
(!unit || thoroughUnitCheck) &&
id.endsWith("relative_to_own_unrealized_profit_plus_loss")
id.endsWith("rel_to_circulating_supply")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%cp+l";
setUnit("%all");
}
if (
(!unit || thoroughUnitCheck) &&
id.endsWith("relative_to_realized_cap")
(id.includes("rel_to_realized_profit") ||
id.includes("rel_to_realized_loss"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%rcap";
setUnit("%pnl");
}
if (
(!unit || thoroughUnitCheck) &&
id.endsWith("relative_to_circulating_supply")
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%all";
}
if (
(!unit || thoroughUnitCheck) &&
(id.includes("relative_to_realized_profit") ||
id.includes("relative_to_realized_loss"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%pnl";
}
if ((!unit || thoroughUnitCheck) && id.endsWith("relative_to_own_supply")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "%self";
if ((!unit || thoroughUnitCheck) && id.endsWith("rel_to_own_supply")) {
setUnit("%self");
}
if ((!unit || thoroughUnitCheck) && id.endsWith("epoch")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Epoch";
setUnit("Epoch");
}
if ((!unit || thoroughUnitCheck) && id === "difficulty") {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Difficulty";
setUnit("Difficulty");
}
if ((!unit || thoroughUnitCheck) && id === "blockhash") {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Hash";
setUnit("Hash");
}
if (
(!unit || thoroughUnitCheck) &&
(id.includes("days_between") || id.includes("days_since"))
) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Days";
setUnit("Days");
}
if ((!unit || thoroughUnitCheck) && id.includes("years_between")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "Years";
setUnit("Years");
}
if ((!unit || thoroughUnitCheck) && id.startsWith("constant")) {
if (unit) throw Error(`Unit "${unit}" already assigned "${id}"`);
unit = "constant";
setUnit("constant");
}
if (!unit) {
@@ -1205,6 +1187,10 @@ function createUtils() {
return "weekindex";
case /** @satisfies {YearIndex} */ (24):
return "yearindex";
case /** @satisfies {LoadedAddressIndex} */ (25):
return "loadedaddressindex";
case /** @satisfies {EmptyAddressIndex} */ (26):
return "emptyaddressindex";
}
},
},

File diff suppressed because it is too large Load Diff

View File

@@ -836,7 +836,7 @@ export function init({
});
vecsResources
.getOrCreate(/** @satisfies {DateIndex} */ (0), "close")
.getOrCreate(/** @satisfies {DateIndex} */ (0), "price_close")
.fetch()
.then((_closes) => {
if (!_closes) return;

View File

@@ -422,6 +422,8 @@ function createSerializedIndexes() {
/** @satisfies {VecId} */ ("unknownoutputindex"),
/** @satisfies {VecId} */ ("weekindex"),
/** @satisfies {VecId} */ ("yearindex"),
/** @satisfies {VecId} */ ("loadedaddressindex"),
/** @satisfies {VecId} */ ("emptyaddressindex"),
]);
}
/** @typedef {ReturnType<typeof createSerializedIndexes>} SerializedIndexes */
@@ -483,6 +485,10 @@ function serializedIndexToIndex(serializedIndex) {
return /** @satisfies {EmptyOutputIndex} */ (3);
case "unknownoutputindex":
return /** @satisfies {UnknownOutputIndex} */ (22);
case "emptyaddressindex":
return /** @satisfies {EmptyAddressIndex} */ (26);
case "loadedaddressindex":
return /** @satisfies {LoadedAddressIndex} */ (25);
}
}
@@ -514,7 +520,7 @@ function createIndexToVecIds(vecIdToIndexes) {
*/
function serializeValue({ value, unit }) {
if (typeof value !== "number") {
return String(value);
return JSON.stringify(value);
} else if (value !== 18446744073709552000) {
if (unit === "USD" || unit === "Difficulty" || unit === "sat/vB") {
return value.toLocaleString("en-us", {

View File

@@ -53,11 +53,17 @@ sw.addEventListener("fetch", (event) => {
if (
req.method !== "GET" ||
url.pathname.startsWith("/api") ||
url.pathname === "/discord" ||
url.pathname === "/github" ||
url.pathname === "/mcp" ||
url.pathname === "/crates" ||
url.pathname === "/github" ||
url.pathname === "/status" ||
url.pathname === "/cli" ||
url.pathname === "/hosting" ||
url.pathname === "/nostr" ||
url.pathname === "/status"
url.pathname === "/discord" ||
url.pathname === "/nostr" ||
url.pathname === "/health" ||
url.pathname === "/version"
) {
return; // let the browser handle it
}