-
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
Allow specifying payable
constructors
#1065
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1065 +/- ##
==========================================
- Coverage 78.99% 78.82% -0.18%
==========================================
Files 248 251 +3
Lines 9346 9384 +38
==========================================
+ Hits 7383 7397 +14
- Misses 1963 1987 +24
Continue to review full report at Codecov.
|
So UI support for this isn't quite there since polkadot-js/apps#6645 hasn't been tackled, but really the only "gotcha" here for users is that if they specify a |
Does this PR also includes this information into the metadata? Currently, constructors don't have a payable field. |
It doesn't look like it has the extra metadata field, as Jaco says in that issue there should be a It would go in this: https://github.com/paritytech/ink/blob/master/crates/metadata/src/specs.rs#L223 |
So in this PR we need to:
|
Ah, okay I didn't realize Jaco was referring to the metadata on our end. Sure I can add this |
/// | ||
/// If no ink! constructor within the same ink! smart contract | ||
/// is payable then this flag will be `true` since the check | ||
/// then is moved before the constructor dispatch as an optimization. |
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.
Hmm, not happy about this. This possibility of payable
being set to true
despite no payable constructor seems to be destined for a bug. How about we reflect this information e.g. with an enum here as a wrapper around the bool
?
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 there was already a small bug here actually. If there were indeed no payable messages for example, we'd never hit this check. Although to be fair, payment would have been denied in call() (maybe this was the optimization alluded to in the comment?).
Either way, this was confusing and I think it's unnecessary so I removed it.
It looks like this was meant to be part of an optimization, however it doesn't look like this is necessary anymore. If no constructor or message is payable we already do early deny payment checks in `deploy()` and `call()` respectively.
Can you create a follow-up issue for |
@@ -706,7 +732,6 @@ impl Dispatch<'_> { | |||
); | |||
let accepts_payment = quote_spanned!(message_span=> | |||
false || | |||
!#any_message_accept_payment || |
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.
Can we have a UI test for this: Multiple constructors which are all not payable?
Done: use-ink/ink-docs#41 |
* Add `payable` constructor support to IR * Add payable associated type to `DispatchableConstructorInfo` * Allow constructors to be payable in dispatcher codegen * Add UI tests * Remove test related to constructors being implicitly payable * Add some failing UI tests * Deny payments on `deploy` if there are no payable constructors * Appease Clippy * Deny payments when executing constructors * `s/message/constructor/g` * RustFmt * Address `unnecessary_to_owned` lint Reference: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned * Address `needless_borrow` lint Reference: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow * Make a note about this PR in the RELEASES doc * Allow `clippy::nonminimal_bool` for `deploy()` * Remove `any_payable_*` checks from individual Config creation It looks like this was meant to be part of an optimization, however it doesn't look like this is necessary anymore. If no constructor or message is payable we already do early deny payment checks in `deploy()` and `call()` respectively. * Add UI test for multiple non-payable constructors
Before this change ink! constructors were payable by default. This was because all
contracts were required to place an endowment in order to stay alive.
However, with the changes introduced in paritytech/substrate#10082 this is no
longer necessary. Instead we can allow users to specify whether or not they want their
constructors to be
payable
.We'll need to wait for the Substrate PR to get merged before merging this one. This is
because if we deploy a contract without also initializing it with some value we get a
NewContractNotFunded
error.Closes #1027.
P.S, we'll also want to change
endowment
tovalue
to be consistent withpallet-contracts
, but that can be done in a follow-up PR.