diff --git a/Cargo.lock b/Cargo.lock index 60c57795b..917948b15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,7 +343,6 @@ name = "brk_cli" version = "0.0.3" dependencies = [ "brk_computer", - "brk_core", "brk_exit", "brk_indexer", "brk_logger", @@ -361,7 +360,6 @@ version = "0.0.3" dependencies = [ "brk_core", "brk_exit", - "brk_fetcher", "brk_indexer", "brk_logger", "brk_parser", @@ -478,11 +476,9 @@ dependencies = [ "brk_query", "brk_vec", "color-eyre", - "derive_deref", "jiff", "log", "oxc", - "serde", "serde_json", "tokio", "tower-http", diff --git a/README.md b/README.md index edc46a0a5..eacf8a812 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # Bitcoin Research Kit -> ⚠️ In the middle of a massive rewrite, use very carefully ⚠️ -> Everything is still a work in progress - ## Description The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node. @@ -30,54 +27,7 @@ Feel free to open an issue if you want to add another instance ## Setup -### Hardware - -#### Recommended - -- [Latest base model Mac mini](https://www.apple.com/mac-mini/) -- [Thunderbolt 4 SSD enclosure](https://satechi.net/products/usb4-nvme-ssd-pro-enclosure/Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDE4ODQ3MDA2NzI4OA==?queryID=7961465089021ee203a60db7e62e90d2) -- [2 TB NVMe SSD](https://shop.sandisk.com/products/ssd/internal-ssd/wd-black-sn850x-nvme-ssd?sku=WDS200T2X0E-00BCA0) - -#### Minimum - -To be determined - -### Requirements - -- Unix based operating system (Mac OS or Linux) - - Ubuntu users need to install `open-ssl` via `sudo apt install libssl-dev pkg-config` -- [Bitcoin](https://bitcoin.org/en/full-node) - - Example: `bitcoind -datadir="$HOME/.bitcoin" -blocksonly` -- [Rust](https://www.rust-lang.org/tools/install) - - Install: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` - - Update: `rustup update` - -### Build - -Then you need to choose a path where the project will reside and then clone it - -```bash -cd ??? -git clone https://github.com/kibo-money/kibo.git -cd kibo -``` - -If it's your first time running kibo, it will need several information such as: - -- `--bitcoindir PATH`: path to bitcoin core data directory, `???/bitcoin` -- `--kibodir PATH`: path to kibo outputs, if you have enough space on your main disk `~/.kibo` is fine - -Everything will be saved at `~/.kibo/config.toml`, which will allow you to simply run `cargo run -r` next time - -If you need more options please run `cargo run -r --help` to see what parameters are available. - -Here's an example - -```bash -cargo run -r -- --bitcoindir=~/Developer/bitcoin --kibodir=~/.kibo -``` - -Then the easiest to let others access your server is to use `cloudflared` which will also cache requests. For more information go to: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/ +[Guide](https://crates.io/crates/brk_cli) ## Donate diff --git a/crates/brk/src/lib.rs b/crates/brk/src/lib.rs index 838b48b03..30046f602 100644 --- a/crates/brk/src/lib.rs +++ b/crates/brk/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../../../README.md")] +#![doc = include_str!(concat!("../", env!("CARGO_PKG_README")))] #[cfg(feature = "core")] pub mod core { diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml index 11e307448..4d8e0a3ff 100644 --- a/crates/brk_cli/Cargo.toml +++ b/crates/brk_cli/Cargo.toml @@ -7,7 +7,6 @@ license.workspace = true repository.workspace = true [dependencies] -brk_core = { workspace = true } brk_computer = { workspace = true } brk_exit = { workspace = true } brk_indexer = { workspace = true } @@ -15,7 +14,7 @@ brk_logger = { workspace = true } brk_parser = { workspace = true } brk_query = { workspace = true } brk_server = { workspace = true } -clap = { workspace = true } +clap = { workspace = true , features = ["string"] } color-eyre = { workspace = true } log = { workspace = true } diff --git a/crates/brk_cli/README.md b/crates/brk_cli/README.md index fb5f600d1..21bdcc825 100644 --- a/crates/brk_cli/README.md +++ b/crates/brk_cli/README.md @@ -1 +1,61 @@ # BRK Cli + +## Setup + +### Hardware + +#### Recommended + +- [Latest base model Mac mini](https://www.apple.com/mac-mini/) +- [Thunderbolt 4 SSD enclosure](https://satechi.net/products/usb4-nvme-ssd-pro-enclosure/Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80MDE4ODQ3MDA2NzI4OA==?queryID=7961465089021ee203a60db7e62e90d2) +- [2 TB NVMe SSD](https://shop.sandisk.com/products/ssd/internal-ssd/wd-black-sn850x-nvme-ssd?sku=WDS200T2X0E-00BCA0) + +#### Minimum + +To be determined + +### Software + +- Unix based operating system (Mac OS or Linux) + - Ubuntu users need to install `open-ssl` via `sudo apt install libssl-dev pkg-config` +- [Bitcoin](https://bitcoin.org/en/full-node) + - Example: `bitcoind -datadir="$HOME/.bitcoin" -blocksonly` +- [Rust](https://www.rust-lang.org/tools/install) + - Install: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` + - Update: `rustup update` + +### Install + +```bash +cargo install brk_cli +``` + +If it's your first time running `brk`, it will need several information such as: + +- `--bitcoindir PATH`: path to bitcoin core data directory, `???/bitcoin` +- `--outputdir PATH`: path to various outputs, if you have enough space on your main disk `~/.brk` is fine + +Everything will be saved at `~/.brk/config.toml`, which will allow you to simply run `brk run` next time + +If you need more options please run `brk -h` to see what parameters are available. + +Here's an example + +```bash +brk run --bitcoindir=~/Developer/bitcoin --outputdir=~/.brk +``` + +Then the easiest to let others access your server is to use `cloudflared` which will also cache requests. For more information go to: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/ + +### Update + +```bash +cargo install brk_cli +``` + +or + +```bash +cargo install cargo-update +cargo install-update -a +``` diff --git a/crates/brk_cli/src/main.rs b/crates/brk_cli/src/main.rs index b0b91b5a0..60b5f43f8 100644 --- a/crates/brk_cli/src/main.rs +++ b/crates/brk_cli/src/main.rs @@ -42,7 +42,7 @@ fn main() -> color_eyre::Result<()> { let mut computer = Computer::import(&outputs_dir.join("computed"))?; match &cli.command { - Commands::Run(args) => { + Commands::Run(_) => { let data_dir = Path::new("../../../bitcoin"); let rpc = Box::leak(Box::new(rpc::Client::new( "http://localhost:8332", diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml index f34dbb718..4522c51eb 100644 --- a/crates/brk_computer/Cargo.toml +++ b/crates/brk_computer/Cargo.toml @@ -9,7 +9,6 @@ repository.workspace = true [dependencies] brk_core = { workspace = true } brk_exit = { workspace = true } -brk_fetcher = { workspace = true } brk_indexer = { workspace = true } brk_logger = { workspace = true } brk_parser = { workspace = true } diff --git a/crates/brk_computer/src/lib.rs b/crates/brk_computer/src/lib.rs index 84da65cce..02d50fa08 100644 --- a/crates/brk_computer/src/lib.rs +++ b/crates/brk_computer/src/lib.rs @@ -72,10 +72,17 @@ impl Computer { // exit, // )?; + self.vecs.height_to_height.compute_transform( + starting_indexes.height, + &mut indexer.vecs.height_to_timestamp, + |_, height| height, + exit, + )?; + self.vecs.height_to_date.compute_transform( starting_indexes.height, &mut indexer.vecs.height_to_timestamp, - |timestamp| Date::from(*timestamp), + |timestamp, _| Date::from(*timestamp), exit, )?; diff --git a/crates/brk_computer/src/storage/vecs.rs b/crates/brk_computer/src/storage/vecs.rs index 6553b633c..ecb8ebe58 100644 --- a/crates/brk_computer/src/storage/vecs.rs +++ b/crates/brk_computer/src/storage/vecs.rs @@ -25,6 +25,7 @@ pub struct Vecs { pub dateindex_to_open_in_dollars: StorableVec>, pub height_to_close_in_cents: StorableVec>, pub height_to_close_in_dollars: StorableVec>, + pub height_to_height: StorableVec, pub height_to_high_in_cents: StorableVec>, pub height_to_high_in_dollars: StorableVec>, pub height_to_low_in_cents: StorableVec>, @@ -101,6 +102,7 @@ impl Vecs { &path.join("height_to_close_in_dollars"), Version::from(1), )?, + height_to_height: StorableVec::import(&path.join("height_to_height"), Version::from(1))?, height_to_high_in_cents: StorableVec::import(&path.join("height_to_high_in_cents"), Version::from(1))?, height_to_high_in_dollars: StorableVec::import(&path.join("height_to_high_in_dollars"), Version::from(1))?, height_to_low_in_cents: StorableVec::import(&path.join("height_to_low_in_cents"), Version::from(1))?, @@ -152,6 +154,7 @@ impl Vecs { pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> { vec![ &self.height_to_date as &dyn AnyStorableVec, + &self.height_to_height, // &self.dateindex_to_close_in_dollars, // &self.dateindex_to_high_in_cents, // &self.dateindex_to_high_in_dollars, diff --git a/crates/brk_query/src/index.rs b/crates/brk_query/src/index.rs index ec1c278d4..5179f0b70 100644 --- a/crates/brk_query/src/index.rs +++ b/crates/brk_query/src/index.rs @@ -38,7 +38,7 @@ impl Index { ] } - pub fn ids(&self) -> &[&str] { + pub fn self_to_ids(&self) -> &[&str] { match self { Self::Dateindex => &["d", "date", "dateindex"], Self::Height => &["h", "height"], @@ -55,25 +55,32 @@ impl Index { Self::P2WSHindex => &["p2wshi", "p2wshindex"], } } + + pub fn ids() -> Vec { + Self::all() + .iter() + .flat_map(|i| i.self_to_ids().iter().map(|s| s.to_string())) + .collect::>() + } } impl TryFrom<&str> for Index { type Error = color_eyre::Report; fn try_from(value: &str) -> Result { Ok(match value { - v if (Self::Dateindex).ids().contains(&v) => Self::Dateindex, - v if (Self::Height).ids().contains(&v) => Self::Height, - v if (Self::Txindex).ids().contains(&v) => Self::Txindex, - v if (Self::Txinindex).ids().contains(&v) => Self::Txinindex, - v if (Self::Txoutindex).ids().contains(&v) => Self::Txoutindex, - v if (Self::Addressindex).ids().contains(&v) => Self::Addressindex, - v if (Self::P2PK33index).ids().contains(&v) => Self::P2PK33index, - v if (Self::P2PK65index).ids().contains(&v) => Self::P2PK65index, - v if (Self::P2PKHindex).ids().contains(&v) => Self::P2PKHindex, - v if (Self::P2SHindex).ids().contains(&v) => Self::P2SHindex, - v if (Self::P2TRindex).ids().contains(&v) => Self::P2TRindex, - v if (Self::P2WPKHindex).ids().contains(&v) => Self::P2WPKHindex, - v if (Self::P2WSHindex).ids().contains(&v) => Self::P2WSHindex, + v if (Self::Dateindex).self_to_ids().contains(&v) => Self::Dateindex, + v if (Self::Height).self_to_ids().contains(&v) => Self::Height, + v if (Self::Txindex).self_to_ids().contains(&v) => Self::Txindex, + v if (Self::Txinindex).self_to_ids().contains(&v) => Self::Txinindex, + v if (Self::Txoutindex).self_to_ids().contains(&v) => Self::Txoutindex, + v if (Self::Addressindex).self_to_ids().contains(&v) => Self::Addressindex, + v if (Self::P2PK33index).self_to_ids().contains(&v) => Self::P2PK33index, + v if (Self::P2PK65index).self_to_ids().contains(&v) => Self::P2PK65index, + v if (Self::P2PKHindex).self_to_ids().contains(&v) => Self::P2PKHindex, + v if (Self::P2SHindex).self_to_ids().contains(&v) => Self::P2SHindex, + v if (Self::P2TRindex).self_to_ids().contains(&v) => Self::P2TRindex, + v if (Self::P2WPKHindex).self_to_ids().contains(&v) => Self::P2WPKHindex, + v if (Self::P2WSHindex).self_to_ids().contains(&v) => Self::P2WSHindex, _ => return Err(eyre!("Bad index")), }) } diff --git a/crates/brk_query/src/params.rs b/crates/brk_query/src/params.rs index a07f49465..c904e2e98 100644 --- a/crates/brk_query/src/params.rs +++ b/crates/brk_query/src/params.rs @@ -1,11 +1,11 @@ -use clap::Parser; +use clap::{Parser, builder::PossibleValuesParser}; use serde::Deserialize; -use crate::Format; +use crate::{Format, Index}; #[derive(Debug, Deserialize, Parser)] pub struct Params { - #[clap(short, long)] + #[clap(short, long, value_parser = PossibleValuesParser::new(Index::ids()))] pub index: String, #[clap(short, long, value_delimiter = ' ', num_args = 1..)] pub values: Vec, diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 8330a1359..5a2e2b4b5 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -16,11 +16,9 @@ brk_parser = { workspace = true } brk_query = { workspace = true } brk_vec = { workspace = true } color-eyre = { workspace = true } -derive_deref = { workspace = true } jiff = { workspace = true } log = { workspace = true } oxc = { version = "0.53.0", features = ["codegen", "minifier"] } -serde = { workspace = true } serde_json = { workspace = true } tokio = { version = "1.43.0", features = ["full"] } tower-http = { version = "0.6.2", features = ["compression-full"] } diff --git a/crates/brk_vec/src/lib.rs b/crates/brk_vec/src/lib.rs index 4fae959a7..eea78d687 100644 --- a/crates/brk_vec/src/lib.rs +++ b/crates/brk_vec/src/lib.rs @@ -565,12 +565,12 @@ where ) -> Result<()> where A: StoredType, - F: Fn(&A) -> T, + F: Fn(&A, I) -> T, { self.validate_computed_version_or_reset_file(Version::from(0) + self.version + other.version)?; let index = max_from.min(I::from(self.len())); - other.iter_from(index, |(i, a)| self.push_and_flush_if_needed(i, t(a), exit))?; + other.iter_from(index, |(i, a)| self.push_and_flush_if_needed(i, t(a, i), exit))?; Ok(self.safe_flush(exit)?) } diff --git a/publish.sh b/publish.sh index 5af089e54..7a07cbb56 100755 --- a/publish.sh +++ b/publish.sh @@ -3,39 +3,39 @@ cd crates/brk cd ../brk_core -cargo publish +cargo publish --allow-dirty cd ../brk_exit -cargo publish +cargo publish --allow-dirty cd ../brk_vec -cargo publish +cargo publish --allow-dirty cd ../brk_logger -cargo publish +cargo publish --allow-dirty cd ../brk_indexer -cargo publish +cargo publish --allow-dirty cd ../brk_parser -cargo publish +cargo publish --allow-dirty cd ../brk_fetcher -cargo publish +cargo publish --allow-dirty cd ../brk_computer -cargo publish +cargo publish --allow-dirty cd ../brk_query -cargo publish +cargo publish --allow-dirty cd ../brk_server -cargo publish +cargo publish --allow-dirty cd ../brk_cli -cargo publish +cargo publish --allow-dirty cd ../brk -cargo publish +cargo publish --allow-dirty cd ../..