-
Notifications
You must be signed in to change notification settings - Fork 50
/
owned.sw
59 lines (51 loc) · 1.46 KB
/
owned.sw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
contract;
use std::execution::run_external;
use standards::src5::{AccessError, State};
use standards::src14::{SRC14, SRC14_TARGET_STORAGE, SRC14Extension};
/// The owner of this contract at deployment.
#[allow(dead_code)]
const INITIAL_OWNER: Identity = Identity::Address(Address::zero());
storage {
SRC14 {
/// The [ContractId] of the target contract.
///
/// # Additional Information
///
/// `target` is stored at sha256("storage_SRC14_0")
target in 0x7bb458adc1d118713319a5baa00a2d049dd64d2916477d2688d76970c898cd55: ContractId = ContractId::zero(),
/// The [State] of the proxy owner.
owner: State = State::Initialized(INITIAL_OWNER),
},
}
impl SRC14 for Contract {
#[storage(read, write)]
fn set_proxy_target(new_target: ContractId) {
only_owner();
storage::SRC14.target.write(new_target);
}
#[storage(read)]
fn proxy_target() -> Option<ContractId> {
storage::SRC14.target.try_read()
}
}
impl SRC14Extension for Contract {
#[storage(read)]
fn proxy_owner() -> State {
storage::SRC14.owner.read()
}
}
#[fallback]
#[storage(read)]
fn fallback() {
// pass through any other method call to the target
run_external(storage::SRC14.target.read())
}
#[storage(read)]
fn only_owner() {
require(
storage::SRC14
.owner
.read() == State::Initialized(msg_sender().unwrap()),
AccessError::NotOwner,
);
}