Skip to content

Commit 8e55180

Browse files
feat: track almanac registrations
1 parent 6379b3e commit 8e55180

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

project.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,10 @@ dataSources:
130130
kind: cosmos/MessageHandler
131131
filter:
132132
type: "/cosmos.authz.v1beta1.MsgExec"
133+
- handler: handleAlmanacRegistration
134+
kind: cosmos/EventHandler
135+
filter:
136+
type: "wasm"
137+
messageFilter:
138+
type: "/cosmwasm.wasm.v1.MsgExecuteContract"
139+
contractCall: "register"

src/mappings/almanac/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./registrations";
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {attemptHandling, messageId, unprocessedEventHandler} from "../utils";
2+
import {CosmosEvent} from "@subql/types-cosmos";
3+
import {AlmanacRecord, AlmanacRegistration} from "../../types";
4+
5+
export async function handleAlmanacRegistration(event: CosmosEvent): Promise<void> {
6+
await attemptHandling(event, _handleAlmanacRegistration, unprocessedEventHandler);
7+
}
8+
9+
async function _handleAlmanacRegistration(event: CosmosEvent): Promise<void> {
10+
const id = messageId(event);
11+
logger.info(`[handleAlmanacRegistration] (tx ${event.tx.hash}): indexing AlmanacRegistration ${id}`);
12+
logger.debug(`[handleAlmanacRegistration] (event.log.log): ${JSON.stringify(event.log.log, null, 2)}`);
13+
14+
const attributes = event.event.attributes.reduce((acc, curr) => {
15+
acc[curr.key] = curr.value;
16+
return acc;
17+
}, {});
18+
19+
const {address, record: recordStr, expiry_height} = attributes as unknown as any;
20+
if (!address) {
21+
logger.warn("[handleAlmanacRegistration]: missing address");
22+
return;
23+
}
24+
25+
if (!expiry_height) {
26+
logger.warn("[handleAlmanacRegistration]: missing expiry_height");
27+
return;
28+
}
29+
30+
if (!recordStr) {
31+
logger.warn("[handleAlmanacRegistration]: missing record");
32+
return;
33+
}
34+
35+
const record = JSON.parse(recordStr);
36+
if (!record || !record.Service) {
37+
logger.warn("[handleAlmanacRegistration]: missing record service");
38+
return;
39+
}
40+
41+
const recordEntity = AlmanacRecord.create({
42+
id,
43+
service: record.service,
44+
// eventId: id,
45+
transactionId: event.tx.hash,
46+
blockId: event.block.block.id,
47+
});
48+
await recordEntity.save();
49+
50+
const registrationEntity = AlmanacRegistration.create({
51+
id,
52+
expiryHeight: expiry_height,
53+
accountId: address,
54+
recordId: id,
55+
// eventId: id,
56+
transactionId: event.tx.hash,
57+
blockId: event.block.block.id,
58+
});
59+
await registrationEntity.save();
60+
}

src/mappings/mappingHandlers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./authz";
2+
export * from "./almanac";
23
export * from "./bank";
34
export * from "./dist";
45
export * from "./gov";

0 commit comments

Comments
 (0)