-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSOCH-Token.sol
140 lines (119 loc) · 4.75 KB
/
SOCH-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
pragma solidity ^0.4.9;
import "./ReceiverInterface.sol";
import "./ERC23Interface.sol";
contract SOCHToken is ERC23 {
// Called when tokens moves between addresses
event Transfer(address indexed from, address indexed to, uint value);
// Total amount of issued tokens
uint256 public totalSupply;
// Contract Name
string public name="SoundChain token";
// Contract Symbol
string public symbol="SOCH";
// Contract decimals
uint public decimals=16;
// Balance of the accounts
mapping (address => uint256) public balances;
address public owner;
//////////////////////////////////////////////////////////////////
// PUBLIC METHODS
//////////////////////////////////////////////////////////////////
// The contract can be initialized with a number of tokens
// All the tokens are deposited to the owner address
//
// @param _balance Initial supply of the contract
// @param _name Token Name
// @param _symbol Token symbol
// @param _decimals Token decimals
function SOCHToken(uint256 _initialSupply, string _name, string _symbol, uint _decimals){
totalSupply = _initialSupply;
name = _name;
symbol = _symbol;
decimals = _decimals;
balances[owner] = _initialSupply;
}
// Return the balance of a specified address
function balanceOf(address addr) public constant returns (uint256) {
return balances[addr];
}
// Returns the total amount of issued tokens
function totalSupply() public constant returns (uint256 total) {
return totalSupply;
}
// ERC20 default transfer function that is called without data by some UI wallets
// @param to address to move funds to
// @param amount number of tokens to move
function transfer(address _to, uint256 _amount) returns (bool){
bytes memory emptyData;
if(isContract(_to)) {
return transferToContract(_to, _amount, emptyData);
}
else {
return transferToAddress(_to, _amount, emptyData);
}
}
// Transfer owned tokens to another address
// @param to address to move funds to
// @param amount number of tokens to move
// @param data special data that can be attached to transactions (could be empty)
function transfer(address _to, uint256 _amount, bytes _data) returns (bool){
if(isContract(_to)) {
return transferToContract(_to, _amount, _data);
}
else {
return transferToAddress(_to, _amount, _data);
}
}
function tokenFallback(address _from, uint _amount, bytes _data) returns (bool) {
throw;
}
// Check if the receiver is a contract or an address
// when transferring tokens.
// @param _addr address that needs to be checked
function isContract(address _addr) private constant returns (bool is_contract) {
uint length;
assembly {
//Retrieve the size of the code on target address, this needs assembly
//if there is no code length will be 0.
length := extcodesize(_addr)
}
if(length>0) {
return true;
}
else {
return false;
}
}
// Private function that actually move the tokens between addresses
// @param _to destination address
// @param _amount token to be transferred
// @param _data bytes data attached (could be empty)
function transferToAddress(address _to, uint _amount, bytes _data) private returns (bool success) {
if(balances[msg.sender] >= _amount && balances[_to] + _amount >= balances[_to]) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
Transfer(msg.sender, _to, _amount);
return true;
}
else {
return false;
}
}
// Private function that actually move the tokens between address and contract
// @param _to destination address
// @param _amount token to be transferred
// @param _data bytes data attached (could be empty)
function transferToContract(address _to, uint _amount, bytes _data) private returns (bool success) {
if(balances[msg.sender] >= _amount && balances[_to] + _amount >= balances[_to]) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
ReceiverInterface reciever = ReceiverInterface(_to);
reciever.tokenFallback(msg.sender, _amount, _data);
Transfer(msg.sender, _to, _amount);
return true;
}
else {
return false;
}
}
}