bigshortbets / indexer

Subsquid indexer aligned with P2P Market metadata
MIT License
1 stars 3 forks source link

Substrate node processor

This project purpose is to aggregate events from the Substrate-based blockchain and provide GraphQL API enpoint for accessing on chain historic data, events and calls. Project uses Subsquid squid technology, for more information see Subsquid documentation.

Prerequisites

Quickstart

  1. Run the processor
    • Run docker container via docker compose
    • Build the squid, for more information follow this documentation
      • from the processor dir run: npm i -g @subsquid/cli@latest
      • check version: sqd --version
      • initialize squid with : sqd init <project-name> --template substrate
      • install dependencies: npm i
    • Launch Postgres in a detached Docker container: sqd up
    • Generate model files, v1 and events: Workflow section, parts 1 and 3.
    • Build the project and start the processor: sqd process
    • On another instance of the terminal run GraphQL server: sqd serve
    • GraphQL API will be accessible under /graphql endpoint on the port prompted by sqd serve

Workflow

  1. Entities are generated based on the schema.graphql file, instruction on defining entities may be found under this Subsquid documentation page. To map changes from schema.graphql to the codebase (files inside /model/generated) call sqd codegen method, delta between current state of database and state of the model is represented by the migration file - new one must be generated after each change made to the model (using sqd migration:generate command).
  2. All squid command's with brief explanation are defined in the commands.json file
  3. In /types directory there are generated classes that represent access API for the Substate chain metadata: to update those files after chain node change call generate .jsonl file by running: squid-substrate-metadata-explorer --chain <url> --out <file> where in <url> write chain node url and in <file> output destination and name of your .jsonl file (by relation to the root project directory). Next call sqd typegen <file>.
  4. CRUD operations on the database are made using BatchContext.store TypeormDatabase member. General info about using TypeormDatabase is available here. For advanced query operations see this documentation page.

Project conventions

Squid tools assume a certain project layout.

See the full description in the documentation.