Skip to content

Commit

Permalink
feat: added handler to index MsgInstallBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
frazarshad committed Jun 13, 2024
1 parent f4a7b8c commit 2ed2579
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
14 changes: 14 additions & 0 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ const project: CosmosProject = {
file: "./proto/cosmos/gov/v1beta1/gov.proto",
messages: ["WeightedVoteOption"],
},
],
[
"/agoric.swingset.MsgInstallBundle",
{
file: "./proto/agoric/swingset/msgs.proto",
messages: ["MsgInstallBundle"],
},
],
]),
},
Expand Down Expand Up @@ -107,6 +114,13 @@ const project: CosmosProject = {
type: "state_change",
},
},
{
handler: 'handleBundleInstallMessage',
kind: CosmosHandlerKind.Message,
filter: {
type: '/agoric.swingset.MsgInstallBundle',
},
},
],
},
},
Expand Down
10 changes: 10 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,13 @@ type VaultStatesDaily @entity {
liquidated: BigInt!
liquidatedClosed: BigInt!
}

type BundleInstall @entity {
id: ID!
blockHeight: BigInt!
blockTime: Date!
uncompressedSize: BigInt!
bundle: String!
compressedBundle: String!
submitter: String!
}
27 changes: 25 additions & 2 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StateChangeEvent, IBCChannel, IBCTransfer, TransferType } from '../types';
import { CosmosEvent } from '@subql/types-cosmos';
import { StateChangeEvent, IBCChannel, IBCTransfer, TransferType, BundleInstall } from '../types';
import { CosmosEvent, CosmosMessage } from '@subql/types-cosmos';
import {
b64decode,
extractStoragePath,
Expand Down Expand Up @@ -128,6 +128,29 @@ export async function handleIbcReceivePacketEvent(cosmosEvent: CosmosEvent): Pro
await Promise.allSettled([transferRecord.save(), ibcChannel]);
}

export async function handleBundleInstallMessage(message: CosmosMessage): Promise<void> {
const { msg, block, tx } = message;

if (msg.typeUrl !== '/agoric.swingset.MsgInstallBundle') {
logger.warn('message type is not /agoric.swingset.MsgInstallBundle');
return;
}

// JSON.stringify converts the object from Uint8Array to readable string
const { uncompressedSize, compressedBundle, submitter, bundle } = JSON.parse(JSON.stringify(msg.decodedMsg));
const bundleRecord = new BundleInstall(
tx.hash,
BigInt(block.header.height),
block.header.time as any,
BigInt(uncompressedSize),
bundle || '',
compressedBundle || '',
submitter,
);

await bundleRecord.save();
}

export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<void> {
const { event, block } = cosmosEvent;

Expand Down

0 comments on commit 2ed2579

Please sign in to comment.