This repository has been archived by the owner on Jul 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathToken.sol
163 lines (132 loc) · 4.74 KB
/
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
pragma solidity >=0.4.4;
import 'Common.sol';
//ERC20 token
contract Token is SafeMath, Owned, Constants {
uint public totalSupply;
address ico;
address controller;
string public name;
uint8 public decimals;
string public symbol;
modifier onlyControllers() {
if (msg.sender != ico &&
msg.sender != controller) throw;
_;
}
modifier onlyPayloadSize(uint numwords) {
assert(msg.data.length == numwords * 32 + 4);
_;
}
function Token() {
owner = msg.sender;
name = "Monolith TKN";
decimals = uint8(DECIMALS);
symbol = "TKN";
}
function setICO(address _ico) onlyOwner {
if (ico != 0) throw;
ico = _ico;
}
function setController(address _controller) onlyOwner {
if (controller != 0) throw;
controller = _controller;
}
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
event Mint(address owner, uint amount);
//only called from contracts so don't need msg.data.length check
function mint(address addr, uint amount) onlyControllers {
if (maxSupply > 0 && safeAdd(totalSupply, amount) > maxSupply) throw;
balanceOf[addr] = safeAdd(balanceOf[addr], amount);
totalSupply = safeAdd(totalSupply, amount);
Mint(addr, amount);
}
mapping(address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
function transfer(address _to, uint _value)
onlyPayloadSize(2)
returns (bool success) {
if (balanceOf[msg.sender] < _value) return false;
balanceOf[msg.sender] = balanceOf[msg.sender] - _value;
balanceOf[_to] = safeAdd(balanceOf[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value)
onlyPayloadSize(3)
returns (bool success) {
if (balanceOf[_from] < _value) return false;
var allowed = allowance[_from][msg.sender];
if (allowed < _value) return false;
balanceOf[_to] = safeAdd(balanceOf[_to], _value);
balanceOf[_from] = safeSub(balanceOf[_from], _value);
allowance[_from][msg.sender] = safeSub(allowed, _value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint _value)
onlyPayloadSize(2)
returns (bool success) {
//require user to set to zero before resetting to nonzero
if ((_value != 0) && (allowance[msg.sender][_spender] != 0)) {
return false;
}
allowance[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function increaseApproval (address _spender, uint _addedValue)
onlyPayloadSize(2)
returns (bool success) {
uint oldValue = allowance[msg.sender][_spender];
allowance[msg.sender][_spender] = safeAdd(oldValue, _addedValue);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue)
onlyPayloadSize(2)
returns (bool success) {
uint oldValue = allowance[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowance[msg.sender][_spender] = 0;
} else {
allowance[msg.sender][_spender] = safeSub(oldValue, _subtractedValue);
}
return true;
}
//Holds accumulated dividend tokens other than TKN
TokenHolder tokenholder;
//once locked, can no longer upgrade tokenholder
bool lockedTokenHolder;
function lockTokenHolder() onlyOwner {
lockedTokenHolder = true;
}
//while unlocked,
//this gives owner lots of power over held dividend tokens
//effectively can deny access to all accumulated tokens
//thus crashing TKN value
function setTokenHolder(address _th) onlyOwner {
if (lockedTokenHolder) throw;
tokenholder = TokenHolder(_th);
}
event Burn(address burner, uint amount);
function burn(uint _amount) returns (bool result) {
if (_amount > balanceOf[msg.sender]) return false;
balanceOf[msg.sender] = safeSub(balanceOf[msg.sender], _amount);
totalSupply = safeSub(totalSupply, _amount);
result = tokenholder.burn(msg.sender, _amount);
if (!result) throw;
Burn(msg.sender, _amount);
}
uint public maxSupply;
function setMaxSupply(uint _maxSupply) {
if (msg.sender != controller) throw;
if (maxSupply > 0) throw;
maxSupply = _maxSupply;
}
}
contract TokenHolder {
function burn(address _burner, uint _amount)
returns (bool result) {
return false;
}
}