starknet.js: Bug parsing events when nested events involved
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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26
Found some
[#flat]in OpenZeppelin contracts. I have found a corresponding event. So, I finalize and clean my code. then, I will propose quickly a PR.yeap works
For the test suite of Starknet.js, could you provide me a link in Sepolia for an example these events :
OK, I have now a good understanding of this problem. I will use a nested
findIndex / includesto find the right key.Seems to be the hash of
BalancerEvent