-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0x138a8752093f4f9a79aaedf48d4b9248fab93c9c-MCI-Musiconomi.sol
221 lines (160 loc) · 6.68 KB
/
0x138a8752093f4f9a79aaedf48d4b9248fab93c9c-MCI-Musiconomi.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
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;
}
}
contract IERC20Token {
function totalSupply() constant returns (uint256 totalSupply);
function balanceOf(address _owner) constant returns (uint256 balance) {}
function transfer(address _to, uint256 _value) returns (bool success) {}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
function approve(address _spender, uint256 _value) returns (bool success) {}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract ItokenRecipient {
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);
}
contract IToken {
function totalSupply() constant returns (uint256 totalSupply);
function mintTokens(address _to, uint256 _amount) {}
}
contract IMintableToken {
function mintTokens(address _to, uint256 _amount){}
}
contract Owned {
address public owner;
address public newOwner;
function Owned() {
owner = msg.sender;
}
modifier onlyOwner {
assert(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
require(_newOwner != owner);
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
OwnerUpdate(owner, newOwner);
owner = newOwner;
newOwner = 0x0;
}
event OwnerUpdate(address _prevOwner, address _newOwner);
}
contract Lockable is Owned{
uint256 public lockedUntilBlock;
event ContractLocked(uint256 _untilBlock, string _reason);
modifier lockAffected {
require(block.number > lockedUntilBlock);
_;
}
function lockFromSelf(uint256 _untilBlock, string _reason) internal {
lockedUntilBlock = _untilBlock;
ContractLocked(_untilBlock, _reason);
}
function lockUntil(uint256 _untilBlock, string _reason) onlyOwner {
lockedUntilBlock = _untilBlock;
ContractLocked(_untilBlock, _reason);
}
}
contract ReentrnacyHandlingContract{
bool locked;
modifier noReentrancy() {
require(!locked);
locked = true;
_;
locked = false;
}
}
contract MusiconomiToken is IERC20Token, Owned, Lockable{
using SafeMath for uint256;
/* Public variables of the token */
string public standard = "Musiconomi token v1.0";
string public name = "Musiconomi";
string public symbol = "MCI";
uint8 public decimals = 18;
address public crowdsaleContractAddress;
/* Private variables of the token */
uint256 supply = 0;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowances;
/* Events */
event Mint(address indexed _to, uint256 _value);
/* Initializes contract */
function MusiconomiToken() { // TO-DO: set block lock
crowdsaleContractAddress = 0xB9e0FC2a1C9d567Af555E07E72f27E686f2c6872;
lockFromSelf(4342900, "Lock before crowdsale starts");
}
/* Returns total supply of issued tokens */
function totalSupply() constant returns (uint256) {
return supply;
}
/* Returns balance of address */
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/* Transfers tokens from your address to other */
function transfer(address _to, uint256 _value) lockAffected returns (bool success) {
require(_to != 0x0 && _to != address(this));
balances[msg.sender] = balances[msg.sender].sub(_value); // Deduct senders balance
balances[_to] = balances[_to].add(_value); // Add recivers blaance
Transfer(msg.sender, _to, _value); // Raise Transfer event
return true;
}
/* Approve other address to spend tokens on your account */
function approve(address _spender, uint256 _value) lockAffected returns (bool success) {
allowances[msg.sender][_spender] = _value; // Set allowance
Approval(msg.sender, _spender, _value); // Raise Approval event
return true;
}
/* Approve and then communicate the approved contract in a single tx */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) lockAffected returns (bool success) {
ItokenRecipient spender = ItokenRecipient(_spender); // Cast spender to tokenRecipient contract
approve(_spender, _value); // Set approval to contract for _value
spender.receiveApproval(msg.sender, _value, this, _extraData); // Raise method on _spender contract
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) lockAffected returns (bool success) {
require(_to != 0x0 && _to != address(this));
balances[_from] = balances[_from].sub(_value); // Deduct senders balance
balances[_to] = balances[_to].add(_value); // Add recipient blaance
allowances[_from][msg.sender] = allowances[_from][msg.sender].sub(_value); // Deduct allowance for this address
Transfer(_from, _to, _value); // Raise Transfer event
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowances[_owner][_spender];
}
function mintTokens(address _to, uint256 _amount) {
require(msg.sender == crowdsaleContractAddress);
supply = supply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(0x0, _to, _amount);
}
function salvageTokensFromContract(address _tokenAddress, address _to, uint _amount) onlyOwner{
IERC20Token(_tokenAddress).transfer(_to, _amount);
}
}