Skip to content

Commit

Permalink
Feat: Add Identity Handler (#28)
Browse files Browse the repository at this point in the history
* Add statement handler

Signed-off-by: Adi Bhagavath <[email protected]>

* remove .vscode

* Add DecoderUtils to converst the hex to string

Signed-off-by: System Administrator <[email protected]>

* update statement

Signed-off-by: Adi Bhagavath <[email protected]>

* use extrinsic.block to get the blocknumber

* minor fixes

Signed-off-by: System Administrator <[email protected]>

* remove logs and correct the alignment

Signed-off-by: System Administrator <[email protected]>

* Add call index

Signed-off-by: Adi Bhagavath <[email protected]>

* feat: Add identity handler

Signed-off-by: Adi Bhagavath <[email protected]>

* Remove GitHub Actions

---------

Signed-off-by: Adi Bhagavath <[email protected]>
Signed-off-by: System Administrator <[email protected]>
Co-authored-by: Ujjwal Sharma <[email protected]>
  • Loading branch information
adi-a11y and ujjwal6792 authored Feb 5, 2024
1 parent 2a3c068 commit 85d9b7e
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 3 deletions.
38 changes: 38 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,41 @@ type Schema @entity {
authorization: String
schema_id: String
}

type SetIdentity @entity {
id: ID!

method: String
callIndex: String
blockNumber: BigInt

display: String
legal: String
web: String
email: String
additional: String

}

type ProvidedJudgement @entity{
id: ID!

method: String
callIndex: String
blockNumber: BigInt

targetId: String
judgement: String
digest: String
}

type JudgementRequest @entity{
id: ID!

method: String
callIndex: String
blockNumber: BigInt

registrar: String
}

9 changes: 6 additions & 3 deletions src/handlers/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { AnyCall, DispatchedCallData } from "./types";
import { SubstrateExtrinsic } from "@subql/types";
import { Dispatcher, getBatchInterruptedIndex, getKVData } from "./utils";
import { createScore } from "./score";
import { Dispatcher, getBatchInterruptedIndex, getKVData } from './utils';
import { createScore } from './score';
import { indexDidCall } from './did'
import { createStatement } from "./statement";
import { indexAssetCall } from "./asset";

import { indexIdentityCall } from "./identity";

async function traverExtrinsic(
extrinsic: Extrinsic,
Expand Down Expand Up @@ -88,6 +86,11 @@ async function traverExtrinsic(
await createSchema(raw, call, id as string, data.method);
}

if (call.section === "identity") {
logger.info(`${data.method}`);
await indexIdentityCall(raw, id as string, data.method);
}

if (depth < 1 && section === 'utility' && (method === 'batch' || method === 'batchAll')) {
const temp = args[0] as unknown as Vec<AnyCall>

Expand Down
86 changes: 86 additions & 0 deletions src/handlers/identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { SubstrateExtrinsic } from "@subql/types";
import { SetIdentity, ProvidedJudgement, JudgementRequest } from "../types";

export async function indexIdentityCall(
extrinsic: SubstrateExtrinsic,
id: string,
method: string
): Promise<void> {
const data = extrinsic.extrinsic.method;

const arrayed = JSON.parse(JSON.stringify(data));

if (method === "setIdentity") {
let identity = new SetIdentity(id);
identity.method = method;
identity.callIndex = arrayed.callIndex;
identity.blockNumber = extrinsic.block.block.header.number.toBigInt();

identity.display = arrayed.args.info.display.raw;
identity.legal = arrayed.args.info.legal.raw;
identity.web = arrayed.args.info.web.raw;
identity.email = arrayed.args.info.email.raw;
identity.additional = JSON.stringify(arrayed.args.info.additional);

await identity.save();
}
if (method === "requestJudgement") {
let judgementRequest = new JudgementRequest(id);
judgementRequest.method = method;
judgementRequest.callIndex = arrayed.callIndex;
judgementRequest.blockNumber =
extrinsic.block.block.header.number.toBigInt();
judgementRequest.registrar = arrayed.args.registrar;

await judgementRequest.save();
}
if (method === "provideJudgement") {
let providedJudgement = new ProvidedJudgement(id);
providedJudgement.method = method;
providedJudgement.callIndex = arrayed.callIndex;
providedJudgement.blockNumber =
extrinsic.block.block.header.number.toBigInt();

providedJudgement.callIndex = arrayed.callIndex;
providedJudgement.targetId = arrayed.args.target.id;
providedJudgement.judgement = arrayed.args.judgement;
providedJudgement.digest = arrayed.args.digest;

await providedJudgement.save();
}

if (method === "identityCleared") {
// ToDo:
// Develop a demo script within the GitHub repository at github.com/dhiway/cord.js which
// calls this method. Execute the script to capture the extrinsic information, analyze the obtained data,
// and complete the implementation.
}
if (method === "identityKilled") {
/* ToDo:
Develop a demo script within the GitHub repository at github.com/dhiway/cord.js which
calls this method. Execute the script to capture the extrinsic information, analyze the obtained data,
and complete the implementation.
*/
}
if (method === "judgementUnrequested") {
/* ToDo:
Develop a demo script within the GitHub repository at github.com/dhiway/cord.js which
calls this method. Execute the script to capture the extrinsic information, analyze the obtained data,
and complete the implementation.
*/
}
if (method === "registrarAdded") {
/* ToDo:
Develop a demo script within the GitHub repository at github.com/dhiway/cord.js which
calls this method. Execute the script to capture the extrinsic information, analyze the obtained data,
and complete the implementation.
*/
}
if (method === "registrarRemoved") {
/* ToDo:
Develop a demo script within the GitHub repository at github.com/dhiway/cord.js which
calls this method. Execute the script to capture the extrinsic information, analyze the obtained data,
and complete the implementation.
*/
}
}

0 comments on commit 85d9b7e

Please sign in to comment.