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

Fix queries and tx integrations #29

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ical10
Copy link

@ical10 ical10 commented May 22, 2024

Issues

We are trying to integrate this package into our project ink!athon, but ran into some issues (scio-labs/inkathon#64).

The issues are:

  • Incorrect type generation: some unescaped control characters show up in the generated stringified JSON
  • Typed transaction doesn't work: undefined error when getting event identifier

Expected Results

It should work seamlessly without any issues. This PR aims to solve it.

In addition, I added a sample contract in our boilerplate as an example, created some tests for it, and checked that other tests still pass.

cc @forgetso @wottpal

@forgetso
Copy link
Member

@ical10 thanks for the PR! Is the format below (ContractName::MethodName::EventName) specified anywhere like in /node_modules/@polkadot/types-support/metadata/v15/substrate-types.json ?

		// extract event identifier (ContractName::MethodName::EventName -> EventName)
		const length = event.identifier.toString().split("::").length;
		const name = event.identifier.toString().split("::")[length - 1] ?? event.identifier.toString();

How does polkadotJs apps pluck the event name from the DecodedEvent?

@ical10
Copy link
Author

ical10 commented May 30, 2024

Hi @forgetso

Is the format below (ContractName::MethodName::EventName) specified anywhere like in /node_modules/@polkadot/types-support/metadata/v15/substrate-types.json ?

This isn't defined anywhere in the metadata, but this is coming from the new format inside events field in contract's ABI (contract.json) generated by ink v5.0.

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

Events 2.0

How does polkadotJs apps pluck the event name from the DecodedEvent?

Not sure about how it exactly works. In any case, in order to get the typesafe tx call working, we need to "grab" only label from the DecodedEvent (which is currently prepended with module_path).

@forgetso
Copy link
Member

forgetso commented Jun 1, 2024

@ical10 thanks for the explanation. I just want to make sure that the string format is always going to be the same so the code always works. Having read it a bit more closely, I can see the code works if there are no :: separators.

You'll need to get the tests working in order to merge.

Please also make this a variable instead of writing it twice:

event.identifier.toString().split("::")

Otherwise, looks good! :)

@ical10
Copy link
Author

ical10 commented Jun 24, 2024

@forgetso

Sorry for the delay. I've added your feedbacks, also ran the tests and all passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants