solidity/test/compilationTests/zeppelin/token/LimitedTransferToken.sol

58 lines
2.2 KiB
Solidity
Raw Normal View History

2017-07-05 10:28:15 +00:00
pragma solidity ^0.4.11;
import "./ERC20.sol";
/**
* @title LimitedTransferToken
* @dev LimitedTransferToken defines the generic interface and the implementation to limit token
* transferability for different events. It is intended to be used as a base class for other token
* contracts.
2017-07-05 10:28:15 +00:00
* LimitedTransferToken has been designed to allow for different limiting factors,
* this can be achieved by recursively calling super.transferableTokens() until the base class is
2017-07-05 10:28:15 +00:00
* hit. For example:
2018-07-02 09:14:28 +00:00
* function transferableTokens(address holder, uint64 time) view public returns (uint256) {
2017-07-05 10:28:15 +00:00
* return min256(unlockedTokens, super.transferableTokens(holder, time));
* }
* A working example is VestedToken.sol:
* https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/VestedToken.sol
*/
contract LimitedTransferToken is ERC20 {
/**
* @dev Checks whether it can transfer or otherwise throws.
*/
modifier canTransfer(address _sender, uint256 _value) {
if (_value > transferableTokens(_sender, uint64(now))) revert();
2017-07-05 10:28:15 +00:00
_;
}
/**
* @dev Checks modifier and allows transfer if tokens are not locked.
* @param _to The address that will receive the tokens.
2017-07-05 10:28:15 +00:00
* @param _value The amount of tokens to be transferred.
*/
2018-07-04 17:20:51 +00:00
function transfer(address _to, uint256 _value) canTransfer(msg.sender, _value) public {
2017-07-05 10:28:15 +00:00
super.transfer(_to, _value);
}
/**
* @dev Checks modifier and allows transfer if tokens are not locked.
* @param _from The address that will send the tokens.
* @param _to The address that will receive the tokens.
2017-07-05 10:28:15 +00:00
* @param _value The amount of tokens to be transferred.
*/
2018-07-04 17:20:51 +00:00
function transferFrom(address _from, address _to, uint256 _value) public canTransfer(_from, _value) {
2017-07-05 10:28:15 +00:00
super.transferFrom(_from, _to, _value);
}
/**
* @dev Default transferable tokens function returns all tokens for a holder (no limit).
* @dev Overwriting transferableTokens(address holder, uint64 time) is the way to provide the
2017-07-05 10:28:15 +00:00
* specific logic for limiting token transferability for a holder over time.
*/
2018-07-02 09:14:28 +00:00
function transferableTokens(address holder, uint64 time) view public returns (uint256) {
2017-07-05 10:28:15 +00:00
return balanceOf(holder);
}
}