updated TestToken to include approveAndCall like SNT contract
This commit is contained in:
parent
d213d4cbad
commit
7c8b4eda72
|
@ -0,0 +1,5 @@
|
|||
pragma solidity ^0.4.11;
|
||||
|
||||
contract ApprovalReceiver {
|
||||
function receiveApproval(address from, uint value, address tokenContract, bytes extraData) returns (bool);
|
||||
}
|
|
@ -20,14 +20,23 @@ contract StandardToken is ERC20Token {
|
|||
return transfer(msg.sender, _to, _value);
|
||||
}
|
||||
|
||||
function approve(address _spender, uint256 _value)
|
||||
external
|
||||
returns (bool success)
|
||||
{
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
emit Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender.
|
||||
* @param _spender The address which will spend the funds.
|
||||
* @param _value The amount of tokens to be spent.
|
||||
*/
|
||||
function approve(address _spender, uint256 _value) returns (bool) {
|
||||
|
||||
// To change the approve amount you first have to reduce the addresses`
|
||||
// allowance to zero by calling `approve(_spender, 0)` if it is not
|
||||
// already 0 to mitigate the race condition described here:
|
||||
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
|
||||
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
|
||||
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function transferFrom(
|
||||
address _from,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
pragma solidity ^0.4.23;
|
||||
|
||||
import "./StandardToken.sol";
|
||||
import './ApprovalReceiver.sol';
|
||||
|
||||
/**
|
||||
* @notice ERC20Token for test scripts, can be minted by anyone.
|
||||
|
@ -16,4 +17,10 @@ contract TestToken is StandardToken {
|
|||
function mint(uint256 _amount) public {
|
||||
mint(msg.sender, _amount);
|
||||
}
|
||||
|
||||
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
|
||||
assert(approve(_spender, _value));
|
||||
return ApprovalReceiver(_spender).receiveApproval(msg.sender, _value, this, _extraData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue