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

Open
danielbate opened this issue Jun 17, 2024 · 0 comments
Open

Implement VoidCoder #2532

danielbate opened this issue Jun 17, 2024 · 0 comments
Labels
feat Issue is a feature p2 Low Priority

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.

@danielbate danielbate added feat Issue is a feature p2 Low Priority labels Jun 17, 2024
@danielbate danielbate added this to the 0.x post-launch milestone Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature p2 Low Priority
Projects
None yet
Development

No branches or pull requests

1 participant