sui
sui copied to clipboard
[Events] Querying EventsByModule does not give events from module that fired event
Steps to Reproduce Issue
RPC call “events by module” returns not the event module but the frontend one (eg entry fun). For example:
call capy_admin::batch_breed_and_list(
-> capy::batch() -> CapyBorn
-> capy_market::list() -> CapyListed
)
I really expected RPC to give me events (CapyBorn and CapyListed) in requests: eventsByModule(capy) and eventsByModule(capy_market). But in this case events are queried by “capy_admin”. Can we change it? That makes it impossible to track all capys ever bred if someone builds a breeding house. Or if someone wraps capy marketplace logic in their marketplace
If we query actual module that fired event, that would solve my issue.
The problem here is if you have
module M1 {
public entry fun f() {
M2::g()
}
}
module M2 {
struct Event { ... }
public fun g() {
event::emit(Event {... })
}
}
and query by events emitted for M2, you get nothing. If you query events by M1, you will see M2::Event's. The expected behavior is the opposite: querying M2 for its events should show M2::Event's, and querying M1 for events should show nothing. I think this is just a bug. (edited)
Expected Result
Specify what outcome you expected should have resulted, but didn't.
e.g.
Expected
Actual Result
Specify what the actual unexpected outcome was.
e.g.
System Information
- OS: <specify OS version>
- Compiler:
/cc @damirka @sblackshear
Hey @velvia @patrickkuo. Any chance we could prioritize this for this / next week? It would save a lot of time writing event synchronization logic in capys.
@damirka will have a quick look...
@damirka I think you should be able to get what you want today using the new EventQuery API, using this type of query:
| { "MoveEvent": string }
The equiv Rust definition with example of the input format:
/// Return events with the given move event struct name
MoveEvent(
/// the event struct name type, e.g. `0x2::devnet_nft::MintNFTEvent` or `0x2::SUI::test_foo<address, vector<u8>>` with type params
String,
),
So instead of using query by module (which is the module where the event was fired from) if you query by MoveEvent with the format above for your copy event, then you will get all such events regardless of where they are emitted. Try that and see if that solves this issue!
More followup from @damirka .... he is already indeed already using EventName API? and want to return just move events, but from multiple events defined in the module.
This would look like an "MoveEventModule" query which is is "MoveEvent" but matches just the first two components
(ie 0x2::devnet_nft
instead of the entire 0x2::devnet_nft::MintNFTEvent
)
This should be fixed now in main.