-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0xc0eb85285d83217cd7c891702bcbc0fc401e2d9d-HVN-Hive_Project_Token.sol
389 lines (329 loc) · 11.4 KB
/
0xc0eb85285d83217cd7c891702bcbc0fc401e2d9d-HVN-Hive_Project_Token.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/**
* ERC-20 Standard Token Smart Contract implementation.
*
* Copyright © 2017 by Hive Project Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND (express or implied).
*/
pragma solidity ^0.4.11;
/**
* ERC-20 Standard Token Smart Contract Interface.
*
* Copyright © 2017 by Hive Project Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND (express or implied).
*/
/**
* ERC-20 standard token interface, as defined
* <a href="http://github.com/ethereum/EIPs/issues/20">here</a>.
*/
contract ERC20Interface {
/**
* Get total number of tokens in circulation.
*/
uint256 public totalSupply;
/**
* @dev Get number of tokens currently belonging to given owner.
*
* @param _owner address to get number of tokens currently belonging to the
* owner of
* @return number of tokens currently belonging to the owner of given address
*/
function balanceOf (address _owner) constant returns (uint256 balance);
/**
* @dev Transfer given number of tokens from message sender to given recipient.
*
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer to the owner of given address
* @return true if tokens were transferred successfully, false otherwise
*/
function transfer (address _to, uint256 _value) returns (bool success);
/**
* @dev Transfer given number of tokens from given owner to given recipient.
*
* @param _from address to transfer tokens from the owner of
* @param _to address to transfer tokens to the owner of
* @param _value number of tokens to transfer from given owner to given
* recipient
* @return true if tokens were transferred successfully, false otherwise
*/
function transferFrom (address _from, address _to, uint256 _value)
returns (bool success);
/**
* @dev Allow given spender to transfer given number of tokens from message sender.
*
* @param _spender address to allow the owner of to transfer tokens from
* message sender
* @param _value number of tokens to allow to transfer
* @return true if token transfer was successfully approved, false otherwise
*/
function approve (address _spender, uint256 _value) returns (bool success);
/**
* @dev Tell how many tokens given spender is currently allowed to transfer from
* given owner.
*
* @param _owner address to get number of tokens allowed to be transferred
* from the owner of
* @param _spender address to get number of tokens allowed to be transferred
* by the owner of
* @return number of tokens given spender is currently allowed to transfer
* from given owner
*/
function allowance (address _owner, address _spender) constant
returns (uint256 remaining);
/**
* @dev Logged when tokens were transferred from one owner to another.
*
* @param _from address of the owner, tokens were transferred from
* @param _to address of the owner, tokens were transferred to
* @param _value number of tokens transferred
*/
event Transfer (address indexed _from, address indexed _to, uint256 _value);
/**
* @dev Logged when owner approved his tokens to be transferred by some spender.
*
* @param _owner owner who approved his tokens to be transferred
* @param _spender spender who were allowed to transfer the tokens belonging
* to the owner
* @param _value number of tokens belonging to the owner, approved to be
* transferred by the spender
*/
event Approval (
address indexed _owner, address indexed _spender, uint256 _value);
}
contract Owned {
address public owner;
address public newOwner;
function Owned() {
owner = msg.sender;
}
modifier ownerOnly {
assert(msg.sender == owner);
_;
}
/**
* @dev Transfers ownership. New owner has to accept in order ownership change to take effect
*/
function transferOwnership(address _newOwner) public ownerOnly {
require(_newOwner != owner);
newOwner = _newOwner;
}
/**
* @dev Accepts transferred ownership
*/
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnerUpdate(owner, newOwner);
owner = newOwner;
newOwner = 0x0;
}
event OwnerUpdate(address _prevOwner, address _newOwner);
}
/**
* Safe Math Smart Contract.
*
* Copyright © 2017 by Hive Project Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND (express or implied).
*/
/**
* Provides methods to safely add, subtract and multiply uint256 numbers.
*/
contract SafeMath {
/**
* @dev Add two uint256 values, throw in case of overflow.
*
* @param a first value to add
* @param b second value to add
* @return x + y
*/
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
/**
* @dev Subtract one uint256 value from another, throw in case of underflow.
*
* @param a value to subtract from
* @param b value to subtract
* @return a - b
*/
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Multiply two uint256 values, throw in case of overflow.
*
* @param a first value to multiply
* @param b second value to multiply
* @return c = a * b
*/
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
/**
* @dev Divide two uint256 values, throw in case of overflow.
*
* @param a first value to divide
* @param b second value to divide
* @return c = a / b
*/
function div(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a / b;
return c;
}
}
/*
* TokenRecepient
*
* Copyright © 2017 by Hive Project Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND (express or implied).
*/
contract TokenRecipient {
/**
* receive approval
*/
function receiveApproval(address _from, uint256 _value, address _to, bytes _extraData);
}
/**
* Standard Token Smart Contract that implements ERC-20 token interface
*/
contract HVNToken is ERC20Interface, SafeMath, Owned {
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
string public constant name = "Hive Project Token";
string public constant symbol = "HVN";
uint8 public constant decimals = 8;
string public version = '0.0.2';
bool public transfersFrozen = false;
/**
* Protection against short address attack
*/
modifier onlyPayloadSize(uint numwords) {
assert(msg.data.length == numwords * 32 + 4);
_;
}
/**
* Check if transfers are on hold - frozen
*/
modifier whenNotFrozen(){
if (transfersFrozen) revert();
_;
}
function HVNToken() ownerOnly {
totalSupply = 50000000000000000;
balances[owner] = totalSupply;
}
/**
* Freeze token transfers.
*/
function freezeTransfers () ownerOnly {
if (!transfersFrozen) {
transfersFrozen = true;
Freeze (msg.sender);
}
}
/**
* Unfreeze token transfers.
*/
function unfreezeTransfers () ownerOnly {
if (transfersFrozen) {
transfersFrozen = false;
Unfreeze (msg.sender);
}
}
/**
* Transfer sender's tokens to a given address
*/
function transfer(address _to, uint256 _value) whenNotFrozen onlyPayloadSize(2) returns (bool success) {
require(_to != 0x0);
balances[msg.sender] = sub(balances[msg.sender], _value);
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer _from's tokens to _to's address
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotFrozen onlyPayloadSize(3) returns (bool success) {
require(_to != 0x0);
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value);
balances[_from] = sub(balances[_from], _value);
balances[_to] += _value;
allowed[_from][msg.sender] = sub(allowed[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
/**
* Returns number of tokens owned by given address.
*/
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/**
* Sets approved amount of tokens for spender.
*/
function approve(address _spender, uint256 _value) returns (bool success) {
require(_value == 0 || allowed[msg.sender][_spender] == 0);
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* Approve and then communicate the approved contract in a single transaction
*/
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
TokenRecipient spender = TokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/**
* Returns number of allowed tokens for given address.
*/
function allowance(address _owner, address _spender) onlyPayloadSize(2) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* Peterson's Law Protection
* Claim tokens
*/
function claimTokens(address _token) ownerOnly {
if (_token == 0x0) {
owner.transfer(this.balance);
return;
}
HVNToken token = HVNToken(_token);
uint balance = token.balanceOf(this);
token.transfer(owner, balance);
Transfer(_token, owner, balance);
}
event Freeze (address indexed owner);
event Unfreeze (address indexed owner);
}