From 48526095fa20ec1b2fffca5ca42b67fc32fa3025 Mon Sep 17 00:00:00 2001 From: Justin <328965+justinbarry@users.noreply.github.com> Date: Fri, 4 Oct 2024 10:52:31 -0700 Subject: [PATCH] Support multiple contract code IDs in event handlers Updated the SMART_ACCOUNT_CONTRACT_CODE_ID to handle multiple values by converting it into an array. Adapted event handlers to process each code ID individually, improving flexibility and extensibility in managing smart account contracts. --- .project-cid | 2 +- project.ts | 77 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.project-cid b/.project-cid index 96d176a..97edef4 100644 --- a/.project-cid +++ b/.project-cid @@ -1 +1 @@ -Qmbm4CY7si2mZQQYeyAH71mkxDgTn1zZskK65xt1bc1atK \ No newline at end of file +QmXaytzoC6bBtAHW8xumHcuuzUwCqsRMpK9abj8XyU9mhz \ No newline at end of file diff --git a/project.ts b/project.ts index e87ffa3..f8ce5cd 100644 --- a/project.ts +++ b/project.ts @@ -2,11 +2,16 @@ import { CosmosDatasourceKind, CosmosHandlerKind, CosmosProject, + CosmosRuntimeHandler, } from "@subql/types-cosmos"; // These defaults are the testnet values -const SMART_ACCOUNT_CONTRACT_CODE_ID = - process.env.SMART_ACCOUNT_CONTRACT_CODE_ID || "793"; +let SMART_ACCOUNT_CONTRACT_CODE_ID = process.env + .SMART_ACCOUNT_CONTRACT_CODE_ID || ["21", "793"]; + +SMART_ACCOUNT_CONTRACT_CODE_ID = Array.isArray(SMART_ACCOUNT_CONTRACT_CODE_ID) + ? SMART_ACCOUNT_CONTRACT_CODE_ID + : [SMART_ACCOUNT_CONTRACT_CODE_ID]; const CHAIN_ID = process.env.CHAIN_ID || "xion-testnet-1"; const ENDPOINT_URL = @@ -67,41 +72,47 @@ const project: CosmosProject = { startBlock: START_BLOCK, mapping: { file: "./dist/index.js", - handlers: [ - { - handler: "handleSmartAccountContractInstantiateMetadata", - kind: CosmosHandlerKind.Event, - filter: { - type: "wasm-create_abstract_account", - messageFilter: { - type: "/abstractaccount.v1.MsgRegisterAccount", - values: { - codeId: SMART_ACCOUNT_CONTRACT_CODE_ID, + handlers: SMART_ACCOUNT_CONTRACT_CODE_ID.reduce< + Array + >( + (result, codeId) => + result.concat([ + { + handler: "handleSmartAccountContractInstantiateMetadata", + kind: CosmosHandlerKind.Event, + filter: { + type: "wasm-create_abstract_account", + messageFilter: { + type: "/abstractaccount.v1.MsgRegisterAccount", + values: { + codeId: codeId, + }, + }, }, }, - }, - }, - { - handler: "handleSmartAccountContractAddAuthenticator", - kind: CosmosHandlerKind.Event, - filter: { - type: "wasm-add_auth_method", - messageFilter: { - type: "/cosmwasm.wasm.v1.MsgExecuteContract", + { + handler: "handleSmartAccountContractAddAuthenticator", + kind: CosmosHandlerKind.Event, + filter: { + type: "wasm-add_auth_method", + messageFilter: { + type: "/cosmwasm.wasm.v1.MsgExecuteContract", + }, + }, }, - }, - }, - { - handler: "handleSmartAccountContractRemoveAuthenticator", - kind: CosmosHandlerKind.Event, - filter: { - type: "wasm-remove_auth_method", - messageFilter: { - type: "/cosmwasm.wasm.v1.MsgExecuteContract", + { + handler: "handleSmartAccountContractRemoveAuthenticator", + kind: CosmosHandlerKind.Event, + filter: { + type: "wasm-remove_auth_method", + messageFilter: { + type: "/cosmwasm.wasm.v1.MsgExecuteContract", + }, + }, }, - }, - }, - ], + ]), + [], + ), }, }, ],