Skip to content

Commit

Permalink
feat(mapping): add store object handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikssonJoakim committed Aug 4, 2023
1 parent 923893f commit 07fabfc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 64 deletions.
2 changes: 1 addition & 1 deletion project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ network:
- MsgExecuteContract
dataSources:
- kind: cosmos/Runtime
startBlock: 2910000
startBlock: 3492166
mapping:
file: ./dist/index.js
handlers:
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//Exports all handler functions
export * from './mappings/mappingHandlers'
export * from "./mappings/handleStoreObject";
17 changes: 17 additions & 0 deletions src/mappings/handleStoreObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { CosmosMessage } from "@subql/types-cosmos";
import type { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { ObjectariumObject } from "../types";
import { getObjectariumObjectId } from "../utils/utils";

export const handleStoreObject = async (
msg: CosmosMessage<MsgExecuteContract>
): Promise<void> => {
const objectId = getObjectariumObjectId(msg.tx.tx.events);

objectId &&
(await ObjectariumObject.create({
id: objectId,
sender: msg.msg.decodedMsg.sender,
contract: msg.msg.decodedMsg.contract,
}).save());
};
62 changes: 0 additions & 62 deletions src/mappings/mappingHandlers.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Event } from "@cosmjs/tendermint-rpc/build/tendermint37";

export const getObjectariumObjectId = (
events: Readonly<Event[]>
): string | undefined =>
events
.find((event) => event.type === "wasm")
?.attributes.find((attribute) => attribute.key === "id")?.value;

0 comments on commit 07fabfc

Please sign in to comment.