diff --git a/Cargo.lock b/Cargo.lock index 36d48d05a..176740a8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,6 +446,7 @@ dependencies = [ name = "brk_exit" version = "0.0.9" dependencies = [ + "brk_logger", "ctrlc", "log", ] @@ -489,6 +490,7 @@ dependencies = [ "color-eyre", "env_logger", "jiff", + "log", ] [[package]] diff --git a/README.md b/README.md index 577c9f26a..be8a9d959 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,22 @@ # Bitcoin Research Kit

+ + GitHub Repo stars + + + License + Version Documentation - - License - Size + + Dependency status + Chat diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml index 269f855d9..61eb15622 100644 --- a/crates/brk_cli/Cargo.toml +++ b/crates/brk_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brk_cli" -description = "A command line interface to interact with the Bitcoin Research Kit" +description = "A command line interface to interact with the full Bitcoin Research Kit" version.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/brk_cli/README.md b/crates/brk_cli/README.md index 21bdcc825..27445772a 100644 --- a/crates/brk_cli/README.md +++ b/crates/brk_cli/README.md @@ -1,6 +1,32 @@ # BRK Cli -## Setup +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A command line interface to interact with the full Bitcoin Research Kit. It's built on top of every other create and gives the possility to use BRK using the terminal instead of Rust. + +It has 2 commandes for now (other than `help` and `version`) which are `run` and `query`. The former is used to run the processing (indexer + computer) and/or the server. The latter uses `brk_query` as its backend just like to server to be able to get datasets via the terminal instead of the API. Both commands are very costumizable by having all the parameters of their Rust counterparts ([`run`](https://github.com/bitcoinresearchkit/brk/blob/main/crates/brk_cli/src/run.rs#L91-L147), [`query`](https://github.com/bitcoinresearchkit/brk/blob/main/crates/brk_query/src/params.rs)). + +## Requirements ### Hardware @@ -16,46 +42,29 @@ To be determined ### Software +- [Bitcoin](https://bitcoin.org/en/full-node) +- [Rust](https://www.rust-lang.org/tools/install) - 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 +## Install ```bash -cargo install brk_cli +cargo install brk # or `cargo install brk_cli`, the result is the same ``` -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 +## Update ```bash -brk run --bitcoindir=~/Developer/bitcoin --outputdir=~/.brk +cargo install brk # or `cargo install-update -a` if you have `cargo-update` installed ``` +## Usage + +Run `brk -h` to view each available command and their respective description. + +`-h` works also for commands, which mean that `brk run -h` will explain all the parameters of `brk run` for example. + +Every parameter set for `brk run` will be saved at `~/.brk/config.toml`, which will allow you to simply run `brk run` next time. + 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_computer/README.md b/crates/brk_computer/README.md index 4851b1013..e12bc6771 100644 --- a/crates/brk_computer/README.md +++ b/crates/brk_computer/README.md @@ -1 +1,25 @@ # BRK Computer + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A dataset computer, built on top of `brk_indexer` and `brk_fetcher`. It computes any dataset you can think of and if it doesn't feel free to create an issue. diff --git a/crates/brk_core/README.md b/crates/brk_core/README.md index 0f1719a80..574a555f2 100644 --- a/crates/brk_core/README.md +++ b/crates/brk_core/README.md @@ -1 +1,25 @@ # BRK Core + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A list of structs that are used throughout the project as units, think of `Date`, `Height`, `Sats`, `Txindex` or anything that can be either a key and/or a value of a dataset. diff --git a/crates/brk_exit/Cargo.toml b/crates/brk_exit/Cargo.toml index 713a7a79e..37926470e 100644 --- a/crates/brk_exit/Cargo.toml +++ b/crates/brk_exit/Cargo.toml @@ -7,5 +7,6 @@ license.workspace = true repository.workspace = true [dependencies] -ctrlc = "3.4.5" +brk_logger = { workspace = true } +ctrlc = { version = "3.4.5", features = ["termination"] } log = { workspace = true } diff --git a/crates/brk_exit/README.md b/crates/brk_exit/README.md index 68b918da7..78954b2c7 100644 --- a/crates/brk_exit/README.md +++ b/crates/brk_exit/README.md @@ -1 +1,27 @@ # BRK Exit + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A simple crate that stops the program from exitting when blocking is activated until it is released. The purpose of that is to prevent exitting when a program is in the middle of saving data and thus prevent partial writes. + +It's built on top of [ctrlc](https://crates.io/crates/ctrlc) which handles Ctrl + C (SIGINT), stopping the program using the `kill` command (SIGTERM) and closing the terminal (SIGHUP) but it doesn't support force kills (`kill -9`). diff --git a/crates/brk_exit/examples/main.rs b/crates/brk_exit/examples/main.rs new file mode 100644 index 000000000..4d911f89c --- /dev/null +++ b/crates/brk_exit/examples/main.rs @@ -0,0 +1,28 @@ +use std::{path::Path, thread::sleep, time::Duration}; + +use brk_exit::Exit; +use log::info; + +fn main() { + let exit = Exit::new(); + + brk_logger::init(Some(Path::new(".log"))); + + exit.block(); + + let mut i = 0; + while i < 21 { + info!("i = {i}"); + sleep(Duration::from_secs(1)); + i += 1; + } + + exit.release(); + + let mut j = 0; + while j < 10 { + info!("j = {j}"); + sleep(Duration::from_secs(1)); + j += 1; + } +} diff --git a/crates/brk_exit/src/lib.rs b/crates/brk_exit/src/lib.rs index d574cf433..8824a2a6e 100644 --- a/crates/brk_exit/src/lib.rs +++ b/crates/brk_exit/src/lib.rs @@ -1,4 +1,7 @@ #![doc = include_str!("../README.md")] +#![doc = "\n## Example\n\n```rust"] +#![doc = include_str!("../examples/main.rs")] +#![doc = "```"] use std::{ process::exit, diff --git a/crates/brk_fetcher/README.md b/crates/brk_fetcher/README.md index 549046768..af946d0d3 100644 --- a/crates/brk_fetcher/README.md +++ b/crates/brk_fetcher/README.md @@ -1 +1,25 @@ # BRK Fetcher + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A crate that can fetch the Bitcoin price, either by date or height, from multiple APIs such Kraken, Binance and Kibo.money. diff --git a/crates/brk_indexer/README.md b/crates/brk_indexer/README.md index 1a5c98ccc..c7bcaccee 100644 --- a/crates/brk_indexer/README.md +++ b/crates/brk_indexer/README.md @@ -1,6 +1,28 @@ # BRK Indexer -A [Bitcoin Core](https://bitcoincore.org/en/about/) node indexer which iterates over the chain (via `../brk_parser`) and creates a database of the vecs (`../brk_vec`) and key/value stores ([`fjall`](https://crates.io/crates/fjall)) that can be used in your Rust code. +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A [Bitcoin Core](https://bitcoincore.org/en/about/) node indexer which iterates over the chain (via `../brk_parser`) and creates a database of the vecs (`brk_vec`) and key/value stores ([`fjall`](https://crates.io/crates/fjall)) that can be used in your Rust code. The crate only stores the bare minimum to be self sufficient and not have to use an RPC client (except for scripts which are not stored). If you need more data, checkout `../computer` which uses the outputs from the indexer to compute a whole range of datasets. diff --git a/crates/brk_logger/Cargo.toml b/crates/brk_logger/Cargo.toml index f275a0afe..dcd76802e 100644 --- a/crates/brk_logger/Cargo.toml +++ b/crates/brk_logger/Cargo.toml @@ -10,3 +10,4 @@ repository.workspace = true color-eyre = { workspace = true } env_logger = "0.11.7" jiff = { workspace = true } +log = { workspace = true } diff --git a/crates/brk_logger/README.md b/crates/brk_logger/README.md index 6a8fce291..600c76e66 100644 --- a/crates/brk_logger/README.md +++ b/crates/brk_logger/README.md @@ -1 +1,27 @@ # BRK Logger + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A simple crate built on top of [`env_logger`](https://crates.io/crates/env_logger) to display logs from the [`log`](https://crates.io/crates/log) crate in a colorful and clean format. + +It can also save logs into a file if desired. diff --git a/crates/brk_logger/examples/main.rs b/crates/brk_logger/examples/main.rs index d2a6728ea..91b658c27 100644 --- a/crates/brk_logger/examples/main.rs +++ b/crates/brk_logger/examples/main.rs @@ -1,3 +1,10 @@ +use log::{debug, error, info, trace}; + fn main() { brk_logger::init(None); + + info!("info"); + debug!("debug"); + error!("error"); + trace!("trace"); } diff --git a/crates/brk_parser/README.md b/crates/brk_parser/README.md index 46d4bdb96..af38b3181 100644 --- a/crates/brk_parser/README.md +++ b/crates/brk_parser/README.md @@ -1,5 +1,27 @@ # BRK Parser +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ A very fast and simple Rust library which reads raw block files (*blkXXXXX.dat*) from Bitcoin Core node and creates an iterator over all the requested blocks in sequential order (0, 1, 2, ...). The element returned by the iterator is a tuple which includes the: diff --git a/crates/brk_query/README.md b/crates/brk_query/README.md index e66becfcd..5dcbd9f1d 100644 --- a/crates/brk_query/README.md +++ b/crates/brk_query/README.md @@ -1 +1,31 @@ # BRK Query + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A crate that searches for datasets from either `brk_indexer` or `brk_computer` according to given parameters. + +It's possible to search for one or multiple dataset if they have the same index and specify range with both the `from` and `to` being optional and supporting negative values. + +The output will depend on the format choson which can be Markdown, Json, CSV or TSV and might vary if there is a one or mutiple datasets, and if one dataset one or multiple values. + +In the future, it will support more features similar to a real query engine like in a Postgres databases and presets to fetch data grouped by address, transaction or blockhash/height. diff --git a/crates/brk_server/Cargo.toml b/crates/brk_server/Cargo.toml index 95fca48d8..e6552877f 100644 --- a/crates/brk_server/Cargo.toml +++ b/crates/brk_server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brk_server" -description = "A server that serves Bitcoin data and swappable front-ends, built on top of brk_indexer, brk_fetcher and brk_computer" +description = "A crate that serves Bitcoin data and swappable front-ends, built on top of brk_indexer, brk_computer and brk_query" version.workspace = true edition.workspace = true license.workspace = true diff --git a/crates/brk_server/README.md b/crates/brk_server/README.md index 744ea2968..fd697c21d 100644 --- a/crates/brk_server/README.md +++ b/crates/brk_server/README.md @@ -1 +1,29 @@ # BRK Server + +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

+ +A crate that serves Bitcoin data and swappable front-ends, built on top of `brk_indexer`, `brk_computer` and `brk_query`. + +The file handler, will serve the website specified by the user if any, which can be *no website*, *kibo.money* or *custom* (which is a blank folder for people to experiment). If a website is specified and the server is ran outside of the brk project and thus can't find the requested website, it will download the whole project with the correct version from Github and store it in `.brk` to be able to serve to website. This is due to the crate size limit on [crates.io](https://crates.io) and the various shenanigans that need to be done to have a website in a crate. + +The API uses `brk_query` and so inherites all of its features including formats. diff --git a/crates/brk_vec/README.md b/crates/brk_vec/README.md index 45325123b..641bdfc89 100644 --- a/crates/brk_vec/README.md +++ b/crates/brk_vec/README.md @@ -1,14 +1,32 @@ # BRK Vec -A very small, fast, efficient and simple storable `vec` which uses `mmap2` for speed. +

+ + GitHub Repo stars + + + License + + + Version + + + Documentation + + Size + + Dependency status + + + Chat + +

-## Features +A `Vec` (an array) that is stored on disk and thus which can be much larger than the available RAM. -- [x] Get (Rayon compatible) -- [x] Push -- [ ] Update -- [ ] Insert -- [ ] Remove +Compared to a key/value store, the data stored is raw byte interpretation of the Vec's values without any overhead which is very efficient. Additionally it uses close to no RAM when caching isn't active and up to 100 MB when it is. + +Compression is also available and built on top [`zstd`](https://crates.io/crates/zstd) to save even more space (from 0 to 75%). The tradeoff being slower reading speeds, especially random reading speeds. This is due to the data being stored in compressed pages of 16 KB, which means that if you to read even one value in that page you have to uncompress the whole page. ## Disclaimer