-
Notifications
You must be signed in to change notification settings - Fork 480
Implement wildcard selector, add proxy example
#1020
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
Changes from 1 commit
64901a9
2eaf655
bd7eea1
7b7c43b
4677a59
fbe82d2
2e633e3
23e2baf
75886af
0299f4d
1d102b0
7f1a7ea
7dba798
66a3455
f643a30
1b0c396
5cb1f3c
ee3d140
3ed386c
724ff9f
f4a2765
dc2a9fd
17067e7
a7e624a
f1429cf
0b7cf6e
cc078ea
c2a2697
99a4ff8
a2ba30a
9f58738
1a7b33c
00f360d
1bc3bb6
98da359
b498308
36a374c
d55c84b
fbc6097
7698ad5
c297f50
21bb558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,18 @@ | ||
| //! This example demonstrates how the Proxy/Forward pattern can be | ||
| //! implemented in ink!. | ||
| //! | ||
| //! What the contract does is: | ||
| //! | ||
| //! * Any call to this contract that does not match a selector | ||
| //! of it is forwarded to a specified address. | ||
| //! * The instantiator of the contract can modify this specified | ||
| //! `forward_to` address at any point. | ||
| //! | ||
| //! Using this pattern it is possible to implement upgradable contracts. | ||
| //! | ||
| //! Note though that the contract to which calls are forwarded still | ||
| //! contains it's own state. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use ink_lang as ink; | ||
|
|
@@ -36,7 +51,9 @@ pub mod proxy { | |
| assert_eq!( | ||
| self.env().caller(), | ||
| self.admin, | ||
| "caller does not have sufficient permissions" | ||
| "caller {:?} does not have sufficient permissions, only {:?} does", | ||
| self.env().caller(), | ||
| self.admin, | ||
| ); | ||
| self.forward_to = new_address; | ||
| } | ||
|
|
@@ -49,8 +66,7 @@ pub mod proxy { | |
| /// - We allow payable messages here and would forward any optionally supplied | ||
| /// value as well. | ||
| /// - If the self receiver were `forward(&mut self)` here, this would not | ||
| /// imply that the contract to which we forward to does not mutate it's own | ||
| /// state. | ||
| /// have any effect whatsover on the contract we forward to. | ||
cmichi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #[ink(message, payable, selector = "_")] | ||
| pub fn forward(&self) -> u32 { | ||
| ink_env::call::build_call::<ink_env::DefaultEnvironment>() | ||
|
|
@@ -63,7 +79,12 @@ pub mod proxy { | |
| .gas_limit(0) | ||
cmichi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .transferred_value(self.env().transferred_balance()) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should unify this API to be just
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also for constructors with their
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| .fire() | ||
| .expect("cross-contract call failed"); | ||
| .unwrap_or_else(|err| { | ||
| panic!( | ||
| "cross-contract call to {:?} failed due to {:?}", | ||
| self.forward_to, err | ||
| ) | ||
| }); | ||
| unreachable!( | ||
| "the forwarded call will never return since `tail_call` was set" | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.