Skip to content
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

Support new ink! contract events #5789

Closed
1 of 4 tasks
ascjones opened this issue Feb 1, 2024 · 8 comments · Fixed by #5791
Closed
1 of 4 tasks

Support new ink! contract events #5789

ascjones opened this issue Feb 1, 2024 · 8 comments · Fixed by #5791

Comments

@ascjones
Copy link
Contributor

ascjones commented Feb 1, 2024

I'm submitting a ...

  • Bug report
  • Feature request
  • Support request
  • Other

ink! events are changing in version 5.0. See use-ink/ink#1827, and https://use.ink/5.x/basics/events/.

The most important change is that there is a new field on each event definition in the metadata: signature_topic which must now be used to identify the type of event being received. Previously the index of the event i.e its position in the json array was used to determine which event to decode.

Now when handling an event, the first topic of the substrate event is matched to that signature topic in the metadata. If the event is anonymous, there is no signature topic in that case the raw hex bytes of the event can be returned and leave it up to the user what to do there.

Event decoding here:

#createEvent = (spec: ContractEventSpecLatest, index: number): AbiEvent => {

@cmichi
Copy link

cmichi commented Feb 1, 2024

I'm uploading a zip with two contracts here: erc20-4.0-vs-5.0.zip. It contains:

  • ERC-20 with ink! 4.0
  • ERC-20 with ink! 5.0

The diff comes down to

    "events": [
      {
        "args": [ ... ],
        "docs": [ ... ],
        "label": "...",
+       "module_path": "erc20::erc20",
+       "signature_topic": "0xb5b61a3e6a21a16be4f044b517c28ac692492f73c5bfd3f60178ad98c767f4cb"
      },
      ...
  ]

@cmichi
Copy link

cmichi commented Feb 1, 2024

@jacogr We would be very grateful if you could tackle this soonish. The context is that we're about to release ink! 5.0 and just now realized that polkadot-js/api needs to be updated.

@peetzweg peetzweg mentioned this issue Feb 1, 2024
@peetzweg
Copy link
Contributor

peetzweg commented Feb 27, 2024

@ascjones Is this actually ink! specific? Would ask! and solang compiled contract emit events in the same way?

@ascjones
Copy link
Contributor Author

@ascjones Is this actually ink! specific? Would ask! and solang compiled contract emit events in the same way?

I'm not sure what the current state is, but we would expect them to emit events in this way in the future i.e. have the first topic be the signature topic and include that in the metadata. /cc @xermicus

@peetzweg
Copy link
Contributor

Would be a bit of a hassle to not only treat contract compiled with different ink version differently but also languages. Is there something like an language overarching specification how pallet-contracts wasm contracts should behave?

@cmichi
Copy link

cmichi commented Feb 28, 2024

That's basically the ink! metadata. Solang & co just implement the same metadata format as ink!, Solang also uses the ink! crates for parts of that. I think Solang is still on the Metadata v4.

When interpreting the metadata there should be no language-specific logic needed.

@xermicus
Copy link

Yes as soon as ink! 5.0 is released I'll keep Solang up and make a new release. As for the events, this shouldn't be any issue to adapt.

In general the metadata is mostly compatible. The only compromise so far is about how Solang Solidity contracts make use of lang_error, because the concepts of errors and error handling is fundamentally different between Solidity and ink!. We might be able to solve this by changing ink! metadata. Maybe it's also just way more pragramatic to just have some "special cases" instead of trying to make the ink! metadata format too generic (I don't have a hard opinion). But this is the status quo already and not related to events, which I should be able to adapt in solang without problems.

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Mar 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants