starknet-io / starknet.js

JavaScript library for StarkNet
https://www.starknetjs.com
MIT License
1.21k stars 706 forks source link

BUG: Nested events not handled #1140

Closed PhilippeR26 closed 3 weeks ago

PhilippeR26 commented 1 month ago

Motivation and Resolution

Solves #1134 . Cairo is now using a new concept : the components. Events can be nested in these components. To differentiate them, an event name can now be defined with more than one hash number ; so the number of felts to represent the hashed name in key[] can be greater than one (unless usage of the Cairo #[flat] attribute). See https://book.cairo-lang.org/ch14-03-contract-events.html?highlight=events#defining-events . As the current code is not taking into account this case of nested events, the parse of a such event is returning an empty array. This PR is solving this case.

Usage related changes

[!WARNING] Breaking change: Today, a parsed event is identified only by its name, without the complete path. As the same event name can now be present in several components in the same contract (one real example is used in tests, with 2 events called Deposit), to be able to differentiate them, the name is now the complete name : path + name. Example :

  • was : Deposit
  • is now : kurosawa_akira::DepositComponent::deposit_component::Deposit

Development related changes

Checklist:

PhilippeR26 commented 1 month ago

I think I will first commit something to answer to @tabaktoni, and when it will be accepted, I will focus on @ivpavici requests.

PhilippeR26 commented 1 month ago

All comments implemented, except the ones waiting answers to my questions : @tabaktoni :

@ivpavici :

PhilippeR26 commented 1 month ago

@tabaktoni I have added the types from rpc 0.6 (as rpc 0.7 event types can't be imported with current libs used by SNJS) : abi.ts :

import type { ENUM_EVENT, EVENT_FIELD, STRUCT_EVENT } from '../../api/rpcspec_0_6/contract';

I will move to 0.7 when exports available.

NOTA : I have now a huge quantity of commits listed in this PR, that appeared after merge to next-version branch. I don't know how to solve this. If it's a problem, if somebody can solve this ...

Should be now good to merge...