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 DID and statement handler #24

Merged
merged 2 commits into from
Feb 1, 2024
Merged
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
15 changes: 0 additions & 15 deletions .github/scripts/publish-deploy.sh

This file was deleted.

34 changes: 0 additions & 34 deletions .github/workflows/cli-deploy.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/pr.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dist/
# lock files
yarn.lock
package-lock.json
settings.json

# Compiled Java class files
*.class
Expand Down
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#ffb733",
"activityBar.background": "#ffb733",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#008053",
"activityBarBadge.foreground": "#e7e7e7",
"commandCenter.border": "#15202b99",
"sash.hoverBorder": "#ffb733",
"statusBar.background": "#ffa500",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#cc8400",
"statusBarItem.remoteBackground": "#ffa500",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#ffa500",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#ffa50099",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.color": "orange"
}
41 changes: 41 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,44 @@ type Rating @entity {
entityType: String
ratingType: String
}

type Did @entity {
id: ID!

method: String
blockNumber: BigInt
identifier: String
submitter: String
signature: String

keyAgreementKeys: String
assertionKey: String
delegationKey: String
serviceDetails: [String]
}

type DidSubmitCall @entity {
id: ID!
blockNumber: BigInt

didUri: String
callIndex: String
txCounter: Int
submitter: String
signature: String
}

type Statement @entity {
id: ID!

method: String
callIndex: String
blockNumber: BigInt
submitter: String
signature: String

statement_id: String
authorization: String
schema_id: 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 @@ -5,6 +5,8 @@ import { AnyCall, DispatchedCallData } from './types'
import { SubstrateExtrinsic } from "@subql/types";
import { Dispatcher, getBatchInterruptedIndex, getKVData } from './utils';
import { createScore } from './score';
import { indexDidCall } from './did';
import { createStatement } from './statement';

async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): Promise<Call[]> {
const list: any[] = []
Expand Down Expand Up @@ -57,6 +59,16 @@ async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): P
logger.info("Scoring call");
await createScore(raw, id as string);
}

if (call.section === 'did') {
logger.info("DID call")
await indexDidCall(raw, id as string, data.method)
}

if (call.section === "statement") {
logger.info(`${data.method}`);
await createStatement(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
64 changes: 64 additions & 0 deletions src/handlers/did.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { SubstrateExtrinsic } from "@subql/types";
import { Did, DidSubmitCall } from "../types";

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

if (method === "create") {
let arrayed = JSON.parse(JSON.stringify(data));
let serviceDetailsFromChain = arrayed.args.details.newServiceDetails;
let serviceDetails: string[] = [];

await serviceDetailsFromChain.forEach((item: any) => {
let serviceDetail = {
id: item.id,
serviceTypes: item.serviceTypes,
urls: item.urls,
};

serviceDetails.push(JSON.stringify(serviceDetail));
});

let did = new Did(id);
did.method = method;
did.blockNumber = extrinsic.block.block.header.number.toBigInt();
did.identifier = arrayed.args.details.did;
did.submitter = arrayed.args.details.submitter;
did.signature = JSON.stringify(arrayed.args.signature);

did.keyAgreementKeys = JSON.stringify(
arrayed.args.details.newKeyAgreementKeys
);
did.assertionKey = JSON.stringify(arrayed.args.details.newAssertionKey);
did.delegationKey = JSON.stringify(arrayed.args.details.newDelegationKey);
did.serviceDetails = serviceDetails;
await did.save();
}
if (method === "update") {
// 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 === "delete") {
// 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 === "submitDidCall") {
let arrayed = JSON.parse(JSON.stringify(data));
let didSubmitCall = new DidSubmitCall(id);
didSubmitCall.blockNumber = extrinsic.block.block.header.number.toBigInt();
didSubmitCall.didUri = arrayed.args.did_call.did;
didSubmitCall.callIndex = arrayed.args.did_call.call.callIndex;
didSubmitCall.txCounter = arrayed.args.did_call.txCounter;
didSubmitCall.submitter = arrayed.args.did_call.submitter;
didSubmitCall.signature = JSON.stringify(arrayed.args.signature);
await didSubmitCall.save();
}
}
64 changes: 64 additions & 0 deletions src/handlers/statement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { SubstrateExtrinsic } from "@subql/types";
import { Statement } from "../types";

export async function createStatement(
extrinsic: SubstrateExtrinsic,
id: string,
method: string
): Promise<void> {
const data = extrinsic.extrinsic.method;
let arrayed = JSON.parse(JSON.stringify(data));
if (method === "register") {
let arrayed = JSON.parse(JSON.stringify(data));
let statementId = JSON.parse(JSON.stringify(extrinsic.events))[0].event
.data[0];
let statement = new Statement(id);
statement.method = method;
statement.callIndex = arrayed.args.did_call.call.callIndex
statement.blockNumber = extrinsic.block.block.header.number.toBigInt();
statement.submitter = arrayed.args.did_call.submitter;
statement.signature = JSON.stringify(arrayed.args.signature);
statement.statement_id = statementId;
statement.authorization = arrayed.args.did_call.call.args.authorization;
statement.schema_id = arrayed.args.did_call.call.args.schema_id;
statement.digest = arrayed.args.did_call.call.args.digest;
await statement.save();
}
if (method === "update") {
let arrayed = JSON.parse(JSON.stringify(data));
let statement = new Statement(id);
statement.method = method;
statement.callIndex = arrayed.args.did_call.call.callIndex
statement.blockNumber = extrinsic.block.block.header.number.toBigInt();
statement.submitter = arrayed.args.did_call.submitter;
statement.signature = JSON.stringify(arrayed.args.signature);
statement.statement_id = arrayed.args.did_call.call.args.statement_id;
statement.digest = arrayed.args.did_call.call.args.digest;
statement.authorization = arrayed.args.did_call.call.args.authorization;
await statement.save();
}
if (method === "revoke") {
let arrayed = JSON.parse(JSON.stringify(data));
let statement = new Statement(id);
statement.method = method;
statement.callIndex = arrayed.args.did_call.call.callIndex
statement.blockNumber = extrinsic.block.block.header.number.toBigInt();
statement.submitter = arrayed.args.did_call.submitter;
statement.signature = JSON.stringify(arrayed.args.signature);
statement.statement_id = arrayed.args.did_call.call.args.statement_id;
statement.authorization = arrayed.args.did_call.call.args.authorization;
await statement.save();
}
if (method === "restore") {
let arrayed = JSON.parse(JSON.stringify(data));
let statement = new Statement(id);
statement.method = method;
statement.callIndex = arrayed.args.did_call.call.callIndex
statement.blockNumber = extrinsic.block.block.header.number.toBigInt();
statement.submitter = arrayed.args.did_call.submitter;
statement.signature = JSON.stringify(arrayed.args.signature);
statement.statement_id = arrayed.args.did_call.call.args.statement_id;
statement.authorization = arrayed.args.did_call.call.args.authorization;
await statement.save();
}
}