-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SmartToken contract with tests and documentation
- Loading branch information
Showing
5 changed files
with
459 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
pragma solidity ^0.4.13; | ||
|
||
import "./StandardToken.sol"; | ||
|
||
/** | ||
@title SmartToken, an extension of ERC20 token standard | ||
Implementation the SmartToken, following the ERC20 standard with extra | ||
methods to transfer value and data and execute calls in transfers and | ||
approvals. | ||
Uses OpenZeppelin StandardToken. | ||
*/ | ||
contract SmartToken is StandardToken { | ||
|
||
/** | ||
@dev `approveData` is an addition to ERC20 token methods. It allows to | ||
approve the transfer of value and execute a call with the sent data. | ||
Beware that changing an allowance with this method brings the risk that | ||
someone may use both the old and the new allowance by unfortunate | ||
transaction ordering. One possible solution to mitigate this race condition | ||
is to first reduce the spender's allowance to 0 and set the desired value | ||
afterwards: | ||
https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | ||
@param _spender The address that will spend the funds. | ||
@param _value The amount of tokens to be spent. | ||
@param _data ABI-encoded contract call to call `_to` address. | ||
@return true if the call function was executed successfully | ||
*/ | ||
function approveData(address _spender, uint256 _value, bytes _data) returns (bool) { | ||
require(_spender != address(this)); | ||
|
||
super.approve(_spender, _value); | ||
|
||
require(_spender.call(_data)); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
@dev Addition to ERC20 token methods. Transfer tokens to a specified | ||
address and execute a call with the sent data on the same transaction | ||
@param _to address The address which you want to transfer to | ||
@param _value uint256 the amout of tokens to be transfered | ||
@param _data ABI-encoded contract call to call `_to` address. | ||
@return true if the call function was executed successfully | ||
*/ | ||
function transferData(address _to, uint256 _value, bytes _data) public returns (bool) { | ||
require(_to != address(this)); | ||
|
||
require(_to.call(_data)); | ||
|
||
super.transfer(_to, _value); | ||
return true; | ||
} | ||
|
||
/** | ||
@dev Addition to ERC20 token methods. Transfer tokens from one address to | ||
another and make a contract call on the same transaction | ||
@param _from The address which you want to send tokens from | ||
@param _to The address which you want to transfer to | ||
@param _value The amout of tokens to be transferred | ||
@param _data ABI-encoded contract call to call `_to` address. | ||
@return true if the call function was executed successfully | ||
*/ | ||
function transferDataFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) { | ||
require(_to != address(this)); | ||
|
||
require(_to.call(_data)); | ||
|
||
super.transferFrom(_from, _to, _value); | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SmartToken | ||
============================================= | ||
|
||
Inherits from contract StandardToken. Implementation of a ERC20 compatible token with methods to transfer value and execute calls in transfers and approvals (see https://github.com/ethereum/EIPs/issues/20) | ||
|
||
approveData(address _spender, uint _value, bytes _data) returns (bool success) | ||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
It allows to approve the transfer of value and execute a call with the sent data. | ||
|
||
function transferData(address _to, uint _value, bytes _data) returns (bool success) | ||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
Transfer tokens to a specified address and execute a call with the sent data on the same transaction | ||
|
||
transferDataFrom(address _from, address _to, uint _value, bytes _data) returns (bool success) | ||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | ||
Transfer tokens from one address to another and make a contract call on the same transaction |
Oops, something went wrong.