-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0xe5a7c12972f3bbfe70ed29521c8949b8af6a0970-BLX-Blockchain_Index.sol
239 lines (203 loc) · 5.75 KB
/
0xe5a7c12972f3bbfe70ed29521c8949b8af6a0970-BLX-Blockchain_Index.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
pragma solidity ^0.4.10;
contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
/// @title ICONOMI Daa token
contract DaaToken {
//
// events
//
// ERC20 events
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
// mint/burn events
event Mint(address indexed _to, uint256 _amount, uint256 _newTotalSupply);
event Burn(address indexed _from, uint256 _amount, uint256 _newTotalSupply);
// admin events
event BlockLockSet(uint256 _value);
event NewOwner(address _newOwner);
event NewMinter(address _minter);
modifier onlyOwner {
if (msg.sender == owner) {
_;
}
}
modifier minterOrOwner {
if (msg.sender == minter || msg.sender == owner) {
_;
}
}
modifier blockLock(address _sender) {
if (!isLocked() || _sender == owner) {
_;
}
}
modifier validTransfer(address _from, address _to, uint256 _amount) {
if (isTransferValid(_from, _to, _amount)) {
_;
}
}
uint256 public totalSupply;
string public name;
uint8 public decimals;
string public symbol;
string public version = '0.0.1';
address public owner;
address public minter;
uint256 public lockedUntilBlock;
function DaaToken(
string _tokenName,
uint8 _decimalUnits,
string _tokenSymbol,
uint256 _lockedUntilBlock
) {
name = _tokenName;
decimals = _decimalUnits;
symbol = _tokenSymbol;
lockedUntilBlock = _lockedUntilBlock;
owner = msg.sender;
}
function transfer(address _to, uint256 _value)
public
blockLock(msg.sender)
validTransfer(msg.sender, _to, _value)
returns (bool success)
{
// transfer tokens
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value)
public
returns (bool success)
{
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value)
public
blockLock(_from)
validTransfer(_from, _to, _value)
returns (bool success)
{
// check sufficient allowance
if (_value > allowed[_from][msg.sender]) {
return false;
}
// transfer tokens
balances[_from] -= _value;
balances[_to] += _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData)
public
returns (bool success)
{
if (approve(_spender, _value)) {
tokenRecipient(_spender).receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
/// @notice Mint new tokens. Can only be called by minter or owner
function mint(address _to, uint256 _value)
public
minterOrOwner
blockLock(msg.sender)
returns (bool success)
{
// ensure _value is greater than zero and
// doesn't overflow
if (totalSupply + _value <= totalSupply) {
return false;
}
balances[_to] += _value;
totalSupply += _value;
Mint(_to, _value, totalSupply);
Transfer(0x0, _to, _value);
return true;
}
/// @notice Burn tokens. Can be called by any account
function burn(uint256 _value)
public
blockLock(msg.sender)
returns (bool success)
{
if (_value == 0 || _value > balances[msg.sender]) {
return false;
}
balances[msg.sender] -= _value;
totalSupply -= _value;
Burn(msg.sender, _value, totalSupply);
Transfer(msg.sender, 0x0, _value);
return true;
}
/// @notice Set block lock. Until that block (exclusive) transfers are disallowed
function setBlockLock(uint256 _lockedUntilBlock)
public
onlyOwner
returns (bool success)
{
lockedUntilBlock = _lockedUntilBlock;
BlockLockSet(_lockedUntilBlock);
return true;
}
/// @notice Replace current owner with new one
function replaceOwner(address _newOwner)
public
onlyOwner
returns (bool success)
{
owner = _newOwner;
NewOwner(_newOwner);
return true;
}
/// @notice Set account that can mint new tokens
function setMinter(address _newMinter)
public
onlyOwner
returns (bool success)
{
minter = _newMinter;
NewMinter(_newMinter);
return true;
}
function balanceOf(address _owner)
public
constant
returns (uint256 balance)
{
return balances[_owner];
}
function allowance(address _owner, address _spender)
public
constant
returns (uint256 remaining)
{
return allowed[_owner][_spender];
}
/// @notice Are transfers currently disallowed
function isLocked()
public
constant
returns (bool success)
{
return lockedUntilBlock > block.number;
}
/// @dev Checks if transfer parameters are valid
function isTransferValid(address _from, address _to, uint256 _amount)
private
constant
returns (bool isValid)
{
return balances[_from] >= _amount && // sufficient balance
_amount > 0 && // amount is positive
_to != address(this) && // prevent sending tokens to contract
_to != 0x0 // prevent sending token to 0x0 address
;
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
}