-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacet2.sol
46 lines (40 loc) · 1.25 KB
/
Facet2.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
pragma solidity ^0.8.13;
import "../../libs/Storage.sol";
contract DiamondFacet2 {
modifier onlyOnce() {
bytes32 init_slot = bytes32(
uint256(keccak256("facet2.initialized")) - 1
);
bool init = Storage.getBool(init_slot).v;
require(!init, "already initialized");
Storage.setBool(init_slot, true);
_;
}
// this must be called only once
function initialize_2() public onlyOnce {
Storage.setUint256(
bytes32(uint256(keccak256("facet2.number")) - 1),
42
);
}
// decrements a uint256 stored in a shared facet storage
function decrement_shared() public {
Storage.Uint256 storage nb = Storage.getUint256(
bytes32(uint256(keccak256("shared.number")) - 1)
);
nb.v--;
}
// decrements a uint256 stored in a dedicated facet storage
function decrement() public {
Storage.Uint256 storage nb = Storage.getUint256(
bytes32(uint256(keccak256("facet2.number")) - 1)
);
nb.v--;
}
function number_2() public view returns (uint256) {
return
Storage
.getUint256(bytes32(uint256(keccak256("facet2.number")) - 1))
.v;
}
}