A basic blockchain-based key-value database with a CLI for interacting, a Python class wrapper for the API, and Docker support for orchestrating a cluster of nodes.
BBD is a simple blockchain-based key-value database that allows users to store key-value pairs in a blockchain. The project includes a Go application for the blockchain node, a Python CLI for interacting with the blockchain, and Docker support for orchestrating a cluster of nodes. One of the blockchain nodes is exposed to the host machine to interact with the user, but all of the nodes are capable of adding, storing and retrieving key-value pairs if needed.
src/cmd/main/main.go
: Main Go application for the blockchain node.cli/cli.py
: Python CLI for interacting with the blockchain..github/workflows/docker-image.yml
: GitHub Actions workflow for building the Docker image.run.sh
: Script to orchestrate the blockchain cluster detached and add the IP of the nodes to the host file.rebuild.sh
: Script to rebuild the Docker image and orchestrate the blockchain cluster NON-DETACHED.docker-compose.yml
: Docker Compose configuration for the blockchain cluster.Dockerfile
: Dockerfile for building the blockchain node image.
- Docker (tested with version 27.3.1)
- Docker Compose (tested with version 1.29.7)
- Go 1.23.2+ (tested on version 1.23.2)(for local development)
- Python 3.10.12+ (tested from python 3.10.12 to 3.12.7)(for CLI and API wrapper)
The recommended and tested way to run the blockchain node is compiling the container from the Dockerfile and running the cluster with Docker Compose.
-
Build the Docker image:
docker compose build --no-cache
-
Run the blockchain cluster:
./run.sh <number_of_nodes>
-
Rebuild the Docker image and run the cluster:
./rebuild.sh <number_of_nodes>
It is also possible to retrieve the container from Docker Hub and run the cluster with Docker Compose. In this case, the run.sh
and rebuild.sh
scripts may not work as expected.
-
Pull the Docker image:
docker pull 02loveslollipop/basic-blockchain-db:latest
-
Run the blockchain cluster:
docker compose up --scale node=<number_of_nodes>
Use the Python CLI to interact with the blockchain.
-
Install dependencies:
pip install -r requirements.txt
-
Add a key-value pair to the blockchain:
python cli/cli.py add --data "key":"value" --url <server_url> --port <server_port>
-
Get the current key-value pairs in the blockchain:
python cli/cli.py fetch --url <server_url> --port <server_port>
-
Get the current state of the blockchain:
python cli/cli.py rawfetch --url <server_url> --port <server_port>
The blockchain node exposes the following API endpoints for interacting with the blockchain:
GET /blockchain
: Get the current blockchain in the node.POST /append
: Add a key-value pair to the blockchain.GET /ping
: Check if the node is running.
The project includes a GitHub Actions workflow to build the Docker image on push or pull request to the main
branch.
- If a node joins the network after the blockchain has been initialized, it might not be able to fetch the current blockchain from the other nodes.