-
Notifications
You must be signed in to change notification settings - Fork 0
/
ICON.sol
254 lines (208 loc) · 6.53 KB
/
ICON.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
pragma solidity ^0.4.11;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
function Migrations() {
owner = msg.sender;
}
function setCompleted(uint completed) restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
contract ERC20 {
function totalSupply() constant returns (uint supply);
function balanceOf( address who ) constant returns (uint value);
function allowance( address owner, address spender ) constant returns (uint _allowance);
function transfer( address to, uint value) returns (bool ok);
function transferFrom( address from, address to, uint value) returns (bool ok);
function approve( address spender, uint value ) returns (bool ok);
event Transfer( address indexed from, address indexed to, uint value);
event Approval( address indexed owner, address indexed spender, uint value);
}
contract Lockable {
uint public creationTime;
bool public lock;
bool public tokenTransfer;
address public owner;
mapping( address => bool ) public unlockaddress;
mapping( address => bool ) public lockaddress;
event Locked(address lockaddress,bool status);
event Unlocked(address unlockedaddress, bool status);
// if Token transfer
modifier isTokenTransfer {
// if token transfer is not allow
if(!tokenTransfer) {
require(unlockaddress[msg.sender]);
}
_;
}
// This modifier check whether the contract should be in a locked
// or unlocked state, then acts and updates accordingly if
// necessary
modifier checkLock {
if (lockaddress[msg.sender]) {
throw;
}
_;
}
modifier isOwner {
require(owner == msg.sender);
_;
}
function Lockable() {
creationTime = now;
tokenTransfer = false;
owner = msg.sender;
}
// Lock Address
function lockAddress(address target, bool status)
external
isOwner
{
require(owner != target);
lockaddress[target] = status;
Locked(target, status);
}
// UnLock Address
function unlockAddress(address target, bool status)
external
isOwner
{
unlockaddress[target] = status;
Unlocked(target, status);
}
}
library SafeMath {
function mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
function add(uint a, uint b) internal returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
return a < b ? a : b;
}
function assert(bool assertion) internal {
if (!assertion) {
throw;
}
}
}
// ICON ICX Token
/// @author DongOk Ryu - <pop@theloop.co.kr>
contract IcxToken is ERC20, Lockable {
using SafeMath for uint;
mapping( address => uint ) _balances;
mapping( address => mapping( address => uint ) ) _approvals;
uint _supply;
address public walletAddress;
//event TokenMint(address newTokenHolder, uint amountOfTokens);
event TokenBurned(address burnAddress, uint amountOfTokens);
event TokenTransfer();
// aca esta el error! deberia ser ==
modifier onlyFromWallet {
require(msg.sender != walletAddress);
_;
}
function IcxToken( uint initial_balance, address wallet) {
require(wallet != 0);
require(initial_balance != 0);
_balances[msg.sender] = initial_balance;
_supply = initial_balance;
walletAddress = wallet;
}
function totalSupply() constant returns (uint supply) {
return _supply;
}
function balanceOf( address who ) constant returns (uint value) {
return _balances[who];
}
function allowance(address owner, address spender) constant returns (uint _allowance) {
return _approvals[owner][spender];
}
function transfer( address to, uint value)
isTokenTransfer
checkLock
returns (bool success) {
require( _balances[msg.sender] >= value );
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
Transfer( msg.sender, to, value );
return true;
}
function transferFrom( address from, address to, uint value)
isTokenTransfer
checkLock
returns (bool success) {
// if you don't have enough balance, throw
require( _balances[from] >= value );
// if you don't have approval, throw
require( _approvals[from][msg.sender] >= value );
// transfer and return true
_approvals[from][msg.sender] = _approvals[from][msg.sender].sub(value);
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
Transfer( from, to, value );
return true;
}
function approve(address spender, uint value)
isTokenTransfer
checkLock
returns (bool success) {
_approvals[msg.sender][spender] = value;
Approval( msg.sender, spender, value );
return true;
}
// burnToken burn tokensAmount for sender balance
function burnTokens(uint tokensAmount)
isTokenTransfer
external
{
require( _balances[msg.sender] >= tokensAmount );
_balances[msg.sender] = _balances[msg.sender].sub(tokensAmount);
_supply = _supply.sub(tokensAmount);
TokenBurned(msg.sender, tokensAmount);
}
function enableTokenTransfer()
external
onlyFromWallet {
tokenTransfer = true;
TokenTransfer();
}
function disableTokenTransfer()
external
onlyFromWallet {
tokenTransfer = false;
TokenTransfer();
}
}