Skip to content

Commit

Permalink
Support multiple contract code IDs in event handlers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justinbarry committed Oct 4, 2024
1 parent d0efdce commit 4852609
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .project-cid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Qmbm4CY7si2mZQQYeyAH71mkxDgTn1zZskK65xt1bc1atK
QmXaytzoC6bBtAHW8xumHcuuzUwCqsRMpK9abj8XyU9mhz
77 changes: 44 additions & 33 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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<CosmosRuntimeHandler>
>(
(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",
},
},
},
},
},
],
]),
[],
),
},
},
],
Expand Down

0 comments on commit 4852609

Please sign in to comment.