Balance Tracker app is used to graph HBD and Hive balances for Hive account by increment of block or time. This app was created as a simple example of how to create HAF apps. Balance Tracker uses JavaScript's REACT for web app style UI, python's BaseHTTPRequestHandler for forking HTTP server and postgREST server. There are two versions of backend that can be run for the same app but not in parallel.
Tested on Ubuntu 20.04 and 22.04
- HAF instance
- Node version higher or equal 14.0.0. Check version
node-v
ornode --version
.
To clone the repository run the following command
git clone https://gitlab.syncad.com/hive/balance_tracker.git # or [email protected]:hive/balance_tracker.git
cd balance_tracker
git submodule update --init --recursive
HAF submodule is not necessary to build or run the balance_tracker.
If you already have an instance of HAF running or are planning to set it up separately (for example using a prebuilt Docker image), you can safely disable it by running:
git config --local submodule.haf.update none
before checking out the submodules (that is running git submodule update --init --recursive
).
The submodule is, however, necessary, for test run in CI. As such when updating it please update the commit hash in files .gitlab-ci.yml and docker/.env.
- Install backend runtime dependencies:
./balance-tracker.sh install backend-runtime-dependencies
- Install PostgREST:
./balance-tracker.sh install postgrest
- Set up the database:
./balance-tracker.sh install-app
(assuming HAF database runs on localhost on port 5432) - Process blocks:
./balance-tracker.sh process-blocks --number-of-blocks=5000000
(assuming HAF database runs on localhost on port 5432 and contains 5'000'000 blocks)
If you skip--number-of-blocks
parameter balance tracker will process all blocks in the database and then wait for more. You can keep this running in the background. - Start backend server:
./balance-tracker.sh serve postgrest-backend
- Install frontend runtime dependencies:
./balance-tracker.sh install frontend-runtime-dependencies
- Set up
$PATH
:export VOLTA_HOME="$HOME/.volta"; export PATH="$VOLTA_HOME/bin:$PATH"
- or you can simply reopen the terminal - Install Node.js via Volta:
volta install node
- Start frontend server:
./balance-tracker.sh serve frontend
Note: python backend is not configured to be used with web UI!
- Create btracker_app schema, process blocks.
./run.sh re-db ${n_blocks}
.
n_blocks
is the number of blocks you have inhaf_block_log
db. - Start the server
python3 main.py --host=localhost --port=3000
. - Call server with
curl
GET requests as in examples:
curl "http://localhost:3000/rpc/find_matching_accounts/?_partial_account_name=d"
curl "http://localhost:3000/rpc/get_balance_for_coin_by_block/?_account_name=dantheman&_coin_type=21&_start_block=0&_end_block=10000"
curl "http://localhost:3000/rpc/get_balance_for_coin_by_time/?_account_name=dantheman&_coin_type=21&_start_time=2016-03-24%2016:05:00&_end_time=2016-03-25%2000:34:48"
- After blocks were added to btracker_app schema, PostgREST backend server can be started up quickly with
./balance-tracker.sh serve postgrest-backend
. - If you have added more blocks to
haf_block_log
db, or you want to run live sync, you can run:
./balance-tracker.sh process-blocks --number-of-blocks=0
This will keep indexer waiting for new blocks and process them while the backend is running.
Running Balance tracker with Docker is described in Docker-specific README.
api/
- contains SQL API scripts
db/
- contains SQL backend code
dump_accounts/
- contains SQL code for account dump
endpoints/
- contains endpoint SQL code
scripts/
- contains various shell scripts
py_config.ini
and postgrest.conf
are configs for Python and PostgREST versions of backend. They contain parameters for PostgreSQL access.
balance-tracker.sh
can be used to start up PostgREST backend versions and UI, or run tests. Execute ./balance-tracker.sh help
for detailed list of parameters.
run.sh
is a legacy script for starting both backend versions, UI and running tests.
server/serve.py
- Listens for requests, parses parameters, sends requests to postgres, returns response.server/adapter.py
- Used to connect python backend with postgres server.db/backend.py
- Contains queries for psql, sent throughadapter.py
main.py
- parses arguments and starts server
api/btracker_api.sql
- Contains the same queries asdb/backend.py
JMeter performance tests are configured for different backends. To run tests:
- Start PostgREST backend server on port 3000
- Install test dependencies:
./balance-tracker.sh install test-dependencies
- Install jmeter:
./balance-tracker.sh install jmeter
- Run tests:
./balance-tracker.sh run-tests
Note: If you already have jmeter installed and on $PATH
you can skip straight to the last point.
If you want to serve the HTTP report on port 8000 run ./balance-tracker.sh serve test-results
.
You can also simply open tests/performance/result_report/index.html in your browser.
- Start Python backend server on port 3000
- Install JMeter
./run.sh install-jmeter
- Run tests for python
./run.sh test-py
Result report dashboard (HTML) will be generated at tests/performance/result_report/index.html