From 4d8b9f37c0ca341ee0cae72da78aebefc5a74c88 Mon Sep 17 00:00:00 2001 From: pulkit Date: Fri, 20 Jan 2023 16:31:26 +0530 Subject: [PATCH 1/2] feat: add tuning handler --- project.yaml | 7 +++++++ schema.graphql | 13 ++++++++++++ src/mappings/wasm/tuning.ts | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/mappings/wasm/tuning.ts diff --git a/project.yaml b/project.yaml index b10f32455..e033652b2 100644 --- a/project.yaml +++ b/project.yaml @@ -137,3 +137,10 @@ dataSources: messageFilter: type: "/cosmwasm.wasm.v1.MsgExecuteContract" contractCall: "register" + - handler: handleTuningContractExecute + kind: cosmos/EventHandler + filter: + type: "execute" + messageFilter: + type: "/cosmwasm.wasm.v1.MsgExecuteContract" + contractCall: "tuning" diff --git a/schema.graphql b/schema.graphql index bf3276f25..a452170bf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -148,6 +148,7 @@ type Account @entity { chainId: String! @index nativeBalanceChanges: [NativeBalanceChange]! @derivedFrom(field: "account") cw20BalanceChanges: [Cw20BalanceChange]! @derivedFrom(field: "account") + tuningData: [Cw20BalanceChange]! @derivedFrom(field: "account") genesisBalances: [GenesisBalance] @derivedFrom(field: "account") } @@ -249,6 +250,18 @@ type Cw20BalanceChange @entity { block: Block! } +type TuningData @entity { + id: ID! + balanceOffset: BigInt! + contract: Contract! + account: Account! + executeContractMessage: ExecuteContractMessage! + event: Event! + message: Message! + transaction: Transaction! + block: Block! +} + enum Interface { Uncertain, CW20, diff --git a/src/mappings/wasm/tuning.ts b/src/mappings/wasm/tuning.ts new file mode 100644 index 000000000..7bf1d57fa --- /dev/null +++ b/src/mappings/wasm/tuning.ts @@ -0,0 +1,42 @@ +import {CosmosEvent} from "@subql/types-cosmos"; +import {Cw20BalanceChange, Cw20Transfer, TuningData} from "../../types"; +import { + attemptHandling, + checkBalancesAccount, + unprocessedEventHandler, + messageId, +} from "../utils"; + +export async function handleTuningContractExecute(event: CosmosEvent): Promise { + await attemptHandling(event, _handleTuningContractExecute, unprocessedEventHandler); +} + +async function _handleTuningContractExecute(event: CosmosEvent): Promise { + logger.fatal("HERE : INSIDE _handleTuningContract") + const id = messageId(event.msg); + logger.info(`[handleTuningExecute] (tx ${event.tx.hash}): indexing TuningExecute ${id}`); + logger.debug(`[handleTuningExecute] (event.msg.msg): ${JSON.stringify(event.msg.msg, null, 2)}`); + + const msg = event.msg?.msg?.decodedMsg; + const contractId = msg?.contract; + + + if (!contractId) { + logger.warn(`[handleTuningExecute] (tx ${event.tx.hash}): cannot index event (event.event): ${JSON.stringify(event.event, null, 2)}`); + return; + } + + const TuningDataEntity = TuningData.create({ + id, + balanceOffset: BigInt(1), + contractId, + accountId: "sample", + executeContractMessageId: msg, + eventId: "sample", + messageId: id, + transactionId: event.tx.hash, + blockId: event.block.block.id + }); + + await TuningDataEntity.save(); +} From 119e05f3b610322e910e9944da7362ff1cad3d3c Mon Sep 17 00:00:00 2001 From: pulkit Date: Fri, 20 Jan 2023 16:51:16 +0530 Subject: [PATCH 2/2] refactor: fix lint issues --- src/mappings/wasm/tuning.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mappings/wasm/tuning.ts b/src/mappings/wasm/tuning.ts index 7bf1d57fa..6df4c8849 100644 --- a/src/mappings/wasm/tuning.ts +++ b/src/mappings/wasm/tuning.ts @@ -1,8 +1,7 @@ import {CosmosEvent} from "@subql/types-cosmos"; -import {Cw20BalanceChange, Cw20Transfer, TuningData} from "../../types"; +import {TuningData} from "../../types"; import { attemptHandling, - checkBalancesAccount, unprocessedEventHandler, messageId, } from "../utils";