@@ -17,6 +17,7 @@ import {
1717 SupplierServiceConfig ,
1818 SupplierUnbondingReason ,
1919 MorseSupplierClaimSignerType ,
20+ EventSupplierServiceConfigActivated ,
2021} from "../../types" ;
2122import { MsgClaimMorseSupplierProps } from "../../types/models/MsgClaimMorseSupplier" ;
2223import { 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+
345392async 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+
547600export async function handleSupplierUnbondingBeginEvent (
548601 events : Array < CosmosEvent > ,
549602) : Promise < void > {
0 commit comments