-
Notifications
You must be signed in to change notification settings - Fork 431
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
Support Result<Self, E> returning ink! constructors #988
Comments
After some fiddling, we can use the same approach for failable constructors as one for messages, but it would require including Otherwise, we need a different approach where we deduce whether the constructor has a |
I'm just wondering why we don't require this bound for |
I guess Why just not use the approach that we did for messages? |
@xgreenx - This is exactly the approach I am following. As you correctly mentioned, there is already partial support for failable constructors, it wasn't just used at the time. @cmichi - I also realised that, it absolutely makes sense for storage to also derive |
If the type implements |
I was thinking of manually checking the result output. If the constructor fails => return encoded Error, otherwise push the contract to storage. |
Yeah, it is what we need to do, but to push the contract into the storage we don't need to impl |
The usage of We have two possible solutions to do it:
|
While this is true, is it necessary bad? The reason why the storage derives Event existing implementation of |
Currently it is not possible to return anything but
Self
in ink! constructors.This is an artificial limitation created to make things a bit easier, however, technically as well as from a design perspective nothing speaks against introducing fallible ink! constructors.
They will behave in the same way to fallible ink! messages in that they will revert state in case
Result::Err
is returned.Mainly
ink_lang_ir
as well asink_lang_codegen
crates are required to be modified in order to implement this feature.After this change ink! constructors can either return
Self
orResult<Self, E>
whereE
is some error type:The text was updated successfully, but these errors were encountered: