Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions src/mappings/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@ import { CosmosEvent, CosmosMessage } from "@subql/types-cosmos";
import { handleAuthzExec } from "./authz/exec";
import { handleEventGrant, handleMsgGrant } from "./authz/grants";
import { handleNativeTransfer } from "./bank";
import {
handleApplicationUnbondingBeginEvent,
handleApplicationUnbondingEndEvent,
handleAppMsgStake,
handleDelegateToGatewayMsg,
handleMsgClaimMorseApplication,
handleTransferApplicationBeginEvent,
handleTransferApplicationEndEvent,
handleTransferApplicationErrorEvent,
handleTransferApplicationMsg,
handleUndelegateFromGatewayMsg,
handleUnstakeApplicationMsg,
} from "./pocket/applications";
import {
handleGatewayMsgStake,
handleGatewayMsgUnstake,
Expand Down Expand Up @@ -58,19 +45,19 @@ export const MsgHandlers: Record<string, (messages: Array<CosmosMessage>) => Pro
"/pocket.migration.MsgClaimMorseAccount": handleMsgClaimMorseAccount,
// this is currently being handle inside Authz handler
"/pocket.migration.MsgRecoverMorseAccount": noOp,
"/pocket.migration.MsgClaimMorseApplication": handleMsgClaimMorseApplication,
"/pocket.migration.MsgClaimMorseApplication": noOp,
// bank
"/cosmos.bank.v1beta1.MsgSend": handleNativeTransfer,
// validator
"/cosmos.staking.v1beta1.MsgCreateValidator": handleValidatorMsgCreate,
// params
"/cosmos.authz.v1beta1.MsgExec": handleAuthzExec,
// application
"/pocket.application.MsgStakeApplication": handleAppMsgStake,
"/pocket.application.MsgDelegateToGateway": handleDelegateToGatewayMsg,
"/pocket.application.MsgUndelegateFromGateway": handleUndelegateFromGatewayMsg,
"/pocket.application.MsgUnstakeApplication": handleUnstakeApplicationMsg,
"/pocket.application.MsgTransferApplication": handleTransferApplicationMsg,
// application - now handling app msgs in indexApplications (called from indexStake)
"/pocket.application.MsgStakeApplication": noOp,
"/pocket.application.MsgDelegateToGateway": noOp,
"/pocket.application.MsgUndelegateFromGateway": noOp,
"/pocket.application.MsgUnstakeApplication": noOp,
"/pocket.application.MsgTransferApplication": noOp,
// service
"/pocket.service.MsgAddService": handleMsgAddService,
// supplier - handled by batch processing in indexSupplier (called from indexStake)
Expand Down Expand Up @@ -102,12 +89,12 @@ export const EventHandlers: Record<string, (events: Array<CosmosEvent>) => Promi
// This event is emitted when a validator or delegator claims their staking rewards.
// It happens when they trigger a manual withdrawal, moving rewards from the staking module to their balance.
// This is the moment where rewards are actually turned into spendable tokens.
// application
"pocket.application.EventTransferBegin": handleTransferApplicationBeginEvent,
"pocket.application.EventTransferEnd": handleTransferApplicationEndEvent,
"pocket.application.EventTransferError": handleTransferApplicationErrorEvent,
"pocket.application.EventApplicationUnbondingBegin": handleApplicationUnbondingBeginEvent,
"pocket.application.EventApplicationUnbondingEnd": handleApplicationUnbondingEndEvent,
// application - now handling app events in indexApplications (called from indexStake)
"pocket.application.EventTransferBegin": noOp,
"pocket.application.EventTransferEnd": noOp,
"pocket.application.EventTransferError": noOp,
"pocket.application.EventApplicationUnbondingBegin": noOp,
"pocket.application.EventApplicationUnbondingEnd": noOp,
// supplier - handled by batch processing in indexSupplier (called from indexStake)
"pocket.supplier.EventSupplierServiceConfigActivated": noOp, // - now handled in indexSupplier
"pocket.supplier.EventSupplierUnbondingBegin": noOp, // - now handled in indexSupplier
Expand Down
67 changes: 1 addition & 66 deletions src/mappings/indexer.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EventHandlers,
MsgHandlers,
} from "./handlers";
import { indexApplications } from "./pocket/applications";
import { handleAddBlockReports } from "./pocket/reports";
import { indexSupplier } from "./pocket/suppliers";
import {
Expand Down Expand Up @@ -211,72 +212,6 @@ async function indexService(msgByType: MessageByType, eventByType: EventByType):
])
}

// any application msg or event
async function indexApplications(msgByType: MessageByType, eventByType: EventByType): Promise<void> {
const msgTypes = [
"/pocket.application.MsgDelegateToGateway",
"/pocket.application.MsgUndelegateFromGateway",
"/pocket.application.MsgUnstakeApplication",
"/pocket.application.MsgStakeApplication",
"/pocket.migration.MsgClaimMorseApplication",
"/pocket.application.MsgTransferApplication",
];
const eventTypes = [
"pocket.application.EventTransferBegin",
"pocket.application.EventTransferEnd",
"pocket.application.EventTransferError",
"pocket.application.EventApplicationUnbondingBegin",
"pocket.application.EventApplicationUnbondingEnd",
];

const getIdOfTransferEvents = (attributes: CosmosEvent['event']["attributes"]) => {
return attributes.find(({key}) => key === "source_address")?.value as string
}

const getIdOfBondingEvents = (attributes: CosmosEvent['event']["attributes"]) => {
for (const {key, value} of attributes) {
if (key !== "application") continue

return JSON.parse(value as string).address
}

return null
}

await indexStakeEntity([
...msgTypes.map(type => msgByType[type]).flat(),
...eventTypes.map(type => eventByType[type]).flat()
],
{
"/pocket.application.MsgDelegateToGateway": "appAddress",
"/pocket.application.MsgUndelegateFromGateway": "appAddress",
"/pocket.application.MsgUnstakeApplication": "address",
"/pocket.application.MsgStakeApplication": "address",
"/pocket.migration.MsgClaimMorseApplication": "shannonDestAddress",
"/pocket.application.MsgTransferApplication": "sourceAddress",
"pocket.application.EventTransferBegin": getIdOfTransferEvents,
"pocket.application.EventTransferEnd": (attributes) => {
// here we need to return two ids (id of the source and id of the destination app)
// to group the data of those two apps
const ids: Array<string> = []

for (const {key, value} of attributes) {
if (key === 'source_address' || key === 'destination_address') {
// the source address is surrounded by quotes
ids.push((value as string).replaceAll("\"", ""))
}

if (ids.length === 2) break
}

return ids
},
"pocket.application.EventTransferError": getIdOfTransferEvents,
"pocket.application.EventApplicationUnbondingBegin": getIdOfBondingEvents,
"pocket.application.EventApplicationUnbondingEnd": getIdOfBondingEvents,
})
}

// any gateway msg or event
async function indexGateway(msgByType: MessageByType, eventByType: EventByType): Promise<void> {
const msgTypes = [
Expand Down
Loading
Loading