@@ -7,6 +7,17 @@ import "../abstracts/extensions/FreezeBalance.sol";
7
7
import "../abstracts/extensions/FreezeToken.sol " ;
8
8
9
9
contract MockForest is ForestToken , FreezeAddress , FreezeBalance , FreezeToken {
10
+ enum RESTRICT_TYPES { NULL, EQUAL, LESS, GREATER, BETWEEN }
11
+
12
+ struct Restrict {
13
+ RESTRICT_TYPES types;
14
+ bool enable;
15
+ uint256 start;
16
+ uint256 end;
17
+ }
18
+
19
+ mapping (bytes32 => Restrict) private _restricts;
20
+
10
21
/// @custom:event for keep tracking token from root.
11
22
event Transfer (address from , address to , bytes32 indexed root , bytes32 indexed parent , uint256 value );
12
23
@@ -20,30 +31,51 @@ contract MockForest is ForestToken, FreezeAddress, FreezeBalance, FreezeToken {
20
31
_;
21
32
}
22
33
23
- // TODO
24
- // modifier checkFrozenLevel(bytes32 tokenId) {
25
- // check root equal check equal
26
- // _;
27
- // }
28
-
29
- // TODO
30
- // modifier checkFrozenBeforeLevel(bytes32 tokenId)
31
- // check root equal and check less than
32
- // _;
33
- // }
34
+ modifier checkFrozenLevel (bytes32 tokenId ) {
35
+ Restrict memory restrict = getPartition (tokenId);
36
+ if (restrict.types == RESTRICT_TYPES.EQUAL && (restrict.enable)) {
37
+ if (transactionLevel (tokenId) == restrict.start) {
38
+ revert TokenFrozen ();
39
+ }
40
+ }
41
+ _;
42
+ }
34
43
35
- // TODO
36
- // modifier checkFrozenAfterLevel(bytes32 tokenId)
37
- // check root equal check greater than
38
- // _;
39
- // }
44
+ modifier checkFrozenBeforeLevel (bytes32 tokenId ) {
45
+ Restrict memory restrict = getPartition (tokenId);
46
+ if (restrict.types == RESTRICT_TYPES.LESS && (restrict.enable)) {
47
+ if (transactionLevel (tokenId) < restrict.start) {
48
+ revert TokenFrozen ();
49
+ }
50
+ }
51
+ _;
52
+ }
53
+
54
+ modifier checkFrozenAfterLevel (bytes32 tokenId ) {
55
+ Restrict memory restrict = getPartition (tokenId);
56
+ uint256 txLevel = transactionLevel (tokenId);
57
+ if (restrict.types == RESTRICT_TYPES.GREATER && (restrict.enable)) {
58
+ if (transactionLevel (tokenId) > restrict.start && txLevel < restrict.end) {
59
+ revert TokenFrozen ();
60
+ }
61
+ }
62
+ _;
63
+ }
40
64
41
- // TODO
42
- // modifier checkFrozenInBetweenLevel(bytes32 tokenId)
65
+ /** @dev restrict in partitioning style */
66
+ modifier checkFrozenInBetweenLevel (bytes32 tokenId ) {
43
67
// check root equal check greater than 'x' and less than 'y'
44
- // _;
45
- // }
46
-
68
+ Restrict memory restrict = getPartition (tokenId);
69
+ uint256 txLevel = transactionLevel (tokenId);
70
+ if (restrict.types == RESTRICT_TYPES.BETWEEN && (restrict.enable)) {
71
+ if (txLevel > restrict.start && txLevel < restrict.end) {
72
+ revert TokenFrozen ();
73
+ }
74
+ }
75
+ _;
76
+ }
77
+
78
+ /** @notice ERC20 Transfer also emit. */
47
79
function _transfer (
48
80
address from ,
49
81
address to ,
@@ -58,7 +90,7 @@ contract MockForest is ForestToken, FreezeAddress, FreezeBalance, FreezeToken {
58
90
checkFrozenRootOrParent (tokenId)
59
91
checkFrozenToken (tokenId)
60
92
{
61
- /// @notice ERC20 Transfer also emit.
93
+
62
94
super ._transfer (from, to, tokenId, value);
63
95
Forest.Tx memory txn = _transaction (tokenId);
64
96
emit Transfer (from, to, txn.root, txn.parent, value);
@@ -71,4 +103,20 @@ contract MockForest is ForestToken, FreezeAddress, FreezeBalance, FreezeToken {
71
103
function burn (address account , bytes32 tokenId , uint256 value ) public {
72
104
_burnTransaction (account, tokenId, value);
73
105
}
106
+
107
+ function setPartition (bytes32 tokenId , uint256 start , uint256 end , RESTRICT_TYPES restrict ) public {
108
+ bytes32 rootTokenId = transactionRoot (tokenId);
109
+ _restricts[rootTokenId].types = restrict;
110
+ _restricts[rootTokenId].enable = true ;
111
+ _restricts[rootTokenId].start = start;
112
+ _restricts[rootTokenId].end = end;
113
+ }
114
+
115
+ function clearPartition (bytes32 tokenId ) public {
116
+ delete _restricts[transactionRoot (tokenId)];
117
+ }
118
+
119
+ function getPartition (bytes32 tokenId ) public view returns (Restrict memory ) {
120
+ return _restricts[transactionRoot (tokenId)];
121
+ }
74
122
}
0 commit comments