Skip to content

Latest commit

 

History

History
97 lines (66 loc) · 3.77 KB

README.md

File metadata and controls

97 lines (66 loc) · 3.77 KB

Cere Squid Indexer

This is an indexer for Cerebellum Network blockchain built using Subsquid squid-sdk.

Usage

Example commands below use sqd. Please install it before proceeding.

# 0. Clone the repository.
git clone [email protected]:Cerebellum-Network/cere-squid-indexer.git && cd cere-squid-indexer

# 1. Install dependencies
npm ci

# 2. Create `.env` file with environment variables. Example file values start Devnet indexing from the first block.
cp .env.example .env

# 3. Start target Postgres database.
sqd up:db

# 4. Apply database migrations and start indexing processor.
sqd process

# 5. Start GraphQL server.
sqd serve

# 7. Open GraphQL playground in a browser.
sqd open

A GraphiQL playground will be available at 127.0.0.1:4350/graphql.

How to extend the processor

Read the docs first: Simple Substrate squid.

1. Update database schema

Start by updating 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.

2. Regenerate TypeORM classes

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 sqd codegen command.

3. Generate database migration

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.

# Update database connection credentials in .env and load them.
source .env

# 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!
sqd generate

4. Extend processor

Create or extend an existing processor with new events listening and RPC requests in src/processors. Now you can add processor state persistance to the processor.run callback.

Project conventions

Squid tools assume a certain project layout.

  • All compiled js files must reside in lib and all TypeScript sources in src. The layout of lib must reflect src.
  • All TypeORM classes must be exported by src/model/index.ts (lib/model module).
  • Database schema must be defined in schema.graphql.
  • Database migrations must reside in db/migrations and must be plain js files.
  • squid-*(1) executables consult .env file for a number of environment variables.

See the full description in the documentation.

Runtime metadata

In order to add new blockchain or if there was a runtime upgrade of an existing blockchain we should add the blockchain specification file with the runtime metadata. Create blockchain specification file for typegen.json using substrate-metadata-explorer.

# Export new runtime metadata
npx @subsquid/substrate-metadata-explorer --rpc $RPC_WS --fromBlock $FROM_BLOCK_NUMBER --out specs/out.jsonl

# Add new runtime metadata to existing file used in `typegen.json` and regenerate types.
npx squid-substrate-typegen ./typegen.json