-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing of events #697
Comments
I'm willing to implement this btw |
Hello! The issue was that nodes didn't have web sockets implemented... But there are developments in this area being done as we speak... Does this "help" or you have a different use case in mind? |
I meant something different, after using |
Usage would be like?
Or with the event name? Where event/s would be nicely formatted and parsed to js data based on ABI. |
I was thinking more of this:
Then you don't need to query the blockchain again as every event is already stored in
to the |
The hash of an event is : starkCurve.keccak(eventName) It will be necessary to take care that the event can write in both keys and data arrays : {
"type": "event",
"name": "PhilTest2::PhilTest2::MyTestContract::CounterIncreased",
"kind": "struct",
"members": [
{
"name": "from",
"type": "core::starknet::contract_address::ContractAddress",
"kind": "key"
},
{
"name": "amount",
"type": "core::integer::u128",
"kind": "data"
}
]
}, My feeling is that we should have : const events: ParsedEvent[] = myContract.parseEvents(transactionResult); For example with this : {
data: [ '0xa' ],
from_address: '0x45b73ec5c290f6a5ed780bcde055ba5d914e1931ac3f04be9c51d091bbe2094',
keys: [
'0xd3651022da7ddf0a226dd81c8a16106318358829bd09702eb656630219c030',
'0x6c8fe36d7454901424063b5c1b949d7e347ce3872d2487b30b76f3a4fd7c219'
]
} The result could be (type ParsedEvent) : {
eventName : "CounterIncreased",
keys: {from: "0x6c8fe36d7454901424063b5c1b949d7e347ce3872d2487b30b76f3a4fd7c219"},
data: {amount: "0xa"}
} |
Yep, exactly what I had in mind, thank you for the example! |
Ok, so implementation can be made in utils/events/responseParser.ts ? public parseEvents(receipt: GetTransactionReceiptResponse): ParsedEvent |
@edisontim You can start working on this task |
On this point final result should be js representation of data so for Struct of this types: {
CounterIncreased: {
from: BigInt,
amount: BigInt,
}
} |
Implemented in #704 |
Could someone have a look at the PR? The CI doesn't pass but I've tried to reproduce the failure locally and can't manage to @ivpavici ? |
Had to slightly change the final representation as multiple events of the same type can be in the same receipt:
|
I made a test with this format, and I am not fully convinced.
I find this format not adapted for post processing (ex : how to count the nb of events?).
|
I agree this format is inconvenient. It can be flattened before return if the refractor is complicated easily by: Object.entries(events).map(i=>i[1].flatMap(t=>({[i[0]]:t}))).flat() Even doe this can be used to flatter results now it is not trivial. |
Ok, I thought the format was easier but the change is done :) |
🎉 This issue has been resolved in version 5.19.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolved in #712 |
Is your feature request related to a problem? Please describe.
Not related to a problem per se but it would facilitate the usage of events in Starknet js
Describe the solution you'd like
It's a hassle to read events coming from a contract for which we have the ABI available. I think it would be very nice to have a ParseEvent function available in the Contract class
For now I believe the only way of reading events is by parsing it manually: https://www.starknetjs.com/docs/guides/events
The text was updated successfully, but these errors were encountered: