-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16-Modifiers-Solution.sol
40 lines (31 loc) · 868 Bytes
/
16-Modifiers-Solution.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract PausableToken {
address public owner;
bool public paused;
mapping(address => uint) public balances;
constructor() {
owner = msg.sender;
paused = false;
balances[owner] = 1000;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can perform this action");
_;
}
modifier notPaused() {
require(!paused, "Contract is paused");
_;
}
function pause() public onlyOwner {
paused = true;
}
function unpause() public onlyOwner {
paused = false;
}
function transfer(address to, uint amount) public notPaused {
require(balances[msg.sender] >= amount, "Insufficient balance");
balances[msg.sender] -= amount;
balances[to] += amount;
}
}