mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-23 04:36:11 -07:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c66f008f07 | |||
| 37d9498d90 | |||
| 1ff67093db | |||
| daed37ccb8 | |||
| d41d807b4f | |||
| d6fa5c8a55 | |||
| 2dd608dfed | |||
| a98546f605 | |||
| 3567559d4e | |||
| 216476ee45 | |||
| 3fc28c07fb | |||
| 85f6ef063d | |||
| 1e71e2d68f | |||
| b24a29895f | |||
| 0167a2ae59 | |||
| 2c867103ca | |||
| 8c289df336 | |||
| 4489920cbf | |||
| 029a85081b | |||
| 1bc739d07f | |||
| c229e218f6 | |||
| a66f4ad4bd | |||
| 1dd687dab7 | |||
| 50ff6e2745 | |||
| 811dec713b |
@@ -18,3 +18,8 @@ _*
|
||||
|
||||
# Logs
|
||||
.log
|
||||
|
||||
# Profiling
|
||||
profile.json.gz
|
||||
flamegraph.svg
|
||||
*.trace
|
||||
|
||||
Generated
+98
-97
@@ -170,9 +170,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||
|
||||
[[package]]
|
||||
name = "async-compression"
|
||||
version = "0.4.25"
|
||||
version = "0.4.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40f6024f3f856663b45fd0c9b6f2024034a702f453549449e0d84a305900dad4"
|
||||
checksum = "937f41778d8baa0b8984a101f48ec5d2e5b0d23a3f9235b2066eef29c3472bb9"
|
||||
dependencies = [
|
||||
"brotli",
|
||||
"flate2",
|
||||
@@ -477,7 +477,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_bundler",
|
||||
"brk_cli",
|
||||
@@ -497,7 +497,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_bundler"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_rolldown",
|
||||
"log",
|
||||
@@ -508,7 +508,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_cli"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"bitcoincore-rpc",
|
||||
"brk_computer",
|
||||
@@ -531,7 +531,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_computer"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bitcoin",
|
||||
@@ -548,7 +548,6 @@ dependencies = [
|
||||
"derive_deref",
|
||||
"either",
|
||||
"fjall",
|
||||
"jiff",
|
||||
"log",
|
||||
"rayon",
|
||||
"serde",
|
||||
@@ -558,7 +557,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_core"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bitcoin",
|
||||
@@ -579,7 +578,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_exit"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_logger",
|
||||
"ctrlc",
|
||||
@@ -588,7 +587,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_fetcher"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_core",
|
||||
"brk_logger",
|
||||
@@ -600,7 +599,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_indexer"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
@@ -618,7 +617,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_interface"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_computer",
|
||||
"brk_core",
|
||||
@@ -636,7 +635,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_logger"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"env_logger",
|
||||
@@ -646,7 +645,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_mcp"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"brk_interface",
|
||||
@@ -656,7 +655,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_parser"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
@@ -714,9 +713,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d183b16c52419ff7fb0f6f83fa06e125f7c9ec9ce7867b8d11de569adcebde8"
|
||||
checksum = "e84c9b257b6d6e15e6598f320fbe6dcc8615827dbd207aa73378a86723485e9f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"append-only-vec",
|
||||
@@ -761,9 +760,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_common"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3ebe13a90609e4b5f10db4aa5656994b6a6f3e00e15bcba080a7d99059e8fe0"
|
||||
checksum = "ca6da445ded7b4b07e9b48fd1855091ca87ee83777ae49326644019c0255278b"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arcstr",
|
||||
@@ -794,9 +793,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_debug"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7339046fd38b2727597b407577f872540d5283a5431b066f603f8113b5be155f"
|
||||
checksum = "a554a589c6027241dc5735ed2f9387ca4e6771b5a3c68b974b086cde857475a9"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"brk_rolldown_debug_action",
|
||||
@@ -810,9 +809,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_debug_action"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "255823c7e4d226c20cb51b467462023514f63202cf81da64a7ffaebe16696ab3"
|
||||
checksum = "4f0f12e60c7f66ff8efe64dfb47da84ce6216e9c969442f70fb0edf4f3d7d5d1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"ts-rs",
|
||||
@@ -820,9 +819,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_ecmascript"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f598679b4c80d73830682acdc3346cf31200fc05c9dc4c3488b05760c7f211d"
|
||||
checksum = "d0e6d41996222d97ada7efb7f00be28becae01fd6dd68ced9b2d659f9811f3ff"
|
||||
dependencies = [
|
||||
"arcstr",
|
||||
"brk_rolldown_error",
|
||||
@@ -833,9 +832,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_ecmascript_utils"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a529bbaaf1850e8694ebaf752a3a0e7119de1bf40425d44935de6bdf7a75041a"
|
||||
checksum = "43216eb0cd76628bfc878a34c26f8deaba7f1ab2a3afed3912670c53eae67c25"
|
||||
dependencies = [
|
||||
"brk_rolldown_common",
|
||||
"oxc",
|
||||
@@ -844,9 +843,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_error"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52d474d15e41f5fed2e5edead30b0fe25d1bfb6591d49e2b3d7a8509c328a6bd"
|
||||
checksum = "744db025ff88c465df4d4faed5e3c8f3ef91ae9b3183bbc80c62d41dc636c4f5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arcstr",
|
||||
@@ -864,9 +863,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_fs"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a5882bedde49617620fb7f805ba5f97e98d835cd5010d87e6d1eaee3a632c8"
|
||||
checksum = "9c38de0fd6c358c873e4a70e0054b65b6e08262f0676c47394c4f9f392f11c42"
|
||||
dependencies = [
|
||||
"oxc_resolver",
|
||||
"vfs",
|
||||
@@ -874,9 +873,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_plugin"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4070a9556dff16f432862c418d59ca117a67a76220f0a0e7a5d2302860a4ae8d"
|
||||
checksum = "66b3739b2e98ee755130b5d624135d2a8623051341a1b942ac1aed4fe65d5a95"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arcstr",
|
||||
@@ -904,9 +903,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_plugin_data_uri"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b56d0794cde76a0aeb8e9719c8f6a898a6ae261c4b23baf936517b46a8f28a25"
|
||||
checksum = "36f094093ec33d62c17012772db763bd1f3b9d8ee5bcbc374e6f8e9d66555279"
|
||||
dependencies = [
|
||||
"arcstr",
|
||||
"base64-simd",
|
||||
@@ -918,9 +917,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_plugin_hmr"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18123805fe6655cfa5cf1f3a00dbd453ce0ab4021585a1dceb148dc72fcbc115"
|
||||
checksum = "37ed61d459d0aa300b568ac2cf2153c7c4e5c510f901b9efce744f0d5134cc7f"
|
||||
dependencies = [
|
||||
"arcstr",
|
||||
"brk_rolldown_common",
|
||||
@@ -930,9 +929,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_resolver"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f101abf724d5eafd4dafa54d5f6b837ecaabf97a3480cb0433687456970b5d73"
|
||||
checksum = "65ae763e1c514bcfec0dd87be351f5000658feb0e4b1bcb5f199c60e6cbe7150"
|
||||
dependencies = [
|
||||
"arcstr",
|
||||
"brk_rolldown_common",
|
||||
@@ -946,18 +945,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_rstr"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f7364e946414a025a72bb42e19840d25f0d0b456cc57e9c367a996079b40ba2"
|
||||
checksum = "a251b8c38c8b6c177319a5d1f1fb609a120f35e73a52af575792f94dfd42fd1a"
|
||||
dependencies = [
|
||||
"oxc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_sourcemap"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be25fa71e8ede71edeb4261ac3f1588b66b6f1a44ea7be172c3d3870f27ec9de"
|
||||
checksum = "a5465d4ebe0e0801f163d19779bf9858051aff2c291efc64fa6dde83d2e3238d"
|
||||
dependencies = [
|
||||
"brk_rolldown_utils",
|
||||
"memchr",
|
||||
@@ -968,18 +967,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_std_utils"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d49fde6b6ae1ac6ef1936f35f3414caff18caed00e82b25ed0beae92f1073ef0"
|
||||
checksum = "50a28045a4b7ec4c5f8ff06a170d21e0c9a1d41e2baecc8348241f4d3d69a165"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_tracing"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5370886723348f90cd2b1b771feaba03e0ac18c97ea142a1a266b2bd38ce5a58"
|
||||
checksum = "35845acebabca843c6b2c3e1928c393c588ff0ba4bb4bcfcd571c1cc11b13d89"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-chrome",
|
||||
@@ -988,9 +987,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_rolldown_utils"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da6270ab2386f2c0669c37a13d099a0b8700c00fc3495de16fa04498d8d37a98"
|
||||
checksum = "22e3b2a75f83b012138bc63c16e238dfebd9484f99fb77a35fe96a10ff6ef437"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"arcstr",
|
||||
@@ -1025,7 +1024,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_server"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"bitcoincore-rpc",
|
||||
@@ -1055,7 +1054,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_store"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"brk_core",
|
||||
"byteview",
|
||||
@@ -1065,9 +1064,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_string_wizard"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66e8cc17586b31359186c2f3c2faa30c4f9fb02dc4594ed903a64b86596955bb"
|
||||
checksum = "a3e6948e03baceed9fc3e8b3274bf9fefdf56bcdd517a6ff4ecf1843a59178f7"
|
||||
dependencies = [
|
||||
"oxc_index",
|
||||
"oxc_sourcemap",
|
||||
@@ -1077,7 +1076,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_vec"
|
||||
version = "0.0.74"
|
||||
version = "0.0.79"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"brk_core",
|
||||
@@ -1150,28 +1149,18 @@ checksum = "6236364b88b9b6d0bc181ba374cf1ab55ba3ef97a1cb6f8cddad48a273767fb5"
|
||||
|
||||
[[package]]
|
||||
name = "bzip2"
|
||||
version = "0.5.2"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
|
||||
checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff"
|
||||
dependencies = [
|
||||
"bzip2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bzip2-sys"
|
||||
version = "0.1.13+1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"libbz2-rs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "castaway"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5"
|
||||
checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
@@ -1237,18 +1226,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.40"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f"
|
||||
checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.40"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e"
|
||||
checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -1258,9 +1247,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.40"
|
||||
version = "4.5.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce"
|
||||
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@@ -1381,9 +1370,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.4.2"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
|
||||
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
@@ -1912,11 +1901,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.2+wasi-0.2.4",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2316,6 +2303,12 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libbz2-rs-sys"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "775bf80d5878ab7c2b1080b5351a48b2f737d9f6f8b383574eebcc22be0dfccb"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.174"
|
||||
@@ -2437,9 +2430,9 @@ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
version = "0.9.5"
|
||||
version = "0.9.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f"
|
||||
checksum = "483758ad303d734cec05e5c12b41d7e93e6a6390c5e9dae6bdeb7c1259012d28"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
@@ -2654,10 +2647,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "oxc-browserslist"
|
||||
version = "2.0.9"
|
||||
version = "2.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b4d0b44c7165e123b48802d48ca15cfa510584014e4751956ba7fc26c1f2800"
|
||||
checksum = "20605046d78dbba8ed6c1c10b5ee21a83d265825943bce8bc40d17b4c48d5aca"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"nom",
|
||||
"rustc-hash",
|
||||
"serde",
|
||||
@@ -3317,6 +3311,12 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppmd-rust"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c834641d8ad1b348c9ee86dec3b9840d805acd5f24daa5f90c788951a52ff59b"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
@@ -3552,9 +3552,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "regress"
|
||||
version = "0.10.3"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ef7fa9ed0256d64a688a3747d0fef7a88851c18a5e1d57f115f38ec2e09366"
|
||||
checksum = "145bb27393fe455dd64d6cbc8d059adfa392590a45eadf079c01b11857e7b010"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.4",
|
||||
"memchr",
|
||||
@@ -4239,9 +4239,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.9.0"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f271e09bde39ab52250160a67e88577e0559ad77e9085de6e9051a2c4353f8f8"
|
||||
checksum = "ed0aee96c12fa71097902e0bb061a5e1ebd766a6636bb605ba401c45c1650eac"
|
||||
dependencies = [
|
||||
"indexmap 2.10.0",
|
||||
"serde",
|
||||
@@ -4263,18 +4263,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5c1c469eda89749d2230d8156a5969a69ffe0d6d01200581cdc6110674d293e"
|
||||
checksum = "97200572db069e74c512a14117b296ba0a80a30123fbbb5aa1f4a348f639ca30"
|
||||
dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.0.0"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b679217f2848de74cabd3e8fc5e6d66f40b7da40f8e1954d92054d9010690fd5"
|
||||
checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64"
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
@@ -4573,9 +4573,9 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "vfs"
|
||||
version = "0.12.1"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ec343ec20aa715908fd028a4b8e7c99a349d13143224222e4d61c316d1e7f0a"
|
||||
checksum = "9e723b9e1c02a3cf9f9d0de6a4ddb8cdc1df859078902fe0ae0589d615711ae6"
|
||||
dependencies = [
|
||||
"filetime",
|
||||
]
|
||||
@@ -4928,9 +4928,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.11"
|
||||
version = "0.7.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74c7b26e3480b707944fc872477815d29a8e429d2f93a1ce000f5fa84a15cbcd"
|
||||
checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
@@ -4995,9 +4995,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "zip"
|
||||
version = "4.2.0"
|
||||
version = "4.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ab361742de920c5535880f89bbd611ee62002bf11341d16a5f057bb8ba6899"
|
||||
checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"arbitrary",
|
||||
@@ -5012,6 +5012,7 @@ dependencies = [
|
||||
"liblzma",
|
||||
"memchr",
|
||||
"pbkdf2",
|
||||
"ppmd-rust",
|
||||
"sha1",
|
||||
"time",
|
||||
"zeroize",
|
||||
|
||||
+17
-17
@@ -4,7 +4,7 @@ members = ["crates/*"]
|
||||
package.description = "The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node"
|
||||
package.license = "MIT"
|
||||
package.edition = "2024"
|
||||
package.version = "0.0.74"
|
||||
package.version = "0.0.79"
|
||||
package.homepage = "https://bitcoinresearchkit.org"
|
||||
package.repository = "https://github.com/bitcoinresearchkit/brk"
|
||||
|
||||
@@ -26,25 +26,25 @@ axum = "0.8.4"
|
||||
bincode = { version = "2.0.1", features = ["serde"] }
|
||||
bitcoin = { version = "0.32.6", features = ["serde"] }
|
||||
bitcoincore-rpc = "0.19.0"
|
||||
brk_bundler = { version = "0.0.74", path = "crates/brk_bundler" }
|
||||
brk_cli = { version = "0.0.74", path = "crates/brk_cli" }
|
||||
brk_computer = { version = "0.0.74", path = "crates/brk_computer" }
|
||||
brk_core = { version = "0.0.74", path = "crates/brk_core" }
|
||||
brk_exit = { version = "0.0.74", path = "crates/brk_exit" }
|
||||
brk_fetcher = { version = "0.0.74", path = "crates/brk_fetcher" }
|
||||
brk_indexer = { version = "0.0.74", path = "crates/brk_indexer" }
|
||||
brk_interface = { version = "0.0.74", path = "crates/brk_interface" }
|
||||
brk_logger = { version = "0.0.74", path = "crates/brk_logger" }
|
||||
brk_mcp = { version = "0.0.74", path = "crates/brk_mcp" }
|
||||
brk_parser = { version = "0.0.74", path = "crates/brk_parser" }
|
||||
brk_bundler = { version = "0.0.79", path = "crates/brk_bundler" }
|
||||
brk_cli = { version = "0.0.79", path = "crates/brk_cli" }
|
||||
brk_computer = { version = "0.0.79", path = "crates/brk_computer" }
|
||||
brk_core = { version = "0.0.79", path = "crates/brk_core" }
|
||||
brk_exit = { version = "0.0.79", path = "crates/brk_exit" }
|
||||
brk_fetcher = { version = "0.0.79", path = "crates/brk_fetcher" }
|
||||
brk_indexer = { version = "0.0.79", path = "crates/brk_indexer" }
|
||||
brk_interface = { version = "0.0.79", path = "crates/brk_interface" }
|
||||
brk_logger = { version = "0.0.79", path = "crates/brk_logger" }
|
||||
brk_mcp = { version = "0.0.79", path = "crates/brk_mcp" }
|
||||
brk_parser = { version = "0.0.79", path = "crates/brk_parser" }
|
||||
brk_rmcp = { version = "0.2.1", features = ["transport-streamable-http-server", "transport-worker"]}
|
||||
# brk_rmcp = { path = "../rust-sdk/crates/rmcp", features = ["transport-streamable-http-server", "transport-worker"]}
|
||||
brk_server = { version = "0.0.74", path = "crates/brk_server" }
|
||||
brk_store = { version = "0.0.74", path = "crates/brk_store" }
|
||||
brk_vec = { version = "0.0.74", path = "crates/brk_vec" }
|
||||
brk_server = { version = "0.0.79", path = "crates/brk_server" }
|
||||
brk_store = { version = "0.0.79", path = "crates/brk_store" }
|
||||
brk_vec = { version = "0.0.79", path = "crates/brk_vec" }
|
||||
byteview = "=0.6.1"
|
||||
clap = { version = "4.5.40", features = ["string"] }
|
||||
clap_derive = "4.5.40"
|
||||
clap = { version = "4.5.41", features = ["string"] }
|
||||
clap_derive = "4.5.41"
|
||||
color-eyre = "0.6.5"
|
||||
derive_deref = "1.1.1"
|
||||
fjall = "2.11.1"
|
||||
|
||||
@@ -17,14 +17,19 @@
|
||||
- add address counts relative to all datasets
|
||||
- make decade, quarter, year datasets `computed` instead of `eager`
|
||||
- add 6 months (semester) interval datasets to builder
|
||||
- some datasets in `indexes` can probably be removed
|
||||
- add revived/sent supply datasets
|
||||
- add `in-sats` version of all price datasets (average and co)
|
||||
- add `p2pk` group (sum of `p2pk33` and `p2pk65`)
|
||||
- add chopiness datasets
|
||||
- add utxo count, address count, supply data for by reused addresses in groups by address type
|
||||
- add more date ranges (3-6 months and more)
|
||||
- add puell multiple dataset
|
||||
- add pi cycle dataset
|
||||
- add ema of price
|
||||
- add emas of price
|
||||
- add 7d and 30d ema to sell side risk ratio and sopr
|
||||
- don't compute everything for all cohorts as some datasets combinations are irrelevant
|
||||
- addresses/utxos by amount don't need mvrvz for example
|
||||
- add all possible charts from:
|
||||
- https://mainnet.observer
|
||||
- https://glassnode.com
|
||||
@@ -50,6 +55,7 @@
|
||||
- api
|
||||
- add extensions support (.json .csv …)
|
||||
- if format instead of extension then don't download file
|
||||
- add support for https (rustls)
|
||||
- _vec_
|
||||
- add native lock file support (once it's available in stable rust)
|
||||
- improve compressed mode (slow reads)
|
||||
@@ -73,6 +79,7 @@
|
||||
- remove `sum` series when it's a duplicate of the `base` (in subsidy for example)
|
||||
- selected unit sometimes changes when going back end forth
|
||||
- add support for custom charts
|
||||
- separate z-score charts from "realized price" (with their own prices), have 4y, 2y and 1y
|
||||
- price scale format depends on unit, hide digits for sats for example (if/when possible)
|
||||
- table
|
||||
- pagination
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
profile.json.gz
|
||||
flamegraph.svg
|
||||
@@ -10,7 +10,7 @@ repository.workspace = true
|
||||
[dependencies]
|
||||
log = { workspace = true }
|
||||
notify = "8.1.0"
|
||||
brk_rolldown = "0.1.0"
|
||||
brk_rolldown = "0.1.1"
|
||||
# brk_rolldown = { path = "../../../rolldown/crates/rolldown"}
|
||||
sugar_path = "1.2.0"
|
||||
tokio = { workspace = true }
|
||||
|
||||
@@ -24,7 +24,7 @@ color-eyre = { workspace = true }
|
||||
log = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
toml = "0.9.0"
|
||||
toml = "0.9.2"
|
||||
|
||||
[[bin]]
|
||||
name = "brk"
|
||||
|
||||
@@ -23,7 +23,6 @@ color-eyre = { workspace = true }
|
||||
derive_deref = { workspace = true }
|
||||
either = "1.15.0"
|
||||
fjall = { workspace = true }
|
||||
jiff = { workspace = true }
|
||||
log = { workspace = true }
|
||||
rayon = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -13,7 +13,8 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
|
||||
brk_logger::init(Some(Path::new(".log")));
|
||||
|
||||
let bitcoin_dir = default_bitcoin_path();
|
||||
// let bitcoin_dir = default_bitcoin_path();
|
||||
let bitcoin_dir = Path::new("/Volumes/WD_BLACK/bitcoin");
|
||||
|
||||
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
|
||||
"http://localhost:8332",
|
||||
@@ -23,11 +24,11 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
|
||||
// Can't increase main thread's stack programatically, thus we need to use another thread
|
||||
thread::Builder::new()
|
||||
.stack_size(32 * 1024 * 1024)
|
||||
.stack_size(256 * 1024 * 1024)
|
||||
.spawn(move || -> color_eyre::Result<()> {
|
||||
let parser = Parser::new(bitcoin_dir.join("blocks"), rpc);
|
||||
|
||||
let _outputs_dir = default_brk_path().join("outputs");
|
||||
let _outputs_dir = Path::new("/Volumes/WD_BLACK/brk").join("outputs");
|
||||
let outputs_dir = _outputs_dir.as_path();
|
||||
// let outputs_dir = Path::new("../../_outputs");
|
||||
|
||||
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
cargo build --profile profiling
|
||||
flamegraph -- ../../target/profiling/examples/main
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
cargo build --example main --profile profiling
|
||||
samply record ../../target/profiling/examples/main
|
||||
@@ -598,7 +598,6 @@ impl Stores {
|
||||
}
|
||||
|
||||
pub fn rotate_memtables(&self) {
|
||||
info!("Rotatin memtables...");
|
||||
self.as_slice()
|
||||
.into_iter()
|
||||
.for_each(|store| store.rotate_memtable());
|
||||
|
||||
@@ -8,9 +8,11 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
|
||||
|
||||
use crate::vecs::grouped::Source;
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
@@ -34,8 +36,9 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
height_to_interval: EagerVec::forced_import(
|
||||
@@ -47,18 +50,22 @@ impl Vecs {
|
||||
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"timestamp",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_interval",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_percentiles()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
@@ -66,32 +73,32 @@ impl Vecs {
|
||||
indexes_to_block_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_weight",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_size",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
height_to_vbytes: EagerVec::forced_import(
|
||||
path,
|
||||
@@ -102,12 +109,12 @@ impl Vecs {
|
||||
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_vbytes",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
difficultyepoch_to_timestamp: EagerVec::forced_import(
|
||||
path,
|
||||
|
||||
@@ -7,13 +7,13 @@ use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
|
||||
|
||||
use crate::vecs::{
|
||||
fetched,
|
||||
grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight},
|
||||
grouped::{ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, Source},
|
||||
stateful, transactions,
|
||||
};
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromHeight, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
@@ -51,8 +51,9 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let compute_dollars = fetched.is_some();
|
||||
@@ -61,194 +62,234 @@ impl Vecs {
|
||||
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"coinblocks_created",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"coinblocks_stored",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_liveliness: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"liveliness",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_vaultedness: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"vaultedness",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"activity_to_vaultedness_ratio",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
"vaulted_supply",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
"active_supply",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"thermo_cap",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_investor_cap: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"investor_cap",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"vaulted_cap",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_active_cap: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"active_cap",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"vaulted_price",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"vaulted_price",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
true,
|
||||
)?,
|
||||
indexes_to_active_price: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"active_price",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"active_price",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
true,
|
||||
)?,
|
||||
indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"true_market_mean",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"true_market_mean",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
true,
|
||||
)?,
|
||||
indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"cointime_value_destroyed",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"cointime_value_created",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"cointime_value_stored",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_cointime_price: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"cointime_price",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"cointime_cap",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"cointime_price",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
true,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format};
|
||||
|
||||
use crate::vecs::grouped::Source;
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromHeight, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
@@ -25,41 +27,50 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
constant_0: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"constant_0",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
constant_1: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"constant_1",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
constant_50: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"constant_50",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
constant_100: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"constant_100",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,18 +2,22 @@ use std::path::Path;
|
||||
|
||||
use brk_core::{
|
||||
Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex,
|
||||
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, Version, WeekIndex, YearIndex,
|
||||
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, SemesterIndex, Version, WeekIndex,
|
||||
YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_fetcher::Fetcher;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format, StoredIndex};
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, StoredIndex,
|
||||
VecIterator,
|
||||
};
|
||||
|
||||
use crate::vecs::grouped::Source;
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{
|
||||
ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions,
|
||||
},
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
@@ -57,6 +61,8 @@ pub struct Vecs {
|
||||
pub monthindex_to_ohlc_in_sats: EagerVec<MonthIndex, OHLCSats>,
|
||||
pub quarterindex_to_ohlc: EagerVec<QuarterIndex, OHLCDollars>,
|
||||
pub quarterindex_to_ohlc_in_sats: EagerVec<QuarterIndex, OHLCSats>,
|
||||
pub semesterindex_to_ohlc: EagerVec<SemesterIndex, OHLCDollars>,
|
||||
pub semesterindex_to_ohlc_in_sats: EagerVec<SemesterIndex, OHLCSats>,
|
||||
pub yearindex_to_ohlc: EagerVec<YearIndex, OHLCDollars>,
|
||||
pub yearindex_to_ohlc_in_sats: EagerVec<YearIndex, OHLCSats>,
|
||||
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
|
||||
@@ -72,8 +78,9 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let mut fetched_path = path.to_owned();
|
||||
fetched_path.pop();
|
||||
@@ -83,7 +90,7 @@ impl Vecs {
|
||||
dateindex_to_ohlc_in_cents: EagerVec::forced_import(
|
||||
&fetched_path,
|
||||
"ohlc_in_cents",
|
||||
version + VERSION + Version::ZERO,
|
||||
version + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
dateindex_to_ohlc: EagerVec::forced_import(
|
||||
@@ -125,7 +132,7 @@ impl Vecs {
|
||||
height_to_ohlc_in_cents: EagerVec::forced_import(
|
||||
&fetched_path,
|
||||
"ohlc_in_cents",
|
||||
version + VERSION + Version::ZERO,
|
||||
version + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
height_to_ohlc: EagerVec::forced_import(
|
||||
@@ -167,122 +174,138 @@ impl Vecs {
|
||||
timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"open",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"high",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_max(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_max(),
|
||||
)?,
|
||||
timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"low",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_min(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_min(),
|
||||
)?,
|
||||
timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"close",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"open_in_sats",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"high_in_sats",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_max(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_max(),
|
||||
)?,
|
||||
timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"low_in_sats",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_min(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_min(),
|
||||
)?,
|
||||
timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"close_in_sats",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"open",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"high",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_max(),
|
||||
VecBuilderOptions::default().add_max(),
|
||||
)?,
|
||||
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"low",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_min(),
|
||||
VecBuilderOptions::default().add_min(),
|
||||
)?,
|
||||
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"close",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"open_in_sats",
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
VecBuilderOptions::default().add_first(),
|
||||
)?,
|
||||
chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"high_in_sats",
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_max(),
|
||||
VecBuilderOptions::default().add_max(),
|
||||
)?,
|
||||
chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"low_in_sats",
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_min(),
|
||||
VecBuilderOptions::default().add_min(),
|
||||
)?,
|
||||
chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
|
||||
path,
|
||||
"close_in_sats",
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
weekindex_to_ohlc: EagerVec::forced_import(
|
||||
path,
|
||||
@@ -332,6 +355,18 @@ impl Vecs {
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
semesterindex_to_ohlc: EagerVec::forced_import(
|
||||
path,
|
||||
"ohlc",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
semesterindex_to_ohlc_in_sats: EagerVec::forced_import(
|
||||
path,
|
||||
"ohlc_in_sats",
|
||||
version + VERSION + VERSION_IN_SATS + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
yearindex_to_ohlc: EagerVec::forced_import(
|
||||
path,
|
||||
"ohlc",
|
||||
@@ -422,27 +457,34 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut prev = None;
|
||||
self.dateindex_to_ohlc_in_cents.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.dateindex_to_date,
|
||||
|(di, d, this)| {
|
||||
let mut ohlc = fetcher.get_date(d).unwrap_or_else(|_| {
|
||||
this.get_or_read(di, &this.mmap().load())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_owned()
|
||||
});
|
||||
if prev.is_none() {
|
||||
let i = di.unwrap_to_usize();
|
||||
prev.replace(if i > 0 {
|
||||
this.into_iter().unwrap_get_inner_(i - 1)
|
||||
} else {
|
||||
OHLCCents::default()
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(prev) = di.decremented() {
|
||||
let prev_open = *this
|
||||
.get_or_read(prev, &this.mmap().load())
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.close;
|
||||
let ohlc = if di.unwrap_to_usize() + 100 >= this.len()
|
||||
&& let Ok(mut ohlc) = fetcher.get_date(d)
|
||||
{
|
||||
let prev_open = *prev.as_ref().unwrap().close;
|
||||
*ohlc.open = prev_open;
|
||||
*ohlc.high = (*ohlc.high).max(prev_open);
|
||||
*ohlc.low = (*ohlc.low).min(prev_open);
|
||||
}
|
||||
ohlc
|
||||
} else {
|
||||
prev.clone().unwrap()
|
||||
};
|
||||
|
||||
prev.replace(ohlc.clone());
|
||||
|
||||
(di, ohlc)
|
||||
},
|
||||
exit,
|
||||
@@ -610,12 +652,15 @@ impl Vecs {
|
||||
starting_indexes.weekindex,
|
||||
self.timeindexes_to_close.weekindex.unwrap_last(),
|
||||
|(i, close, ..)| {
|
||||
let open = weekindex_first_iter.unwrap_get_inner(i);
|
||||
let high = weekindex_max_iter.unwrap_get_inner(i);
|
||||
let low = weekindex_min_iter.unwrap_get_inner(i);
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: weekindex_first_iter.unwrap_get_inner(i),
|
||||
high: weekindex_max_iter.unwrap_get_inner(i),
|
||||
low: weekindex_min_iter.unwrap_get_inner(i),
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -693,6 +738,27 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut semesterindex_first_iter =
|
||||
self.timeindexes_to_open.semesterindex.unwrap_first().iter();
|
||||
let mut semesterindex_max_iter = self.timeindexes_to_high.semesterindex.unwrap_max().iter();
|
||||
let mut semesterindex_min_iter = self.timeindexes_to_low.semesterindex.unwrap_min().iter();
|
||||
self.semesterindex_to_ohlc.compute_transform(
|
||||
starting_indexes.semesterindex,
|
||||
self.timeindexes_to_close.semesterindex.unwrap_last(),
|
||||
|(i, close, ..)| {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: semesterindex_first_iter.unwrap_get_inner(i),
|
||||
high: semesterindex_max_iter.unwrap_get_inner(i),
|
||||
low: semesterindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut yearindex_first_iter = self.timeindexes_to_open.yearindex.unwrap_first().iter();
|
||||
let mut yearindex_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter();
|
||||
let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter();
|
||||
@@ -1044,6 +1110,40 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut semesterindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.semesterindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut semesterindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.semesterindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut semesterindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.semesterindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.semesterindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.semesterindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
.semesterindex
|
||||
.unwrap_last(),
|
||||
|(i, close, ..)| {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: semesterindex_first_iter.unwrap_get_inner(i),
|
||||
high: semesterindex_max_iter.unwrap_get_inner(i),
|
||||
low: semesterindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut yearindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.yearindex
|
||||
@@ -1133,6 +1233,7 @@ impl Vecs {
|
||||
&self.difficultyepoch_to_ohlc,
|
||||
&self.monthindex_to_ohlc,
|
||||
&self.quarterindex_to_ohlc,
|
||||
&self.semesterindex_to_ohlc,
|
||||
&self.yearindex_to_ohlc,
|
||||
// &self.halvingepoch_to_ohlc,
|
||||
&self.decadeindex_to_ohlc,
|
||||
@@ -1142,6 +1243,7 @@ impl Vecs {
|
||||
&self.difficultyepoch_to_ohlc_in_sats,
|
||||
&self.monthindex_to_ohlc_in_sats,
|
||||
&self.quarterindex_to_ohlc_in_sats,
|
||||
&self.semesterindex_to_ohlc_in_sats,
|
||||
&self.yearindex_to_ohlc_in_sats,
|
||||
// &self.halvingepoch_to_ohlc_in_sats,
|
||||
&self.decadeindex_to_ohlc_in_sats,
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{FromCoarserIndex, Result, Version};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyIterableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, Computation,
|
||||
ComputedVec, ComputedVecFrom2, Format, StoredIndex,
|
||||
};
|
||||
|
||||
use crate::vecs::grouped::{EagerVecBuilder, VecBuilderOptions};
|
||||
|
||||
use super::ComputedType;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecBuilder<I, T, S1I, S2T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: ComputedType,
|
||||
S2T: ComputedType,
|
||||
{
|
||||
pub first: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub average: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub sum: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub max: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub min: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub last: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
pub cumulative: Option<Box<ComputedVecFrom2<I, T, S1I, T, I, S2T>>>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<I, T, S1I, S2T> ComputedVecBuilder<I, T, S1I, S2T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: ComputedType + 'static,
|
||||
S1I: StoredIndex + 'static + FromCoarserIndex<I>,
|
||||
S2T: ComputedType,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
format: Format,
|
||||
computation: Computation,
|
||||
source: Option<BoxedAnyIterableVec<S1I, T>>,
|
||||
source_extra: &EagerVecBuilder<S1I, T>,
|
||||
len_source: BoxedAnyIterableVec<I, S2T>,
|
||||
options: ComputedVecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let only_one_active = options.is_only_one_active();
|
||||
|
||||
let suffix = |s: &str| format!("{name}_{s}");
|
||||
|
||||
let maybe_suffix = |s: &str| {
|
||||
if only_one_active {
|
||||
name.to_string()
|
||||
} else {
|
||||
suffix(s)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
first: options.first.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&maybe_suffix("first"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra
|
||||
.first
|
||||
.as_ref()
|
||||
.map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source
|
||||
.next_at(S1I::min_from(i))
|
||||
.map(|(_, cow)| cow.into_owned())
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
last: options.last.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra.last.as_ref().map_or_else(
|
||||
|| {
|
||||
source
|
||||
.as_ref()
|
||||
.unwrap_or_else(|| {
|
||||
dbg!(path, name, I::to_string());
|
||||
panic!()
|
||||
})
|
||||
.clone()
|
||||
},
|
||||
|v| v.clone(),
|
||||
),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source
|
||||
.next_at(S1I::max_from(i, source.len()))
|
||||
.map(|(_, cow)| cow.into_owned())
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
min: options.min.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&maybe_suffix("min"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra
|
||||
.min
|
||||
.as_ref()
|
||||
.map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned()))
|
||||
.min()
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
max: options.max.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&maybe_suffix("max"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra
|
||||
.max
|
||||
.as_ref()
|
||||
.map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned()))
|
||||
.max()
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
average: options.average.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&maybe_suffix("average"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra
|
||||
.average
|
||||
.as_ref()
|
||||
.map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
let vec = S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned()))
|
||||
.collect::<Vec<_>>();
|
||||
if vec.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut sum = T::from(0);
|
||||
let len = vec.len();
|
||||
vec.into_iter().for_each(|v| sum += v);
|
||||
Some(sum / len)
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
sum: options.sum.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&(if !options.last && !options.average && !options.min && !options.max {
|
||||
name.to_string()
|
||||
} else {
|
||||
maybe_suffix("sum")
|
||||
}),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra
|
||||
.sum
|
||||
.as_ref()
|
||||
.map_or_else(|| source.as_ref().unwrap().clone(), |v| v.clone()),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
let vec = S1I::inclusive_range_from(i, source.len())
|
||||
.flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned()))
|
||||
.collect::<Vec<_>>();
|
||||
if vec.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut sum = T::from(0);
|
||||
vec.into_iter().for_each(|v| sum += v);
|
||||
Some(sum)
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
cumulative: options.cumulative.then(|| {
|
||||
Box::new(
|
||||
ComputedVec::forced_import_or_init_from_2(
|
||||
computation,
|
||||
path,
|
||||
&suffix("cumulative"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
source_extra.cumulative.as_ref().unwrap().boxed_clone(),
|
||||
len_source.clone(),
|
||||
|i: I, source, len_source| {
|
||||
if i.unwrap_to_usize() >= len_source.len() {
|
||||
return None;
|
||||
}
|
||||
source
|
||||
.next_at(S1I::max_from(i, source.len()))
|
||||
.map(|(_, cow)| cow.into_owned())
|
||||
},
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_if_necessary<T2>(
|
||||
&mut self,
|
||||
max_from: I,
|
||||
len_source: &impl AnyIterableVec<I, T2>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
first.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(last) = self.last.as_mut() {
|
||||
last.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(min) = self.min.as_mut() {
|
||||
min.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(max) = self.max.as_mut() {
|
||||
max.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(average) = self.average.as_mut() {
|
||||
average.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(sum) = self.sum.as_mut() {
|
||||
sum.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
if let Some(cumulative) = self.cumulative.as_mut() {
|
||||
cumulative.compute_if_necessary(max_from, len_source, exit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn starting_index(&self, max_from: I) -> I {
|
||||
max_from.min(I::from(
|
||||
self.vecs().into_iter().map(|v| v.len()).min().unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn unwrap_first(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.first.as_ref().unwrap()
|
||||
}
|
||||
#[allow(unused)]
|
||||
pub fn unwrap_average(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.average.as_ref().unwrap()
|
||||
}
|
||||
pub fn unwrap_sum(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.sum.as_ref().unwrap()
|
||||
}
|
||||
pub fn unwrap_max(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.max.as_ref().unwrap()
|
||||
}
|
||||
pub fn unwrap_min(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.min.as_ref().unwrap()
|
||||
}
|
||||
pub fn unwrap_last(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.last.as_ref().unwrap()
|
||||
}
|
||||
#[allow(unused)]
|
||||
pub fn unwrap_cumulative(&self) -> &ComputedVecFrom2<I, T, S1I, T, I, S2T> {
|
||||
self.cumulative.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
|
||||
let mut v: Vec<&dyn AnyCollectableVec> = vec![];
|
||||
|
||||
if let Some(first) = self.first.as_ref() {
|
||||
v.push(first.as_ref());
|
||||
}
|
||||
if let Some(last) = self.last.as_ref() {
|
||||
v.push(last.as_ref());
|
||||
}
|
||||
if let Some(min) = self.min.as_ref() {
|
||||
v.push(min.as_ref());
|
||||
}
|
||||
if let Some(max) = self.max.as_ref() {
|
||||
v.push(max.as_ref());
|
||||
}
|
||||
if let Some(average) = self.average.as_ref() {
|
||||
v.push(average.as_ref());
|
||||
}
|
||||
if let Some(sum) = self.sum.as_ref() {
|
||||
v.push(sum.as_ref());
|
||||
}
|
||||
if let Some(cumulative) = self.cumulative.as_ref() {
|
||||
v.push(cumulative.as_ref());
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub struct ComputedVecBuilderOptions {
|
||||
average: bool,
|
||||
sum: bool,
|
||||
max: bool,
|
||||
min: bool,
|
||||
first: bool,
|
||||
last: bool,
|
||||
cumulative: bool,
|
||||
}
|
||||
|
||||
impl From<VecBuilderOptions> for ComputedVecBuilderOptions {
|
||||
fn from(value: VecBuilderOptions) -> Self {
|
||||
Self {
|
||||
average: value.average(),
|
||||
sum: value.sum(),
|
||||
max: value.max(),
|
||||
min: value.min(),
|
||||
first: value.first(),
|
||||
last: value.last(),
|
||||
cumulative: value.cumulative(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputedVecBuilderOptions {
|
||||
pub fn add_first(mut self) -> Self {
|
||||
self.first = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_last(mut self) -> Self {
|
||||
self.last = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_min(mut self) -> Self {
|
||||
self.min = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_max(mut self) -> Self {
|
||||
self.max = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_average(mut self) -> Self {
|
||||
self.average = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_sum(mut self) -> Self {
|
||||
self.sum = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_cumulative(mut self) -> Self {
|
||||
self.cumulative = true;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn rm_min(mut self) -> Self {
|
||||
self.min = false;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn rm_max(mut self) -> Self {
|
||||
self.max = false;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn rm_average(mut self) -> Self {
|
||||
self.average = false;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn rm_sum(mut self) -> Self {
|
||||
self.sum = false;
|
||||
self
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn rm_cumulative(mut self) -> Self {
|
||||
self.cumulative = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_minmax(mut self) -> Self {
|
||||
self.min = true;
|
||||
self.max = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_only_one_active(&self) -> bool {
|
||||
[
|
||||
self.average,
|
||||
self.sum,
|
||||
self.max,
|
||||
self.min,
|
||||
self.first,
|
||||
self.last,
|
||||
self.cumulative,
|
||||
]
|
||||
.iter()
|
||||
.filter(|b| **b)
|
||||
.count()
|
||||
== 1
|
||||
}
|
||||
|
||||
pub fn copy_self_extra(&self) -> Self {
|
||||
Self {
|
||||
cumulative: self.cumulative,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
-6
@@ -10,7 +10,7 @@ use crate::utils::get_percentile;
|
||||
use super::ComputedType;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ComputedVecBuilder<I, T>
|
||||
pub struct EagerVecBuilder<I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: ComputedType,
|
||||
@@ -31,7 +31,7 @@ where
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<I, T> ComputedVecBuilder<I, T>
|
||||
impl<I, T> EagerVecBuilder<I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: ComputedType,
|
||||
@@ -41,7 +41,7 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let only_one_active = options.is_only_one_active();
|
||||
|
||||
@@ -384,7 +384,7 @@ where
|
||||
pub fn from_aligned<I2>(
|
||||
&mut self,
|
||||
max_from: I,
|
||||
source: &ComputedVecBuilder<I2, T>,
|
||||
source: &EagerVecBuilder<I2, T>,
|
||||
first_indexes: &impl AnyIterableVec<I, I2>,
|
||||
count_indexes: &impl AnyIterableVec<I, StoredUsize>,
|
||||
exit: &Exit,
|
||||
@@ -706,7 +706,7 @@ where
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub struct StorableVecGeneatorOptions {
|
||||
pub struct VecBuilderOptions {
|
||||
average: bool,
|
||||
sum: bool,
|
||||
max: bool,
|
||||
@@ -721,7 +721,55 @@ pub struct StorableVecGeneatorOptions {
|
||||
cumulative: bool,
|
||||
}
|
||||
|
||||
impl StorableVecGeneatorOptions {
|
||||
impl VecBuilderOptions {
|
||||
pub fn average(&self) -> bool {
|
||||
self.average
|
||||
}
|
||||
|
||||
pub fn sum(&self) -> bool {
|
||||
self.sum
|
||||
}
|
||||
|
||||
pub fn max(&self) -> bool {
|
||||
self.max
|
||||
}
|
||||
|
||||
pub fn _90p(&self) -> bool {
|
||||
self._90p
|
||||
}
|
||||
|
||||
pub fn _75p(&self) -> bool {
|
||||
self._75p
|
||||
}
|
||||
|
||||
pub fn median(&self) -> bool {
|
||||
self.median
|
||||
}
|
||||
|
||||
pub fn _25p(&self) -> bool {
|
||||
self._25p
|
||||
}
|
||||
|
||||
pub fn _10p(&self) -> bool {
|
||||
self._10p
|
||||
}
|
||||
|
||||
pub fn min(&self) -> bool {
|
||||
self.min
|
||||
}
|
||||
|
||||
pub fn first(&self) -> bool {
|
||||
self.first
|
||||
}
|
||||
|
||||
pub fn last(&self) -> bool {
|
||||
self.last
|
||||
}
|
||||
|
||||
pub fn cumulative(&self) -> bool {
|
||||
self.cumulative
|
||||
}
|
||||
|
||||
pub fn add_first(mut self) -> Self {
|
||||
self.first = true;
|
||||
self
|
||||
@@ -1,15 +1,18 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{
|
||||
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, Version, WeekIndex, YearIndex,
|
||||
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, SemesterIndex, Version, WeekIndex,
|
||||
YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Computation, EagerVec, Format,
|
||||
};
|
||||
|
||||
use crate::vecs::{Indexes, indexes};
|
||||
use crate::vecs::{Indexes, grouped::ComputedVecBuilder, indexes};
|
||||
|
||||
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
|
||||
use super::{ComputedType, EagerVecBuilder, Source, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromDateIndex<T>
|
||||
@@ -17,33 +20,37 @@ where
|
||||
T: ComputedType + PartialOrd,
|
||||
{
|
||||
pub dateindex: Option<EagerVec<DateIndex, T>>,
|
||||
pub dateindex_extra: ComputedVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
|
||||
pub dateindex_extra: EagerVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex, WeekIndex>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
|
||||
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedVecsFromDateIndex<T>
|
||||
where
|
||||
T: ComputedType,
|
||||
T: ComputedType + 'static,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<DateIndex, T>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
computation: Computation,
|
||||
indexes: &indexes::Vecs,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let dateindex = compute_source.then(|| {
|
||||
let dateindex = source.is_compute().then(|| {
|
||||
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
|
||||
});
|
||||
|
||||
let dateindex_extra = ComputedVecBuilder::forced_import(
|
||||
let dateindex_extra = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -53,44 +60,77 @@ where
|
||||
|
||||
let options = options.remove_percentiles();
|
||||
|
||||
let dateindex_source = source.vec().or(dateindex.as_ref().map(|v| v.boxed_clone()));
|
||||
|
||||
Ok(Self {
|
||||
dateindex,
|
||||
dateindex_extra,
|
||||
weekindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
computation,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.weekindex_to_weekindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
monthindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.monthindex_to_monthindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
quarterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.quarterindex_to_quarterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
semesterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.semesterindex_to_semesterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
yearindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.yearindex_to_yearindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
decadeindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
dateindex_source.clone(),
|
||||
&dateindex_extra,
|
||||
indexes.decadeindex_to_decadeindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
dateindex,
|
||||
dateindex_extra,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -133,65 +173,45 @@ where
|
||||
if let Some(dateindex) = dateindex {
|
||||
self.dateindex_extra
|
||||
.extend(starting_indexes.dateindex, dateindex, exit)?;
|
||||
|
||||
self.weekindex.compute(
|
||||
starting_indexes.weekindex,
|
||||
dateindex,
|
||||
&indexes.weekindex_to_first_dateindex,
|
||||
&indexes.weekindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex.compute(
|
||||
starting_indexes.monthindex,
|
||||
dateindex,
|
||||
&indexes.monthindex_to_first_dateindex,
|
||||
&indexes.monthindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
} else {
|
||||
let dateindex = self.dateindex.as_ref().unwrap();
|
||||
|
||||
self.dateindex_extra
|
||||
.extend(starting_indexes.dateindex, dateindex, exit)?;
|
||||
|
||||
self.weekindex.compute(
|
||||
starting_indexes.weekindex,
|
||||
dateindex,
|
||||
&indexes.weekindex_to_first_dateindex,
|
||||
&indexes.weekindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex.compute(
|
||||
starting_indexes.monthindex,
|
||||
dateindex,
|
||||
&indexes.monthindex_to_first_dateindex,
|
||||
&indexes.monthindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
self.quarterindex.from_aligned(
|
||||
self.weekindex.compute_if_necessary(
|
||||
starting_indexes.weekindex,
|
||||
&indexes.weekindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex.compute_if_necessary(
|
||||
starting_indexes.monthindex,
|
||||
&indexes.monthindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex.compute_if_necessary(
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
&indexes.quarterindex_to_first_monthindex,
|
||||
&indexes.quarterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.from_aligned(
|
||||
self.semesterindex.compute_if_necessary(
|
||||
starting_indexes.semesterindex,
|
||||
&indexes.semesterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.compute_if_necessary(
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
&indexes.yearindex_to_first_monthindex,
|
||||
&indexes.yearindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex.from_aligned(
|
||||
self.decadeindex.compute_if_necessary(
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
&indexes.decadeindex_to_first_yearindex,
|
||||
&indexes.decadeindex_to_yearindex_count,
|
||||
exit,
|
||||
)?;
|
||||
@@ -208,6 +228,7 @@ where
|
||||
self.weekindex.vecs(),
|
||||
self.monthindex.vecs(),
|
||||
self.quarterindex.vecs(),
|
||||
self.semesterindex.vecs(),
|
||||
self.yearindex.vecs(),
|
||||
self.decadeindex.vecs(),
|
||||
]
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::{
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, Version,
|
||||
WeekIndex, YearIndex,
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result,
|
||||
SemesterIndex, Version, WeekIndex, YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Computation, EagerVec, Format,
|
||||
};
|
||||
|
||||
use crate::vecs::{Indexes, indexes};
|
||||
use crate::vecs::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecBuilder, Source},
|
||||
indexes,
|
||||
};
|
||||
|
||||
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
|
||||
use super::{ComputedType, EagerVecBuilder, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromHeight<T>
|
||||
@@ -18,38 +24,41 @@ where
|
||||
T: ComputedType + PartialOrd,
|
||||
{
|
||||
pub height: Option<EagerVec<Height, T>>,
|
||||
pub height_extra: ComputedVecBuilder<Height, T>,
|
||||
pub dateindex: ComputedVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
|
||||
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
|
||||
// 6 months
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T>,
|
||||
pub height_extra: EagerVecBuilder<Height, T>,
|
||||
pub dateindex: EagerVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex, WeekIndex>,
|
||||
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
|
||||
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
|
||||
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedVecsFromHeight<T>
|
||||
where
|
||||
T: ComputedType + Ord + From<f64>,
|
||||
T: ComputedType + Ord + From<f64> + 'static,
|
||||
f64: From<T>,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<Height, T>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
computation: Computation,
|
||||
indexes: &indexes::Vecs,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let height = compute_source.then(|| {
|
||||
let height = source.is_compute().then(|| {
|
||||
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
|
||||
});
|
||||
|
||||
let height_extra = ComputedVecBuilder::forced_import(
|
||||
let height_extra = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -57,7 +66,7 @@ where
|
||||
options.copy_self_extra(),
|
||||
)?;
|
||||
|
||||
let dateindex = ComputedVecBuilder::forced_import(
|
||||
let dateindex = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -68,46 +77,77 @@ where
|
||||
let options = options.remove_percentiles();
|
||||
|
||||
Ok(Self {
|
||||
height,
|
||||
height_extra,
|
||||
dateindex,
|
||||
weekindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
difficultyepoch: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
computation,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.weekindex_to_weekindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
monthindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.monthindex_to_monthindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
quarterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.quarterindex_to_quarterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
semesterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.semesterindex_to_semesterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
yearindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.yearindex_to_yearindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
decadeindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.decadeindex_to_decadeindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
|
||||
decadeindex: ComputedVecBuilder::forced_import(
|
||||
height,
|
||||
height_extra,
|
||||
dateindex,
|
||||
difficultyepoch: EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -189,42 +229,38 @@ where
|
||||
)?;
|
||||
}
|
||||
|
||||
self.weekindex.from_aligned(
|
||||
self.weekindex.compute_if_necessary(
|
||||
starting_indexes.weekindex,
|
||||
&self.dateindex,
|
||||
&indexes.weekindex_to_first_dateindex,
|
||||
&indexes.weekindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex.from_aligned(
|
||||
self.monthindex.compute_if_necessary(
|
||||
starting_indexes.monthindex,
|
||||
&self.dateindex,
|
||||
&indexes.monthindex_to_first_dateindex,
|
||||
&indexes.monthindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex.from_aligned(
|
||||
self.quarterindex.compute_if_necessary(
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
&indexes.quarterindex_to_first_monthindex,
|
||||
&indexes.quarterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.from_aligned(
|
||||
self.semesterindex.compute_if_necessary(
|
||||
starting_indexes.semesterindex,
|
||||
&indexes.semesterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.compute_if_necessary(
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
&indexes.yearindex_to_first_monthindex,
|
||||
&indexes.yearindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex.from_aligned(
|
||||
self.decadeindex.compute_if_necessary(
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
&indexes.decadeindex_to_first_yearindex,
|
||||
&indexes.decadeindex_to_yearindex_count,
|
||||
exit,
|
||||
)?;
|
||||
@@ -243,6 +279,7 @@ where
|
||||
self.difficultyepoch.vecs(),
|
||||
self.monthindex.vecs(),
|
||||
self.quarterindex.vecs(),
|
||||
self.semesterindex.vecs(),
|
||||
self.yearindex.vecs(),
|
||||
// self.halvingepoch.vecs(),
|
||||
self.decadeindex.vecs(),
|
||||
|
||||
@@ -5,9 +5,9 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, EagerVec, Format};
|
||||
|
||||
use crate::vecs::{indexes, Indexes};
|
||||
use crate::vecs::{Indexes, indexes};
|
||||
|
||||
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
|
||||
use super::{ComputedType, EagerVecBuilder, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromHeightStrict<T>
|
||||
@@ -15,8 +15,8 @@ where
|
||||
T: ComputedType + PartialOrd,
|
||||
{
|
||||
pub height: EagerVec<Height, T>,
|
||||
pub height_extra: ComputedVecBuilder<Height, T>,
|
||||
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
|
||||
pub height_extra: EagerVecBuilder<Height, T>,
|
||||
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
|
||||
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ where
|
||||
name: &str,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let height =
|
||||
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?;
|
||||
|
||||
let height_extra = ComputedVecBuilder::forced_import(
|
||||
let height_extra = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -50,7 +50,7 @@ where
|
||||
Ok(Self {
|
||||
height,
|
||||
height_extra,
|
||||
difficultyepoch: ComputedVecBuilder::forced_import(
|
||||
difficultyepoch: EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
|
||||
@@ -2,17 +2,22 @@ use std::path::Path;
|
||||
|
||||
use brk_core::{
|
||||
Bitcoin, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, MonthIndex, QuarterIndex,
|
||||
Result, Sats, TxIndex, Version, WeekIndex, YearIndex,
|
||||
Result, Sats, SemesterIndex, TxIndex, Version, WeekIndex, YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, VecIterator,
|
||||
AnyCollectableVec, AnyVec, CloneableAnyIterableVec, CollectableVec, Computation, EagerVec,
|
||||
Format, StoredIndex, VecIterator,
|
||||
};
|
||||
|
||||
use crate::vecs::{Indexes, fetched, indexes};
|
||||
use crate::vecs::{
|
||||
Indexes, fetched,
|
||||
grouped::{ComputedVecBuilder, Source},
|
||||
indexes,
|
||||
};
|
||||
|
||||
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
|
||||
use super::{ComputedType, EagerVecBuilder, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedVecsFromTxindex<T>
|
||||
@@ -20,40 +25,44 @@ where
|
||||
T: ComputedType + PartialOrd,
|
||||
{
|
||||
pub txindex: Option<Box<EagerVec<TxIndex, T>>>,
|
||||
pub height: ComputedVecBuilder<Height, T>,
|
||||
pub dateindex: ComputedVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T>,
|
||||
pub difficultyepoch: ComputedVecBuilder<DifficultyEpoch, T>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T>,
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T>,
|
||||
pub height: EagerVecBuilder<Height, T>,
|
||||
pub dateindex: EagerVecBuilder<DateIndex, T>,
|
||||
pub weekindex: ComputedVecBuilder<WeekIndex, T, DateIndex, WeekIndex>,
|
||||
pub difficultyepoch: EagerVecBuilder<DifficultyEpoch, T>,
|
||||
pub monthindex: ComputedVecBuilder<MonthIndex, T, DateIndex, MonthIndex>,
|
||||
pub quarterindex: ComputedVecBuilder<QuarterIndex, T, DateIndex, QuarterIndex>,
|
||||
pub semesterindex: ComputedVecBuilder<SemesterIndex, T, DateIndex, SemesterIndex>,
|
||||
pub yearindex: ComputedVecBuilder<YearIndex, T, DateIndex, YearIndex>,
|
||||
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T>,
|
||||
pub decadeindex: ComputedVecBuilder<DecadeIndex, T, DateIndex, DecadeIndex>,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl<T> ComputedVecsFromTxindex<T>
|
||||
where
|
||||
T: ComputedType + Ord + From<f64>,
|
||||
T: ComputedType + Ord + From<f64> + 'static,
|
||||
f64: From<T>,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<TxIndex, T>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
computation: Computation,
|
||||
indexes: &indexes::Vecs,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let txindex = compute_source.then(|| {
|
||||
let txindex = source.is_compute().then(|| {
|
||||
Box::new(
|
||||
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let height = ComputedVecBuilder::forced_import(
|
||||
let height = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -63,45 +72,86 @@ where
|
||||
|
||||
let options = options.remove_percentiles();
|
||||
|
||||
let dateindex = EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
txindex,
|
||||
height,
|
||||
dateindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
weekindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
difficultyepoch: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
computation,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.weekindex_to_weekindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
monthindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.monthindex_to_monthindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
quarterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.quarterindex_to_quarterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
semesterindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.semesterindex_to_semesterindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
yearindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.yearindex_to_yearindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
decadeindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
Computation::Lazy,
|
||||
None,
|
||||
&dateindex,
|
||||
indexes.decadeindex_to_decadeindex.boxed_clone(),
|
||||
options.into(),
|
||||
)?,
|
||||
|
||||
txindex,
|
||||
height,
|
||||
dateindex,
|
||||
difficultyepoch: EagerVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
@@ -109,13 +159,6 @@ where
|
||||
options,
|
||||
)?,
|
||||
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
|
||||
decadeindex: ComputedVecBuilder::forced_import(
|
||||
path,
|
||||
name,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
options,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -196,42 +239,38 @@ where
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.weekindex.from_aligned(
|
||||
self.weekindex.compute_if_necessary(
|
||||
starting_indexes.weekindex,
|
||||
&self.dateindex,
|
||||
&indexes.weekindex_to_first_dateindex,
|
||||
&indexes.weekindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex.from_aligned(
|
||||
self.monthindex.compute_if_necessary(
|
||||
starting_indexes.monthindex,
|
||||
&self.dateindex,
|
||||
&indexes.monthindex_to_first_dateindex,
|
||||
&indexes.monthindex_to_dateindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex.from_aligned(
|
||||
self.quarterindex.compute_if_necessary(
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
&indexes.quarterindex_to_first_monthindex,
|
||||
&indexes.quarterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.from_aligned(
|
||||
self.semesterindex.compute_if_necessary(
|
||||
starting_indexes.semesterindex,
|
||||
&indexes.semesterindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex.compute_if_necessary(
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
&indexes.yearindex_to_first_monthindex,
|
||||
&indexes.yearindex_to_monthindex_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex.from_aligned(
|
||||
self.decadeindex.compute_if_necessary(
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
&indexes.decadeindex_to_first_yearindex,
|
||||
&indexes.decadeindex_to_yearindex_count,
|
||||
exit,
|
||||
)?;
|
||||
@@ -258,6 +297,7 @@ where
|
||||
self.difficultyepoch.vecs(),
|
||||
self.monthindex.vecs(),
|
||||
self.quarterindex.vecs(),
|
||||
self.semesterindex.vecs(),
|
||||
self.yearindex.vecs(),
|
||||
// self.halvingepoch.vecs(),
|
||||
self.decadeindex.vecs(),
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
mod builder;
|
||||
mod builder_computed;
|
||||
mod builder_eager;
|
||||
mod from_dateindex;
|
||||
mod from_height;
|
||||
mod from_height_strict;
|
||||
mod from_txindex;
|
||||
mod ratio_from_dateindex;
|
||||
mod source;
|
||||
mod r#type;
|
||||
mod value_from_dateindex;
|
||||
mod value_from_height;
|
||||
mod value_from_txindex;
|
||||
mod value_height;
|
||||
|
||||
pub use builder::*;
|
||||
pub use builder_computed::*;
|
||||
pub use builder_eager::*;
|
||||
pub use from_dateindex::*;
|
||||
pub use from_height::*;
|
||||
pub use from_height_strict::*;
|
||||
pub use from_txindex::*;
|
||||
pub use ratio_from_dateindex::*;
|
||||
pub use source::*;
|
||||
use r#type::*;
|
||||
pub use value_from_dateindex::*;
|
||||
pub use value_from_height::*;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
use brk_vec::BoxedAnyIterableVec;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Source<I, T> {
|
||||
Compute,
|
||||
None,
|
||||
Vec(BoxedAnyIterableVec<I, T>),
|
||||
}
|
||||
|
||||
impl<I, T> Source<I, T> {
|
||||
pub fn is_compute(&self) -> bool {
|
||||
matches!(self, Self::Compute)
|
||||
}
|
||||
|
||||
pub fn is_none(&self) -> bool {
|
||||
matches!(self, Self::None)
|
||||
}
|
||||
|
||||
pub fn is_vec(&self) -> bool {
|
||||
matches!(self, Self::Vec(_))
|
||||
}
|
||||
|
||||
pub fn vec(self) -> Option<BoxedAnyIterableVec<I, T>> {
|
||||
match self {
|
||||
Self::Vec(v) => Some(v),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> From<bool> for Source<I, T> {
|
||||
fn from(value: bool) -> Self {
|
||||
if value { Self::Compute } else { Self::None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> From<BoxedAnyIterableVec<I, T>> for Source<I, T> {
|
||||
fn from(value: BoxedAnyIterableVec<I, T>) -> Self {
|
||||
Self::Vec(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> From<Option<BoxedAnyIterableVec<I, T>>> for Source<I, T> {
|
||||
fn from(value: Option<BoxedAnyIterableVec<I, T>>) -> Self {
|
||||
if let Some(v) = value {
|
||||
Self::Vec(v)
|
||||
} else {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use brk_vec::StoredType;
|
||||
|
||||
pub trait ComputedType
|
||||
where
|
||||
Self: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord,
|
||||
Self:
|
||||
StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + AddAssign + Ord,
|
||||
{
|
||||
}
|
||||
impl<T> ComputedType for T where
|
||||
T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + Ord
|
||||
T: StoredType + From<usize> + Div<usize, Output = Self> + Add<Output = Self> + AddAssign + Ord
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ use std::path::Path;
|
||||
use brk_core::{Bitcoin, DateIndex, Dollars, Result, Sats, Version};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
|
||||
use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec};
|
||||
|
||||
use crate::vecs::{Indexes, fetched, grouped::ComputedVecsFromDateIndex, indexes};
|
||||
|
||||
use super::StorableVecGeneatorOptions;
|
||||
use super::{Source, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedValueVecsFromDateIndex {
|
||||
@@ -19,39 +19,48 @@ pub struct ComputedValueVecsFromDateIndex {
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ComputedValueVecsFromDateIndex {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<DateIndex, Sats>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
computation: Computation,
|
||||
options: VecBuilderOptions,
|
||||
compute_dollars: bool,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
sats: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
name,
|
||||
compute_source,
|
||||
source,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
bitcoin: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_in_btc"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
dollars: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&format!("{name}_in_usd"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
@@ -3,11 +3,11 @@ use std::path::Path;
|
||||
use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
|
||||
use brk_vec::{AnyCollectableVec, CollectableVec, Computation, EagerVec, Format, StoredVec};
|
||||
|
||||
use crate::vecs::{Indexes, fetched, indexes};
|
||||
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
|
||||
|
||||
use super::{ComputedVecsFromHeight, StorableVecGeneatorOptions};
|
||||
use super::{ComputedVecsFromHeight, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedValueVecsFromHeight {
|
||||
@@ -19,39 +19,48 @@ pub struct ComputedValueVecsFromHeight {
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
impl ComputedValueVecsFromHeight {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<Height, Sats>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
options: StorableVecGeneatorOptions,
|
||||
computation: Computation,
|
||||
options: VecBuilderOptions,
|
||||
compute_dollars: bool,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
sats: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
name,
|
||||
compute_source,
|
||||
source,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
bitcoin: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&format!("{name}_in_btc"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?,
|
||||
dollars: compute_dollars.then(|| {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&format!("{name}_in_usd"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
@@ -4,13 +4,13 @@ use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Computation,
|
||||
ComputedVecFrom3, Format, LazyVecFrom1, StoredIndex, StoredVec,
|
||||
AnyCollectableVec, CloneableAnyIterableVec, CollectableVec, Computation, ComputedVecFrom3,
|
||||
Format, LazyVecFrom1, StoredIndex, StoredVec,
|
||||
};
|
||||
|
||||
use crate::vecs::{Indexes, fetched, indexes};
|
||||
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
|
||||
|
||||
use super::{ComputedVecsFromTxindex, StorableVecGeneatorOptions};
|
||||
use super::{ComputedVecsFromTxindex, VecBuilderOptions};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedValueVecsFromTxindex {
|
||||
@@ -41,14 +41,13 @@ impl ComputedValueVecsFromTxindex {
|
||||
path: &Path,
|
||||
name: &str,
|
||||
indexes: &indexes::Vecs,
|
||||
source: Option<BoxedAnyIterableVec<TxIndex, Sats>>,
|
||||
source: Source<TxIndex, Sats>,
|
||||
version: Version,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
options: StorableVecGeneatorOptions,
|
||||
options: VecBuilderOptions,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let compute_source = source.is_none();
|
||||
let compute_dollars = fetched.is_some();
|
||||
|
||||
let name_in_btc = format!("{name}_in_btc");
|
||||
@@ -57,16 +56,20 @@ impl ComputedValueVecsFromTxindex {
|
||||
let sats = ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
name,
|
||||
compute_source,
|
||||
source.clone(),
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?;
|
||||
|
||||
let source_vec = source.vec();
|
||||
|
||||
let bitcoin_txindex = LazyVecFrom1::init(
|
||||
&name_in_btc,
|
||||
version + VERSION,
|
||||
source.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|
||||
source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|
||||
|txindex: TxIndex, iter| {
|
||||
iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| {
|
||||
let sats = value.into_owned();
|
||||
@@ -78,9 +81,11 @@ impl ComputedValueVecsFromTxindex {
|
||||
let bitcoin = ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
&name_in_btc,
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)?;
|
||||
|
||||
@@ -124,9 +129,11 @@ impl ComputedValueVecsFromTxindex {
|
||||
ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
&name_in_usd,
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
options,
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
@@ -5,7 +5,7 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
|
||||
|
||||
use crate::vecs::{Indexes, fetched, indexes};
|
||||
use crate::vecs::{Indexes, fetched, grouped::Source, indexes};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ComputedHeightValueVecs {
|
||||
@@ -20,13 +20,13 @@ impl ComputedHeightValueVecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
name: &str,
|
||||
compute_source: bool,
|
||||
source: Source<Height, Sats>,
|
||||
version: Version,
|
||||
format: Format,
|
||||
compute_dollars: bool,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
sats: compute_source.then(|| {
|
||||
sats: source.is_compute().then(|| {
|
||||
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
|
||||
.unwrap()
|
||||
}),
|
||||
|
||||
@@ -5,8 +5,8 @@ use brk_core::{
|
||||
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2ABytes, P2MSOutputIndex,
|
||||
P2PK33AddressIndex, P2PK33Bytes, P2PK65AddressIndex, P2PK65Bytes, P2PKHAddressIndex,
|
||||
P2PKHBytes, P2SHAddressIndex, P2SHBytes, P2TRAddressIndex, P2TRBytes, P2WPKHAddressIndex,
|
||||
P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, StoredUsize, Timestamp,
|
||||
TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
|
||||
P2WPKHBytes, P2WSHAddressIndex, P2WSHBytes, QuarterIndex, Sats, SemesterIndex, StoredUsize,
|
||||
Timestamp, TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -50,6 +50,7 @@ pub struct Vecs {
|
||||
pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>,
|
||||
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
|
||||
pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>,
|
||||
pub monthindex_to_semesterindex: EagerVec<MonthIndex, SemesterIndex>,
|
||||
pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>,
|
||||
pub opreturnindex_to_opreturnindex:
|
||||
ComputedVecFrom1<OpReturnIndex, OpReturnIndex, OpReturnIndex, TxIndex>,
|
||||
@@ -76,6 +77,9 @@ pub struct Vecs {
|
||||
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
|
||||
pub quarterindex_to_monthindex_count: EagerVec<QuarterIndex, StoredUsize>,
|
||||
pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>,
|
||||
pub semesterindex_to_first_monthindex: EagerVec<SemesterIndex, MonthIndex>,
|
||||
pub semesterindex_to_monthindex_count: EagerVec<SemesterIndex, StoredUsize>,
|
||||
pub semesterindex_to_semesterindex: EagerVec<SemesterIndex, SemesterIndex>,
|
||||
pub txindex_to_height: EagerVec<TxIndex, Height>,
|
||||
pub txindex_to_input_count:
|
||||
ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, InputIndex, InputIndex, OutputIndex>,
|
||||
@@ -413,6 +417,12 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
monthindex_to_semesterindex: EagerVec::forced_import(
|
||||
path,
|
||||
"semesterindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
monthindex_to_yearindex: EagerVec::forced_import(
|
||||
path,
|
||||
"yearindex",
|
||||
@@ -425,6 +435,12 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
semesterindex_to_first_monthindex: EagerVec::forced_import(
|
||||
path,
|
||||
"first_monthindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
weekindex_to_first_dateindex: EagerVec::forced_import(
|
||||
path,
|
||||
"first_dateindex",
|
||||
@@ -443,6 +459,12 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
semesterindex_to_semesterindex: EagerVec::forced_import(
|
||||
path,
|
||||
"semesterindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
weekindex_to_weekindex: EagerVec::forced_import(
|
||||
path,
|
||||
"weekindex",
|
||||
@@ -521,6 +543,12 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
semesterindex_to_monthindex_count: EagerVec::forced_import(
|
||||
path,
|
||||
"monthindex_count",
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)?,
|
||||
yearindex_to_monthindex_count: EagerVec::forced_import(
|
||||
path,
|
||||
"monthindex_count",
|
||||
@@ -943,6 +971,45 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// SemesterIndex
|
||||
// ---
|
||||
|
||||
let starting_semesterindex = self
|
||||
.monthindex_to_semesterindex
|
||||
.into_iter()
|
||||
.get_inner(starting_monthindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.monthindex_to_semesterindex.compute_from_index(
|
||||
starting_monthindex,
|
||||
&self.monthindex_to_first_dateindex,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.semesterindex_to_first_monthindex
|
||||
.compute_inverse_more_to_less(
|
||||
starting_monthindex,
|
||||
&self.monthindex_to_semesterindex,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// let semester_count = self.semesterindex_to_first_monthindex.len();
|
||||
|
||||
self.semesterindex_to_semesterindex.compute_from_index(
|
||||
starting_semesterindex,
|
||||
&self.semesterindex_to_first_monthindex,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.semesterindex_to_monthindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_semesterindex,
|
||||
&self.semesterindex_to_first_monthindex,
|
||||
&self.monthindex_to_monthindex,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// YearIndex
|
||||
// ---
|
||||
@@ -1051,6 +1118,7 @@ impl Vecs {
|
||||
weekindex: starting_weekindex,
|
||||
monthindex: starting_monthindex,
|
||||
quarterindex: starting_quarterindex,
|
||||
semesterindex: starting_semesterindex,
|
||||
yearindex: starting_yearindex,
|
||||
decadeindex: starting_decadeindex,
|
||||
difficultyepoch: starting_difficultyepoch,
|
||||
@@ -1088,6 +1156,7 @@ impl Vecs {
|
||||
&self.monthindex_to_first_dateindex,
|
||||
&self.monthindex_to_monthindex,
|
||||
&self.monthindex_to_quarterindex,
|
||||
&self.monthindex_to_semesterindex,
|
||||
&self.monthindex_to_yearindex,
|
||||
&self.opreturnindex_to_opreturnindex,
|
||||
&self.outputindex_to_outputindex,
|
||||
@@ -1103,6 +1172,9 @@ impl Vecs {
|
||||
&self.quarterindex_to_first_monthindex,
|
||||
&self.quarterindex_to_monthindex_count,
|
||||
&self.quarterindex_to_quarterindex,
|
||||
&self.semesterindex_to_first_monthindex,
|
||||
&self.semesterindex_to_monthindex_count,
|
||||
&self.semesterindex_to_semesterindex,
|
||||
&self.txindex_to_height,
|
||||
&self.txindex_to_txindex,
|
||||
&self.txindex_to_input_count,
|
||||
@@ -1126,6 +1198,7 @@ pub struct Indexes {
|
||||
pub weekindex: WeekIndex,
|
||||
pub monthindex: MonthIndex,
|
||||
pub quarterindex: QuarterIndex,
|
||||
pub semesterindex: SemesterIndex,
|
||||
pub yearindex: YearIndex,
|
||||
pub decadeindex: DecadeIndex,
|
||||
pub difficultyepoch: DifficultyEpoch,
|
||||
@@ -1145,6 +1218,7 @@ impl Indexes {
|
||||
self.weekindex = WeekIndex::from(self.dateindex);
|
||||
self.monthindex = MonthIndex::from(self.dateindex);
|
||||
self.quarterindex = QuarterIndex::from(self.monthindex);
|
||||
self.semesterindex = SemesterIndex::from(self.monthindex);
|
||||
self.yearindex = YearIndex::from(self.monthindex);
|
||||
self.decadeindex = DecadeIndex::from(self.dateindex);
|
||||
self.difficultyepoch = DifficultyEpoch::from(self.height);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,9 +5,11 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
|
||||
|
||||
use crate::vecs::grouped::Source;
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, VecBuilderOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
@@ -24,33 +26,40 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> color_eyre::Result<Self> {
|
||||
Ok(Self {
|
||||
indexes_to_difficulty: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"difficulty",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"difficultyepoch",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
"halvingepoch",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
@@ -70,30 +71,35 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
)?,
|
||||
mining: mining::Vecs::forced_import(
|
||||
path,
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
)?,
|
||||
constants: constants::Vecs::forced_import(
|
||||
path,
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
)?,
|
||||
market: market::Vecs::forced_import(
|
||||
path,
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
)?,
|
||||
stateful: stateful::Vecs::forced_import(
|
||||
path,
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
fetched.as_ref(),
|
||||
)?,
|
||||
transactions: transactions::Vecs::forced_import(
|
||||
@@ -110,6 +116,7 @@ impl Vecs {
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
&indexes,
|
||||
fetched.as_ref(),
|
||||
)?,
|
||||
indexes,
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
states::AddressCohortState,
|
||||
vecs::{
|
||||
Indexes, fetched,
|
||||
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
indexes, market,
|
||||
stateful::{
|
||||
common,
|
||||
@@ -42,6 +42,7 @@ impl Vecs {
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
states_path: &Path,
|
||||
compute_relative_to_all: bool,
|
||||
@@ -66,10 +67,12 @@ impl Vecs {
|
||||
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("address_count"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
inner: common::Vecs::forced_import(
|
||||
path,
|
||||
@@ -77,8 +80,10 @@ impl Vecs {
|
||||
computation,
|
||||
format,
|
||||
version,
|
||||
indexes,
|
||||
fetched,
|
||||
compute_relative_to_all,
|
||||
false,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use derive_deref::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::vecs::{
|
||||
Indexes, fetched,
|
||||
Indexes, fetched, indexes,
|
||||
stateful::{
|
||||
address_cohort,
|
||||
r#trait::{CohortVecs, DynCohortVecs},
|
||||
@@ -28,6 +28,7 @@ impl Vecs {
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
states_path: &Path,
|
||||
) -> color_eyre::Result<Self> {
|
||||
@@ -40,6 +41,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -50,6 +52,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -60,6 +63,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -70,6 +74,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -80,6 +85,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -90,6 +96,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -100,6 +107,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -110,6 +118,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -120,6 +129,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -130,6 +140,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -140,6 +151,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -150,6 +162,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -160,6 +173,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -170,6 +184,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -180,6 +195,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -192,6 +208,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -202,6 +219,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -212,6 +230,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -222,6 +241,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -232,6 +252,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -242,6 +263,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -252,6 +274,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -262,6 +285,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -272,6 +296,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -282,6 +307,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -292,6 +318,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -302,6 +329,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -312,6 +340,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -324,6 +353,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -334,6 +364,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -344,6 +375,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -354,6 +386,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -364,6 +397,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -374,6 +408,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -384,6 +419,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -394,6 +430,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -404,6 +441,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -414,6 +452,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -424,6 +463,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -434,6 +474,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
@@ -444,6 +485,7 @@ impl Vecs {
|
||||
_computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
fetched,
|
||||
states_path,
|
||||
true,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
use std::{collections::BTreeSet, mem};
|
||||
|
||||
use brk_core::TypeIndex;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use super::ByAddressType;
|
||||
|
||||
#[derive(Debug, Deref, DerefMut)]
|
||||
pub struct AddressTypeToTypeIndexSet(ByAddressType<BTreeSet<TypeIndex>>);
|
||||
|
||||
impl AddressTypeToTypeIndexSet {
|
||||
pub fn merge(mut self, mut other: Self) -> Self {
|
||||
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
|
||||
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
|
||||
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
|
||||
Self::merge_(&mut self.p2sh, &mut other.p2sh);
|
||||
Self::merge_(&mut self.p2wpkh, &mut other.p2wpkh);
|
||||
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
|
||||
Self::merge_(&mut self.p2tr, &mut other.p2tr);
|
||||
Self::merge_(&mut self.p2a, &mut other.p2a);
|
||||
self
|
||||
}
|
||||
|
||||
fn merge_(own: &mut BTreeSet<TypeIndex>, other: &mut BTreeSet<TypeIndex>) {
|
||||
if own.len() >= other.len() {
|
||||
own.append(other);
|
||||
} else {
|
||||
other.append(own);
|
||||
mem::swap(own, other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AddressTypeToTypeIndexSet {
|
||||
fn default() -> Self {
|
||||
Self(ByAddressType {
|
||||
p2pk65: BTreeSet::default(),
|
||||
p2pk33: BTreeSet::default(),
|
||||
p2pkh: BTreeSet::default(),
|
||||
p2sh: BTreeSet::default(),
|
||||
p2wpkh: BTreeSet::default(),
|
||||
p2wsh: BTreeSet::default(),
|
||||
p2tr: BTreeSet::default(),
|
||||
p2a: BTreeSet::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use super::ByAddressType;
|
||||
pub struct AddressTypeToTypeIndexTree<T>(ByAddressType<BTreeMap<TypeIndex, T>>);
|
||||
|
||||
impl<T> AddressTypeToTypeIndexTree<T> {
|
||||
pub fn merge(&mut self, mut other: Self) {
|
||||
pub fn merge(mut self, mut other: Self) -> Self {
|
||||
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
|
||||
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
|
||||
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
|
||||
@@ -18,6 +18,7 @@ impl<T> AddressTypeToTypeIndexTree<T> {
|
||||
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
|
||||
Self::merge_(&mut self.p2tr, &mut other.p2tr);
|
||||
Self::merge_(&mut self.p2a, &mut other.p2a);
|
||||
self
|
||||
}
|
||||
|
||||
fn merge_(own: &mut BTreeMap<TypeIndex, T>, other: &mut BTreeMap<TypeIndex, T>) {
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
use std::mem;
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use super::ByAddressType;
|
||||
|
||||
#[derive(Debug, Default, Deref, DerefMut)]
|
||||
pub struct AddressTypeToVec<T>(ByAddressType<Vec<T>>);
|
||||
|
||||
impl<T> AddressTypeToVec<T> {
|
||||
pub fn merge(&mut self, mut other: Self) {
|
||||
Self::merge_(&mut self.p2pk65, &mut other.p2pk65);
|
||||
Self::merge_(&mut self.p2pk33, &mut other.p2pk33);
|
||||
Self::merge_(&mut self.p2pkh, &mut other.p2pkh);
|
||||
Self::merge_(&mut self.p2sh, &mut other.p2sh);
|
||||
Self::merge_(&mut self.p2wpkh, &mut other.p2wpkh);
|
||||
Self::merge_(&mut self.p2wsh, &mut other.p2wsh);
|
||||
Self::merge_(&mut self.p2tr, &mut other.p2tr);
|
||||
Self::merge_(&mut self.p2a, &mut other.p2a);
|
||||
}
|
||||
|
||||
fn merge_(own: &mut Vec<T>, other: &mut Vec<T>) {
|
||||
if own.len() >= other.len() {
|
||||
own.append(other);
|
||||
} else {
|
||||
other.append(own);
|
||||
mem::swap(own, other);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use super::ByAddressType;
|
||||
|
||||
#[derive(Debug, Deref, DerefMut)]
|
||||
pub struct AddressTypeToVec<T>(ByAddressType<Vec<T>>);
|
||||
|
||||
impl<T> Default for AddressTypeToVec<T> {
|
||||
fn default() -> Self {
|
||||
Self(ByAddressType {
|
||||
p2pk65: vec![],
|
||||
p2pk33: vec![],
|
||||
p2pkh: vec![],
|
||||
p2sh: vec![],
|
||||
p2wpkh: vec![],
|
||||
p2wsh: vec![],
|
||||
p2tr: vec![],
|
||||
p2a: vec![],
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ use brk_core::{
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, Format, VecIterator,
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, CloneableAnyIterableVec, Computation, EagerVec,
|
||||
Format, VecIterator,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -16,7 +17,7 @@ use crate::{
|
||||
grouped::{
|
||||
ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex,
|
||||
ComputedValueVecsFromDateIndex, ComputedVecsFromDateIndex, ComputedVecsFromHeight,
|
||||
StorableVecGeneatorOptions,
|
||||
Source, VecBuilderOptions,
|
||||
},
|
||||
indexes, market,
|
||||
},
|
||||
@@ -132,11 +133,13 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
path: &Path,
|
||||
cohort_name: Option<&str>,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
compute_relative_to_all: bool,
|
||||
ratio_extended: bool,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let compute_dollars = fetched.is_some();
|
||||
|
||||
@@ -144,8 +147,57 @@ impl Vecs {
|
||||
|
||||
let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}"));
|
||||
|
||||
Ok(Self {
|
||||
let dateindex_to_supply_in_profit = compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let dateindex_to_supply_even = compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_even"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let dateindex_to_supply_in_loss = compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let dateindex_to_unrealized_profit = compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_profit"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
let dateindex_to_unrealized_loss = compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
height_to_supply_in_profit: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -155,27 +207,21 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_in_profit: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_supply_in_profit: compute_dollars.then(|| {
|
||||
ComputedValueVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit"),
|
||||
false,
|
||||
dateindex_to_supply_in_profit.as_ref().map(|v | v.boxed_clone()).into(),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_in_profit,
|
||||
height_to_supply_even: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -185,27 +231,21 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_even: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_even"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_supply_even: compute_dollars.then(|| {
|
||||
ComputedValueVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_even"),
|
||||
false,
|
||||
dateindex_to_supply_even.as_ref().map(|v | v.boxed_clone()).into(),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_even,
|
||||
height_to_supply_in_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -215,27 +255,21 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_in_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_supply_in_loss: compute_dollars.then(|| {
|
||||
ComputedValueVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss"),
|
||||
false,
|
||||
dateindex_to_supply_in_loss.as_ref().map(|v | v.boxed_clone()).into(),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_supply_in_loss,
|
||||
height_to_unrealized_profit: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -245,26 +279,20 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_profit: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_profit"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_profit: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_profit"),
|
||||
false,
|
||||
dateindex_to_unrealized_profit.as_ref().map(|v | v.boxed_clone()).into(),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_profit,
|
||||
height_to_unrealized_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -292,26 +320,20 @@ impl Vecs {
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_loss"),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
indexes_to_unrealized_loss: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("unrealized_loss"),
|
||||
false,
|
||||
dateindex_to_unrealized_loss.as_ref().map(|v | v.boxed_clone()).into(),
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
dateindex_to_unrealized_loss,
|
||||
height_to_realized_cap: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
path,
|
||||
@@ -325,10 +347,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_cap"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -336,10 +360,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("min_price_paid"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -347,10 +373,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("max_price_paid"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -363,7 +391,7 @@ impl Vecs {
|
||||
height_to_supply_value: ComputedHeightValueVecs::forced_import(
|
||||
path,
|
||||
&suffix("supply"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
compute_dollars,
|
||||
@@ -371,11 +399,13 @@ impl Vecs {
|
||||
indexes_to_supply: ComputedValueVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
height_to_utxo_count: EagerVec::forced_import(
|
||||
path,
|
||||
@@ -386,19 +416,23 @@ impl Vecs {
|
||||
indexes_to_utxo_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("utxo_count"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_realized_price: compute_dollars.then(|| {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_price"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -406,9 +440,12 @@ impl Vecs {
|
||||
ComputedRatioVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("realized_price"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
computation,
|
||||
indexes,
|
||||
ratio_extended,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -425,10 +462,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_profit"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
)
|
||||
@@ -447,10 +486,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_loss"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
)
|
||||
@@ -460,10 +501,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("negative_realized_loss"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -480,10 +523,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("value_created"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -491,10 +536,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_value"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -511,10 +558,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("adjusted_value_created"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -531,10 +580,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("value_destroyed"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -551,10 +602,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("adjusted_value_destroyed"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -562,10 +615,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("realized_cap_30d_change"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -573,10 +628,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("net_realized_profit_and_loss"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
)
|
||||
@@ -612,7 +669,7 @@ impl Vecs {
|
||||
height_to_halved_supply_value: ComputedHeightValueVecs::forced_import(
|
||||
path,
|
||||
&suffix("halved_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
compute_dollars,
|
||||
@@ -620,11 +677,13 @@ impl Vecs {
|
||||
indexes_to_halved_supply: ComputedValueVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("halved_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
height_to_negative_unrealized_loss: compute_dollars.then(|| {
|
||||
EagerVec::forced_import(
|
||||
@@ -639,10 +698,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("negative_unrealized_loss"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -659,10 +720,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("net_unrealized_profit_and_loss"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -682,10 +745,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("net_unrealized_profit_and_loss_relative_to_market_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
@@ -694,10 +759,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_profit_relative_to_realized_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -705,10 +772,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("realized_loss_relative_to_realized_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -717,10 +786,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("net_realized_profit_and_loss_relative_to_realized_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum(),
|
||||
)
|
||||
.unwrap()
|
||||
},
|
||||
@@ -729,7 +800,7 @@ impl Vecs {
|
||||
ComputedHeightValueVecs::forced_import(
|
||||
path,
|
||||
&suffix("supply_even"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
compute_dollars,
|
||||
@@ -740,7 +811,7 @@ impl Vecs {
|
||||
ComputedHeightValueVecs::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
compute_dollars,
|
||||
@@ -751,7 +822,7 @@ impl Vecs {
|
||||
ComputedHeightValueVecs::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit"),
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
compute_dollars,
|
||||
@@ -789,10 +860,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_even_relative_to_own_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -800,10 +873,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss_relative_to_own_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -811,10 +886,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit_relative_to_own_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -822,10 +899,12 @@ impl Vecs {
|
||||
ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("supply_relative_to_circulating_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -868,10 +947,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_even_relative_to_circulating_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -881,10 +962,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_loss_relative_to_circulating_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -894,10 +977,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("supply_in_profit_relative_to_circulating_supply"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ONE,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -916,27 +1001,33 @@ impl Vecs {
|
||||
indexes_to_coinblocks_destroyed: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("coinblocks_destroyed"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
&suffix("coindays_destroyed"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::TWO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_sum().add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_net_realized_profit_and_loss_cumulative_30d_change: compute_dollars.then(|| {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("net_realized_profit_and_loss_cumulative_30d_change"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::new(3),
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last()
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -944,10 +1035,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_realized_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::new(3),
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last()
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
@@ -955,10 +1048,12 @@ impl Vecs {
|
||||
ComputedVecsFromDateIndex::forced_import(
|
||||
path,
|
||||
&suffix("net_realized_profit_and_loss_cumulative_30d_change_relative_to_market_cap"),
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::new(3),
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last()
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use brk_core::Height;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::vecs::stateful::AddressTypeToVec;
|
||||
|
||||
#[derive(Debug, Default, Deref, DerefMut)]
|
||||
pub struct HeightToAddressTypeToVec<T>(pub BTreeMap<Height, AddressTypeToVec<T>>);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use brk_vec::{IndexedVec, StoredIndex, StoredType};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RangeMap<I, T>(BTreeMap<I, T>);
|
||||
|
||||
impl<I, T> RangeMap<I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: StoredIndex,
|
||||
{
|
||||
pub fn get(&self, key: I) -> Option<&T> {
|
||||
self.0.range(..=key).next_back().map(|(&min, value)| {
|
||||
if min > key {
|
||||
unreachable!()
|
||||
}
|
||||
value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> From<&IndexedVec<I, T>> for RangeMap<T, I>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: StoredIndex + StoredType,
|
||||
{
|
||||
fn from(vec: &IndexedVec<I, T>) -> Self {
|
||||
Self(
|
||||
vec.into_iter()
|
||||
.map(|(i, v)| (v.into_owned(), i))
|
||||
.collect::<BTreeMap<_, _>>(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,11 @@ impl Vecs {
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
fetched: Option<&fetched::Vecs>,
|
||||
states_path: &Path,
|
||||
compute_relative_to_all: bool,
|
||||
ratio_extended: bool,
|
||||
) -> color_eyre::Result<Self> {
|
||||
let compute_dollars = fetched.is_some();
|
||||
|
||||
@@ -54,8 +56,10 @@ impl Vecs {
|
||||
computation,
|
||||
format,
|
||||
version,
|
||||
indexes,
|
||||
fetched,
|
||||
compute_relative_to_all,
|
||||
ratio_extended,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -11,11 +11,13 @@ use brk_vec::{
|
||||
ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator,
|
||||
};
|
||||
|
||||
use crate::vecs::grouped::Source;
|
||||
|
||||
use super::{
|
||||
Indexes, fetched,
|
||||
grouped::{
|
||||
ComputedValueVecsFromHeight, ComputedValueVecsFromTxindex, ComputedVecsFromHeight,
|
||||
ComputedVecsFromTxindex, StorableVecGeneatorOptions,
|
||||
ComputedVecsFromTxindex, VecBuilderOptions,
|
||||
},
|
||||
indexes,
|
||||
};
|
||||
@@ -237,7 +239,8 @@ impl Vecs {
|
||||
// true,
|
||||
// version + VERSION + Version::ZERO,
|
||||
// format,
|
||||
// StorableVecGeneatorOptions::default()
|
||||
// computation,
|
||||
// StorableVecGeneatorOptions::default()
|
||||
// .add_average()
|
||||
// .add_sum()
|
||||
// .add_cumulative(),
|
||||
@@ -286,7 +289,8 @@ impl Vecs {
|
||||
// true,
|
||||
// version + VERSION + Version::ZERO,
|
||||
// format,
|
||||
// StorableVecGeneatorOptions::default()
|
||||
// computation,
|
||||
// StorableVecGeneatorOptions::default()
|
||||
// .add_average()
|
||||
// .add_sum()
|
||||
// .add_cumulative(),
|
||||
@@ -339,10 +343,12 @@ impl Vecs {
|
||||
indexes_to_tx_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"tx_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -352,10 +358,12 @@ impl Vecs {
|
||||
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"input_count",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -365,10 +373,12 @@ impl Vecs {
|
||||
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"output_count",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -378,43 +388,43 @@ impl Vecs {
|
||||
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"tx_v1",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_tx_v2: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"tx_v2",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_tx_v3: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"tx_v3",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
)?,
|
||||
indexes_to_fee: ComputedValueVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"fee",
|
||||
indexes,
|
||||
Some(txindex_to_fee.boxed_clone()),
|
||||
Source::Vec(txindex_to_fee.boxed_clone()),
|
||||
version + VERSION + Version::ZERO,
|
||||
computation,
|
||||
format,
|
||||
fetched,
|
||||
StorableVecGeneatorOptions::default()
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative()
|
||||
.add_percentiles()
|
||||
@@ -424,10 +434,12 @@ impl Vecs {
|
||||
indexes_to_feerate: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"feerate",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_percentiles()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
@@ -435,10 +447,12 @@ impl Vecs {
|
||||
indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"tx_vsize",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_percentiles()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
@@ -446,10 +460,12 @@ impl Vecs {
|
||||
indexes_to_tx_weight: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"tx_weight",
|
||||
false,
|
||||
Source::None,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_percentiles()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
@@ -457,49 +473,55 @@ impl Vecs {
|
||||
indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
"subsidy",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
VecBuilderOptions::default()
|
||||
.add_percentiles()
|
||||
.add_sum()
|
||||
.add_cumulative()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
"coinbase",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
VecBuilderOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative()
|
||||
.add_percentiles()
|
||||
.add_minmax()
|
||||
.add_average(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import(
|
||||
path,
|
||||
"unclaimed_rewards",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
.add_sum()
|
||||
.add_cumulative(),
|
||||
computation,
|
||||
VecBuilderOptions::default().add_sum().add_cumulative(),
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_p2a_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2a_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -509,10 +531,12 @@ impl Vecs {
|
||||
indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2ms_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -522,10 +546,12 @@ impl Vecs {
|
||||
indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2pk33_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -535,10 +561,12 @@ impl Vecs {
|
||||
indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2pk65_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -548,10 +576,12 @@ impl Vecs {
|
||||
indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2pkh_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -561,10 +591,12 @@ impl Vecs {
|
||||
indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2sh_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -574,10 +606,12 @@ impl Vecs {
|
||||
indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2tr_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -587,10 +621,12 @@ impl Vecs {
|
||||
indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2wpkh_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -600,10 +636,12 @@ impl Vecs {
|
||||
indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"p2wsh_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -613,10 +651,12 @@ impl Vecs {
|
||||
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"opreturn_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -626,10 +666,12 @@ impl Vecs {
|
||||
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"unknownoutput_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -639,10 +681,12 @@ impl Vecs {
|
||||
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"emptyoutput_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default()
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
@@ -652,10 +696,12 @@ impl Vecs {
|
||||
indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"exact_utxo_count",
|
||||
true,
|
||||
Source::Compute,
|
||||
version + VERSION + Version::ZERO,
|
||||
format,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
computation,
|
||||
indexes,
|
||||
VecBuilderOptions::default().add_last(),
|
||||
)?,
|
||||
txindex_to_is_coinbase,
|
||||
inputindex_to_value,
|
||||
|
||||
@@ -18,15 +18,15 @@ impl AddressData {
|
||||
}
|
||||
|
||||
pub fn realized_price(&self) -> Dollars {
|
||||
(self.realized_cap / Bitcoin::from(self.amount())).round_nearest_cent()
|
||||
(self.realized_cap / Bitcoin::from(self.amount())).round_to_4_digits()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn has_0_sats(&self) -> bool {
|
||||
self.amount() == Sats::ZERO
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn has_0_utxos(&self) -> bool {
|
||||
self.outputs_len == 0
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
ops::{Add, Div, Mul},
|
||||
ops::{Add, AddAssign, Div, Mul},
|
||||
};
|
||||
|
||||
use serde::Serialize;
|
||||
@@ -20,6 +20,12 @@ impl Add for Bitcoin {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Bitcoin {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul for Bitcoin {
|
||||
type Output = Self;
|
||||
fn mul(self, rhs: Self) -> Self::Output {
|
||||
|
||||
@@ -24,10 +24,28 @@ use super::Dollars;
|
||||
)]
|
||||
pub struct Cents(i64);
|
||||
|
||||
const SIGNIFICANT_DIGITS: i32 = 4;
|
||||
|
||||
impl Cents {
|
||||
pub const fn mint(value: i64) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
|
||||
pub fn round_to_4_digits(self) -> Self {
|
||||
let v = self.0;
|
||||
|
||||
let ilog10 = v.checked_ilog10().unwrap_or(0) as i32;
|
||||
|
||||
Self::from(if ilog10 >= SIGNIFICANT_DIGITS {
|
||||
let log_diff = ilog10 - SIGNIFICANT_DIGITS + 1;
|
||||
|
||||
let pow = 10.0_f64.powi(log_diff);
|
||||
|
||||
((v as f64 / pow).round() * pow) as i64
|
||||
} else {
|
||||
v
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Dollars> for Cents {
|
||||
|
||||
@@ -31,6 +31,10 @@ impl Date {
|
||||
pub fn day(&self) -> u8 {
|
||||
(self.0 % 1_00) as u8
|
||||
}
|
||||
|
||||
pub fn into_jiff(self) -> Date_ {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Date {
|
||||
|
||||
@@ -3,11 +3,14 @@ use std::{
|
||||
ops::{Add, Rem},
|
||||
};
|
||||
|
||||
use jiff::Span;
|
||||
use serde::Serialize;
|
||||
// use color_eyre::eyre::eyre;
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
use crate::{CheckedSub, Error, Printable};
|
||||
use crate::{
|
||||
CheckedSub, DecadeIndex, Error, FromCoarserIndex, MonthIndex, Printable, QuarterIndex,
|
||||
SemesterIndex, WeekIndex, YearIndex,
|
||||
};
|
||||
|
||||
use super::Date;
|
||||
|
||||
@@ -103,3 +106,135 @@ impl Printable for DateIndex {
|
||||
&["d", "date", "dateindex"]
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<WeekIndex> for DateIndex {
|
||||
fn min_from(coarser: WeekIndex) -> usize {
|
||||
let coarser = usize::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else if coarser == 1 {
|
||||
1
|
||||
} else {
|
||||
4 + (coarser - 2) * 7
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: WeekIndex) -> usize {
|
||||
let coarser = usize::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else if coarser == 1 {
|
||||
3
|
||||
} else {
|
||||
3 + (coarser - 1) * 7
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<MonthIndex> for DateIndex {
|
||||
fn min_from(coarser: MonthIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else {
|
||||
let d = Date::new(2009, 1, 1)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(coarser))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: MonthIndex) -> usize {
|
||||
let d = Date::new(2009, 1, 31)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(u16::from(coarser)))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<QuarterIndex> for DateIndex {
|
||||
fn min_from(coarser: QuarterIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else {
|
||||
let d = Date::new(2009, 1, 1)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(3 * coarser))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: QuarterIndex) -> usize {
|
||||
let d = Date::new(2009, 3, 31)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(3 * u16::from(coarser)))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<SemesterIndex> for DateIndex {
|
||||
fn min_from(coarser: SemesterIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else {
|
||||
let d = Date::new(2009, 1, 1)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(6 * coarser))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: SemesterIndex) -> usize {
|
||||
let d = Date::new(2009, 5, 31)
|
||||
.into_jiff()
|
||||
.checked_add(Span::new().months(1 + 6 * u16::from(coarser)))
|
||||
.unwrap();
|
||||
DateIndex::try_from(Date::from(d)).unwrap().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<YearIndex> for DateIndex {
|
||||
fn min_from(coarser: YearIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else {
|
||||
Self::try_from(Date::new(2009 + coarser, 1, 1))
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: YearIndex) -> usize {
|
||||
Self::try_from(Date::new(2009 + u16::from(coarser), 12, 31))
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromCoarserIndex<DecadeIndex> for DateIndex {
|
||||
fn min_from(coarser: DecadeIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
if coarser == 0 {
|
||||
0
|
||||
} else {
|
||||
Self::try_from(Date::new(2000 + 10 * coarser, 1, 1))
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn max_from_(coarser: DecadeIndex) -> usize {
|
||||
let coarser = u16::from(coarser);
|
||||
Self::try_from(Date::new(2009 + (10 * coarser), 12, 31))
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -31,6 +34,18 @@ impl From<u8> for DecadeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecadeIndex> for u8 {
|
||||
fn from(value: DecadeIndex) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecadeIndex> for u16 {
|
||||
fn from(value: DecadeIndex) -> Self {
|
||||
value.0 as u16
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for DecadeIndex {
|
||||
fn from(value: usize) -> Self {
|
||||
Self(value as u8)
|
||||
@@ -51,6 +66,27 @@ impl Add<usize> for DecadeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<DecadeIndex> for DecadeIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for DecadeIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for DecadeIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for DecadeIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, Div},
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -54,6 +54,12 @@ impl Add for DifficultyEpoch {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for DifficultyEpoch {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for DifficultyEpoch {
|
||||
type Output = Self;
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ impl Dollars {
|
||||
pub fn round_nearest_cent(self) -> Self {
|
||||
Dollars((self.0 * 100.0).round() / 100.0)
|
||||
}
|
||||
|
||||
pub fn round_to_4_digits(self) -> Self {
|
||||
Self::from(Cents::from(self).round_to_4_digits())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for Dollars {
|
||||
@@ -239,7 +243,7 @@ impl Mul<Sats> for Dollars {
|
||||
self
|
||||
} else {
|
||||
Self::from(Cents::from(
|
||||
u128::from(rhs) * u128::from(Cents::from(self)) / u128::from(Sats::ONE_BTC),
|
||||
u128::from(rhs) * u128::from(Cents::from(self)) / Sats::ONE_BTC_U128,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
ops::{Add, Div},
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::Serialize;
|
||||
@@ -35,6 +35,12 @@ impl Add for Feerate {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Feerate {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for Feerate {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: usize) -> Self::Output {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, Div},
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -60,6 +60,12 @@ impl Add for HalvingEpoch {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for HalvingEpoch {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for HalvingEpoch {
|
||||
type Output = Self;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ mod p2wshaddressindex;
|
||||
mod quarterindex;
|
||||
mod rawlocktime;
|
||||
mod sats;
|
||||
mod semesterindex;
|
||||
mod stored_f32;
|
||||
mod stored_f64;
|
||||
mod stored_u32;
|
||||
@@ -90,6 +91,7 @@ pub use p2wshaddressindex::*;
|
||||
pub use quarterindex::*;
|
||||
pub use rawlocktime::*;
|
||||
pub use sats::*;
|
||||
pub use semesterindex::*;
|
||||
pub use stored_f32::*;
|
||||
pub use stored_f64::*;
|
||||
pub use stored_u8::*;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -31,6 +34,12 @@ impl From<u16> for MonthIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonthIndex> for u16 {
|
||||
fn from(value: MonthIndex) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for MonthIndex {
|
||||
fn from(value: usize) -> Self {
|
||||
Self(value as u16)
|
||||
@@ -51,6 +60,27 @@ impl Add<usize> for MonthIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<MonthIndex> for MonthIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for MonthIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for MonthIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for MonthIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use serde::{Serialize, Serializer, ser::SerializeTuple};
|
||||
@@ -236,6 +236,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for Open<T>
|
||||
where
|
||||
T: Add<Output = T> + Clone,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
**self = self.0.clone() + rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Div<usize> for Open<T>
|
||||
where
|
||||
T: Div<usize, Output = T>,
|
||||
@@ -324,6 +333,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for High<T>
|
||||
where
|
||||
T: Add<Output = T> + Clone,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
**self = self.0.clone() + rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Div<usize> for High<T>
|
||||
where
|
||||
T: Div<usize, Output = T>,
|
||||
@@ -412,6 +430,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for Low<T>
|
||||
where
|
||||
T: Add<Output = T> + Clone,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
**self = self.0.clone() + rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Div<usize> for Low<T>
|
||||
where
|
||||
T: Div<usize, Output = T>,
|
||||
@@ -515,6 +542,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddAssign for Close<T>
|
||||
where
|
||||
T: Add<Output = T> + Clone,
|
||||
{
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
**self = self.0.clone() + rhs.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Div<usize> for Close<T>
|
||||
where
|
||||
T: Div<usize, Output = T>,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -37,6 +40,12 @@ impl From<usize> for QuarterIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<QuarterIndex> for u16 {
|
||||
fn from(value: QuarterIndex) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<QuarterIndex> for usize {
|
||||
fn from(value: QuarterIndex) -> Self {
|
||||
value.0 as usize
|
||||
@@ -51,6 +60,27 @@ impl Add<usize> for QuarterIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<QuarterIndex> for QuarterIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for QuarterIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for QuarterIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonthIndex> for QuarterIndex {
|
||||
fn from(value: MonthIndex) -> Self {
|
||||
Self((usize::from(value) / 3) as u16)
|
||||
|
||||
@@ -53,6 +53,7 @@ impl Sats {
|
||||
pub const ONE_BTC: Self = Self(1_00_000_000);
|
||||
pub const MAX: Self = Self(u64::MAX);
|
||||
pub const FIFTY_BTC: Self = Self(50_00_000_000);
|
||||
pub const ONE_BTC_U128: u128 = 1_00_000_000;
|
||||
|
||||
pub fn new(sats: u64) -> Self {
|
||||
Self(sats)
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
use crate::{CheckedSub, Printable};
|
||||
|
||||
use super::MonthIndex;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
)]
|
||||
pub struct SemesterIndex(u16);
|
||||
|
||||
impl From<u16> for SemesterIndex {
|
||||
fn from(value: u16) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for SemesterIndex {
|
||||
fn from(value: usize) -> Self {
|
||||
Self(value as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SemesterIndex> for u16 {
|
||||
fn from(value: SemesterIndex) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SemesterIndex> for usize {
|
||||
fn from(value: SemesterIndex) -> Self {
|
||||
value.0 as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for SemesterIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: usize) -> Self::Output {
|
||||
Self::from(self.0 + rhs as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<SemesterIndex> for SemesterIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for SemesterIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for SemesterIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MonthIndex> for SemesterIndex {
|
||||
fn from(value: MonthIndex) -> Self {
|
||||
Self((usize::from(value) / 6) as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl CheckedSub for SemesterIndex {
|
||||
fn checked_sub(self, rhs: Self) -> Option<Self> {
|
||||
self.0.checked_sub(rhs.0).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Printable for SemesterIndex {
|
||||
fn to_string() -> &'static str {
|
||||
"semesterindex"
|
||||
}
|
||||
|
||||
fn to_possible_strings() -> &'static [&'static str] {
|
||||
&["s", "semester", "semesterindex"]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use core::panic;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
ops::{Add, Div, Mul, Sub},
|
||||
ops::{Add, AddAssign, Div, Mul, Sub},
|
||||
};
|
||||
|
||||
use derive_deref::Deref;
|
||||
@@ -70,6 +70,12 @@ impl Add for StoredF32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredF32 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoredF32> for f32 {
|
||||
fn from(value: StoredF32) -> Self {
|
||||
value.0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
f64,
|
||||
ops::{Add, Div, Mul},
|
||||
ops::{Add, AddAssign, Div, Mul},
|
||||
};
|
||||
|
||||
use derive_deref::Deref;
|
||||
@@ -65,6 +65,12 @@ impl Add for StoredF64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredF64 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoredF64> for f64 {
|
||||
fn from(value: StoredF64) -> Self {
|
||||
value.0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
@@ -73,6 +73,12 @@ impl Add for StoredU32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredU32 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for StoredU32 {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > u32::MAX as f64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
@@ -65,6 +65,12 @@ impl Add for StoredU64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredU64 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for StoredU64 {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > u32::MAX as f64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
@@ -66,6 +66,12 @@ impl Add for StoredU8 {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredU8 {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for StoredU8 {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > u32::MAX as f64 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use serde::Serialize;
|
||||
@@ -71,6 +71,12 @@ impl Add for StoredUsize {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for StoredUsize {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for StoredUsize {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > u32::MAX as f64 {
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
ops::{Add, Div},
|
||||
};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use jiff::{civil::date, tz::TimeZone};
|
||||
@@ -29,7 +26,9 @@ use super::Date;
|
||||
)]
|
||||
pub struct Timestamp(u32);
|
||||
|
||||
const ONE_DAY_IN_SEC: i64 = 24 * 60 * 60;
|
||||
const ONE_HOUR_IN_SEC: u32 = 60 * 60;
|
||||
const ONE_DAY_IN_SEC: u32 = 24 * 60 * 60;
|
||||
const ONE_DAY_IN_SEC_F64: f64 = ONE_DAY_IN_SEC as f64;
|
||||
|
||||
impl Timestamp {
|
||||
pub const ZERO: Self = Self(0);
|
||||
@@ -50,34 +49,25 @@ impl Timestamp {
|
||||
Self::from(trunc_date_time.to_zoned(TimeZone::UTC).unwrap().timestamp())
|
||||
}
|
||||
|
||||
pub fn difference_in_days_between(&self, other: Self) -> usize {
|
||||
match self.cmp(&other) {
|
||||
Ordering::Equal => 0,
|
||||
Ordering::Greater => other.difference_in_days_between(*self),
|
||||
Ordering::Less => {
|
||||
(jiff::Timestamp::from(*self)
|
||||
.duration_until(jiff::Timestamp::from(other))
|
||||
.as_secs()
|
||||
/ ONE_DAY_IN_SEC) as usize
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn difference_in_days_between(&self, older: Self) -> usize {
|
||||
// if self.0 < older.0 {
|
||||
// unreachable!()
|
||||
// }
|
||||
((self.0 - older.0) / ONE_DAY_IN_SEC) as usize
|
||||
}
|
||||
|
||||
pub fn difference_in_days_between_float(&self, other: Self) -> f64 {
|
||||
match self.cmp(&other) {
|
||||
Ordering::Equal => 0.0,
|
||||
Ordering::Greater => other.difference_in_days_between_float(*self),
|
||||
Ordering::Less => {
|
||||
jiff::Timestamp::from(*self)
|
||||
.duration_until(jiff::Timestamp::from(other))
|
||||
.as_secs() as f64
|
||||
/ ONE_DAY_IN_SEC as f64
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn difference_in_days_between_float(&self, older: Self) -> f64 {
|
||||
// if self.0 < older.0 {
|
||||
// unreachable!()
|
||||
// }
|
||||
(self.0 - older.0) as f64 / ONE_DAY_IN_SEC_F64
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_more_than_hour(&self) -> bool {
|
||||
jiff::Timestamp::from(*self).as_second() >= 60 * 60
|
||||
self.0 >= ONE_HOUR_IN_SEC
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +132,12 @@ impl Add for Timestamp {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Timestamp {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for Timestamp {
|
||||
fn from(value: f64) -> Self {
|
||||
if value < 0.0 || value > u32::MAX as f64 {
|
||||
|
||||
@@ -65,6 +65,12 @@ impl Version {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Version> for u64 {
|
||||
fn from(value: Version) -> u64 {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Version {
|
||||
fn from(value: u64) -> Self {
|
||||
Self(value)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -31,6 +34,12 @@ impl From<u16> for WeekIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WeekIndex> for u16 {
|
||||
fn from(value: WeekIndex) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<usize> for WeekIndex {
|
||||
fn from(value: usize) -> Self {
|
||||
Self(value as u16)
|
||||
@@ -43,6 +52,27 @@ impl From<WeekIndex> for usize {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<WeekIndex> for WeekIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for WeekIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for WeekIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<usize> for WeekIndex {
|
||||
type Output = Self;
|
||||
|
||||
@@ -68,7 +98,6 @@ impl From<Date> for WeekIndex {
|
||||
let d = jiff::civil::Date::new(year, 6, 6).unwrap();
|
||||
let i = d.iso_week_date();
|
||||
let w = i.weeks_in_year();
|
||||
// dbg!(d, w);
|
||||
week += w as u16;
|
||||
year += 1;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::ops::{Add, Div};
|
||||
use std::ops::{Add, AddAssign, Div};
|
||||
|
||||
use derive_deref::Deref;
|
||||
use serde::Serialize;
|
||||
@@ -58,6 +58,12 @@ impl Add for Weight {
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Weight {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for Weight {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: usize) -> Self::Output {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::{fmt::Debug, ops::Add};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
ops::{Add, AddAssign, Div},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
@@ -51,6 +54,27 @@ impl Add<usize> for YearIndex {
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<YearIndex> for YearIndex {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self::from(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for YearIndex {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = Self(self.0 + rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<usize> for YearIndex {
|
||||
type Output = Self;
|
||||
fn div(self, _: usize) -> Self::Output {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DateIndex> for YearIndex {
|
||||
fn from(value: DateIndex) -> Self {
|
||||
Self::from(Date::from(value))
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
pub trait FromCoarserIndex<T>
|
||||
where
|
||||
T: Ord + From<usize>,
|
||||
{
|
||||
fn min_from(coarser: T) -> usize;
|
||||
fn max_from_(coarser: T) -> usize;
|
||||
fn max_from(coarser: T, len: usize) -> usize {
|
||||
Self::max_from_(coarser).min(len - 1)
|
||||
}
|
||||
fn inclusive_range_from(coarser: T, len: usize) -> RangeInclusive<usize>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
Self::min_from(coarser.clone())..=Self::max_from(coarser, len)
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
mod from_coarser;
|
||||
mod printable;
|
||||
|
||||
pub use from_coarser::*;
|
||||
pub use printable::*;
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn setrlimit() -> io::Result<()> {
|
||||
|
||||
rlimit::setrlimit(
|
||||
Resource::NOFILE,
|
||||
no_file_limit.0.max(210_000),
|
||||
no_file_limit.0.max(10_000),
|
||||
no_file_limit.1,
|
||||
)?;
|
||||
|
||||
|
||||
+246
-188
@@ -15,7 +15,7 @@ use bitcoin::{Transaction, TxIn, TxOut};
|
||||
use brk_exit::Exit;
|
||||
use brk_parser::Parser;
|
||||
use brk_store::AnyStore;
|
||||
use brk_vec::{AnyVec, VecIterator};
|
||||
use brk_vec::{AnyVec, Mmap, VecIterator};
|
||||
use color_eyre::eyre::{ContextCompat, eyre};
|
||||
use log::{error, info};
|
||||
use rayon::prelude::*;
|
||||
@@ -40,6 +40,7 @@ pub struct Indexer {
|
||||
impl Indexer {
|
||||
pub fn forced_import(outputs_dir: &Path) -> color_eyre::Result<Self> {
|
||||
setrlimit()?;
|
||||
|
||||
Ok(Self {
|
||||
vecs: Vecs::forced_import(&outputs_dir.join("vecs/indexed"), VERSION + Version::ZERO)?,
|
||||
stores: Stores::forced_import(&outputs_dir.join("stores"), VERSION + Version::ZERO)?,
|
||||
@@ -88,9 +89,9 @@ impl Indexer {
|
||||
height: Height,
|
||||
rem: bool,
|
||||
exit: &Exit|
|
||||
-> color_eyre::Result<()> {
|
||||
-> color_eyre::Result<bool> {
|
||||
if height == 0 || (height % SNAPSHOT_BLOCK_RANGE != 0) != rem || exit.triggered() {
|
||||
return Ok(());
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
info!("Exporting...");
|
||||
@@ -98,15 +99,88 @@ impl Indexer {
|
||||
stores.commit(height)?;
|
||||
vecs.flush(height)?;
|
||||
exit.release();
|
||||
Ok(())
|
||||
Ok(true)
|
||||
};
|
||||
|
||||
let mut txindex_to_first_outputindex_mmap_opt = None;
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_mmap_opt = None;
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_mmap_opt = None;
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt = None;
|
||||
let mut p2shaddressindex_to_p2shbytes_mmap_opt = None;
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt = None;
|
||||
let mut p2wshaddressindex_to_p2wshbytes_mmap_opt = None;
|
||||
let mut p2traddressindex_to_p2trbytes_mmap_opt = None;
|
||||
let mut p2aaddressindex_to_p2abytes_mmap_opt = None;
|
||||
|
||||
let reset_mmaps_options =
|
||||
|vecs: &mut Vecs,
|
||||
txindex_to_first_outputindex_mmap_opt: &mut Option<Mmap>,
|
||||
p2pk65addressindex_to_p2pk65bytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2pk33addressindex_to_p2pk33bytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2pkhaddressindex_to_p2pkhbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2shaddressindex_to_p2shbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2wshaddressindex_to_p2wshbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2traddressindex_to_p2trbytes_mmap_opt: &mut Option<Mmap>,
|
||||
p2aaddressindex_to_p2abytes_mmap_opt: &mut Option<Mmap>| {
|
||||
txindex_to_first_outputindex_mmap_opt
|
||||
.replace(vecs.txindex_to_first_outputindex.create_mmap().unwrap());
|
||||
p2pk65addressindex_to_p2pk65bytes_mmap_opt.replace(
|
||||
vecs.p2pk65addressindex_to_p2pk65bytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
);
|
||||
p2pk33addressindex_to_p2pk33bytes_mmap_opt.replace(
|
||||
vecs.p2pk33addressindex_to_p2pk33bytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
);
|
||||
p2pkhaddressindex_to_p2pkhbytes_mmap_opt
|
||||
.replace(vecs.p2pkhaddressindex_to_p2pkhbytes.create_mmap().unwrap());
|
||||
p2shaddressindex_to_p2shbytes_mmap_opt
|
||||
.replace(vecs.p2shaddressindex_to_p2shbytes.create_mmap().unwrap());
|
||||
p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.replace(
|
||||
vecs.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.create_mmap()
|
||||
.unwrap(),
|
||||
);
|
||||
p2wshaddressindex_to_p2wshbytes_mmap_opt
|
||||
.replace(vecs.p2wshaddressindex_to_p2wshbytes.create_mmap().unwrap());
|
||||
p2traddressindex_to_p2trbytes_mmap_opt
|
||||
.replace(vecs.p2traddressindex_to_p2trbytes.create_mmap().unwrap());
|
||||
p2aaddressindex_to_p2abytes_mmap_opt
|
||||
.replace(vecs.p2aaddressindex_to_p2abytes.create_mmap().unwrap());
|
||||
};
|
||||
|
||||
reset_mmaps_options(
|
||||
vecs,
|
||||
&mut txindex_to_first_outputindex_mmap_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_mmap_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_mmap_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_mmap_opt,
|
||||
);
|
||||
|
||||
parser.parse(start, end).iter().try_for_each(
|
||||
|(height, block, blockhash)| -> color_eyre::Result<()> {
|
||||
info!("Indexing block {height}...");
|
||||
|
||||
idxs.height = height;
|
||||
|
||||
let txindex_to_first_outputindex_mmap = txindex_to_first_outputindex_mmap_opt.as_ref().unwrap();
|
||||
let p2pk65addressindex_to_p2pk65bytes_mmap = p2pk65addressindex_to_p2pk65bytes_mmap_opt.as_ref().unwrap();
|
||||
let p2pk33addressindex_to_p2pk33bytes_mmap = p2pk33addressindex_to_p2pk33bytes_mmap_opt.as_ref().unwrap();
|
||||
let p2pkhaddressindex_to_p2pkhbytes_mmap = p2pkhaddressindex_to_p2pkhbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2shaddressindex_to_p2shbytes_mmap = p2shaddressindex_to_p2shbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2wshaddressindex_to_p2wshbytes_mmap = p2wshaddressindex_to_p2wshbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2traddressindex_to_p2trbytes_mmap = p2traddressindex_to_p2trbytes_mmap_opt.as_ref().unwrap();
|
||||
let p2aaddressindex_to_p2abytes_mmap = p2aaddressindex_to_p2abytes_mmap_opt.as_ref().unwrap();
|
||||
|
||||
// Used to check rapidhash collisions
|
||||
let check_collisions = check_collisions && height > Height::new(COLLISIONS_CHECKED_UP_TO);
|
||||
|
||||
@@ -136,34 +210,6 @@ impl Indexer {
|
||||
vecs.height_to_total_size.push_if_needed(height, block.total_size().into())?;
|
||||
vecs.height_to_weight.push_if_needed(height, block.weight().into())?;
|
||||
|
||||
let inputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vin, txin)| (TxIndex::from(index), Vin::from(vin), txin, tx))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let outputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.output
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (TxIndex::from(index), Vout::from(vout), txout, tx))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let tx_len = block.txdata.len();
|
||||
let outputs_len = outputs.len();
|
||||
let inputs_len = inputs.len();
|
||||
|
||||
let (
|
||||
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_join_handle,
|
||||
input_source_vec_handle,
|
||||
@@ -173,9 +219,9 @@ impl Indexer {
|
||||
scope.spawn(|| -> color_eyre::Result<_> {
|
||||
block
|
||||
.txdata
|
||||
.par_iter()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, tx)| -> color_eyre::Result<_> {
|
||||
.map(|(index, tx)| {
|
||||
let txid = Txid::from(tx.compute_txid());
|
||||
|
||||
let txid_prefix = TxidPrefix::from(&txid);
|
||||
@@ -190,26 +236,21 @@ impl Indexer {
|
||||
|
||||
Ok((txid_prefix, (tx, txid, TxIndex::from(index), prev_txindex_opt)))
|
||||
})
|
||||
.try_fold(BTreeMap::new, |mut map, tuple| {
|
||||
let (key, value) = tuple?;
|
||||
map.insert(key, value);
|
||||
Ok(map)
|
||||
})
|
||||
.try_reduce(BTreeMap::new, |mut map, mut map2| {
|
||||
if map.len() > map2.len() {
|
||||
map.append(&mut map2);
|
||||
Ok(map)
|
||||
} else {
|
||||
map2.append(&mut map);
|
||||
Ok(map2)
|
||||
}
|
||||
})
|
||||
.collect::<color_eyre::Result<BTreeMap<_, _>>>()
|
||||
});
|
||||
|
||||
|
||||
let input_source_vec_handle = scope.spawn(|| {
|
||||
let txindex_to_first_outputindex_mmap = vecs
|
||||
.txindex_to_first_outputindex.mmap().load();
|
||||
let inputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vin, txin)| (TxIndex::from(index), Vin::from(vin), txin, tx))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
inputs
|
||||
.into_par_iter()
|
||||
@@ -241,7 +282,7 @@ impl Indexer {
|
||||
|
||||
let vout = Vout::from(outpoint.vout);
|
||||
|
||||
let outputindex = vecs.txindex_to_first_outputindex.get_or_read(prev_txindex, &txindex_to_first_outputindex_mmap)?
|
||||
let outputindex = vecs.txindex_to_first_outputindex.get_or_read(prev_txindex, txindex_to_first_outputindex_mmap)?
|
||||
.context("Expect outputindex to not be none")
|
||||
.inspect_err(|_| {
|
||||
dbg!(outpoint.txid, prev_txindex, vout);
|
||||
@@ -270,157 +311,155 @@ impl Indexer {
|
||||
})
|
||||
});
|
||||
|
||||
let outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle = scope.spawn(|| {
|
||||
let p2pk65addressindex_to_p2pk65bytes_mmap = vecs
|
||||
.p2pk65addressindex_to_p2pk65bytes.mmap().load();
|
||||
let p2pk33addressindex_to_p2pk33bytes_mmap = vecs.p2pk33addressindex_to_p2pk33bytes.mmap().load();
|
||||
let p2pkhaddressindex_to_p2pkhbytes_mmap = vecs.p2pkhaddressindex_to_p2pkhbytes.mmap().load();
|
||||
let p2shaddressindex_to_p2shbytes_mmap = vecs.p2shaddressindex_to_p2shbytes.mmap().load();
|
||||
let p2wpkhaddressindex_to_p2wpkhbytes_mmap = vecs.p2wpkhaddressindex_to_p2wpkhbytes.mmap().load();
|
||||
let p2wshaddressindex_to_p2wshbytes_mmap = vecs.p2wshaddressindex_to_p2wshbytes.mmap().load();
|
||||
let p2traddressindex_to_p2trbytes_mmap = vecs.p2traddressindex_to_p2trbytes.mmap().load();
|
||||
let p2aaddressindex_to_p2abytes_mmap = vecs.p2aaddressindex_to_p2abytes.mmap().load();
|
||||
let outputs = block
|
||||
.txdata
|
||||
.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, tx)| {
|
||||
tx.output
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(move |(vout, txout)| (TxIndex::from(index), Vout::from(vout), txout, tx))
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
outputs
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(
|
||||
#[allow(clippy::type_complexity)]
|
||||
|(block_outputindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
|
||||
OutputIndex,
|
||||
(
|
||||
&TxOut,
|
||||
TxIndex,
|
||||
Vout,
|
||||
OutputType,
|
||||
brk_core::Result<AddressBytes>,
|
||||
Option<TypeIndex>,
|
||||
&Transaction,
|
||||
),
|
||||
)> {
|
||||
let txindex = idxs.txindex + block_txindex;
|
||||
let outputindex = idxs.outputindex + OutputIndex::from(block_outputindex);
|
||||
let outputindex_to_txout_outputtype_addressbytes_res_addressindex = outputs.into_par_iter()
|
||||
.enumerate()
|
||||
.map(
|
||||
#[allow(clippy::type_complexity)]
|
||||
|(block_outputindex, (block_txindex, vout, txout, tx))| -> color_eyre::Result<(
|
||||
OutputIndex,
|
||||
(
|
||||
&TxOut,
|
||||
TxIndex,
|
||||
Vout,
|
||||
OutputType,
|
||||
brk_core::Result<AddressBytes>,
|
||||
Option<TypeIndex>,
|
||||
&Transaction,
|
||||
),
|
||||
)> {
|
||||
let txindex = idxs.txindex + block_txindex;
|
||||
let outputindex = idxs.outputindex + OutputIndex::from(block_outputindex);
|
||||
|
||||
let script = &txout.script_pubkey;
|
||||
let script = &txout.script_pubkey;
|
||||
|
||||
let outputtype = OutputType::from(script);
|
||||
let outputtype = OutputType::from(script);
|
||||
|
||||
let address_bytes_res =
|
||||
AddressBytes::try_from((script, outputtype)).inspect_err(|_| {
|
||||
// dbg!(&txout, height, txi, &tx.compute_txid());
|
||||
});
|
||||
|
||||
let typeindex_opt = address_bytes_res.as_ref().ok().and_then(|addressbytes| {
|
||||
stores
|
||||
.addressbyteshash_to_typeindex
|
||||
.get(&AddressBytesHash::from((addressbytes, outputtype)))
|
||||
.unwrap()
|
||||
.map(|v| *v)
|
||||
// Checking if not in the future
|
||||
.and_then(|typeindex_local| {
|
||||
(typeindex_local < idxs.typeindex(outputtype)).then_some(typeindex_local)
|
||||
})
|
||||
let address_bytes_res =
|
||||
AddressBytes::try_from((script, outputtype)).inspect_err(|_| {
|
||||
// dbg!(&txout, height, txi, &tx.compute_txid());
|
||||
});
|
||||
|
||||
if let Some(Some(typeindex)) = check_collisions.then_some(typeindex_opt) {
|
||||
let addressbytes = address_bytes_res.as_ref().unwrap();
|
||||
let typeindex_opt = address_bytes_res.as_ref().ok().and_then(|addressbytes| {
|
||||
stores
|
||||
.addressbyteshash_to_typeindex
|
||||
.get(&AddressBytesHash::from((addressbytes, outputtype)))
|
||||
.unwrap()
|
||||
.map(|v| *v)
|
||||
// Checking if not in the future
|
||||
.and_then(|typeindex_local| {
|
||||
(typeindex_local < idxs.typeindex(outputtype)).then_some(typeindex_local)
|
||||
})
|
||||
});
|
||||
|
||||
let prev_addressbytes_opt = match outputtype {
|
||||
OutputType::P2PK65 => vecs
|
||||
.p2pk65addressindex_to_p2pk65bytes
|
||||
.get_or_read(typeindex.into(), &p2pk65addressindex_to_p2pk65bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PK33 => vecs
|
||||
.p2pk33addressindex_to_p2pk33bytes
|
||||
.get_or_read(typeindex.into(), &p2pk33addressindex_to_p2pk33bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PKH => vecs
|
||||
.p2pkhaddressindex_to_p2pkhbytes
|
||||
.get_or_read(typeindex.into(), &p2pkhaddressindex_to_p2pkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2SH => vecs
|
||||
.p2shaddressindex_to_p2shbytes
|
||||
.get_or_read(typeindex.into(), &p2shaddressindex_to_p2shbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WPKH => vecs
|
||||
.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.get_or_read(typeindex.into(), &p2wpkhaddressindex_to_p2wpkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WSH => vecs
|
||||
.p2wshaddressindex_to_p2wshbytes
|
||||
.get_or_read(typeindex.into(), &p2wshaddressindex_to_p2wshbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2TR => vecs
|
||||
.p2traddressindex_to_p2trbytes
|
||||
.get_or_read(typeindex.into(), &p2traddressindex_to_p2trbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2A => vecs
|
||||
.p2aaddressindex_to_p2abytes
|
||||
.get_or_read(typeindex.into(), &p2aaddressindex_to_p2abytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
let prev_addressbytes =
|
||||
prev_addressbytes_opt.as_ref().context("Expect to have addressbytes")?;
|
||||
if let Some(Some(typeindex)) = check_collisions.then_some(typeindex_opt) {
|
||||
let addressbytes = address_bytes_res.as_ref().unwrap();
|
||||
|
||||
if stores.addressbyteshash_to_typeindex.needs(height)
|
||||
&& prev_addressbytes != addressbytes
|
||||
{
|
||||
let txid = tx.compute_txid();
|
||||
dbg!(
|
||||
height,
|
||||
txid,
|
||||
vout,
|
||||
block_txindex,
|
||||
outputtype,
|
||||
prev_addressbytes,
|
||||
addressbytes,
|
||||
&idxs,
|
||||
typeindex,
|
||||
typeindex,
|
||||
txout,
|
||||
AddressBytesHash::from((addressbytes, outputtype)),
|
||||
);
|
||||
panic!()
|
||||
let prev_addressbytes_opt = match outputtype {
|
||||
OutputType::P2PK65 => vecs
|
||||
.p2pk65addressindex_to_p2pk65bytes
|
||||
.get_or_read(typeindex.into(), p2pk65addressindex_to_p2pk65bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PK33 => vecs
|
||||
.p2pk33addressindex_to_p2pk33bytes
|
||||
.get_or_read(typeindex.into(), p2pk33addressindex_to_p2pk33bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PKH => vecs
|
||||
.p2pkhaddressindex_to_p2pkhbytes
|
||||
.get_or_read(typeindex.into(), p2pkhaddressindex_to_p2pkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2SH => vecs
|
||||
.p2shaddressindex_to_p2shbytes
|
||||
.get_or_read(typeindex.into(), p2shaddressindex_to_p2shbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WPKH => vecs
|
||||
.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.get_or_read(typeindex.into(), p2wpkhaddressindex_to_p2wpkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WSH => vecs
|
||||
.p2wshaddressindex_to_p2wshbytes
|
||||
.get_or_read(typeindex.into(), p2wshaddressindex_to_p2wshbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2TR => vecs
|
||||
.p2traddressindex_to_p2trbytes
|
||||
.get_or_read(typeindex.into(), p2traddressindex_to_p2trbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2A => vecs
|
||||
.p2aaddressindex_to_p2abytes
|
||||
.get_or_read(typeindex.into(), p2aaddressindex_to_p2abytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
};
|
||||
let prev_addressbytes =
|
||||
prev_addressbytes_opt.as_ref().context("Expect to have addressbytes")?;
|
||||
|
||||
Ok((
|
||||
outputindex,
|
||||
(
|
||||
txout,
|
||||
txindex,
|
||||
if stores.addressbyteshash_to_typeindex.needs(height)
|
||||
&& prev_addressbytes != addressbytes
|
||||
{
|
||||
let txid = tx.compute_txid();
|
||||
dbg!(
|
||||
height,
|
||||
txid,
|
||||
vout,
|
||||
block_txindex,
|
||||
outputtype,
|
||||
address_bytes_res,
|
||||
typeindex_opt,
|
||||
tx,
|
||||
),
|
||||
))
|
||||
},
|
||||
)
|
||||
.try_fold(BTreeMap::new, |mut map, tuple| -> color_eyre::Result<_> {
|
||||
let (key, value) = tuple?;
|
||||
map.insert(key, value);
|
||||
Ok(map)
|
||||
})
|
||||
.try_reduce(BTreeMap::new, |mut map, mut map2| {
|
||||
if map.len() > map2.len() {
|
||||
map.append(&mut map2);
|
||||
Ok(map)
|
||||
} else {
|
||||
map2.append(&mut map);
|
||||
Ok(map2)
|
||||
prev_addressbytes,
|
||||
addressbytes,
|
||||
&idxs,
|
||||
typeindex,
|
||||
typeindex,
|
||||
txout,
|
||||
AddressBytesHash::from((addressbytes, outputtype)),
|
||||
);
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Ok((
|
||||
outputindex,
|
||||
(
|
||||
txout,
|
||||
txindex,
|
||||
vout,
|
||||
outputtype,
|
||||
address_bytes_res,
|
||||
typeindex_opt,
|
||||
tx,
|
||||
),
|
||||
))
|
||||
},
|
||||
)
|
||||
.try_fold(BTreeMap::new, |mut map, tuple| -> color_eyre::Result<_> {
|
||||
let (key, value) = tuple?;
|
||||
map.insert(key, value);
|
||||
Ok(map)
|
||||
})
|
||||
.try_reduce(BTreeMap::new, |mut map, mut map2| {
|
||||
if map.len() > map2.len() {
|
||||
map.append(&mut map2);
|
||||
Ok(map)
|
||||
} else {
|
||||
map2.append(&mut map);
|
||||
Ok(map2)
|
||||
}
|
||||
});
|
||||
|
||||
(
|
||||
txid_prefix_to_txid_and_block_txindex_and_prev_txindex_handle.join(),
|
||||
input_source_vec_handle.join(),
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle.join(),
|
||||
outputindex_to_txout_outputtype_addressbytes_res_addressindex,
|
||||
)
|
||||
});
|
||||
|
||||
@@ -440,7 +479,11 @@ impl Indexer {
|
||||
.ok()
|
||||
.context(
|
||||
"Expect outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt_handle to join",
|
||||
)??;
|
||||
)?;
|
||||
|
||||
let outputs_len = outputindex_to_txout_outputtype_addressbytes_res_addressindex_opt.len();
|
||||
let inputs_len = input_source_vec.len();
|
||||
let tx_len = block.txdata.len();
|
||||
|
||||
let mut new_txindexvout_to_outputindex: BTreeMap<
|
||||
(TxIndex, Vout),
|
||||
@@ -695,7 +738,22 @@ impl Indexer {
|
||||
idxs.inputindex += InputIndex::from(inputs_len);
|
||||
idxs.outputindex += OutputIndex::from(outputs_len);
|
||||
|
||||
export_if_needed(stores, vecs, height, false, exit)?;
|
||||
let exported = export_if_needed(stores, vecs, height, false, exit)?;
|
||||
|
||||
if exported {
|
||||
reset_mmaps_options(
|
||||
vecs,
|
||||
&mut txindex_to_first_outputindex_mmap_opt,
|
||||
&mut p2pk65addressindex_to_p2pk65bytes_mmap_opt,
|
||||
&mut p2pk33addressindex_to_p2pk33bytes_mmap_opt,
|
||||
&mut p2pkhaddressindex_to_p2pkhbytes_mmap_opt,
|
||||
&mut p2shaddressindex_to_p2shbytes_mmap_opt,
|
||||
&mut p2wpkhaddressindex_to_p2wpkhbytes_mmap_opt,
|
||||
&mut p2wshaddressindex_to_p2wshbytes_mmap_opt,
|
||||
&mut p2traddressindex_to_p2trbytes_mmap_opt,
|
||||
&mut p2aaddressindex_to_p2abytes_mmap_opt,
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
|
||||
@@ -72,7 +72,7 @@ impl Stores {
|
||||
path,
|
||||
"p2aaddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2pk33addressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -81,7 +81,7 @@ impl Stores {
|
||||
path,
|
||||
"p2pk33addressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2pk65addressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -90,7 +90,7 @@ impl Stores {
|
||||
path,
|
||||
"p2pk65addressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2pkhaddressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -99,7 +99,7 @@ impl Stores {
|
||||
path,
|
||||
"p2pkhaddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2shaddressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -108,7 +108,7 @@ impl Stores {
|
||||
path,
|
||||
"p2shaddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2traddressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -117,7 +117,7 @@ impl Stores {
|
||||
path,
|
||||
"p2traddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2wpkhaddressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -126,7 +126,7 @@ impl Stores {
|
||||
path,
|
||||
"p2wpkhaddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
let p2wshaddressindex_with_outputindex = scope.spawn(|| {
|
||||
@@ -135,7 +135,7 @@ impl Stores {
|
||||
path,
|
||||
"p2wshaddressindex_with_outputindex",
|
||||
version + VERSION + Version::ZERO,
|
||||
Some(None),
|
||||
Some(false),
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ use brk_core::{
|
||||
DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height, InputIndex,
|
||||
MonthIndex, OpReturnIndex, OutputIndex, P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex,
|
||||
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex,
|
||||
P2WSHAddressIndex, Printable, QuarterIndex, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
|
||||
P2WSHAddressIndex, Printable, QuarterIndex, SemesterIndex, TxIndex, UnknownOutputIndex,
|
||||
WeekIndex, YearIndex,
|
||||
};
|
||||
use color_eyre::eyre::eyre;
|
||||
use schemars::JsonSchema;
|
||||
@@ -52,6 +53,8 @@ pub enum Index {
|
||||
P2WSHAddressIndex,
|
||||
#[schemars(description = "Quarter index")]
|
||||
QuarterIndex,
|
||||
#[schemars(description = "Semester index")]
|
||||
SemesterIndex,
|
||||
#[schemars(description = "Transaction index")]
|
||||
TxIndex,
|
||||
#[schemars(description = "Unknown output index")]
|
||||
@@ -63,7 +66,7 @@ pub enum Index {
|
||||
}
|
||||
|
||||
impl Index {
|
||||
pub fn all() -> [Self; 24] {
|
||||
pub fn all() -> [Self; 25] {
|
||||
[
|
||||
Self::DateIndex,
|
||||
Self::DecadeIndex,
|
||||
@@ -85,6 +88,7 @@ impl Index {
|
||||
Self::P2WPKHAddressIndex,
|
||||
Self::P2WSHAddressIndex,
|
||||
Self::QuarterIndex,
|
||||
Self::SemesterIndex,
|
||||
Self::TxIndex,
|
||||
Self::UnknownOutputIndex,
|
||||
Self::WeekIndex,
|
||||
@@ -114,6 +118,7 @@ impl Index {
|
||||
Self::P2WPKHAddressIndex => P2WPKHAddressIndex::to_possible_strings(),
|
||||
Self::P2WSHAddressIndex => P2WSHAddressIndex::to_possible_strings(),
|
||||
Self::QuarterIndex => QuarterIndex::to_possible_strings(),
|
||||
Self::SemesterIndex => SemesterIndex::to_possible_strings(),
|
||||
Self::TxIndex => TxIndex::to_possible_strings(),
|
||||
Self::UnknownOutputIndex => UnknownOutputIndex::to_possible_strings(),
|
||||
Self::WeekIndex => WeekIndex::to_possible_strings(),
|
||||
@@ -174,7 +179,7 @@ impl TryFrom<&str> for Index {
|
||||
Self::P2WSHAddressIndex
|
||||
}
|
||||
v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex,
|
||||
v if (Self::QuarterIndex).possible_values().contains(&v) => Self::QuarterIndex,
|
||||
v if (Self::SemesterIndex).possible_values().contains(&v) => Self::SemesterIndex,
|
||||
v if (Self::TxIndex).possible_values().contains(&v) => Self::TxIndex,
|
||||
v if (Self::WeekIndex).possible_values().contains(&v) => Self::WeekIndex,
|
||||
v if (Self::YearIndex).possible_values().contains(&v) => Self::YearIndex,
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use brk_computer::Computer;
|
||||
use brk_core::Result;
|
||||
use brk_core::{Height, Result};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::AnyCollectableVec;
|
||||
use brk_vec::{AnyCollectableVec, AnyIndexedVec};
|
||||
use tabled::settings::Style;
|
||||
|
||||
mod deser;
|
||||
@@ -46,6 +46,10 @@ impl<'a> Interface<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_height(&self) -> Height {
|
||||
self._indexer.vecs.height_to_blockhash.height()
|
||||
}
|
||||
|
||||
pub fn search(&self, params: &Params) -> Vec<(String, &&dyn AnyCollectableVec)> {
|
||||
let tuples = params
|
||||
.ids
|
||||
|
||||
@@ -14,7 +14,7 @@ use color_eyre::owo_colors::OwoColorize;
|
||||
use env_logger::{Builder, Env};
|
||||
use jiff::{Timestamp, tz};
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn init(path: Option<&Path>) {
|
||||
let file = path.map(|path| {
|
||||
let _ = fs::remove_file(path);
|
||||
|
||||
@@ -17,14 +17,14 @@ impl XORIndex {
|
||||
bytes
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn byte(&mut self, mut byte: u8, xor_bytes: &XORBytes) -> u8 {
|
||||
byte ^= xor_bytes[self.0];
|
||||
self.increment();
|
||||
byte
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn increment(&mut self) {
|
||||
self.0 += 1;
|
||||
if self.0 == XOR_LEN {
|
||||
@@ -32,7 +32,7 @@ impl XORIndex {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn add_assign(&mut self, i: usize) {
|
||||
self.0 = (self.0 + i) % XOR_LEN;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ serde = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tower-http = { version = "0.6.6", features = ["compression-full", "trace"] }
|
||||
tracing = "0.1.41"
|
||||
zip = "4.2.0"
|
||||
zip = "4.3.0"
|
||||
|
||||
[package.metadata.cargo-machete]
|
||||
ignored = ["clap"]
|
||||
|
||||
@@ -48,6 +48,8 @@ fn req_to_response_res(
|
||||
let to = params.to();
|
||||
let format = params.format();
|
||||
|
||||
// TODO: From and to should be capped here
|
||||
|
||||
let weight = vecs
|
||||
.iter()
|
||||
.map(|(_, v)| v.range_weight(from, to))
|
||||
@@ -57,7 +59,8 @@ fn req_to_response_res(
|
||||
return Err(eyre!("Request is too heavy, max weight is {MAX_WEIGHT}"));
|
||||
}
|
||||
|
||||
let etag = vecs.first().unwrap().1.etag(to);
|
||||
// TODO: height should be from vec, but good enough for now
|
||||
let etag = vecs.first().unwrap().1.etag(interface.get_height(), to);
|
||||
|
||||
if headers
|
||||
.get_if_none_match()
|
||||
|
||||
@@ -8,7 +8,6 @@ use axum::http::{
|
||||
header::{self, IF_MODIFIED_SINCE, IF_NONE_MATCH},
|
||||
};
|
||||
use jiff::{Timestamp, civil::DateTime, fmt::strtime, tz::TimeZone};
|
||||
use log::info;
|
||||
|
||||
const MODIFIED_SINCE_FORMAT: &str = "%a, %d %b %Y %H:%M:%S GMT";
|
||||
|
||||
@@ -140,7 +139,11 @@ impl HeaderMapExtended for HeaderMap {
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
||||
fn insert_content_type(&mut self, path: &Path) {
|
||||
match path.extension().unwrap().to_str().unwrap() {
|
||||
match path
|
||||
.extension()
|
||||
.map(|s| s.to_str().unwrap_or_default())
|
||||
.unwrap_or_default()
|
||||
{
|
||||
"js" => self.insert_content_type_application_javascript(),
|
||||
"json" | "map" => self.insert_content_type_application_json(),
|
||||
"html" => self.insert_content_type_text_html(),
|
||||
@@ -152,10 +155,7 @@ impl HeaderMapExtended for HeaderMap {
|
||||
"jpg" | "jpeg" => self.insert_content_type_image_jpeg(),
|
||||
"png" => self.insert_content_type_image_png(),
|
||||
"webmanifest" => self.insert_content_type_application_manifest_json(),
|
||||
extension => {
|
||||
info!("Extension unsupported: {extension}");
|
||||
panic!()
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-19
@@ -34,11 +34,9 @@ pub struct Store<Key, Value> {
|
||||
rtx: ReadTransaction,
|
||||
puts: BTreeMap<Key, Value>,
|
||||
dels: BTreeSet<Key>,
|
||||
bloom_filter_bits: Option<Option<u8>>,
|
||||
bloom_filters: Option<bool>,
|
||||
}
|
||||
|
||||
/// Use default if will read
|
||||
const DEFAULT_BLOOM_FILTER_BITS: Option<u8> = Some(5);
|
||||
// const CHECK_COLLISIONS: bool = true;
|
||||
const MAJOR_FJALL_VERSION: Version = Version::TWO;
|
||||
|
||||
@@ -59,7 +57,7 @@ where
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
bloom_filter_bits: Option<Option<u8>>,
|
||||
bloom_filters: Option<bool>,
|
||||
) -> Result<Self> {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
@@ -68,7 +66,7 @@ where
|
||||
&path.join(format!("meta/{name}")),
|
||||
MAJOR_FJALL_VERSION + version,
|
||||
|| {
|
||||
Self::open_partition_handle(keyspace, name, bloom_filter_bits).inspect_err(|e| {
|
||||
Self::open_partition_handle(keyspace, name, bloom_filters).inspect_err(|e| {
|
||||
eprintln!("{e}");
|
||||
eprintln!("Delete {path:?} and try again");
|
||||
})
|
||||
@@ -85,7 +83,7 @@ where
|
||||
rtx,
|
||||
puts: BTreeMap::new(),
|
||||
dels: BTreeSet::new(),
|
||||
bloom_filter_bits,
|
||||
bloom_filters,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -180,17 +178,17 @@ where
|
||||
fn open_partition_handle(
|
||||
keyspace: &TransactionalKeyspace,
|
||||
name: &str,
|
||||
bloom_filter_bits: Option<Option<u8>>,
|
||||
bloom_filters: Option<bool>,
|
||||
) -> Result<TransactionalPartitionHandle> {
|
||||
keyspace
|
||||
.open_partition(
|
||||
name,
|
||||
PartitionCreateOptions::default()
|
||||
.bloom_filter_bits(bloom_filter_bits.unwrap_or(DEFAULT_BLOOM_FILTER_BITS))
|
||||
.max_memtable_size(8 * 1024 * 1024)
|
||||
.manual_journal_persist(true),
|
||||
)
|
||||
.map_err(|e| e.into())
|
||||
let mut options = PartitionCreateOptions::default()
|
||||
.max_memtable_size(8 * 1024 * 1024)
|
||||
.manual_journal_persist(true);
|
||||
|
||||
if bloom_filters.is_some_and(|b| !b) {
|
||||
options = options.bloom_filter_bits(None);
|
||||
}
|
||||
|
||||
keyspace.open_partition(name, options).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
pub fn commit_(
|
||||
@@ -272,8 +270,7 @@ where
|
||||
|
||||
self.meta.reset();
|
||||
|
||||
let partition =
|
||||
Self::open_partition_handle(&self.keyspace, self.name, self.bloom_filter_bits)?;
|
||||
let partition = Self::open_partition_handle(&self.keyspace, self.name, self.bloom_filters)?;
|
||||
|
||||
self.partition.replace(partition);
|
||||
|
||||
@@ -314,7 +311,7 @@ where
|
||||
rtx: self.keyspace.read_tx(),
|
||||
puts: self.puts.clone(),
|
||||
dels: self.dels.clone(),
|
||||
bloom_filter_bits: self.bloom_filter_bits,
|
||||
bloom_filters: self.bloom_filters,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ brk_exit = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
clap_derive = { workspace = true }
|
||||
log = { workspace = true }
|
||||
memmap2 = "0.9.5"
|
||||
memmap2 = "0.9.7"
|
||||
rayon = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{DateIndex, Height, Version};
|
||||
use brk_core::{DateIndex, Height, Printable, Version};
|
||||
use brk_vec::{AnyVec, CollectableVec, Format, GenericStoredVec, StoredVec, VecIterator};
|
||||
|
||||
type I = DateIndex;
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
type VEC = StoredVec<DateIndex, u32>;
|
||||
type VEC = StoredVec<I, u32>;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let _ = fs::remove_dir_all("./vec");
|
||||
let _ = fs::remove_file("./vec");
|
||||
|
||||
let version = Version::TWO;
|
||||
let format = Format::Compressed;
|
||||
let format = Format::Raw;
|
||||
|
||||
{
|
||||
let mut vec: VEC = StoredVec::forced_import(Path::new("."), "vec", version, format)?;
|
||||
@@ -21,6 +23,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let mut iter = vec.into_iter();
|
||||
dbg!(iter.get(0.into()));
|
||||
dbg!(iter.get(1.into()));
|
||||
dbg!(iter.get(2.into()));
|
||||
dbg!(iter.get(20.into()));
|
||||
dbg!(iter.get(21.into()));
|
||||
|
||||
@@ -38,6 +42,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dbg!(iter.get(0.into()));
|
||||
dbg!(iter.get(1.into()));
|
||||
dbg!(iter.get(2.into()));
|
||||
dbg!(iter.get(3.into()));
|
||||
dbg!(iter.get(4.into()));
|
||||
dbg!(iter.get(5.into()));
|
||||
dbg!(iter.get(20.into()));
|
||||
dbg!(iter.get(20.into()));
|
||||
dbg!(iter.get(0.into()));
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::{
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Error, Height, Result, Version};
|
||||
use memmap2::Mmap;
|
||||
use zerocopy::{FromBytes, IntoBytes};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
@@ -31,8 +30,12 @@ impl Header {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn import_and_verify(mmap: &Mmap, vec_version: Version, format: Format) -> Result<Self> {
|
||||
let inner = HeaderInner::import_and_verify(mmap, vec_version, format)?;
|
||||
pub fn import_and_verify(
|
||||
file: &mut File,
|
||||
vec_version: Version,
|
||||
format: Format,
|
||||
) -> Result<Self> {
|
||||
let inner = HeaderInner::import_and_verify(file, vec_version, format)?;
|
||||
Ok(Self {
|
||||
inner: Arc::new(ArcSwap::from_pointee(inner)),
|
||||
modified: false,
|
||||
@@ -100,7 +103,6 @@ impl HeaderInner {
|
||||
compressed: ZeroCopyBool::from(format),
|
||||
};
|
||||
header.write(file)?;
|
||||
// dbg!(file.bytes().map(|b| b.unwrap()).collect::<Vec<_>>());
|
||||
file.seek(SeekFrom::End(0))?;
|
||||
Ok(header)
|
||||
}
|
||||
@@ -109,13 +111,22 @@ impl HeaderInner {
|
||||
file.write_all_at(self.as_bytes(), 0)
|
||||
}
|
||||
|
||||
pub fn import_and_verify(mmap: &Mmap, vec_version: Version, format: Format) -> Result<Self> {
|
||||
if mmap.len() < HEADER_OFFSET {
|
||||
pub fn import_and_verify(
|
||||
file: &mut File,
|
||||
vec_version: Version,
|
||||
format: Format,
|
||||
) -> Result<Self> {
|
||||
let len = file.metadata()?.len();
|
||||
|
||||
if len < HEADER_OFFSET as u64 {
|
||||
return Err(Error::WrongLength);
|
||||
}
|
||||
// dbg!(mmap.len());
|
||||
let header = HeaderInner::read_from_bytes(&mmap[..HEADER_OFFSET])?;
|
||||
// dbg!(&header);
|
||||
|
||||
let mut buf = [0; HEADER_OFFSET];
|
||||
file.read_exact_at(&mut buf, 0)?;
|
||||
|
||||
let header = HeaderInner::read_from_bytes(&buf)?;
|
||||
|
||||
if header.header_version != HEADER_VERSION {
|
||||
return Err(Error::DifferentVersion {
|
||||
found: header.header_version,
|
||||
@@ -136,6 +147,7 @@ impl HeaderInner {
|
||||
{
|
||||
return Err(Error::DifferentCompressionMode);
|
||||
}
|
||||
|
||||
Ok(header)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_core::Version;
|
||||
use brk_core::{Height, Version};
|
||||
|
||||
use super::{BoxedVecIterator, StoredIndex, StoredType};
|
||||
|
||||
@@ -20,10 +20,10 @@ pub trait AnyVec: Send + Sync {
|
||||
}
|
||||
fn index_type_to_string(&self) -> &'static str;
|
||||
fn value_type_to_size_of(&self) -> usize;
|
||||
fn etag(&self, to: Option<i64>) -> String {
|
||||
fn etag(&self, height: Height, to: Option<i64>) -> String {
|
||||
let len = self.len();
|
||||
format!(
|
||||
"{}-{:?}",
|
||||
"{}-{}-{}",
|
||||
to.map_or(len, |to| {
|
||||
if to.is_negative() {
|
||||
len.checked_sub(to.unsigned_abs() as usize)
|
||||
@@ -32,7 +32,8 @@ pub trait AnyVec: Send + Sync {
|
||||
to as usize
|
||||
}
|
||||
}),
|
||||
self.version()
|
||||
u64::from(self.version()),
|
||||
u32::from(height),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@ use std::{
|
||||
fs::{File, OpenOptions},
|
||||
io::{self, Seek, SeekFrom, Write},
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::Result;
|
||||
use memmap2::Mmap;
|
||||
|
||||
@@ -22,6 +20,10 @@ where
|
||||
{
|
||||
const SIZE_OF_T: usize = size_of::<T>();
|
||||
|
||||
#[inline]
|
||||
fn unwrap_read(&self, index: I, mmap: &Mmap) -> T {
|
||||
self.read(index, mmap).unwrap().unwrap()
|
||||
}
|
||||
#[inline]
|
||||
fn read(&self, index: I, mmap: &Mmap) -> Result<Option<T>> {
|
||||
self.read_(index.to_usize()?, mmap)
|
||||
@@ -34,7 +36,7 @@ where
|
||||
}
|
||||
#[inline]
|
||||
fn get_or_read_(&self, index: usize, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
let stored_len = self.stored_len_(mmap);
|
||||
let stored_len = self.stored_len();
|
||||
|
||||
if index >= stored_len {
|
||||
let pushed = self.pushed();
|
||||
@@ -57,10 +59,7 @@ where
|
||||
format!("{}_to_{}", I::to_string(), self.name())
|
||||
}
|
||||
|
||||
fn mmap(&self) -> &ArcSwap<Mmap>;
|
||||
|
||||
fn stored_len(&self) -> usize;
|
||||
fn stored_len_(&self, mmap: &Mmap) -> usize;
|
||||
|
||||
fn pushed(&self) -> &[T];
|
||||
#[inline]
|
||||
@@ -112,7 +111,7 @@ where
|
||||
|
||||
fn file_set_len(&mut self, file: &mut File, len: u64) -> Result<()> {
|
||||
Self::file_set_len_(file, len)?;
|
||||
self.update_mmap(file)
|
||||
Ok(())
|
||||
}
|
||||
fn file_set_len_(file: &mut File, len: u64) -> Result<()> {
|
||||
file.set_len(len)?;
|
||||
@@ -122,13 +121,13 @@ where
|
||||
|
||||
fn file_write_all(&mut self, file: &mut File, buf: &[u8]) -> Result<()> {
|
||||
file.write_all(buf)?;
|
||||
self.update_mmap(file)
|
||||
file.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn file_truncate_and_write_all(&mut self, file: &mut File, len: u64, buf: &[u8]) -> Result<()> {
|
||||
Self::file_set_len_(file, len)?;
|
||||
file.write_all(buf)?;
|
||||
self.update_mmap(file)
|
||||
self.file_write_all(file, buf)
|
||||
}
|
||||
|
||||
fn reset(&mut self) -> Result<()>;
|
||||
@@ -139,14 +138,10 @@ where
|
||||
self.file_truncate_and_write_all(&mut file, HEADER_OFFSET as u64, &[])
|
||||
}
|
||||
|
||||
fn new_mmap(file: &File) -> Result<Arc<Mmap>> {
|
||||
Ok(Arc::new(unsafe { Mmap::map(file)? }))
|
||||
}
|
||||
|
||||
fn update_mmap(&mut self, file: &File) -> Result<()> {
|
||||
let mmap = Self::new_mmap(file)?;
|
||||
self.mmap().store(mmap);
|
||||
Ok(())
|
||||
#[inline]
|
||||
fn create_mmap(&self) -> Result<Mmap> {
|
||||
let file = self.open_file()?;
|
||||
unsafe { Mmap::map(&file).map_err(|e| e.into()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -62,7 +62,7 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Cow<'a, Self::T>)> {
|
||||
fn unwrap_get_inner_(&mut self, i: usize) -> Self::T {
|
||||
self.get_(i)
|
||||
.unwrap_or_else(|| {
|
||||
dbg!(self.name(), i, self.len());
|
||||
dbg!(self.name(), i, self.len(), Self::I::to_string());
|
||||
panic!("unwrap_get_inner_")
|
||||
})
|
||||
.into_owned()
|
||||
|
||||
@@ -120,12 +120,12 @@ where
|
||||
zstd::encode_all(bytes.as_slice(), DEFAULT_COMPRESSION_LEVEL).unwrap()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn index_to_page_index(index: usize) -> usize {
|
||||
index / Self::PER_PAGE
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn page_index_to_index(page_index: usize) -> usize {
|
||||
page_index * Self::PER_PAGE
|
||||
}
|
||||
@@ -180,11 +180,6 @@ where
|
||||
self.inner.mut_header()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
self.inner.mmap()
|
||||
}
|
||||
|
||||
fn parent(&self) -> &Path {
|
||||
self.inner.parent()
|
||||
}
|
||||
@@ -193,10 +188,6 @@ where
|
||||
fn stored_len(&self) -> usize {
|
||||
Self::stored_len__(&self.pages_meta.load())
|
||||
}
|
||||
#[inline]
|
||||
fn stored_len_(&self, _: &Mmap) -> usize {
|
||||
self.stored_len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pushed(&self) -> &[T] {
|
||||
@@ -223,6 +214,8 @@ where
|
||||
|
||||
let stored_len = self.stored_len();
|
||||
|
||||
let mut file = file_opt.unwrap_or(self.open_file()?);
|
||||
|
||||
let mut pages_meta = (**self.pages_meta.load()).clone();
|
||||
|
||||
let mut starting_page_index = pages_meta.len();
|
||||
@@ -236,16 +229,13 @@ where
|
||||
|
||||
let last_page_index = pages_meta.len() - 1;
|
||||
|
||||
values = Self::decode_page_(
|
||||
stored_len,
|
||||
last_page_index,
|
||||
&self.mmap().load(),
|
||||
&pages_meta,
|
||||
)
|
||||
.inspect_err(|_| {
|
||||
dbg!(last_page_index, &pages_meta);
|
||||
})
|
||||
.unwrap();
|
||||
let mmap = unsafe { Mmap::map(&file)? };
|
||||
|
||||
values = Self::decode_page_(stored_len, last_page_index, &mmap, &pages_meta)
|
||||
.inspect_err(|_| {
|
||||
dbg!(last_page_index, &pages_meta);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
truncate_at.replace(pages_meta.pop().unwrap().start);
|
||||
starting_page_index = last_page_index;
|
||||
@@ -287,8 +277,6 @@ where
|
||||
|
||||
pages_meta.write()?;
|
||||
|
||||
let mut file = file_opt.unwrap_or(self.open_file()?);
|
||||
|
||||
if let Some(truncate_at) = truncate_at {
|
||||
self.file_set_len(&mut file, truncate_at)?;
|
||||
}
|
||||
@@ -324,7 +312,11 @@ where
|
||||
|
||||
let page_index = Self::index_to_page_index(index);
|
||||
|
||||
let values = self.decode_page(page_index, &self.mmap().load())?;
|
||||
let mut file = self.open_file()?;
|
||||
|
||||
let mmap = unsafe { Mmap::map(&file)? };
|
||||
|
||||
let values = self.decode_page(page_index, &mmap)?;
|
||||
let mut buf = vec![];
|
||||
|
||||
let mut page = pages_meta.truncate(page_index).unwrap();
|
||||
@@ -348,8 +340,6 @@ where
|
||||
|
||||
self.pages_meta.store(Arc::new(pages_meta));
|
||||
|
||||
let mut file = self.open_file()?;
|
||||
|
||||
self.file_truncate_and_write_all(&mut file, len, &buf)?;
|
||||
|
||||
Ok(())
|
||||
@@ -399,7 +389,7 @@ impl<I, T> Clone for CompressedVec<I, T> {
|
||||
#[derive(Debug)]
|
||||
pub struct CompressedVecIterator<'a, I, T> {
|
||||
vec: &'a CompressedVec<I, T>,
|
||||
guard: Guard<Arc<Mmap>>,
|
||||
mmap: Mmap,
|
||||
decoded_page: Option<(usize, Vec<T>)>,
|
||||
// second_decoded_page?: Option<(usize, Vec<T>)>,
|
||||
pages_meta: Guard<Arc<CompressedPagesMetadata>>,
|
||||
@@ -445,7 +435,7 @@ where
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mmap = &self.guard;
|
||||
let mmap = &self.mmap;
|
||||
let i = self.index;
|
||||
let stored_len = self.stored_len;
|
||||
|
||||
@@ -499,7 +489,7 @@ where
|
||||
let stored_len = CompressedVec::<I, T>::stored_len__(&pages_meta);
|
||||
CompressedVecIterator {
|
||||
vec: self,
|
||||
guard: self.mmap().load(),
|
||||
mmap: self.create_mmap().unwrap(),
|
||||
decoded_page: None,
|
||||
pages_meta,
|
||||
stored_len,
|
||||
|
||||
@@ -92,7 +92,7 @@ where
|
||||
S3T: StoredType,
|
||||
{
|
||||
pub fn forced_import_or_init_from_1(
|
||||
mode: Computation,
|
||||
computation: Computation,
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
@@ -100,7 +100,7 @@ where
|
||||
source: BoxedAnyIterableVec<S1I, S1T>,
|
||||
compute: ComputeFrom1<I, T, S1I, S1T>,
|
||||
) -> Result<Self> {
|
||||
Ok(match mode {
|
||||
Ok(match computation {
|
||||
Computation::Eager => Self::Eager {
|
||||
vec: EagerVec::forced_import(path, name, version, format)?,
|
||||
deps: Dependencies::From1(source, compute),
|
||||
@@ -114,7 +114,7 @@ where
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import_or_init_from_2(
|
||||
mode: Computation,
|
||||
computation: Computation,
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
@@ -123,7 +123,7 @@ where
|
||||
source2: BoxedAnyIterableVec<S2I, S2T>,
|
||||
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
|
||||
) -> Result<Self> {
|
||||
Ok(match mode {
|
||||
Ok(match computation {
|
||||
Computation::Eager => Self::Eager {
|
||||
vec: EagerVec::forced_import(path, name, version, format)?,
|
||||
deps: Dependencies::From2((source1, source2), compute),
|
||||
@@ -137,7 +137,7 @@ where
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn forced_import_or_init_from_3(
|
||||
mode: Computation,
|
||||
computation: Computation,
|
||||
path: &Path,
|
||||
name: &str,
|
||||
version: Version,
|
||||
@@ -147,7 +147,7 @@ where
|
||||
source3: BoxedAnyIterableVec<S3I, S3T>,
|
||||
compute: ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
|
||||
) -> Result<Self> {
|
||||
Ok(match mode {
|
||||
Ok(match computation {
|
||||
Computation::Eager => Self::Eager {
|
||||
vec: EagerVec::forced_import(path, name, version, format)?,
|
||||
deps: Dependencies::From3((source1, source2, source3), compute),
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{
|
||||
Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Error, Result, Sats, StoredF32,
|
||||
StoredUsize, Version,
|
||||
@@ -24,7 +23,7 @@ use crate::{
|
||||
|
||||
const ONE_KIB: usize = 1024;
|
||||
const ONE_MIB: usize = ONE_KIB * ONE_KIB;
|
||||
const MAX_CACHE_SIZE: usize = 210 * ONE_MIB;
|
||||
const MAX_CACHE_SIZE: usize = 256 * ONE_MIB;
|
||||
const DCA_AMOUNT: Dollars = Dollars::mint(100.0);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -108,10 +107,6 @@ where
|
||||
self.0.get_or_read(index, mmap)
|
||||
}
|
||||
|
||||
pub fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
self.0.mmap()
|
||||
}
|
||||
|
||||
pub fn inner_version(&self) -> Version {
|
||||
self.0.version()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::{borrow::Cow, cmp::Ordering, fmt::Debug, path::Path};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Error, Height, Result, Version};
|
||||
|
||||
use crate::{
|
||||
@@ -29,6 +28,11 @@ where
|
||||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn unwrap_read(&self, index: I, mmap: &Mmap) -> T {
|
||||
self.0.unwrap_read(index, mmap)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
self.0.get_or_read(index, mmap)
|
||||
@@ -73,8 +77,8 @@ where
|
||||
self.0.header()
|
||||
}
|
||||
|
||||
pub fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
self.0.mmap()
|
||||
pub fn create_mmap(&self) -> Result<Mmap> {
|
||||
self.0.create_mmap()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -35,8 +35,8 @@ where
|
||||
source: BoxedAnyIterableVec<S1I, S1T>,
|
||||
compute: ComputeFrom1<I, T, S1I, S1T>,
|
||||
) -> Self {
|
||||
if source.index_type_to_string() != I::to_string() {
|
||||
panic!("Should have same index");
|
||||
if I::to_string() != S1I::to_string() {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
Self {
|
||||
|
||||
@@ -5,10 +5,12 @@ use std::{
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
use brk_core::{Error, Result, Version};
|
||||
use memmap2::Mmap;
|
||||
use rayon::prelude::*;
|
||||
@@ -25,9 +27,8 @@ pub struct RawVec<I, T> {
|
||||
header: Header,
|
||||
parent: PathBuf,
|
||||
name: &'static str,
|
||||
// Consider Arc<ArcSwap<Option<Mmap>>> for dataraces when reorg ?
|
||||
mmap: Arc<ArcSwap<Mmap>>,
|
||||
pushed: Vec<T>,
|
||||
stored_len: Arc<AtomicUsize>,
|
||||
phantom: PhantomData<I>,
|
||||
}
|
||||
|
||||
@@ -55,16 +56,18 @@ where
|
||||
|
||||
pub fn import(parent: &Path, name: &str, version: Version) -> Result<Self> {
|
||||
let path = Self::path_(parent, name);
|
||||
let (mmap, header) = match Self::open_file_(&path) {
|
||||
let (header, file) = match Self::open_file_(&path) {
|
||||
Ok(mut file) => {
|
||||
if file.metadata()?.len() == 0 {
|
||||
let header = Header::create_and_write(&mut file, version, Format::Raw)?;
|
||||
let mmap = Self::new_mmap(&file)?;
|
||||
(mmap, header)
|
||||
(
|
||||
Header::create_and_write(&mut file, version, Format::Raw)?,
|
||||
Some(file),
|
||||
)
|
||||
} else {
|
||||
let mmap = Self::new_mmap(&file)?;
|
||||
let header = Header::import_and_verify(&mmap, version, Format::Raw)?;
|
||||
(mmap, header)
|
||||
(
|
||||
Header::import_and_verify(&mut file, version, Format::Raw)?,
|
||||
Some(file),
|
||||
)
|
||||
}
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
@@ -72,21 +75,26 @@ where
|
||||
fs::create_dir_all(Self::folder_(parent, name))?;
|
||||
let mut file = Self::open_file_(&path)?;
|
||||
let header = Header::create_and_write(&mut file, version, Format::Raw)?;
|
||||
let mmap = Self::new_mmap(&file)?;
|
||||
(mmap, header)
|
||||
(header, None)
|
||||
}
|
||||
_ => {
|
||||
return Err(e.into());
|
||||
}
|
||||
_ => return Err(e.into()),
|
||||
},
|
||||
};
|
||||
|
||||
let mmap = Arc::new(ArcSwap::new(mmap));
|
||||
let stored_len = if let Some(file) = file {
|
||||
(file.metadata()?.len() as usize - HEADER_OFFSET) / Self::SIZE_OF_T
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
mmap,
|
||||
header,
|
||||
name: Box::leak(Box::new(name.to_string())),
|
||||
parent: parent.to_owned(),
|
||||
pushed: vec![],
|
||||
stored_len: Arc::new(AtomicUsize::new(stored_len)),
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
@@ -141,18 +149,9 @@ where
|
||||
&mut self.header
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
&self.mmap
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn stored_len(&self) -> usize {
|
||||
self.stored_len_(&self.mmap.load())
|
||||
}
|
||||
#[inline]
|
||||
fn stored_len_(&self, mmap: &Mmap) -> usize {
|
||||
(mmap.len() - HEADER_OFFSET) / Self::SIZE_OF_T
|
||||
self.stored_len.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -194,9 +193,10 @@ where
|
||||
};
|
||||
|
||||
let mut file = file_opt.unwrap_or(self.open_file()?);
|
||||
|
||||
self.file_write_all(&mut file, &bytes)?;
|
||||
|
||||
self.stored_len.fetch_add(pushed_len, Ordering::SeqCst);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -212,6 +212,8 @@ where
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.stored_len.store(index, Ordering::SeqCst);
|
||||
|
||||
let len = index * Self::SIZE_OF_T + HEADER_OFFSET;
|
||||
|
||||
let mut file = self.open_file()?;
|
||||
@@ -221,6 +223,7 @@ where
|
||||
}
|
||||
|
||||
fn reset(&mut self) -> Result<()> {
|
||||
self.stored_len.store(0, Ordering::SeqCst);
|
||||
self.reset_()
|
||||
}
|
||||
}
|
||||
@@ -262,9 +265,9 @@ impl<I, T> Clone for RawVec<I, T> {
|
||||
header: self.header.clone(),
|
||||
parent: self.parent.clone(),
|
||||
name: self.name,
|
||||
mmap: self.mmap.clone(),
|
||||
pushed: vec![],
|
||||
phantom: PhantomData,
|
||||
stored_len: self.stored_len.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +275,7 @@ impl<I, T> Clone for RawVec<I, T> {
|
||||
#[derive(Debug)]
|
||||
pub struct RawVecIterator<'a, I, T> {
|
||||
vec: &'a RawVec<I, T>,
|
||||
guard: Guard<Arc<Mmap>>,
|
||||
mmap: Mmap,
|
||||
index: usize,
|
||||
}
|
||||
|
||||
@@ -305,12 +308,11 @@ where
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mmap = &self.guard;
|
||||
let index = self.index;
|
||||
|
||||
let opt = self
|
||||
.vec
|
||||
.get_or_read_(index, mmap)
|
||||
.get_or_read_(index, &self.mmap)
|
||||
.unwrap()
|
||||
.map(|v| (I::from(index), v));
|
||||
|
||||
@@ -333,7 +335,7 @@ where
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
RawVecIterator {
|
||||
vec: self,
|
||||
guard: self.mmap.load(),
|
||||
mmap: self.create_mmap().unwrap(),
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Result, Version};
|
||||
use memmap2::Mmap;
|
||||
|
||||
@@ -75,14 +74,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
match self {
|
||||
StoredVec::Raw(v) => v.mmap(),
|
||||
StoredVec::Compressed(v) => v.mmap(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn parent(&self) -> &Path {
|
||||
match self {
|
||||
@@ -98,13 +89,6 @@ where
|
||||
StoredVec::Compressed(v) => v.stored_len(),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn stored_len_(&self, mmap: &Mmap) -> usize {
|
||||
match self {
|
||||
StoredVec::Raw(v) => v.stored_len_(mmap),
|
||||
StoredVec::Compressed(v) => v.stored_len_(mmap),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pushed(&self) -> &[T] {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user