-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-contract.sol
67 lines (58 loc) · 1.99 KB
/
simple-contract.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";
import "@openzeppelin/[email protected]/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";
contract MyToken is ERC20, ERC20Burnable, Ownable {
address[] private _frozenAddresses;
constructor() ERC20("TestToken2", "TST2") {
_mint(msg.sender, 1000 * 10 ** decimals());
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
* - the 'to' or 'from' is not belong to frozen list.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
require(!isFrozen(owner));
require(!isFrozen(to));
_transfer(owner, to, amount);
return true;
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
/* 验证是否属于冻结地址 */
function isFrozen(address account) public view returns(bool) {
for (uint i = 0; i < _frozenAddresses.length; i++){
if (account == _frozenAddresses[i]){
return true;
}
}
return false;
}
/* 添加冻结地址 */
function setFrozenAccount(address account, bool status)public returns(bool) {
for (uint i = 0; i < _frozenAddresses.length; i++){
if (account == _frozenAddresses[i]){
if (status == true){ // 存在 且 允许
// pop
_frozenAddresses[i] = _frozenAddresses[_frozenAddresses.length - 1];
_frozenAddresses.pop();
break;
}
}
}
// 不存在
if (status == false){
// push
_frozenAddresses.push(account);
}
return true;
}
}