Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Generate metadata for constructor return type #1460
Generate metadata for constructor return type #1460
Changes from 3 commits
4be003b
68df576
ced904f
1686a8a
42fac54
7e4aed2
2912089
bdd717f
32e99fa
f5ec420
4959e4c
e59821f
e335081
17795d0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This again does syntactical checks instead of using the Rust type system properly and will fail for various syntactic contexts. To do this properly you'd need to take a similar approach as in
generate_trait_messages
with Rust type system reflection such asWe do have the information for ink! messages and constructors as well. They are identified using their selectors which are always known at proc. macro compile time. Therefore you can access them in this scope just like in the linked example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The metadata codegen takes place after the WASM blob compilation, hence at this stage all types have already been evaluated by compiler and we can work with syntax.
In fact, I generally do not do syntactical checks. I only check if the token is
Self
here because metadata generation takes place outside the storage definition, henceSelf
can not be evaluated there. Same logic applies forResult<Self, ...>
.However, if the return type is the explicit type of a contract or
Result
with explicit contract type forOk
variant, then I do the type evaluation, hence why we haveTransformResult
factory.I can be sure that the
Self
is valid in this context is because the WASM build is already done by now.I am not sure how message selectors are relevant here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may be able to refactor this to make it use the Rust type system, I'm looking into this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done an experiment with this in #1491, take a look and see what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what if the return type is
Result<Self, _>
, the value will never be returned. The client decoding will fail because it will expect0x00
forOk
but will get empty bytes instead.I suppose you have not been able to test this since there are no clients which are attempting to decode the return value?
One way to test it would be via the in-contract instantiation with
CreateBuilder
. E.g used indelegator
.