Last active
August 18, 2017 07:13
-
-
Save naterush/53dbc1b187e1ad18f28872ee5f50d4e9 to your computer and use it in GitHub Desktop.
In token contracts where tokens can only be held by permissioned owners, this allows for a backing token. Trades at the price of the real token - risk of having account seized for bad behavior :~)
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
pragma solidity ^0.4.15; | |
import "./MembersOnly.sol"; | |
contract AndSomeNonMembers { | |
MembersOnly token; | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
function AndSomeNonMembers(address _tokenAdd) { | |
token = MembersOnly(_tokenAdd); | |
balances[msg.sender] = token.balanceOf(msg.sender); | |
} | |
function transfer(address _to, uint256 _value) returns (bool success) { | |
require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]); | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { | |
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]); | |
balances[_to] += _value; | |
balances[_from] -= _value; | |
allowed[_from][msg.sender] -= _value; | |
return true; | |
} | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
return true; | |
} | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
// Finalizes transfer in the actual members only contract | |
function finalizeTransfer(address _to, uint _value) constant returns (bool success) { | |
require(balances[msg.sender] >= _value); | |
balances[msg.sender] -= _value; | |
if (token.transfer(_to, _value)) { | |
return true; | |
} else { | |
throw; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment