@@ -133,10 +133,12 @@ function getSettlementOpReasonFromSDK(item: typeof SettlementOpReasonSDKType | n
133133}
134134
135135function parseAttribute ( attribute : unknown ) : string {
136- return ( attribute as string ) . replaceAll ( "\"" , "" ) ;
136+ return ( attribute as string ) . replaceAll ( "\"" , "" ) ;
137137}
138138
139+ // eslint-disable-next-line complexity
139140function getAttributes ( attributes : CosmosEvent [ "event" ] [ "attributes" ] ) {
141+
140142 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
141143 // @ts -ignore
142144 let proof : ProofSDKType = { } ,
@@ -171,6 +173,11 @@ function getAttributes(attributes: CosmosEvent["event"]["attributes"]) {
171173 numRelays = BigInt ( parseAttribute ( attribute . value ) ) ;
172174 }
173175
176+ // in older versions this is the key to get the number of claimed compute units
177+ if ( attribute . key === "num_compute_units" ) {
178+ numClaimedComputedUnits = BigInt ( parseAttribute ( attribute . value ) ) ;
179+ }
180+
174181 if ( attribute . key === "num_claimed_compute_units" ) {
175182 numClaimedComputedUnits = BigInt ( parseAttribute ( attribute . value ) ) ;
176183 }
@@ -578,11 +585,11 @@ function _handleEventApplicationOverserviced(event: CosmosEvent): EventApplicati
578585
579586 for ( const attribute of event . event . attributes ) {
580587 if ( attribute . key === "application_addr" ) {
581- applicationAddress = ( attribute . value as string ) . replaceAll ( '"' , '' ) ;
588+ applicationAddress = parseAttribute ( attribute . value )
582589 }
583590
584591 if ( attribute . key === "supplier_operator_addr" ) {
585- supplierAddress = ( attribute . value as string ) . replaceAll ( '"' , '' ) ;
592+ supplierAddress = parseAttribute ( attribute . value as string )
586593 }
587594
588595 if ( attribute . key === "expected_burn" ) {
@@ -668,18 +675,72 @@ function _handleEventApplicationReimbursementRequest(event: CosmosEvent): EventA
668675 }
669676}
670677
678+ async function _handleOldEventSupplierSlashed ( event : CosmosEvent ) {
679+ let slashingCoin : CoinSDKType | null = null , operatorAddress = '' ;
680+
681+ for ( const attribute of event . event . attributes ) {
682+ if ( attribute . key === "slashing_amount" ) {
683+ slashingCoin = JSON . parse ( attribute . value as string ) ;
684+ }
685+
686+ if ( attribute . key === "supplier_operator_addr" ) {
687+ operatorAddress = parseAttribute ( attribute . value ) ;
688+ }
689+ }
690+
691+ if ( ! slashingCoin ) {
692+ throw new Error ( `[handleEventSupplierSlashed] slashingCoin not found in event` ) ;
693+ }
694+
695+ if ( ! operatorAddress ) {
696+ throw new Error ( `[handleEventSupplierSlashed] operatorAddress not found in event` ) ;
697+ }
698+
699+ const supplier = await Supplier . get ( operatorAddress )
700+
701+ if ( ! supplier ) {
702+ throw new Error ( `[handleEventSupplierSlashed] supplier not found for operator address ${ operatorAddress } ` )
703+ }
704+
705+ supplier . stakeAmount -= BigInt ( slashingCoin . amount )
706+
707+ await Promise . all ( [
708+ supplier . save ( ) ,
709+ EventSupplierSlashed . create ( {
710+ id : getEventId ( event ) ,
711+ supplierId : operatorAddress ,
712+ blockId : getBlockId ( event . block ) ,
713+ eventId : getEventId ( event ) ,
714+ proofMissingPenalty : BigInt ( slashingCoin . amount ) ,
715+ proofMissingPenaltyDenom : slashingCoin . denom ,
716+ previousStakeAmount : supplier . stakeAmount ,
717+ afterStakeAmount : supplier . stakeAmount ,
718+ // in alpha this event does not have the values below, so we are setting them to empty values for now
719+ applicationId : '' ,
720+ serviceId : '' ,
721+ sessionId : '' ,
722+ sessionStartHeight : BigInt ( 0 ) ,
723+ sessionEndHeight : BigInt ( 0 ) ,
724+ } ) . save ( ) ,
725+ ] )
726+ }
727+
671728async function _handleEventSupplierSlashed ( event : CosmosEvent ) {
672729 const {
673730 claim,
674731 proofMissingPenalty
675732 } = getAttributes ( event . event . attributes ) ;
676733
677734 if ( ! claim ) {
678- throw new Error ( `[handleEventSupplierSlashed] claim not found in event` ) ;
735+ logger . warn ( `[handleEventSupplierSlashed] claim not found in event, trying to handle with previous version` ) ;
736+ await _handleOldEventSupplierSlashed ( event )
737+ return
679738 }
680739
681740 if ( ! claim . session_header ) {
682- throw new Error ( `[handleEventSupplierSlashed] session_header not found in event` ) ;
741+ logger . warn ( `[handleEventSupplierSlashed] session_header not found in event, trying to handle with previous version` ) ;
742+ await _handleOldEventSupplierSlashed ( event )
743+ return
683744 }
684745
685746 const supplier = await Supplier . get ( claim . supplier_operator_address )
0 commit comments