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

Implement VoidCoder #2532

Closed
danielbate opened this issue Jun 17, 2024 · 0 comments · Fixed by #2777
Closed

Implement VoidCoder #2532

danielbate opened this issue Jun 17, 2024 · 0 comments · Fixed by #2777
Assignees
Labels
feat Issue is a feature

Comments

@danielbate
Copy link
Contributor

danielbate commented Jun 17, 2024

In sway, 2 types produce a void () value. These are Option::None() and native enums. Both encode to just the case bytes, meaning the value itself is empty.

Internally this is picked up by the TupleCoder due to the bracket regex match, and as it has no children it correctly encodes to empty bytes. However to anyone trying to build this out themselves without using the AbiCoder would have to do this:

const nativeCoder = new EnumCoder('Native', {
    One: new TupleCoder([]),
    Two: new TupleCoder([]),
    Three: new TupleCoder([]),
});

This seems pretty hacky and not immediately obvious to anyone attempting to debug option and native enum problems. We should provide a VoidCoder that does an exact match on the void type for this scenario to provide a better experience for working with void values.

This is a feature but more an implementation detail of our internal encoding, as the VoidCoder itself should not be exported from @fuel-ts/abi-coder.

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

Successfully merging a pull request may close this issue.

3 participants