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

Reflect fallible constructors in metadata #1457

Closed
athei opened this issue Oct 30, 2022 · 0 comments · Fixed by #1460
Closed

Reflect fallible constructors in metadata #1457

athei opened this issue Oct 30, 2022 · 0 comments · Fixed by #1460
Assignees
Labels
A-ink_metadata [ink_metadata] Work item C-bug Something isn't working

Comments

@athei
Copy link
Contributor

athei commented Oct 30, 2022

This is a follow up for #1446 which added support for fallible constructors with with a custom error type: Result<Self, T>. Please note that constructors are still allowed to return only Self in case of them being infallible.

Current behaviour

The data returned by a constructor is not mentioned in the metadata. All constructors return nothing according to metadata. This was fine before #1446 because they never wrote anything into the output buffer. However, now the Err will be written to the output buffer but only when an error is returned (nothing is written on Ok).

Changes Needed

  • The fact that constructors write data into the output buffer needs to be mentioned in metadata. It is necessary for callers so that they can decode the output buffer. Any constructor returning Result<Self, T> should have the following return type in metadata Result<(), T>. Self is replaced by () because ink! constructors do not return any data from successful constructors.
  • Encode Ok(()) into the output buffer in case of a successful construction. This is redundant information but it is necessary to make the constructor behave as advertised in the metadata. This will allow us to emit data from a constructor in the future while being backwards compatible.

Infallible constructors ( -> Self) will continue do not return anything. So they don't have a return type in metadata and never copy anything to the output buffer.

cc @SkymanOne @xermicus @HCastano

@SkymanOne SkymanOne self-assigned this Oct 31, 2022
@SkymanOne SkymanOne added C-bug Something isn't working A-ink_metadata [ink_metadata] Work item labels Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_metadata [ink_metadata] Work item C-bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants