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

research: switch from wrapper types to Go native types #308

Closed
radkomih opened this issue Dec 4, 2023 · 1 comment
Closed

research: switch from wrapper types to Go native types #308

radkomih opened this issue Dec 4, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@radkomih
Copy link
Collaborator

radkomih commented Dec 4, 2023

Research if we can remove the wrapper types and instead, switch to the built-in Go types, which is more idiomatic.

sc.Bool => bool
sc.U8 => uint8
...
@radkomih
Copy link
Collaborator Author

radkomih commented Dec 12, 2023

When the project initially started, Tinygo's support for reflection was very limited. Therefore, using types that implemented a specific interface with an 'Encode()' method did not require extensive reliance on reflection calls. Thus, instead of using the built-in types (bool, uint8, ..., structs, arrays, slices, and maps), wrapper types were introduced to satisfy the interface.

Currently, there is a helper function 'EncodeEach()' that relies on an Encode() method and interface, which simply calls each field's Encode() method.

  • Pros:

    • Does not require extensive reflection calls.
    • Works for custom-defined types.
    • Ensures type safety (requires the Encode() method to be implemented for each field).
  • Cons:

    • Not idiomatic (requires wrapper types); does not work for built-in types.
    • Cannot differentiate properly between arrays and slices (both are encoded as slices).

There are different approaches that may allow switching to Go built-in types instead of the wrapper types. Here are some of the most convenient ones:

A. Fork Gossamer's Scale Codec

Make the necessary changes to eliminate the need for certain unsupported reflection calls, see #210.

B. Refactor Our Goscale Codec

Use the helper function 'EncodeEach()', which relies on an encoding function for built-in types and on an interface and encode method for custom-defined types.

@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Gosemble - Polkadot Runtimes Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

1 participant