/
src_5.sw
58 lines (53 loc) · 1.47 KB
/
src_5.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
library;
/// Determines the state of ownership.
pub enum State {
/// The ownership has not been set.
Uninitialized: (),
/// The user which has been given ownership.
Initialized: Identity,
/// The ownership has been given up and can never be set again.
Revoked: (),
}
impl core::ops::Eq for State {
fn eq(self, other: Self) -> bool {
match (self, other) {
(State::Initialized(owner1), State::Initialized(owner2)) => {
owner1 == owner2
},
(State::Uninitialized, State::Uninitialized) => true,
(State::Revoked, State::Revoked) => true,
_ => false,
}
}
}
/// Error log for when access is denied.
pub enum AccessError {
/// Emitted when the caller is not the owner of the contract.
NotOwner: (),
}
/// Contains the ownership state.
pub struct Ownership {
/// Represents the state of ownership.
state: State,
}
abi SRC_5 {
/// Returns the owner.
///
/// # Return Values
///
/// * [State] - Represents the state of ownership for this contract.
///
/// # Examples
///
/// ```sway
/// fn foo() {
/// match owner() {
/// State::Uninitalized => log("The ownership is uninitalized"),
/// State::Initialized(owner) => log("The ownership is initalized"),
/// State::Revoked => log("The ownership is revoked"),
/// }
/// }
/// ```
#[storage(read)]
fn owner() -> State;
}