Skip to content

Bug parsing events when nested events involved #1134

@NikitaMishin

Description

@NikitaMishin

Location: https://github.com/starknet-io/starknet.js/blob/66a5c0341eccfef0dcdf1312c15627b7d4f6b675/src/utils/events/index.ts#L52C21-L52C28

Encounter issue with parsing events emitted by components:

Sample of code (just take any events that emitted in nested components):

    const eventsC = provider.getEvents(....)
    const abiEvents = STARKNETJS.events.getAbiEvents(abi);
    const abiStructs =  STARKNETJS.CallData.getAbiStruct(abi);
    const abiEnums = STARKNETJS.CallData.getAbiEnum(abi);
    let parsedEvents = STARKNETJS.events.parseEvents(eventsC.events, abiEvents, abiStructs, abiEnums)
    console.log(parsedEvents)

produces 0 parsed events

Reason: AbiEvents not handle correctly case for nested events when they defined by extra key that associated with component. In my particular case second key was the correct one to do lookup to abiEvents
Potential solution:

let abiEvent: EventAbi | undefined;

// Loop through all keys and find the first matching event
for (const key of recEvent.keys) {
    abiEvent = abiEvents[key];
    if (abiEvent) {
        break; // Exit the loop once a match is found
    }
}

iterate over all keys/or first N instead of just first one. I presume there should be no collisions

Metadata

Metadata

Assignees

Labels

Type: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions