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

feat: add tuning handler #235

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 13 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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,
Expand Down
41 changes: 41 additions & 0 deletions src/mappings/wasm/tuning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {CosmosEvent} from "@subql/types-cosmos";
import {TuningData} from "../../types";
import {
attemptHandling,
unprocessedEventHandler,
messageId,
} from "../utils";

export async function handleTuningContractExecute(event: CosmosEvent): Promise<void> {
await attemptHandling(event, _handleTuningContractExecute, unprocessedEventHandler);
}

async function _handleTuningContractExecute(event: CosmosEvent): Promise<void> {
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();
}