Skip to content

Commit 24bc7b9

Browse files
Alann27jorgecuesta
authored andcommitted
Added support for EventSupplierServiceConfigActivated to schema, mappings, and handlers to track supplier service activation events.
1 parent 5a2ffb6 commit 24bc7b9

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

project.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ const project: CosmosProject = {
335335
"EventSupplierStaked",
336336
"EventSupplierUnbondingBegin",
337337
"EventSupplierUnbondingEnd",
338+
"EventSupplierServiceConfigActivated",
338339
],
339340
},
340341
],

schema.graphql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,16 @@ type SupplierServiceConfig @entity {
744744
service: Service!
745745
revShare: [SupplierRevShare]!
746746
endpoints: [SupplierEndpoint]!
747+
# activation block per EventSupplierServiceConfigActivated event
748+
activatedAt: Block
749+
activatedEvent: EventSupplierServiceConfigActivated
750+
}
751+
752+
type EventSupplierServiceConfigActivated @entity {
753+
id: ID!
754+
event: Event!
755+
block: Block!
756+
activatedServicesConfig: [SupplierServiceConfig] @derivedFrom(field: "activatedEvent")
747757
}
748758

749759
type EventSupplierUnbondingBegin @entity {

src/mappings/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from "./pocket/relays";
3838
import { handleEventRelayMiningDifficultyUpdated, handleMsgAddService } from "./pocket/services";
3939
import {
40+
handleEventSupplierServiceConfigActivated,
4041
handleMsgClaimMorseSupplier,
4142
handleSupplierStakeMsg,
4243
handleSupplierUnbondingBeginEvent,
@@ -116,6 +117,7 @@ export const EventHandlers: Record<string, (events: Array<CosmosEvent>) => Promi
116117
"pocket.application.EventApplicationUnbondingBegin": handleApplicationUnbondingBeginEvent,
117118
"pocket.application.EventApplicationUnbondingEnd": handleApplicationUnbondingEndEvent,
118119
// supplier
120+
"pocket.supplier.EventSupplierServiceConfigActivated": handleEventSupplierServiceConfigActivated,
119121
"pocket.supplier.EventSupplierUnbondingBegin": handleSupplierUnbondingBeginEvent,
120122
"pocket.supplier.EventSupplierUnbondingEnd": handleSupplierUnbondingEndEvent,
121123
// service

src/mappings/indexer.manager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ async function indexSupplier(msgByType: MessageByType, eventByType: EventByType)
516516
const eventTypes = [
517517
"pocket.supplier.EventSupplierUnbondingBegin",
518518
"pocket.supplier.EventSupplierUnbondingEnd",
519+
"pocket.supplier.EventSupplierServiceConfigActivated",
519520
// this is here because it modifies the staked tokens of the supplier
520521
"pocket.tokenomics.EventSupplierSlashed"
521522
];
@@ -541,6 +542,7 @@ async function indexSupplier(msgByType: MessageByType, eventByType: EventByType)
541542
"/pocket.migration.MsgClaimMorseSupplier": "shannonOperatorAddress",
542543
"pocket.supplier.EventSupplierUnbondingBegin": eventGetId,
543544
"pocket.supplier.EventSupplierUnbondingEnd": eventGetId,
545+
"pocket.supplier.EventSupplierServiceConfigActivated": eventGetId,
544546
"pocket.tokenomics.EventSupplierSlashed": (attributes) => {
545547
for (const attribute of attributes) {
546548
// in the previous version of this event this is the key to get the supplierId
@@ -618,6 +620,11 @@ async function _indexingHandler(block: CosmosBlock): Promise<void> {
618620
if (isMessageType) {
619621
return false;
620622
}
623+
624+
if (evt.event.type === "tx") {
625+
return false
626+
}
627+
621628
const hasValidAmount = hasValidAmountAttribute(evt);
622629

623630
if (!hasValidAmount) {

src/mappings/pocket/suppliers.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SupplierServiceConfig,
1818
SupplierUnbondingReason,
1919
MorseSupplierClaimSignerType,
20+
EventSupplierServiceConfigActivated,
2021
} from "../../types";
2122
import { MsgClaimMorseSupplierProps } from "../../types/models/MsgClaimMorseSupplier";
2223
import { MsgStakeSupplierServiceProps } from "../../types/models/MsgStakeSupplierService";
@@ -342,6 +343,52 @@ async function _handleUnstakeSupplierMsg(
342343
]);
343344
}
344345

346+
async function _handleEventSupplierServiceConfigActivated(
347+
event: CosmosEvent,
348+
) {
349+
let activationHeight: bigint | null = null, supplierSdk: SupplierSDKType | null = null;
350+
351+
for (const {key, value} of event.event.attributes) {
352+
if (key === "activation_height") {
353+
activationHeight = BigInt((value as string).replaceAll('"', ''));
354+
}
355+
356+
if (key === "supplier") {
357+
supplierSdk = JSON.parse(value as unknown as string);
358+
}
359+
}
360+
361+
if (!activationHeight) {
362+
throw new Error(`[handleEventSupplierServiceConfigActivated] activation_height not found in event`);
363+
}
364+
365+
if (!supplierSdk) {
366+
throw new Error(`[handleEventSupplierServiceConfigActivated] supplier not found in event`);
367+
}
368+
369+
const services = await fetchAllSupplierServiceConfigBySupplier(supplierSdk.operator_address);
370+
371+
const eventId = getEventId(event);
372+
373+
await Promise.all([
374+
EventSupplierServiceConfigActivated.create({
375+
id: eventId,
376+
eventId: eventId,
377+
blockId: getBlockId(event.block),
378+
}).save(),
379+
store.bulkUpdate(
380+
"SupplierServiceConfig",
381+
services
382+
.filter((service) => !service.activatedAtId)
383+
.map((service) => {
384+
service.activatedAtId = activationHeight;
385+
service.activatedEventId = eventId;
386+
return service;
387+
})
388+
)
389+
])
390+
}
391+
345392
async function _handleSupplierUnbondingBeginEvent(
346393
event: CosmosEvent,
347394
) {
@@ -544,6 +591,12 @@ export async function handleUnstakeSupplierMsg(
544591
await Promise.all(messages.map(_handleUnstakeSupplierMsg));
545592
}
546593

594+
export async function handleEventSupplierServiceConfigActivated(
595+
events: Array<CosmosEvent>,
596+
): Promise<void> {
597+
await Promise.all(events.map(_handleEventSupplierServiceConfigActivated));
598+
}
599+
547600
export async function handleSupplierUnbondingBeginEvent(
548601
events: Array<CosmosEvent>,
549602
): Promise<void> {

0 commit comments

Comments
 (0)