feat: add AH GraphQL engine + block handler for pool stakers init

- Add handleBlock to query live chain state for existing pool members
- Add second GraphQL engine container for Asset Hub schema (port 3001)
- Register block handler in pezkuwi-assethub.yaml
This commit is contained in:
2026-02-18 04:07:45 +03:00
parent 1c79402d5c
commit 7b58fa0e4a
3 changed files with 63 additions and 2 deletions
+19 -1
View File
@@ -70,7 +70,6 @@ services:
- 3000:3000
depends_on:
- subquery-node-relay
- subquery-node-assethub
restart: always
environment:
DB_USER: postgres
@@ -83,6 +82,25 @@ services:
- --playground
- --indexer=http://subquery-node-relay:3000
graphql-engine-assethub:
container_name: query-pezkuwi-ah
image: onfinality/subql-query:v1.5.0
ports:
- 3001:3000
depends_on:
- subquery-node-assethub
restart: always
environment:
DB_USER: postgres
DB_PASS: pezkuwi_subquery_2024
DB_DATABASE: postgres
DB_HOST: postgres
DB_PORT: 5432
command:
- --name=subquery-pezkuwi-assethub
- --playground
- --indexer=http://subquery-node-assethub:3000
noter-bot:
container_name: noter-pezkuwi
build:
+3
View File
@@ -23,6 +23,9 @@ dataSources:
mapping:
file: ./dist/index.js
handlers:
# Block handler: initialize active pool stakers from chain state
- handler: handleBlock
kind: substrate/BlockHandler
# Signed extrinsics for history
- handler: handleHistoryElement
kind: substrate/CallHandler
+41 -1
View File
@@ -1,4 +1,4 @@
import { SubstrateEvent } from "@subql/types";
import { SubstrateEvent, SubstrateBlock } from "@subql/types";
import { ActiveStaker } from "../types";
import { Option } from "@pezkuwi/types";
import {
@@ -6,6 +6,46 @@ import {
STAKING_TYPE_NOMINATION_POOL,
} from "./constants";
let poolMembersInitialized = false;
/**
* Block handler: on the FIRST block processed, query the live chain state
* for all current nomination pool members and save them as ActiveStakers.
* This ensures existing pool members are captured even if their Bonded
* events were in pruned blocks.
*/
export async function handleBlock(block: SubstrateBlock): Promise<void> {
if (poolMembersInitialized) return;
poolMembersInitialized = true;
logger.info("Initializing active pool stakers from live chain state...");
const members = await api.query.nominationPools.poolMembers.entries();
let count = 0;
for (const [key, memberOpt] of members) {
const member = (memberOpt as Option<any>);
if (member.isNone) continue;
const unwrapped = member.unwrap();
if (unwrapped.points.toBigInt() === BigInt(0)) continue;
const address = key.args[0].toString();
const stakerId = `${PEZKUWI_ASSET_HUB_GENESIS}-${STAKING_TYPE_NOMINATION_POOL}-${address}`;
const staker = ActiveStaker.create({
id: stakerId,
networkId: PEZKUWI_ASSET_HUB_GENESIS,
stakingType: STAKING_TYPE_NOMINATION_POOL,
address,
});
await staker.save();
count++;
}
logger.info(`Initialized ${count} active pool stakers from chain state`);
}
/**
* Handle nominationPools.Bonded event
* Fired when a member bonds (joins or adds more) to a nomination pool.