11import { toHex } from "@cosmjs/encoding" ;
2- import { CosmosEvent , CosmosMessage , CosmosTransaction } from "@subql/types-cosmos" ;
2+ import {
3+ CosmosEvent ,
4+ CosmosMessage ,
5+ CosmosTransaction ,
6+ } from "@subql/types-cosmos" ;
37import { Coin } from "../../client/cosmos/base/v1beta1/coin" ;
48import {
59 ApplicationUnbondingReason as ApplicationUnbondingReasonSDKType ,
610 applicationUnbondingReasonFromJSON ,
711} from "../../client/pocket/application/event" ;
812import {
913 Application ,
10- ApplicationGateway , ApplicationUnbondingReason ,
14+ ApplicationGateway ,
15+ ApplicationUnbondingReason ,
1116 EventApplicationUnbondingBegin as EventApplicationUnbondingBeginEntity ,
1217 EventApplicationUnbondingEnd as EventApplicationUnbondingEndEntity ,
1318 EventTransferBegin as EventTransferBeginEntity ,
@@ -37,8 +42,12 @@ import {
3742} from "../../types/proto-interfaces/pocket/application/tx" ;
3843import { ApplicationSDKType } from "../../types/proto-interfaces/pocket/application/types" ;
3944import { MsgClaimMorseApplication } from "../../types/proto-interfaces/pocket/migration/tx" ;
40- import { ApplicationServiceConfig as ApplicationServiceConfigType } from "../../types/proto-interfaces/pocket/shared/service"
41- import { getSequelize , getStoreModel , optimizedBulkCreate } from "../utils/db" ;
45+ import { ApplicationServiceConfig as ApplicationServiceConfigType } from "../../types/proto-interfaces/pocket/shared/service" ;
46+ import {
47+ getSequelize ,
48+ getStoreModel ,
49+ optimizedBulkCreate ,
50+ } from "../utils/db" ;
4251import {
4352 getAppDelegatedToGatewayId ,
4453 getBlockId ,
@@ -47,10 +56,17 @@ import {
4756 getStakeServiceId ,
4857 messageId ,
4958} from "../utils/ids" ;
59+ import { parseJson } from "../utils/json" ;
5060import { getDenomAndAmount } from "../utils/primitives" ;
51- import { Ed25519 , pubKeyToAddress } from "../utils/pub_key" ;
61+ import {
62+ Ed25519 ,
63+ pubKeyToAddress ,
64+ } from "../utils/pub_key" ;
5265import { updateMorseClaimableAccounts } from "./migration" ;
53- import { fetchAllApplicationGatewayByApplicationId , fetchAllApplicationServiceByApplicationId } from "./pagination" ;
66+ import {
67+ fetchAllApplicationGatewayByApplicationId ,
68+ fetchAllApplicationServiceByApplicationId ,
69+ } from "./pagination" ;
5470
5571function getAppUnbondingReasonFromSDK ( item : ApplicationUnbondingReasonSDKType | string | number ) : ApplicationUnbondingReason {
5672 switch ( item ) {
@@ -553,8 +569,42 @@ async function _handleTransferApplicationErrorEvent(
553569async function _handleApplicationUnbondingBeginEvent (
554570 event : CosmosEvent ,
555571) {
572+ /**
573+ * {
574+ * "type":"pocket.application.EventApplicationUnbondingBegin",
575+ * "attributes":[
576+ * {
577+ * "key":"application",
578+ * "value":"{\"address\":\"pokt1jz6hcaz3pjrshw9atqelktuzf8zkklqr0jj2mn\",\"stake\":{\"denom\":\"upokt\",\"amount\":\"979738\"},\"service_configs\":[{\"service_id\":\"avax\"}],\"delegatee_gateway_addresses\":[\"pokt1lf0kekv9zcv9v3wy4v6jx2wh7v4665s8e0sl9s\"],\"pending_undelegations\":{},\"unstake_session_end_height\":\"461280\",\"pending_transfer\":null }",
579+ * "index":false
580+ * },
581+ * {
582+ * "key":"reason",
583+ * "value":"\"APPLICATION_UNBONDING_REASON_BELOW_MIN_STAKE\"",
584+ * "index":false
585+ * },
586+ * {
587+ * "key":"session_end_height",
588+ * "value":"\"461280\"",
589+ * "index":false
590+ * },
591+ * {
592+ * "key":"unbonding_end_height",
593+ * "value":"\"461340\"",
594+ * "index":false
595+ * },
596+ * {
597+ * "key":"mode",
598+ * "value":"EndBlock",
599+ * "index":false
600+ * }
601+ * ]
602+ * }
603+ */
556604 const msg = event . msg as CosmosMessage < MsgUnstakeApplication > ;
557605
606+ let address = msg ? msg . msg . decodedMsg . address : "" ;
607+
558608 let unstakingEndHeight = BigInt ( 0 ) , sessionEndHeight = BigInt ( 0 ) , reason : number | null = null ;
559609
560610 for ( const attribute of event . event . attributes ) {
@@ -569,6 +619,12 @@ async function _handleApplicationUnbondingBeginEvent(
569619 if ( attribute . key === "reason" ) {
570620 reason = applicationUnbondingReasonFromJSON ( ( attribute . value as unknown as string ) . replaceAll ( "\"" , "" ) ) ;
571621 }
622+
623+ if ( ! msg && attribute . key === "application" ) {
624+ // now this is a block event?
625+ const application : ApplicationSDKType = parseJson ( attribute . value as unknown as string ) ;
626+ address = application . address ;
627+ }
572628 }
573629
574630 if ( unstakingEndHeight === BigInt ( 0 ) ) {
@@ -583,10 +639,14 @@ async function _handleApplicationUnbondingBeginEvent(
583639 throw new Error ( `[handleApplicationUnbondingBeginEvent] reason not found in event` ) ;
584640 }
585641
586- const application = await Application . get ( msg . msg . decodedMsg . address ) ;
642+ if ( address === "" ) {
643+ throw new Error ( `[handleApplicationUnbondingBeginEvent] address not found in event` ) ;
644+ }
645+
646+ const application = await Application . get ( address ) ;
587647
588648 if ( ! application ) {
589- throw new Error ( `[handleApplicationUnbondingBeginEvent] application not found for operator address ${ msg . msg . decodedMsg . address } ` ) ;
649+ throw new Error ( `[handleApplicationUnbondingBeginEvent] application not found for operator address ${ address } ` ) ;
590650 }
591651
592652 application . unstakingEndHeight = unstakingEndHeight ;
@@ -599,7 +659,7 @@ async function _handleApplicationUnbondingBeginEvent(
599659 application . save ( ) ,
600660 EventApplicationUnbondingBeginEntity . create ( {
601661 id : eventId ,
602- applicationId : msg . msg . decodedMsg . address ,
662+ applicationId : address ,
603663 blockId : getBlockId ( event . block ) ,
604664 unstakingEndHeight,
605665 sessionEndHeight,
0 commit comments