@@ -9,6 +9,10 @@ import "../../math/SafeMath.sol";
9
9
* @dev Implementation of the basic standard token.
10
10
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
11
11
* Originally based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
12
+ *
13
+ * This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
14
+ * all accounts just by listening to said events. Note that this isn't required by the specification, and other
15
+ * compliant implementations may not do it.
12
16
*/
13
17
contract ERC20 is IERC20 {
14
18
using SafeMath for uint256 ;
@@ -73,14 +77,17 @@ contract ERC20 is IERC20 {
73
77
}
74
78
75
79
/**
76
- * @dev Transfer tokens from one address to another
80
+ * @dev Transfer tokens from one address to another.
81
+ * Note that while this function emits an Approval event, this is not required as per the specification,
82
+ * and other compliant implementations may not emit the event.
77
83
* @param from address The address which you want to send tokens from
78
84
* @param to address The address which you want to transfer to
79
85
* @param value uint256 the amount of tokens to be transferred
80
86
*/
81
87
function transferFrom (address from , address to , uint256 value ) public returns (bool ) {
82
88
_allowed[from][msg .sender ] = _allowed[from][msg .sender ].sub (value);
83
89
_transfer (from, to, value);
90
+ emit Approval (from, msg .sender , _allowed[from][msg .sender ]);
84
91
return true ;
85
92
}
86
93
@@ -90,6 +97,7 @@ contract ERC20 is IERC20 {
90
97
* allowed value is better to use this function to avoid 2 calls (and wait until
91
98
* the first transaction is mined)
92
99
* From MonolithDAO Token.sol
100
+ * Emits an Approval event.
93
101
* @param spender The address which will spend the funds.
94
102
* @param addedValue The amount of tokens to increase the allowance by.
95
103
*/
@@ -107,6 +115,7 @@ contract ERC20 is IERC20 {
107
115
* allowed value is better to use this function to avoid 2 calls (and wait until
108
116
* the first transaction is mined)
109
117
* From MonolithDAO Token.sol
118
+ * Emits an Approval event.
110
119
* @param spender The address which will spend the funds.
111
120
* @param subtractedValue The amount of tokens to decrease the allowance by.
112
121
*/
@@ -165,13 +174,13 @@ contract ERC20 is IERC20 {
165
174
* @dev Internal function that burns an amount of the token of a given
166
175
* account, deducting from the sender's allowance for said account. Uses the
167
176
* internal burn function.
177
+ * Emits an Approval event (reflecting the reduced allowance).
168
178
* @param account The account whose tokens will be burnt.
169
179
* @param value The amount that will be burnt.
170
180
*/
171
181
function _burnFrom (address account , uint256 value ) internal {
172
- // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
173
- // this function needs to emit an event with the updated approval.
174
182
_allowed[account][msg .sender ] = _allowed[account][msg .sender ].sub (value);
175
183
_burn (account, value);
184
+ emit Approval (account, msg .sender , _allowed[account][msg .sender ]);
176
185
}
177
186
}
0 commit comments