-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_Enum.sol
47 lines (38 loc) · 900 Bytes
/
7_Enum.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
//Need to express more choices then enum is a great choice
contract Enum {
//Represents a shipping status
enum Status {
None,
Pending,
Shipped,
Completed,
Rejected,
Canceled
}
//Can use state variable
Status public status;
//Can use inside a struct
struct Order {
address buyer;
Status status;
}
Order[] public orders;
//Read status
function get() view external returns(Status) {
return status;
}
//Status set
function set(Status _status) external {
status = _status;
}
//Ship status set
function ship() external {
status = Status.Shipped;
}
//Default value set
function reset() external {
delete status;
}
}