KodaDot's Squid based data processor for KodaDot NFT Marketplace.
- node 16.x
- docker
- npm -- note that
yarn
package manager is not supported
Example commands below use sqd. Please install it before proceeding.
# 1. Update Squid SDK and install dependencies
npm run update
npm ci
# 2. Start target Postgres database and detach
sqd up
# 3. Build the project and start the processor
sqd process
# 4. The command above will block the terminal
# being busy with fetching the chain data,
# transforming and storing it in the target database.
#
# To start the graphql server open a separate terminal
# and run
sqd serve
src/generated
- model/server definitions created bycodegen
. Do not alter the contents of this directory manually.src/server-extension
- module with customtype-graphql
based resolverssrc/types
- data type definitions for chain events and extrinsics created bytypegen
.src/mappings
- mapping module.lib
- compiled js files. The structure of this directory must reflectsrc
..env
- hydra tools are heavily driven by environment variables defined here or supplied by a shell.
Start development by defining the schema of the target database via schema.graphql
.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql
dialect is available here.
Mapping developers use TypeORM entities
to interact with the target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql
. This is done by running npx squid-typeorm-codegen
or (equivalently) sqd codegen
command.
All database changes are applied through migration files located at db/migrations
.
squid-typeorm-migration(1)
tool provides several commands to drive the process.
It is all TypeORM under the hood.
# Connect to database, analyze its state and generate migration to match the target schema.
# The target schema is derived from entity classes generated earlier.
# Don't forget to compile your entity classes beforehand!
npx squid-typeorm-migration generate
# Create template file for custom database changes
npx squid-typeorm-migration create
# Apply database migrations from `db/migrations`
npx squid-typeorm-migration apply
# Revert the last performed migration
npx squid-typeorm-migration revert
Available sqd
shortcuts:
# Build the project, remove any old migrations, then run `npx squid-typeorm-migration generate`
sqd migration:generate
# Run npx squid-typeorm-migration apply
sqd migration:apply
- fast generate event handlers
pbpaste | cut -d '=' -f 1 | tr -d ' ' | xargs -I_ echo "processor.addEventHandler(Event._, dummy);"
- enable debug logs (in .env)
SQD_DEBUG=squid:log
- generate metagetters from getters
pbpaste | grep 'export' | xargs -I_ echo "_ return proc. }"