Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Registry Entry Handler #32

Open
wants to merge 1 commit into
base: working-score
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
12 changes: 12 additions & 0 deletions src/handlers/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" &&
Expand Down
84 changes: 84 additions & 0 deletions src/handlers/entries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { SubstrateExtrinsic } from "@subql/types";
import { Entries } from "../types";

export async function handleRegistryEntries(
extrinsic: SubstrateExtrinsic,
id: string,
method: string
): Promise<void> {
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();
}
}
103 changes: 103 additions & 0 deletions src/handlers/registries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { SubstrateExtrinsic } from "@subql/types";
import { Registry } from "../types";

export async function handleRegistry(
extrinsic: SubstrateExtrinsic,
id: string,
method: string
): Promise<void> {
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();
}
}