-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0x3293cc907fde439b39aedaf1b982785adaff186b-TRIA-Tria.sol
357 lines (295 loc) · 9.7 KB
/
0x3293cc907fde439b39aedaf1b982785adaff186b-TRIA-Tria.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
pragma solidity ^0.4.11;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
/*
file: ReentryProtection.sol
ver: 0.3.0
updated:6-April-2016
author: Darryl Morris
email: o0ragman0o AT gmail.com
Mutex based reentry protection protect.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU lesser General Public License for more details.
<http://www.gnu.org/licenses/>.
*/
contract ReentryProtected
{
// The reentry protection state mutex.
bool __reMutex;
// This modifier can be used on functions with external calls to
// prevent reentry attacks.
// Constraints:
// Protected functions must have only one point of exit.
// Protected functions cannot use the `return` keyword
// Protected functions return values must be through return parameters.
modifier preventReentry() {
require(!__reMutex);
__reMutex = true;
_;
delete __reMutex;
return;
}
// This modifier can be applied to public access state mutation functions
// to protect against reentry if a `preventReentry` function has already
// set the mutex. This prevents the contract from being reenter under a
// different memory context which can break state variable integrity.
modifier noReentry() {
require(!__reMutex);
_;
}
}
/*
file: ERC20.sol
ver: 0.4.4-o0ragman0o
updated:26-July-2017
author: Darryl Morris
email: o0ragman0o AT gmail.com
An ERC20 compliant token with reentry protection and safe math.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See MIT Licence for further details.
<https://opensource.org/licenses/MIT>.
Release Notes
-------------
0.4.4-o0ragman0o
* removed state from interface
* added abstract functions of public state to interface.
* included state into contract implimentation
*/
// ERC20 Standard Token Interface with safe maths and reentry protection
contract ERC20Interface
{
/* Structs */
/* State Valiables */
/* Events */
// Triggered when tokens are transferred.
event Transfer(
address indexed _from,
address indexed _to,
uint256 _value);
// Triggered whenever approve(address _spender, uint256 _value) is called.
event Approval(
address indexed _owner,
address indexed _spender,
uint256 _value);
/* Modifiers */
/* Function Abstracts */
/// @return The total supply of tokens
function totalSupply() public constant returns (uint256);
/// @param _addr The address of a token holder
/// @return The amount of tokens held by `_addr`
function balanceOf(address _addr) public constant returns (uint256);
/// @param _owner The address of a token holder
/// @param _spender the address of a third-party
/// @return The amount of tokens the `_spender` is allowed to transfer
function allowance(address _owner, address _spender) public constant
returns (uint256);
/// @notice Send `_amount` of tokens from `msg.sender` to `_to`
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to transfer
function transfer(address _to, uint256 _amount) public returns (bool);
/// @notice Send `_amount` of tokens from `_from` to `_to` on the condition
/// it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _amount The amount of tokens to transfer
function transferFrom(address _from, address _to, uint256 _amount)
public returns (bool);
/// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
/// its behalf
/// @param _spender The address of the approved spender
/// @param _amount The amount of tokens to transfer
function approve(address _spender, uint256 _amount) public returns (bool);
}
contract ERC20Token is ReentryProtected, ERC20Interface
{
using SafeMath for uint256;
/* State */
// The Total supply of tokens
uint256 totSupply;
// Token ownership mapping
mapping (address => uint256) balance;
// Allowances mapping
mapping (address => mapping (address => uint256)) allowed;
/* Funtions Public */
function ERC20Token()
{
// Supply limited to 2^128 rather than 2^256 to prevent potential
// multiplication overflow
totSupply = 0;
balance[msg.sender] = totSupply;
}
// Using an explicit getter allows for function overloading
function totalSupply()
public
constant
returns (uint256)
{
return totSupply;
}
// Using an explicit getter allows for function overloading
function balanceOf(address _addr)
public
constant
returns (uint256)
{
return balance[_addr];
}
// Using an explicit getter allows for function overloading
function allowance(address _owner, address _spender)
public
constant
returns (uint256 remaining_)
{
return allowed[_owner][_spender];
}
// Send _value amount of tokens to address _to
// Reentry protection prevents attacks upon the state
function transfer(address _to, uint256 _value)
public
noReentry
returns (bool)
{
return xfer(msg.sender, _to, _value);
}
// Send _value amount of tokens from address _from to address _to
// Reentry protection prevents attacks upon the state
function transferFrom(address _from, address _to, uint256 _value)
public
noReentry
returns (bool)
{
require(_value <= allowed[_from][msg.sender]);
allowed[_from][msg.sender] -= _value;
return xfer(_from, _to, _value);
}
// Process a transfer internally.
function xfer(address _from, address _to, uint256 _value)
internal
returns (bool)
{
require(_value > 0 && _value <= balance[_from]);
balance[_from] -= _value;
balance[_to] += _value;
Transfer(_from, _to, _value);
return true;
}
// Approves a third-party spender
// Reentry protection prevents attacks upon the state
function approve(address _spender, uint256 _value)
public
noReentry
returns (bool)
{
require(balance[msg.sender] != 0);
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
/**
* @title Mintable token
* @dev Simple ERC20 Token example, with mintable token creation
* @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
* Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
*/
contract MintableToken is ERC20Token, Ownable {
using SafeMath for uint256;
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will recieve the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint returns (bool) {
totSupply = totSupply.add(_amount);
balance[_to] = balance[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
}
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `StandardToken` functions.
*/
contract TriaToken_v2 is MintableToken {
string public constant name = "TriaToken";
string public constant symbol = "TRIA";
uint256 public constant decimals = 10;
}