-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifier.sol
More file actions
50 lines (40 loc) · 976 Bytes
/
Modifier.sol
File metadata and controls
50 lines (40 loc) · 976 Bytes
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Function modifier - reuse code before and / or after function
// Basic, ineuts, sandwich
contract FuncModifier {
bool public paused;
uint256 public count;
function setPause(bool _paused) external {
paused = _paused;
}
modifier whenNotPaused() {
require(!paused, "paused");
_;
}
function inc() external whenNotPaused {
// require(!paused,"paused");
count++;
}
function dec() external whenNotPaused {
// require(!paused,"paused");
count--;
}
modifier cap(uint256 x) {
require(x < 100, "x >100");
_;
}
function incBy(uint256 _x) external whenNotPaused cap(_x) {
count += _x;
}
modifier sandwich() {
// code here
count += 10;
_;
//more code here
count *= 2;
}
function foo() external sandwich {
count += 1;
}
}