@@ -45,7 +45,7 @@ import {
4545} from "../../types/proto-interfaces/pocket/tokenomics/types" ;
4646import { optimizedBulkCreate } from "../utils/db" ;
4747import { getBlockId , getEventId , messageId } from "../utils/ids" ;
48- import { stringify } from "../utils/json" ;
48+ import { parseJson , stringify } from "../utils/json" ;
4949import { getDenomAndAmount } from "../utils/primitives" ;
5050
5151// this can return undefined because older events do not have this attribute
@@ -310,7 +310,47 @@ function _handleMsgCreateClaim(msg: CosmosMessage<MsgCreateClaim>): MsgCreateCla
310310 const serviceId = sessionHeader ?. serviceId || "" ;
311311 const sessionId = sessionHeader ?. sessionId || "" ;
312312
313- const eventClaimCreated = msg . tx . tx . events . find ( event => event . type === "pocket.proof.EventClaimCreated" ) ;
313+ // here we are looking for the right event because transactions
314+ // can have more than one claim
315+ const eventClaimCreated = msg . tx . tx . events . find ( event => {
316+ if ( event . type === "pocket.proof.EventClaimCreated" ) {
317+ let supplier = '' ,
318+ app = '' ,
319+ service = ''
320+
321+ for ( const { key, value} of event . attributes ) {
322+ if ( key === 'service_id' ) {
323+ service = parseAttribute ( value )
324+ }
325+
326+ if ( key === 'application_address' ) {
327+ app = parseAttribute ( value )
328+ }
329+
330+ if ( key === 'supplier_operator_address' ) {
331+ supplier = parseAttribute ( value )
332+ }
333+
334+ if ( key === 'claim' ) {
335+ const claim : ClaimSDKType = parseJson ( value as string )
336+
337+ app = claim . session_header ?. application_address || ""
338+ service = claim . session_header ?. service_id || ""
339+ supplier = claim . supplier_operator_address || ""
340+ }
341+
342+ if ( service && app && supplier ) {
343+ break
344+ }
345+ }
346+
347+ return service === serviceId &&
348+ app === applicationId &&
349+ supplier === supplierOperatorAddress ;
350+ }
351+
352+ return false
353+ } ) ;
314354
315355 if ( ! eventClaimCreated ) {
316356 throw new Error ( `EventClaimCreated not found for msg MsgCreateClaim ${ msg . idx } ${ msg . tx . hash } ${ msg . block . block . header . height } ` ) ;
0 commit comments