From b4250ebef6139e584061caebdf948573b2c5939f Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Tue, 26 Nov 2024 16:29:28 +0530 Subject: [PATCH] Add Registry Entry Handler Signed-off-by: Adi Bhagavath --- package.json | 9 ++-- project.ts | 2 +- schema.graphql | 29 +++++++++++ src/handlers/call.ts | 12 +++++ src/handlers/entries.ts | 84 ++++++++++++++++++++++++++++++ src/handlers/registries.ts | 103 +++++++++++++++++++++++++++++++++++++ 6 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 src/handlers/entries.ts create mode 100644 src/handlers/registries.ts diff --git a/package.json b/package.json index 5c0071f..78ca0dc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "subql build", "codegen": "subql codegen", "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node test" }, @@ -26,12 +26,15 @@ "@subql/node": "latest", "@subql/testing": "latest", "@subql/types": "latest", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "@subql/node-core": "^15.0.1" + }, "exports": { "chaintypes": "src/chaintypes.ts" }, "dependencies": { - "@cord.network/sdk": "0.9.3-1develop1" + "@cord.network/type-definitions": "^0.9.4", + "@subql/node-core": "^15.0.1" } } diff --git a/project.ts b/project.ts index ea9f0f3..78d0769 100644 --- a/project.ts +++ b/project.ts @@ -27,7 +27,7 @@ const project: SubstrateProject = { network: { /* The genesis hash of the network (hash of block 0) */ chainId: - "0x3a137ff035562c623ff2b7726379a6d9d291c560596dde4518df93a46ff819c7", + "0xb8c0f2929dc429cac419217eb6eb232a86e35b9846220c7991ae2f0ba15b5c4f", /** * This endpoint must be a public non-pruned archive node * Public nodes may be rate limited, which can affect indexing speed diff --git a/schema.graphql b/schema.graphql index b02f832..89c8a18 100644 --- a/schema.graphql +++ b/schema.graphql @@ -256,3 +256,32 @@ type NetworkMembership @entity { networkmembership_Id: String member: String } + +type Registry @entity { + id: ID! + + method: String + blockNumber: BigInt + registry_id: String + schema_id: String + blob: String + submitter: String + state: String + authorization: String + digest: String +} + +type Entries @entity { + id: ID! + + method: String + blockNumber: BigInt + registry_id: String + registry_entry_id: String + blob: String + submitter: String + state: String + authorization: String + digest: String + +} \ No newline at end of file diff --git a/src/handlers/call.ts b/src/handlers/call.ts index 25fedc3..4f3a904 100644 --- a/src/handlers/call.ts +++ b/src/handlers/call.ts @@ -13,6 +13,8 @@ import { handleDidNameCall } from "./didName"; import { createSchema } from "./schema"; import { createChainSpace } from "./chainSpace"; import { createNetworkMembership } from "./networkMembership"; +import { handleRegistry } from "./registries" +import { handleRegistryEntries } from "./entries" export async function createCalls( extrinsic: Extrinsic, @@ -140,6 +142,16 @@ async function traverExtrinsic( await handleDidNameCall(raw, id as string, data.method); } + if (call.section === "registries") { + logger.info(`${data.method}`); + await handleRegistry(raw, id as string, data.method); + } + + if (call.section === "entries") { + logger.info(`${data.method}`); + await handleRegistryEntries(raw, id as string, data.method); + } + if ( depth < 1 && section === "utility" && diff --git a/src/handlers/entries.ts b/src/handlers/entries.ts new file mode 100644 index 0000000..ff02610 --- /dev/null +++ b/src/handlers/entries.ts @@ -0,0 +1,84 @@ +import { SubstrateExtrinsic } from "@subql/types"; +import { Entries } from "../types"; + +export async function handleRegistryEntries( + extrinsic: SubstrateExtrinsic, + id: string, + method: string +): Promise { + const data = extrinsic.extrinsic.method; + + if (method === "create") { + let arrayed = JSON.parse(JSON.stringify(data)); + + let entries = new Entries(id); + + let validJson = JSON.parse( + JSON.stringify(extrinsic.events).replace(/\},\n\{/g, "},{") + ); + let value = validJson.find((entry: any) => entry.event.index === "0x3e00") + ?.event.data[1]; + + entries.method = method; + entries.blockNumber = extrinsic.block.block.header.number.toBigInt(); + entries.registry_id = value; + entries.registry_entry_id = arrayed.args.registry_entry_id; + entries.submitter = JSON.parse( + JSON.stringify(extrinsic.events) + )[0].event.data[0]; + entries.digest = arrayed.args.digest; + entries.blob = arrayed.args.blob; + entries.authorization = arrayed.args.authorization; + + await entries.save(); + } + + if (method === "update") { + let arrayed = JSON.parse(JSON.stringify(data)); + let entries = new Entries(id) + entries.method = method; + entries.blockNumber = extrinsic.block.block.header.number.toBigInt(); + entries.registry_entry_id = JSON.parse( + JSON.stringify(extrinsic.events) + )[0].event.data[2]; + entries.submitter = JSON.parse( + JSON.stringify(extrinsic.events) + )[0].event.data[0]; + entries.digest = arrayed.args.digest; + entries.blob = arrayed.args.blob; + entries.authorization = arrayed.args.authorization; + await entries.save(); + } + + if (method === "revoke") { + let arrayed = JSON.parse(JSON.stringify(data)); + let entries = new Entries(id); + entries.method = method; + entries.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + entries.registry_entry_id = arrayed.args.registry_entry_id; + entries.authorization = arrayed.args.authorization; + entries.state = "Revoked"; + entries.submitter = JSON.parse( + JSON.stringify(extrinsic.events) + )[0].event.data[0]; + + await entries.save(); + } + + if (method === "reinstate") { + let arrayed = JSON.parse(JSON.stringify(data)); + let entries = new Entries(id); + entries.method = method; + entries.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + entries.registry_entry_id = arrayed.args.registry_entry_id; + entries.authorization = arrayed.args.authorization; + entries.state = "Reinstated"; + entries.submitter = JSON.parse( + JSON.stringify(extrinsic.events) + )[0].event.data[0]; + + await entries.save(); + } +} diff --git a/src/handlers/registries.ts b/src/handlers/registries.ts new file mode 100644 index 0000000..c966235 --- /dev/null +++ b/src/handlers/registries.ts @@ -0,0 +1,103 @@ +import { SubstrateExtrinsic } from "@subql/types"; +import { Registry } from "../types"; + +export async function handleRegistry( + extrinsic: SubstrateExtrinsic, + id: string, + method: string + ): Promise { + const data = extrinsic.extrinsic.method; + + if (method === "register") { + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + registry.registry_id = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[0]; + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + registry.schema_id = arrayed.args.schema_id + registry.digest = arrayed.args.digest + registry.blob = arrayed.args.blob + registry.authorization = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[2]; + await registry.save(); + } + + if(method === "update"){ + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + registry.registry_id = arrayed.args.registry_id + registry.digest = arrayed.args.digest + registry.blob = arrayed.args.blob + registry.authorization = arrayed.args.authorization + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + + await registry.save(); + } + + if(method === "revoke") { + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + registry.registry_id = arrayed.args.registry_id + registry.authorization = arrayed.args.authorization + registry.state = "Revoked" + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + + await registry.save(); + } + + if(method === "reinstate") { + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + registry.registry_id = arrayed.args.registry_id + registry.authorization = arrayed.args.authorization + registry.state = "Reinstated" + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + + await registry.save(); + } + + if(method === "archive") { + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + registry.registry_id = arrayed.args.registry_id + registry.authorization = arrayed.args.authorization + registry.state = "Archived" + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + + await registry.save(); + } + + if(method === "restore") { + let arrayed = JSON.parse(JSON.stringify(data)); + let registry = new Registry(id); + registry.method = method; + registry.blockNumber = extrinsic.block.block.header.number.toBigInt(); + + registry.registry_id = arrayed.args.registry_id + registry.authorization = arrayed.args.authorization + registry.state = "Restored" + registry.submitter = JSON.parse(JSON.stringify(extrinsic.events))[0].event + .data[1]; + + await registry.save(); + } +}