Bento is an indexing solution for Kadena blockchain written in Rust.
- out-of-the-box indexes blocks, transactions, events and token transfers
- automatically removes orphan blocks
- handles missed blocks
- HTTP API
- an easy way to extend it and index any custom modules (eg. Marmalade)
- Chainweb Node
- Docker (optional)
The fastest way is to use Docker / Docker Compose as the repo already comes with a docker-compose configuration file. Alternatively you would need to install PostgreSQL, [rust and cargo to build](Build with Cargo) and then execute the binaries.
Important: the headerStream
chainweb node config needs to be set to true
. You can check the configuring the node section of chainweb-data
for more details.
Once the node is setup and synced you can continue with the installation:
- Clone the repository:
git clone [email protected]:ThinEdgeLabs/bento.git
- Create a
.env
file, check the.env-example
to see how it should look like. - Start the containers:
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
-
Install Rust and Cargo using rustup.
-
Build
cargo build --release
The binaries are available at ./target/release/api
and ./target/release/indexer
.
If you used Docker the indexer and api services should already be up and running. Additionally you can run one of the available indexer subcommands like this:
# docker compose -f docker-compose.yml -f docker-compose.prod.yml run indexer [subcommand]
docker compose -f docker-compose.yml -f docker-compose.prod.yml run indexer backfill
Manually starting the services:
API:
./target/release/api
[2023-09-10T08:49:14Z INFO actix_server::builder] starting 8 workers
[2023-09-10T08:49:14Z INFO actix_server::server] Actix runtime found; starting in Actix runtime
Indexer:
By default new blocks are indexed as they are mined. For backfilling and filling gaps use the subcommands
Usage: indexer [COMMAND]
Commands:
backfill Backfill blocks
gaps Index missed blocks
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
Available endpoints:
- GET /tx/{request_key} - get tx result for given request key. If it's a multi-step tx, it will return all completed steps as well.
- POST /txs - get tx results for multiple request keys. Payload example:
{"request_keys": ["req-key-1", "req-key-2"]}
- GET /transfers?from={account_from}&to={account_to}&min_height={100}
- GET /balance/{account} - get balances of all tokens for given account
- GET /balance/{account}/{module} - get token balance on all chains for given account and module
-
Install Rust using rustup, which allows you to easily switch between Rust versions. Bento currently supports Rust Stable and Rust Beta.
-
Install diesel using cargo:
cargo install diesel_cli --no-default-features --features postgres
-
Install docker. Alternatively, you can manually install PostgreSQL on your local machine.
-
Clone this repository and open it in your favorite editor.
-
Create a
.env
file in the project directory with database connection details, Chainweb node host and others. See .env-sample for an example how this should look like. -
Start postgres and adminer containers:
docker compose up -d
- Create the database used for tests:
diesel database setup --database-url=postgres://postgres:postgres@localhost/bento_test
- To confirm everything is setup correctly, try running the test suite:
cargo test
- Start the indexer using cargo:
cargo run --bin indexer
- Start the api using cargo:
cargo run --bin api
We follow the Rust Style Guide, enforced using rustfmt. To run rustfmt tests locally:
-
Use rustup to set rust toolchain to the version specified in the rust-toolchain file.
-
Install the rustfmt and clippy by running
rustup component add rustfmt rustup component add clippy
-
Run clippy using cargo from the root of your bento repo.
cargo clippy
Each PR needs to compile without warning.
-
Run rustfmt using cargo from the root of your bento repo.
To see changes that need to be made, run
cargo fmt --all -- --check
If all code is properly formatted (e.g. if you have not made any changes), this should run without error or output. If your code needs to be reformatted, you will see a diff between your code and properly formatted code. If you see code here that you didn't make any changes to then you are probably running the wrong version of rustfmt. Once you are ready to apply the formatting changes, run
cargo fmt --all
You won't see any output, but all your files will be corrected.
You can also use rustfmt to make corrections or highlight issues in your editor. Check out their README for details.
If you want to contribute to Bento, please follow the coding style rules.
Copyright 2023 ThinEdgeLabs LLC.
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. Files in the project may not be copied, modified, or distributed except according to those terms.