Sample HAF indexer and API server. Indexes Hive from a starting block number for relevant insert_operation_here
operations using the HAF app sync algorithm.
Replace every instance of myhaf_app
with your actual HAF app name in:
- All SQL files in src/sql folder
- src/constants.ts
- .env.example
- scripts/block_processing_healthcheck.sh
- This README file
Replace every instance of myhaf_api
with your actual HAF app API schema name in:
- src/sql/create_apis.sql
- src/sql/drop_db.sql
- src/server.ts
- PostgREST start scripts in scripts folder (including docker)
- docker/compose.yml
- This README file
Replace every instance of myhaf_owner
with your actual HAF app owner role in:
- src/sql/create_apis.sql
- src/sql/builtin_roles.sql
- scripts/block_processing_healthcheck.sh
- Dockerfile
- docker/compose.yml
- This README file
Replace every instance of myhaf_user
with your actual HAF app API user in:
- src/sql/create_apis.sql
- PostgREST start scripts in scripts folder (including docker)
- docker/compose.yml
- This README file
Replace the environment variable prefix HAFAPP
in:
- .env.example
- Dockerfile
- config.ts
- scripts/docker_entrypoint.sh
- This README file
Write the PostgreSQL table definitions in src/sql/create_tables.sql file. All registered tables (forking app) must contain the column hive_rowid
as shown in the example table. List the registered table names (without schema name) in src/schema.ts, under HAF_TABLES
array.
Then define foreign key definitions in the same file under HAF_FKS
object, and list those definitions that has to be dropped when uninstalling the HAF app in src/sql/drop_db.sql.
An example PL/pgSQL function for fetching custom_json
operations has been defined in src/sql/create_functions.sql. Adapt the function to your desired set of operation IDs by referring to the operations list linked in the file.
Define all operation processing methods in the same file.
Define PostgREST API definitions in src/sql/create_apis.sql file under the HAF app API schema.
Define additional configuration required in config.js file. All constants are to be defined in constants.ts.
Include the required validation for operations fetched from myhaf_app.enum_op()
in src/processor.ts file in validateAndParse()
method. Execute the operations by calling the operation processing PL/pgSQL methods in process()
within the same file.
Import the required state providers in src/schema.ts. The accounts
state provider has been included as an example.
A sample Dockerfile and compose.yml is supplied in this template.
- Replace all instances of
myhaf_owner
with your app user. - Replace the image names in scripts/build_instance.sh and docker/compose.yml.
- Replace compose service and profile names in docker/compose.yml and this README file.
- Replace the LICENSE file with your desired license.
- Replace all values in package.json with actual names and URLs.
- Delete this section of the README file and update the HAF app description above.
- Synced HAF node, ideally using
haf_api_node
compose
This assumes HAF is running through haf_api_node
.
Clone this repository, then add the following in the .env
file in haf_api_node
directory:
COMPOSE_FILE="${COMPOSE_FILE}:/path/to/myhaf/repo/docker/compose.yml"
HAFAPP_VERSION=latest
Build the Docker image:
cd /path/to/myhaf/repo
./scripts/build_instance.sh
Run the HAF app sync:
docker compose up -d myhaf-app-block-processing
Run the PostgREST server:
docker compose up -d myhaf-app-postgrest
You may need to add the following entries to PG_ACCESS
in haf_base.yml
:
host haf_block_log haf_admin ${COMPOSE_PROJECT_NAME}-myhaf-install-1.${NETWORK_NAME} trust\n
host haf_block_log myhaf_owner ${COMPOSE_PROJECT_NAME}-myhaf-install-1.${NETWORK_NAME} trust\n
host haf_block_log myhaf_owner ${COMPOSE_PROJECT_NAME}-myhaf-block-processing-1.${NETWORK_NAME} trust\n
host haf_block_log myhaf_user ${COMPOSE_PROJECT_NAME}-myhaf-postgrest-1.${NETWORK_NAME} trust\n
host haf_block_log haf_admin ${COMPOSE_PROJECT_NAME}-myhaf-uninstall-1.${NETWORK_NAME} trust\n
psql -f src/sql/builtin_roles.sql haf_block_log
./scripts/postgrest_install.sh
psql -f src/sql/create_apis.sql block_log
git clone https://github.com/techcoderx/typescript-haf-app-template
cd typescript-haf-app-template
npm i
npm run compile
npm start
./scripts/postgrest_start.sh postgres://myhaf_user:<myhaf_user_password>@localhost:5432/block_log <server_port>