Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
64901a9
Implement wildcard selector, add `proxy` example
cmichi Nov 9, 2021
2eaf655
Minor code and text improvements
cmichi Nov 17, 2021
bd7eea1
Remove code
cmichi Nov 17, 2021
7b7c43b
Fix function name
cmichi Nov 17, 2021
4677a59
Add unit tests for lang parsing
cmichi Nov 17, 2021
fbe82d2
Clarify where state resides
cmichi Nov 17, 2021
2e633e3
Apply suggestions from code review
Nov 17, 2021
23e2baf
Implement comments
cmichi Nov 17, 2021
75886af
Apply suggestions from code review
Nov 22, 2021
0299f4d
Pre-process `_` to `"_"`
cmichi Nov 18, 2021
1d102b0
Update String error message
cmichi Nov 22, 2021
7f1a7ea
Merge branch 'master' into cmichi-implement-wildcard-selector
cmichi Nov 22, 2021
7dba798
Rename `is_wildcard_selector` to `has_wildcard_selector`
cmichi Nov 22, 2021
66a3455
Move `_` to `"_"` transformation to lower layer
cmichi Nov 22, 2021
f643a30
Update test fixtures
cmichi Nov 22, 2021
1b0c396
Update error message
cmichi Nov 22, 2021
5cb1f3c
Update test fixtures
cmichi Nov 22, 2021
ee3d140
Migrate to enum `SelectorOrWildcard`
cmichi Nov 23, 2021
3ed386c
Allow wildcard selectors for constructors
cmichi Nov 23, 2021
724ff9f
Fix tests
cmichi Nov 23, 2021
f4a2765
Include clippy suggestion
cmichi Nov 23, 2021
dc2a9fd
Fix error output matching
cmichi Nov 23, 2021
17067e7
Apply suggestions from code review
Nov 23, 2021
a7e624a
Fix suggestions
cmichi Nov 23, 2021
f1429cf
Implement reviewer suggestions
cmichi Nov 23, 2021
0b7cf6e
Merge branch 'master' into cmichi-implement-wildcard-selector
cmichi Nov 23, 2021
cc078ea
Improve matching
cmichi Nov 23, 2021
c2a2697
Include clippy suggestion
cmichi Nov 23, 2021
99a4ff8
Update test fixture
cmichi Nov 23, 2021
a2ba30a
Detect multiple wildcard selectors in constructors
cmichi Nov 23, 2021
9f58738
Apply suggestions from code review
Nov 23, 2021
1a7b33c
Rename enum variant `Selector` to `UserProvided`
cmichi Nov 23, 2021
00f360d
Return `Result:Err` instead of asserting
cmichi Nov 23, 2021
1bc3bb6
Implement suggestions
cmichi Nov 23, 2021
98da359
Revert "Return `Result:Err` instead of asserting"
cmichi Nov 23, 2021
b498308
Apply `cargo fmt`
cmichi Nov 23, 2021
36a374c
Disable overflow checks for `proxy` example
cmichi Nov 23, 2021
d55c84b
Return `Result:Err` instead of asserting
cmichi Nov 24, 2021
fbc6097
Fix import path
cmichi Nov 24, 2021
7698ad5
Fix import path
cmichi Nov 24, 2021
c297f50
Fix import path
cmichi Nov 24, 2021
21bb558
Revert "Return `Result:Err` instead of asserting"
cmichi Nov 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement comments
  • Loading branch information
cmichi committed Nov 17, 2021
commit 23e2bafeac0e7191dbfa8c533a8026f28a86c69f
29 changes: 25 additions & 4 deletions examples/proxy/lib.rs
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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
#[ink(message, payable, selector = "_")]
pub fn forward(&self) -> u32 {
ink_env::call::build_call::<ink_env::DefaultEnvironment>()
Expand All @@ -63,7 +79,12 @@ pub mod proxy {
.gas_limit(0)
.transferred_value(self.env().transferred_balance())
Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

.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"
);
Expand Down