-
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
Implement wildcard selector, add proxy
example
#1020
Conversation
.set_tail_call(true), | ||
) | ||
.gas_limit(0) | ||
.transferred_value(self.env().transferred_balance()) |
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.
We should unify this API to be just .transferred_balance
everywhere.
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.
also for constructors with their endowment
?
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'd leave it there, but in this case I think it's clear that it should be streamlined.
Codecov Report
@@ Coverage Diff @@
## master #1020 +/- ##
===========================================
+ Coverage 63.52% 77.10% +13.58%
===========================================
Files 246 248 +2
Lines 9260 9381 +121
===========================================
+ Hits 5882 7233 +1351
+ Misses 3378 2148 -1230
Continue to review full report at Codecov.
|
🦑 📈 ink! Example Contracts ‒ Size Change Report 📉 🦑These are the results of building the Link to the run | Last update: Wed Nov 24 07:31:18 CET 2021 |
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 only took a look at the example contract and UI tests. Will take a look at the codegen tomorrow. Looking good though 👍
@@ -1,4 +1,4 @@ | |||
error: #[ink(selector = ..)] attributes with string inputs are deprecated. use an integer instead, e.g. #[ink(selector = 1)] or #[ink(selector = 0xC0DECAFE)]. | |||
error: #[ink(selector = ..)] attributes with string inputs are deprecated (except for the wildcard selector "_"). use an integer instead, e.g. #[ink(selector = 1)] or #[ink(selector = 0xC0DECAFE)]. |
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 is a shame, would've be nice to have consistent syntax. Can you expand on the issue you mentioned in the PR description as to why we weren't able to have selector = _
?
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.
Yeah, so the issue is here. We would need access to _
there.
But the crate which we use for parsing attributes a la #[ink(key = "value")]
does not support parsing verbatims such as _
. Specifically the type syn::Meta::NameValue
which we use as part of the syn::parse_meta
return value does not support this.
I briefly looked into syn::parse_meta
, but it was nothing trivial. Maybe we could also do some pre-processing, so that selector = _
is transformed into selector = "_"
before passing it to syn::parse_meta
, but I haven't looked into that.
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.
Or you can implement your own parse_meta
=) You can copy the main logic from syn
+ add support of _
=)
Co-authored-by: Hernando Castano <[email protected]>
This feature is highly unwanted since it would heavily interfere with trait modularity. We should make sure that traits never allow for wildcard selectors. |
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.
Haven't reviewed the entire thing, yet, however, I have to say that this PR goes a very long way in making sure that a wildcard selector is something completely different from a selector whereas the beauty in the original design actually made a lot of sense from the fact that we can treat both as different kinds of selectors.
So instead of putting is_wildcard_selector
everywhere it would probably a more elegant design to make ir::Selector
an enum that can represent a concrete selector or a wildcard selector.
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.
Nice!
Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: Hernando Castano <[email protected]> Co-authored-by: Alexander Theißen <[email protected]>
Co-authored-by: Robin Freyler <[email protected]>
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 haven't looked at all the new changes just yet, will finish this up tomorrow
pub struct Contract {} | ||
|
||
impl Contract { | ||
#[ink(constructor, selector = _)] |
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.
Are there any invariants around constructors only being able to be run once? If so, then we shouldn't allow this
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 you elaborate on this please? I cannot follow.
crates/lang/tests/ui/contract/fail/trait-message-wildcard-selector.rs
Outdated
Show resolved
Hide resolved
crates/lang/tests/ui/contract/fail/trait-message-wildcard-selector.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Hernando Castano <[email protected]>
This reverts commit 00f360d.
examples/proxy/lib.rs
Outdated
pub fn change_forward_address( | ||
&mut self, | ||
new_address: AccountId, | ||
) -> Result<(), NotAdminErr> { |
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.
@Robbepop While running the waterfall tests for this example, I found that since I switched from assert!
to returning Result::Err
the transaction is no longer reverted ‒ it always results in ExtrinsicFailed
.
If you don't see anything that I missed I'll consider this a bug, revert to assert!
and create a follow-up issue.
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.
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, could be that substrate-contracts-node
is somewhat outdated.
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.
Found it, the UI doesn't reflect this yet: polkadot-js/apps#6465.
Another question, how the user can forward some data via polkadot-js?=) Because I can only read that=D
@xgreenx You have to switch the metadata of this contract to some other contract. This can be done by clicking the "Add an existing contract" button, entering the proxy smart contract address and upload a different .contract
file there. The UI will then use the ABI of this contract to interact with the proxy.
I've reverted returning an |
* Implement wildcard selector, add `proxy` example * Minor code and text improvements * Remove code * Fix function name * Add unit tests for lang parsing * Clarify where state resides * Apply suggestions from code review Co-authored-by: Hernando Castano <[email protected]> * Implement comments * Apply suggestions from code review Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: Hernando Castano <[email protected]> Co-authored-by: Alexander Theißen <[email protected]> * Pre-process `_` to `"_"` * Update String error message * Rename `is_wildcard_selector` to `has_wildcard_selector` * Move `_` to `"_"` transformation to lower layer * Update test fixtures * Update error message * Update test fixtures * Migrate to enum `SelectorOrWildcard` * Allow wildcard selectors for constructors * Fix tests * Include clippy suggestion * Fix error output matching * Apply suggestions from code review Co-authored-by: Robin Freyler <[email protected]> * Fix suggestions * Implement reviewer suggestions * Improve matching * Include clippy suggestion * Update test fixture * Detect multiple wildcard selectors in constructors * Apply suggestions from code review Co-authored-by: Hernando Castano <[email protected]> * Rename enum variant `Selector` to `UserProvided` * Return `Result:Err` instead of asserting * Implement suggestions * Revert "Return `Result:Err` instead of asserting" This reverts commit 00f360d. * Apply `cargo fmt` * Disable overflow checks for `proxy` example * Return `Result:Err` instead of asserting * Fix import path * Fix import path * Fix import path * Revert "Return `Result:Err` instead of asserting" This reverts commit 7698ad5. This reverts commit fbc6097. This reverts commit d55c84b. Co-authored-by: Hernando Castano <[email protected]> Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: Alexander Theißen <[email protected]>
Closes #739.
This PR intentionally
proxy
example. Will be added later.I'll add an E2E test for the
ink-waterfall
as a follow-up.Pictures for the
proxy/readme.md
would also be nice, can also be done as a follow-up.