From 405877a7ac8c22ab113dc0e734da64528db2b5af Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Sat, 27 Jan 2024 12:16:17 +0530 Subject: [PATCH 1/9] Add statement handler Signed-off-by: Adi Bhagavath --- .vscode/settings.json | 22 ++++ project.ts | 2 +- schema.graphql | 10 ++ src/handlers/call.ts | 6 ++ src/handlers/event.ts | 2 +- src/handlers/statement.ts | 209 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/handlers/statement.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e4cb847 --- /dev/null +++ b/.vscode/settings.json @@ -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" +} \ No newline at end of file diff --git a/project.ts b/project.ts index 40d60a5..381dbd2 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: - "0x1104c0bc1c2ecdbb948438a8900f533fbe968c184625bb6127beb55548a76810", + "0x3a137ff035562c623ff2b7726379a6d9d291c560596dde4518df93a46ff819c7", /** * 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 2aeaa8a..e069b6b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -92,3 +92,13 @@ type Rating @entity { entityType: String ratingType: String } + +type Statement @entity { + id: ID! + + method: String + statement_id: String + authorization: String + schema_id: String + digest: String +} \ No newline at end of file diff --git a/src/handlers/call.ts b/src/handlers/call.ts index 5b5826f..518bb2b 100644 --- a/src/handlers/call.ts +++ b/src/handlers/call.ts @@ -5,6 +5,7 @@ import { AnyCall, DispatchedCallData } from './types' import { SubstrateExtrinsic } from "@subql/types"; import { Dispatcher, getBatchInterruptedIndex, getKVData } from './utils'; import { createScore } from './score'; +import { createStatement } from './statement'; async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): Promise { const list: any[] = [] @@ -57,6 +58,11 @@ async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): P logger.info("Scoring call"); await createScore(raw, id as string); } + if(call.section === 'statement'){ + logger.info("\n\n\n\nStatement call inside call.ts and calling createStatement"); + logger.info(`${data.method}`) + await createStatement(raw,call, id as string,data.method); + } if (depth < 1 && section === 'utility' && (method === 'batch' || method === 'batchAll')) { const temp = args[0] as unknown as Vec diff --git a/src/handlers/event.ts b/src/handlers/event.ts index 136a9a4..9d44d7f 100644 --- a/src/handlers/event.ts +++ b/src/handlers/event.ts @@ -57,7 +57,7 @@ export async function createEvent(event: SubstrateEvent) { data.section = section; data.method = method; data.data = eventData; - + logger.info(`\nsection: ${section}\nmethod: ${method}\neventData: ${eventData}`) const extrinsic = await (event.extrinsic ? ensureExtrinsic(event.extrinsic) : undefined); diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts new file mode 100644 index 0000000..c9056c9 --- /dev/null +++ b/src/handlers/statement.ts @@ -0,0 +1,209 @@ +import { SubstrateEvent, SubstrateExtrinsic } from "@subql/types"; +import { ensureCallExist } from "./call"; +import { Statement , Call} from '../types'; +import { Event } from "../types/models"; + +interface KeyValue { + key: string; + value: string; + } + +export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, id: string, method:string): Promise { + const data = extrinsic.extrinsic.method; + + logger.info(` + ------------------------------------------------------------------------------------------------ + \nInside createStatement function\n + ------------------------------------------------------------------------------------------------ + `); + logger.info(`printing call: ${call}`) + + if(method === 'register'){ + // logger.info(`*******************************************\nRegister\n`) + let statement = new Statement(id) + + let stringyfy = JSON.stringify(call.args) + const keyValueArray: KeyValue[] = JSON.parse(stringyfy); + const allValues: string[] = keyValueArray.map(item => item.value); + + statement.digest = allValues[0] + statement.authorization = allValues[1] + statement.schema_id = allValues[2] + await statement.save() + } + if(method === 'update'){ + let stringyfy = JSON.stringify(call.args) + // logger.info(`stringyfy: stringyfy: stringyfy: stringyfy: \n${stringyfy}`) + const keyValueArray: KeyValue[] = JSON.parse(stringyfy); + const allValues: string[] = keyValueArray.map(item => item.value); + + // logger.info(`allValues: allValues: allValues: allValues: allValues:\n${allValues}`) + let statement = new Statement(id) + statement.method = method + statement.statement_id = allValues[0] + + statement.digest = allValues[1] + statement.authorization = allValues[2] + await statement.save() + } + if(method === 'revoke'){ + let stringyfy = JSON.stringify(call.args) + + const keyValueArray: KeyValue[] = JSON.parse(stringyfy); + const allValues: string[] = keyValueArray.map(item => item.value); + + + let statement = new Statement(id) + statement.method = method + statement.statement_id = allValues[0] + statement.authorization = allValues[1] + await statement.save() + } + if(method === 'restore'){ + let statement = new Statement(id) + + let stringyfy = JSON.stringify(call.args) + + const keyValueArray: KeyValue[] = JSON.parse(stringyfy); + const allValues: string[] = keyValueArray.map(item => item.value); + + statement.method = method + statement.statement_id = allValues[0] + statement.authorization = allValues[1] + await statement.save() + } + + logger.info(` + ------------------------------------------------------------------------------------------------ + \End of createStatement function\n + ------------------------------------------------------------------------------------------------ + `); +} + + + + + + + + + + + + + + + + + + + + + + + + + + +// export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, id: string, method:string): Promise { +// const data = extrinsic.extrinsic.method; + + +// // const args = data.args +// logger.info(`\n\n +// ------------------------------------------------------------------------------------------------ +// \nInside createStatement function\n +// ------------------------------------------------------------------------------------------------ +// `); +// // logger.info(`Printing "call":\ncall.args: ${call.args}\ncall.extrinsicId: ${call.extrinsicId}\ncall.section: ${call.section}\ncall.signerId: ${call.signerId}\ncall.method: ${call.method}\ncall._name: ${call._name}`) + + + +// const statement = new Statement(id) +// logger.info(`Priting the method:\n${method}`) + + +// if(method === 'register'){ +// // logger.info(`inside the "if register" method\n`) +// // // statement.did = (data.args[0] as any).did +// // // statement.txCounter = (data.args[0] as any).txCounter +// // statement.callIndex = call.callIndex +// // let stmtId:string = (extrinsic.events[0] as any).event.data[0] + +// // logger.info(`stmtId: ${stmtId}`) +// statement.method = method +// statement.digest = (call.args as any).digest +// statement.authorization = (call.args as any).authorization +// statement.schema_id = (call.args as any).schema_id + +// // // statement.blockNumber = (data.args[0] as any).blockNumber +// // // statement.submitter = (data.args[0] as any).submitter + +// } +// // if(method === 'update'){ + +// // } +// // if(method === 'revoke'){ + +// // } +// // if(method === 'restore'){ + +// // } + + + + + + + + +// logger.info(`Statement identifier: ${extrinsic.events[0].event.data[0]}`); +// // logger.info("test",data?.args[0]) +// logger.info(`Statement Data: \n\n +// data.args[0]:\n\n ${(data.args[0])}\n\n +// data.args[1]:\n\n ${data.args[1]}\n\n +// \n\n\n\n\n +// destracturing args\n\n +// ${(data.args[0] as any).did} +// ${(data.args[0] as any).txCounter} +// ${(data.args[0] as any).call.args} +// `); + +// // const statement = new Statement(id) +// // statement.did = (data.args[0] as any).did +// // statement.txCounter +// // statement.callIndex +// // statement.digest +// // statement.authorization +// // statement.schema_id +// // statement.statement_id +// // statement.blockNumber +// // statement.submitter + + +// /* +// score.entityId = args[0] +// score.providerId = args[1] +// score.totalCount = args[2] +// score.totalRating = args[3] +// score.entityType = args[4]; +// score.ratingType = args[5]; +// */ +// // score.callId = call.id +// await statement.save() + +// } + + + + + + + + + + + + + + From de6c8898477549d5e00084c0d0c6d6c3070d5308 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Sat, 27 Jan 2024 12:19:34 +0530 Subject: [PATCH 2/9] remove .vscode --- .gitignore | 2 ++ .vscode/settings.json | 22 ---------------------- 2 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 9615e3c..ddeaa1e 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,5 @@ Thumbs.db .data .eslintcache + +.vscode diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e4cb847..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "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" -} \ No newline at end of file From a79cf9edb3744a3a6656d7b7d40b9764ffc97ab2 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Mon, 29 Jan 2024 10:53:05 +0530 Subject: [PATCH 3/9] Add DecoderUtils to converst the hex to string Signed-off-by: System Administrator --- package.json | 2 +- src/handlers/statement.ts | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 0dc32d1..5c0071f 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,6 @@ "chaintypes": "src/chaintypes.ts" }, "dependencies": { - "@cord.network/sdk": "^0.9.1" + "@cord.network/sdk": "0.9.3-1develop1" } } diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index c9056c9..1fecb25 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -2,7 +2,7 @@ import { SubstrateEvent, SubstrateExtrinsic } from "@subql/types"; import { ensureCallExist } from "./call"; import { Statement , Call} from '../types'; import { Event } from "../types/models"; - +import * as Cord from '@cord.network/sdk' interface KeyValue { key: string; value: string; @@ -19,16 +19,17 @@ export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, logger.info(`printing call: ${call}`) if(method === 'register'){ - // logger.info(`*******************************************\nRegister\n`) + logger.info(`*******************************************\nRegister\n`) let statement = new Statement(id) let stringyfy = JSON.stringify(call.args) const keyValueArray: KeyValue[] = JSON.parse(stringyfy); const allValues: string[] = keyValueArray.map(item => item.value); - - statement.digest = allValues[0] - statement.authorization = allValues[1] - statement.schema_id = allValues[2] + logger.info(`DecoderUtils.hexToString(allValues[0]):\n${Cord.Utils.DecoderUtils.hexToString(allValues[0])}`) + logger.info(`allValues[0]:\n${allValues[0]}`) + statement.digest = Cord.Utils.DecoderUtils.hexToString(allValues[0]) + statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) + statement.schema_id = Cord.Utils.DecoderUtils.hexToString(allValues[2]) await statement.save() } if(method === 'update'){ @@ -40,10 +41,10 @@ export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, // logger.info(`allValues: allValues: allValues: allValues: allValues:\n${allValues}`) let statement = new Statement(id) statement.method = method - statement.statement_id = allValues[0] - - statement.digest = allValues[1] - statement.authorization = allValues[2] + + statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) + statement.digest = Cord.Utils.DecoderUtils.hexToString(allValues[1]) + statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[2]) await statement.save() } if(method === 'revoke'){ @@ -55,8 +56,8 @@ export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, let statement = new Statement(id) statement.method = method - statement.statement_id = allValues[0] - statement.authorization = allValues[1] + statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) + statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) await statement.save() } if(method === 'restore'){ @@ -68,8 +69,8 @@ export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, const allValues: string[] = keyValueArray.map(item => item.value); statement.method = method - statement.statement_id = allValues[0] - statement.authorization = allValues[1] + statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) + statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) await statement.save() } From 68c5dccf635e1e04230c36701952c1e3f5f119e9 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Mon, 29 Jan 2024 15:31:00 +0530 Subject: [PATCH 4/9] update statement Signed-off-by: Adi Bhagavath --- schema.graphql | 9 +- src/handlers/statement.ts | 264 +++++++++----------------------------- 2 files changed, 64 insertions(+), 209 deletions(-) diff --git a/schema.graphql b/schema.graphql index e069b6b..6ecb6aa 100644 --- a/schema.graphql +++ b/schema.graphql @@ -2,7 +2,6 @@ # Add the `@index` or `@index(unique: true)` annotation after any non-key field # https://academy.subquery.network/build/graphql.html#indexing-by-non-primary-key-field - type KVData @jsonField { key: String value: String @@ -47,7 +46,7 @@ type Call @entity { section: String method: String - args:[KVData] + args: [KVData] timestamp: Date isSuccess: Boolean @@ -97,8 +96,12 @@ type Statement @entity { id: ID! method: String + blockNumber: BigInt + submitter: String + signature: String + statement_id: String authorization: String schema_id: String digest: String -} \ No newline at end of file +} diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index 1fecb25..8079eb8 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -1,210 +1,62 @@ import { SubstrateEvent, SubstrateExtrinsic } from "@subql/types"; import { ensureCallExist } from "./call"; -import { Statement , Call} from '../types'; -import { Event } from "../types/models"; -import * as Cord from '@cord.network/sdk' -interface KeyValue { - key: string; - value: string; +import { Statement, Call } from "../types"; + +export async function createStatement( + extrinsic: SubstrateExtrinsic, + call: Call, + id: string, + method: string +): Promise { + const data = extrinsic.extrinsic.method; + + 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.blockNumber = arrayed.args.did_call.blockNumber; + statement.submitter = arrayed.args.did_call.submitter; + statement.signature = arrayed.args.signature.ed25519; + 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.blockNumber = arrayed.args.did_call.blockNumber; + statement.submitter = arrayed.args.did_call.submitter; + statement.signature = arrayed.args.signature.ed25519; + 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.blockNumber = arrayed.args.did_call.blockNumber; + statement.submitter = arrayed.args.did_call.submitter; + statement.signature = arrayed.args.signature.ed25519; + 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.blockNumber = arrayed.args.did_call.blockNumber; + statement.submitter = arrayed.args.did_call.submitter; + statement.signature = arrayed.args.signature.ed25519; + statement.method = method; + statement.statement_id = arrayed.args.did_call.call.args.statement_id; + statement.authorization = arrayed.args.did_call.call.args.authorization; + await statement.save(); } - -export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, id: string, method:string): Promise { - const data = extrinsic.extrinsic.method; - - logger.info(` - ------------------------------------------------------------------------------------------------ - \nInside createStatement function\n - ------------------------------------------------------------------------------------------------ - `); - logger.info(`printing call: ${call}`) - - if(method === 'register'){ - logger.info(`*******************************************\nRegister\n`) - let statement = new Statement(id) - - let stringyfy = JSON.stringify(call.args) - const keyValueArray: KeyValue[] = JSON.parse(stringyfy); - const allValues: string[] = keyValueArray.map(item => item.value); - logger.info(`DecoderUtils.hexToString(allValues[0]):\n${Cord.Utils.DecoderUtils.hexToString(allValues[0])}`) - logger.info(`allValues[0]:\n${allValues[0]}`) - statement.digest = Cord.Utils.DecoderUtils.hexToString(allValues[0]) - statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) - statement.schema_id = Cord.Utils.DecoderUtils.hexToString(allValues[2]) - await statement.save() - } - if(method === 'update'){ - let stringyfy = JSON.stringify(call.args) - // logger.info(`stringyfy: stringyfy: stringyfy: stringyfy: \n${stringyfy}`) - const keyValueArray: KeyValue[] = JSON.parse(stringyfy); - const allValues: string[] = keyValueArray.map(item => item.value); - - // logger.info(`allValues: allValues: allValues: allValues: allValues:\n${allValues}`) - let statement = new Statement(id) - statement.method = method - - statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) - statement.digest = Cord.Utils.DecoderUtils.hexToString(allValues[1]) - statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[2]) - await statement.save() - } - if(method === 'revoke'){ - let stringyfy = JSON.stringify(call.args) - - const keyValueArray: KeyValue[] = JSON.parse(stringyfy); - const allValues: string[] = keyValueArray.map(item => item.value); - - - let statement = new Statement(id) - statement.method = method - statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) - statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) - await statement.save() - } - if(method === 'restore'){ - let statement = new Statement(id) - - let stringyfy = JSON.stringify(call.args) - - const keyValueArray: KeyValue[] = JSON.parse(stringyfy); - const allValues: string[] = keyValueArray.map(item => item.value); - - statement.method = method - statement.statement_id = Cord.Utils.DecoderUtils.hexToString(allValues[0]) - statement.authorization = Cord.Utils.DecoderUtils.hexToString(allValues[1]) - await statement.save() - } - - logger.info(` - ------------------------------------------------------------------------------------------------ - \End of createStatement function\n - ------------------------------------------------------------------------------------------------ - `); } - - - - - - - - - - - - - - - - - - - - - - - - - - -// export async function createStatement (extrinsic: SubstrateExtrinsic, call:Call, id: string, method:string): Promise { -// const data = extrinsic.extrinsic.method; - - -// // const args = data.args -// logger.info(`\n\n -// ------------------------------------------------------------------------------------------------ -// \nInside createStatement function\n -// ------------------------------------------------------------------------------------------------ -// `); -// // logger.info(`Printing "call":\ncall.args: ${call.args}\ncall.extrinsicId: ${call.extrinsicId}\ncall.section: ${call.section}\ncall.signerId: ${call.signerId}\ncall.method: ${call.method}\ncall._name: ${call._name}`) - - - -// const statement = new Statement(id) -// logger.info(`Priting the method:\n${method}`) - - -// if(method === 'register'){ -// // logger.info(`inside the "if register" method\n`) -// // // statement.did = (data.args[0] as any).did -// // // statement.txCounter = (data.args[0] as any).txCounter -// // statement.callIndex = call.callIndex -// // let stmtId:string = (extrinsic.events[0] as any).event.data[0] - -// // logger.info(`stmtId: ${stmtId}`) -// statement.method = method -// statement.digest = (call.args as any).digest -// statement.authorization = (call.args as any).authorization -// statement.schema_id = (call.args as any).schema_id - -// // // statement.blockNumber = (data.args[0] as any).blockNumber -// // // statement.submitter = (data.args[0] as any).submitter - -// } -// // if(method === 'update'){ - -// // } -// // if(method === 'revoke'){ - -// // } -// // if(method === 'restore'){ - -// // } - - - - - - - - -// logger.info(`Statement identifier: ${extrinsic.events[0].event.data[0]}`); -// // logger.info("test",data?.args[0]) -// logger.info(`Statement Data: \n\n -// data.args[0]:\n\n ${(data.args[0])}\n\n -// data.args[1]:\n\n ${data.args[1]}\n\n -// \n\n\n\n\n -// destracturing args\n\n -// ${(data.args[0] as any).did} -// ${(data.args[0] as any).txCounter} -// ${(data.args[0] as any).call.args} -// `); - -// // const statement = new Statement(id) -// // statement.did = (data.args[0] as any).did -// // statement.txCounter -// // statement.callIndex -// // statement.digest -// // statement.authorization -// // statement.schema_id -// // statement.statement_id -// // statement.blockNumber -// // statement.submitter - - -// /* -// score.entityId = args[0] -// score.providerId = args[1] -// score.totalCount = args[2] -// score.totalRating = args[3] -// score.entityType = args[4]; -// score.ratingType = args[5]; -// */ -// // score.callId = call.id -// await statement.save() - -// } - - - - - - - - - - - - - - From ed89b139ba09a2c6f68cde83c91d935d60b60803 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Tue, 30 Jan 2024 17:37:11 +0530 Subject: [PATCH 5/9] use extrinsic.block to get the blocknumber --- src/handlers/call.ts | 2 +- src/handlers/statement.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/handlers/call.ts b/src/handlers/call.ts index 518bb2b..bcbe7af 100644 --- a/src/handlers/call.ts +++ b/src/handlers/call.ts @@ -61,7 +61,7 @@ async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): P if(call.section === 'statement'){ logger.info("\n\n\n\nStatement call inside call.ts and calling createStatement"); logger.info(`${data.method}`) - await createStatement(raw,call, id as string,data.method); + await createStatement(raw, id as string,data.method); } if (depth < 1 && section === 'utility' && (method === 'batch' || method === 'batchAll')) { diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index 8079eb8..8c483a5 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -1,10 +1,9 @@ -import { SubstrateEvent, SubstrateExtrinsic } from "@subql/types"; +import { SubstrateBlock, SubstrateExtrinsic } from "@subql/types"; import { ensureCallExist } from "./call"; import { Statement, Call } from "../types"; export async function createStatement( extrinsic: SubstrateExtrinsic, - call: Call, id: string, method: string ): Promise { @@ -16,7 +15,7 @@ export async function createStatement( .data[0]; let statement = new Statement(id); statement.method = method; - statement.blockNumber = arrayed.args.did_call.blockNumber; + statement.blockNumber = extrinsic.block.block.header.number.toBigInt() statement.submitter = arrayed.args.did_call.submitter; statement.signature = arrayed.args.signature.ed25519; statement.statement_id = statementId; From f9b715e33cfa6b26e13781ecea6bfdef101e0375 Mon Sep 17 00:00:00 2001 From: System Administrator Date: Thu, 1 Feb 2024 12:52:47 +0530 Subject: [PATCH 6/9] minor fixes Signed-off-by: System Administrator --- src/handlers/statement.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index 8c483a5..5f7d00a 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -1,6 +1,5 @@ -import { SubstrateBlock, SubstrateExtrinsic } from "@subql/types"; -import { ensureCallExist } from "./call"; -import { Statement, Call } from "../types"; +import { SubstrateExtrinsic } from "@subql/types"; +import { Statement } from "../types"; export async function createStatement( extrinsic: SubstrateExtrinsic, @@ -17,7 +16,7 @@ export async function createStatement( statement.method = method; statement.blockNumber = extrinsic.block.block.header.number.toBigInt() statement.submitter = arrayed.args.did_call.submitter; - statement.signature = arrayed.args.signature.ed25519; + 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; @@ -28,9 +27,9 @@ export async function createStatement( let arrayed = JSON.parse(JSON.stringify(data)); let statement = new Statement(id); statement.method = method; - statement.blockNumber = arrayed.args.did_call.blockNumber; + statement.blockNumber = extrinsic.block.block.header.number.toBigInt(); statement.submitter = arrayed.args.did_call.submitter; - statement.signature = arrayed.args.signature.ed25519; + 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; @@ -40,9 +39,9 @@ export async function createStatement( let arrayed = JSON.parse(JSON.stringify(data)); let statement = new Statement(id); statement.method = method; - statement.blockNumber = arrayed.args.did_call.blockNumber; + statement.blockNumber = extrinsic.block.block.header.number.toBigInt(); statement.submitter = arrayed.args.did_call.submitter; - statement.signature = arrayed.args.signature.ed25519; + 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(); @@ -50,9 +49,9 @@ export async function createStatement( if (method === "restore") { let arrayed = JSON.parse(JSON.stringify(data)); let statement = new Statement(id); - statement.blockNumber = arrayed.args.did_call.blockNumber; + statement.blockNumber = extrinsic.block.block.header.number.toBigInt(); statement.submitter = arrayed.args.did_call.submitter; - statement.signature = arrayed.args.signature.ed25519; + statement.signature = JSON.stringify(arrayed.args.signature); statement.method = method; statement.statement_id = arrayed.args.did_call.call.args.statement_id; statement.authorization = arrayed.args.did_call.call.args.authorization; From 6898588264779dffed3de0644893f99b0ec26a1b Mon Sep 17 00:00:00 2001 From: System Administrator Date: Thu, 1 Feb 2024 12:56:05 +0530 Subject: [PATCH 7/9] remove logs and correct the alignment Signed-off-by: System Administrator --- src/handlers/call.ts | 121 +++++++++++++++++++++----------------- src/handlers/event.ts | 15 ++--- src/handlers/statement.ts | 2 +- 3 files changed, 72 insertions(+), 66 deletions(-) diff --git a/src/handlers/call.ts b/src/handlers/call.ts index bcbe7af..eba28b5 100644 --- a/src/handlers/call.ts +++ b/src/handlers/call.ts @@ -1,15 +1,18 @@ -import type { Vec } from '@polkadot/types' -import { Call, Extrinsic } from '../types' -import { AnyCall, DispatchedCallData } from './types' +import type { Vec } from "@polkadot/types"; +import { Call, Extrinsic } from "../types"; +import { AnyCall, DispatchedCallData } from "./types"; import { SubstrateExtrinsic } from "@subql/types"; -import { Dispatcher, getBatchInterruptedIndex, getKVData } from './utils'; -import { createScore } from './score'; -import { createStatement } from './statement'; +import { Dispatcher, getBatchInterruptedIndex, getKVData } from "./utils"; +import { createScore } from "./score"; +import { createStatement } from "./statement"; -async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): Promise { - const list: any[] = [] - const batchInterruptedIndex = getBatchInterruptedIndex(raw) +async function traverExtrinsic( + extrinsic: Extrinsic, + raw: SubstrateExtrinsic +): Promise { + const list: any[] = []; + const batchInterruptedIndex = getBatchInterruptedIndex(raw); const inner = async ( data: AnyCall, @@ -18,35 +21,36 @@ async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): P isRoot: boolean, depth: number ) => { - const id = isRoot ? parentCallId : `${parentCallId}-${idx}` - const method = data.method - const section = data.section - const args = data.args - - if (method === 'submitDidCall' && section === 'did') { - /* there will be one call below */ - const temp = (args[0] as any).call as unknown as AnyCall; - logger.info(`DidSubmitCall: ${temp}`); - await inner(temp, id, 1, false, depth + 1); + const id = isRoot ? parentCallId : `${parentCallId}-${idx}`; + const method = data.method; + const section = data.section; + const args = data.args; + + if (method === "submitDidCall" && section === "did") { + /* there will be one call below */ + const temp = (args[0] as any).call as unknown as AnyCall; + logger.info(`DidSubmitCall: ${temp}`); + await inner(temp, id, 1, false, depth + 1); } - const call = new Call(id) + const call = new Call(id); - call.method = method - call.section = section - call.args = getKVData(data.args, data.argsDef) - call.signerId = extrinsic.signerId - call.isSuccess = depth === 0 ? extrinsic.isSuccess : batchInterruptedIndex > idx; - call.timestamp = extrinsic.timestamp + call.method = method; + call.section = section; + call.args = getKVData(data.args, data.argsDef); + call.signerId = extrinsic.signerId; + call.isSuccess = + depth === 0 ? extrinsic.isSuccess : batchInterruptedIndex > idx; + call.timestamp = extrinsic.timestamp; if (!isRoot) { - call.parentCallId = isRoot ? '' : parentCallId + call.parentCallId = isRoot ? "" : parentCallId; - call.extrinsicId = parentCallId.split('-')[0] + call.extrinsicId = parentCallId.split("-")[0]; } else { - call.extrinsicId = parentCallId + call.extrinsicId = parentCallId; } - list.push(call) + list.push(call); /* await dispatcher.dispatch( @@ -54,43 +58,50 @@ async function traverExtrinsic(extrinsic: Extrinsic, raw: SubstrateExtrinsic): P { call, extrinsic, rawCall: data, rawExtrinsic: raw } ) */ - if (call.section === 'networkScore') { - logger.info("Scoring call"); - await createScore(raw, id as string); + if (call.section === "networkScore") { + logger.info("Scoring call"); + await createScore(raw, id as string); } - if(call.section === 'statement'){ - logger.info("\n\n\n\nStatement call inside call.ts and calling createStatement"); - logger.info(`${data.method}`) - await createStatement(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 - await Promise.all(temp.map((item, idx) => inner(item, id, idx, false, depth + 1))) - } - } + if ( + depth < 1 && + section === "utility" && + (method === "batch" || method === "batchAll") + ) { + const temp = args[0] as unknown as Vec; + + await Promise.all( + temp.map((item, idx) => inner(item, id, idx, false, depth + 1)) + ); + } + }; - await inner(raw.extrinsic.method, extrinsic.id, 0, true, 0) + await inner(raw.extrinsic.method, extrinsic.id, 0, true, 0); - return list + return list; } -export async function createCalls (extrinsic: Extrinsic, raw: SubstrateExtrinsic) { - - const calls = await traverExtrinsic(extrinsic, raw) - logger.info(`Calls: ${calls}`) - await Promise.all(calls.map(async (item) => item.save())); +export async function createCalls( + extrinsic: Extrinsic, + raw: SubstrateExtrinsic +) { + const calls = await traverExtrinsic(extrinsic, raw); + logger.info(`Calls: ${calls}`); + await Promise.all(calls.map(async (item) => item.save())); } -export async function ensureCallExist (id: any) { - let data = await Call.get(id) +export async function ensureCallExist(id: any) { + let data = await Call.get(id); if (!data) { - data = new Call(id) + data = new Call(id); - await data.save() + await data.save(); } - return data + return data; } diff --git a/src/handlers/event.ts b/src/handlers/event.ts index 9d44d7f..57aa8a2 100644 --- a/src/handlers/event.ts +++ b/src/handlers/event.ts @@ -9,13 +9,10 @@ import { DispatchedEventData } from "./types"; const dispatch = new Dispatcher(); dispatch.batchRegist([ - //registry //{ key: 'schema-Create', handler: handleRegistryCreate }, - //schema //{ key: 'schema-Anchor', handler: handleSchemaAnchor }, - //stream //{ key: 'stream-Anchor', handler: handleStreamAnchor }, //{ key: 'stream-Update', handler: handleStreamUpdate }, @@ -25,7 +22,7 @@ dispatch.batchRegist([ export async function ensureEvent(event: SubstrateEvent) { const block = await ensureBlock(event.block); if (!block) { - return null; + return null; } const idx = event.idx; const recordId = `${block.number}-${idx}`; @@ -45,19 +42,17 @@ export async function ensureEvent(event: SubstrateEvent) { export async function createEvent(event: SubstrateEvent) { const data = await ensureEvent(event); - if (!data) - return; + if (!data) return; const section = event.event.section; const method = event.event.method; const eventData = getKVData(event.event.data); - if (section === 'system' && method === 'ExtrinsicSuccess') - return; + if (section === "system" && method === "ExtrinsicSuccess") return; data.section = section; data.method = method; data.data = eventData; - logger.info(`\nsection: ${section}\nmethod: ${method}\neventData: ${eventData}`) + const extrinsic = await (event.extrinsic ? ensureExtrinsic(event.extrinsic) : undefined); @@ -66,7 +61,7 @@ export async function createEvent(event: SubstrateEvent) { data.extrinsicId = extrinsic.id; } -// TODO: once we have separate handling of different events based on section and method, uncomment below + // TODO: once we have separate handling of different events based on section and method, uncomment below await dispatch.dispatch(`${section}-${data.method}`, { event: data, rawEvent: event, diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index 5f7d00a..fa44fe9 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -14,7 +14,7 @@ export async function createStatement( .data[0]; let statement = new Statement(id); statement.method = method; - statement.blockNumber = extrinsic.block.block.header.number.toBigInt() + 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; From bc6ae6789d18258df0be05d2bc0b7da04c3c2e15 Mon Sep 17 00:00:00 2001 From: Adi Bhagavath Date: Thu, 1 Feb 2024 14:27:09 +0530 Subject: [PATCH 8/9] Add call index Signed-off-by: Adi Bhagavath --- schema.graphql | 1 + src/handlers/statement.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/schema.graphql b/schema.graphql index 6ecb6aa..c93913b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -96,6 +96,7 @@ type Statement @entity { id: ID! method: String + callIndex: String blockNumber: BigInt submitter: String signature: String diff --git a/src/handlers/statement.ts b/src/handlers/statement.ts index fa44fe9..dbb6253 100644 --- a/src/handlers/statement.ts +++ b/src/handlers/statement.ts @@ -14,6 +14,7 @@ export async function createStatement( .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); @@ -27,6 +28,7 @@ export async function createStatement( 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); @@ -39,6 +41,7 @@ export async function createStatement( 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); @@ -49,10 +52,11 @@ export async function createStatement( 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.method = method; statement.statement_id = arrayed.args.did_call.call.args.statement_id; statement.authorization = arrayed.args.did_call.call.args.authorization; await statement.save(); From 5395c41647dff0517e1e3baa862a6e100e51bb87 Mon Sep 17 00:00:00 2001 From: Adi Date: Fri, 2 Feb 2024 16:57:07 +0530 Subject: [PATCH 9/9] Remove GitHub Actions --- .github/scripts/publish-deploy.sh | 15 -------------- .github/workflows/cli-deploy.yml | 34 ------------------------------- .github/workflows/pr.yml | 24 ---------------------- 3 files changed, 73 deletions(-) delete mode 100644 .github/scripts/publish-deploy.sh delete mode 100644 .github/workflows/cli-deploy.yml delete mode 100644 .github/workflows/pr.yml diff --git a/.github/scripts/publish-deploy.sh b/.github/scripts/publish-deploy.sh deleted file mode 100644 index 3c9dc04..0000000 --- a/.github/scripts/publish-deploy.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -while getopts p:o:e: flag -do - case "${flag}" in - e) ENDPOINT=${OPTARG};; - p) PROJECTNAME=${OPTARG};; - o) ORG=${OPTARG};; - *) echo "Usage: $0 [-p projectname] [-o org] [-e endpoint]" && exit 1;; - esac -done - -IPFSCID=$(npx subql publish -o -f .) - -npx subql deployment:deploy -d --ipfsCID="$IPFSCID" --projectName="${PROJECTNAME}" --org="${ORG%/*}" --endpoint="${ENDPOINT}" diff --git a/.github/workflows/cli-deploy.yml b/.github/workflows/cli-deploy.yml deleted file mode 100644 index 658d2c6..0000000 --- a/.github/workflows/cli-deploy.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "CLI deploy" - -on: - workflow_dispatch: - inputs: - projectName: - description: "Project name" - required: true - type: string -jobs: - deploy: - name: CLI Deploy - runs-on: ubuntu-latest - environment: - name: DEPLOYMENT - env: - SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }} - ENDPOINT: ${{ secrets.ENDPOINT }} - steps: - - uses: actions/checkout@v2 - - name: Setup Node.js environment - uses: actions/setup-node@v2 - with: - node-version: 16 - - run: yarn - - name: Codegen - run: yarn codegen - - name: Version - run: npx subql --version - - name: repo - run: echo ${{github.repository}} - - name: Publish and Deploy - run: | - sh .github/workflows/scripts/publish-deploy.sh -o ${{github.repository}} -p ${{github.event.inputs.projectName}} -e ${{secrets.ENDPOINT}} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 9f83021..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: PR -on: - pull_request: - paths-ignore: - - ".github/workflows/**" -jobs: - pr: - name: pr - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup Node.js environment - uses: actions/setup-node@v2 - with: - node-version: 20 - - run: yarn - - name: Codegen - run: yarn codegen - - name: Build - run: yarn build - - name: Install subql-node - run: yarn global add @subql/node - - name: Run tests with Subquery Node - run: subql-node test -f ${{ github.workspace }}