-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinitialized_example.sw
43 lines (39 loc) · 1 KB
/
initialized_example.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
contract;
use standards::src5::{SRC5, State};
/// The owner of this contract at deployment.
#[allow(dead_code)]
const INITIAL_OWNER: Identity = Identity::Address(Address::zero());
storage {
/// The owner in storage.
owner: State = State::Initialized(INITIAL_OWNER),
}
impl SRC5 for Contract {
/// Returns the owner.
///
/// # Return Values
///
/// * [State] - Represents the state of ownership for this contract.
///
/// # Number of Storage Accesses
///
/// * Reads: `1`
///
/// # Examples
///
/// ```sway
/// use src5::SRC5;
///
/// fn foo(contract_id: ContractId) {
/// let ownership_abi = abi(contract_id, SRC_5);
///
/// match ownership_abi.owner() {
/// State::Initialized(owner) => log("The ownership is initialized"),
/// _ => log("This example will never reach this statement"),
/// }
/// }
/// ```
#[storage(read)]
fn owner() -> State {
storage.owner.read()
}
}