-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathERC20.sol
175 lines (139 loc) · 4.73 KB
/
ERC20.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
/*
file: ERC20.sol
ver: 0.2.6
updated:20-Apr-2018
author: Darryl Morris
contributors: terraflops
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>.
*/
pragma solidity ^0.4.18;
import "./Math.sol";
import "./Base.sol";
// ERC20 Standard Token Interface with safe maths and reentry protection
contract ERC20Interface
{
/* Structs */
/* Constants */
string constant public VERSION = "ERC20 0.2.6-o0ragman0o";
/* State Valiables */
uint public totalSupply;
uint8 public decimalPlaces;
string public name;
string public symbol;
// Token ownership mapping
mapping (address => uint) balance;
// Transfer allowances mapping
mapping (address => mapping (address => uint)) public allowance;
/* 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 */
/* State variable Accessor Functions (for reference - leave commented) */
// Returns the allowable transfer of tokens by a proxy
// function allowance (address tokenHolders, address proxy, uint allowance) public view returns (uint);
// Get the total token supply
// function totalSupply() public view returns (uint);
// Returns token symbol
// function symbol() public view returns(string);
// Returns token symbol
// function name() public view returns(string);
// Returns decimal places designated for unit of token.
// function decimalPlaces() public returns(uint);
// Send _value amount of tokens to address _to
// function transfer(address _to, uint256 _value) public returns (bool success);
// Send _value amount of tokens from address _from to address _to
// function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
// Allow _spender to withdraw from your account, multiple times, up to the
// _value amount.
// function approve(address _spender, uint256 _value) public returns (bool success);
}
contract ERC20Token is Base, Math, ERC20Interface
{
/* Events */
/* Structs */
/* Constants */
/* State Valiables */
/* Modifiers */
modifier isAvailable(uint _amount) {
require(_amount <= balance[msg.sender]);
_;
}
modifier isAllowed(address _from, uint _amount) {
require(_amount <= allowance[_from][msg.sender] &&
_amount <= balance[_from]);
_;
}
/* Funtions Public */
function ERC20Token(
uint _supply,
uint8 _decimalPlaces,
string _symbol,
string _name) public
{
totalSupply = _supply;
decimalPlaces = _decimalPlaces;
symbol = _symbol;
name = _name;
balance[msg.sender] = totalSupply;
}
function balanceOf(address _addr)
public
constant
returns (uint)
{
return balance[_addr];
}
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
external
canEnter
isAvailable(_value)
returns (bool)
{
balance[msg.sender] = safeSub(balance[msg.sender], _value);
balance[_to] = safeAdd(balance[_to], _value);
Transfer(msg.sender, _to, _value);
return true;
}
// Send _value amount of tokens from address _from to address _to
function transferFrom(address _from, address _to, uint256 _value)
external
canEnter
isAllowed(_from, _value)
returns (bool)
{
balance[_from] = safeSub(balance[_from], _value);
balance[_to] = safeAdd(balance[_to], _value);
allowance[_from][msg.sender] = safeSub(allowance[_from][msg.sender], _value);
Transfer(msg.sender, _to, _value);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the
// _value amount. If this function is called again it overwrites the current
// allowance with _value.
function approve(address _spender, uint256 _value)
external
canEnter
returns (bool success)
{
require(balance[msg.sender] != 0);
allowance[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
}