You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
8 years ago
|
pragma solidity ^0.4.8;
|
||
|
|
||
|
import "./ERC20.sol";
|
||
|
|
||
8 years ago
|
/*
|
||
|
|
||
8 years ago
|
LimitedTransferToken defines the generic interface and the implementation
|
||
8 years ago
|
to limit token transferability for different events.
|
||
|
|
||
|
It is intended to be used as a base class for other token contracts.
|
||
|
|
||
|
Over-writting transferableTokens(address holder, uint64 time) is the way to provide
|
||
|
the specific logic for limitting token transferability for a holder over time.
|
||
|
|
||
8 years ago
|
LimitedTransferToken has been designed to allow for different limitting factors,
|
||
8 years ago
|
this can be achieved by recursively calling super.transferableTokens() until the
|
||
|
base class is hit. For example:
|
||
|
|
||
|
function transferableTokens(address holder, uint64 time) constant public returns (uint256) {
|
||
|
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
|
||
|
|
||
|
*/
|
||
|
|
||
8 years ago
|
contract LimitedTransferToken is ERC20 {
|
||
8 years ago
|
// Checks whether it can transfer or otherwise throws.
|
||
8 years ago
|
modifier canTransfer(address _sender, uint _value) {
|
||
|
if (_value > transferableTokens(_sender, uint64(now))) throw;
|
||
|
_;
|
||
|
}
|
||
|
|
||
8 years ago
|
// Checks modifier and allows transfer if tokens are not locked.
|
||
8 years ago
|
function transfer(address _to, uint _value) canTransfer(msg.sender, _value) returns (bool success) {
|
||
|
return super.transfer(_to, _value);
|
||
|
}
|
||
|
|
||
8 years ago
|
// Checks modifier and allows transfer if tokens are not locked.
|
||
8 years ago
|
function transferFrom(address _from, address _to, uint _value) canTransfer(_from, _value) returns (bool success) {
|
||
|
return super.transferFrom(_from, _to, _value);
|
||
|
}
|
||
|
|
||
8 years ago
|
// Default transferable tokens function returns all tokens for a holder (no limit).
|
||
8 years ago
|
function transferableTokens(address holder, uint64 time) constant public returns (uint256) {
|
||
|
return balanceOf(holder);
|
||
|
}
|
||
|
}
|