Created
March 14, 2017 16:23
-
-
Save yoninachmany/22aa6f4e3c5e2b0eaa0d202982033230 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.8; | |
/// Contract that follows ERC token standard (https://github.com/ethereum/EIPs/issues/20). | |
contract YCash { | |
uint256 supply; | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowances; | |
bool isApproved; | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
function YCash(uint256 totalSupply) { | |
supply = totalSupply; | |
balances[msg.sender] = totalSupply; | |
} | |
/// Get the total token supply. | |
function totalSupply() constant returns (uint256 totalSupply) { | |
return supply; | |
} | |
/// Get the account balance of another account with address _owner | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
/// Send _value amount of tokens to address _to | |
function transfer(address _to, uint256 _value) returns (bool success) { | |
if (balances[msg.sender] < _value) return false; | |
if (_value < 0) return false; | |
// Novel property: can only send values divisble by 2 | |
if (_value % 2 != 0) return false; | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/// Send _value amount of tokens from address _from to address _to | |
// The transferFrom method is used for a withdraw workflow, allowing | |
// contracts to send tokens on your behalf, for example to "deposit" to a | |
// contract address and/or to charge fees in sub-currencies; the command | |
// should fail unless the _from account has deliberately authorized the | |
// sender of the message via some mechanism; we propose these standardized | |
// APIs for approval: | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { | |
if (balances[_from] < _value) return false; | |
if (_value < 0) return false; | |
// Novel property: can only send values divisble by 2 | |
if (_value % 2 != 0) return false; | |
isApproved = approve(_to, _value); | |
Approval(_from, _to, _value); | |
if (!isApproved) return false; | |
if (allowance(msg.sender, _to) < _value) return false; | |
balances[_from] -= _value; | |
balances[_to] += _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} | |
/// Allow _spender to withdraw from your account, multiple times, up to the | |
/// _value amount. If this function is called again it overwrites the | |
/// current allowance with _value. | |
function approve(address _spender, uint256 _value) returns (bool success) { | |
if (!isApproved) { | |
if (allowances[msg.sender][_spender] < _value) return false; | |
if (_value < 0) return false; | |
isApproved = true; | |
return true; | |
} else { | |
if (_value < 0) return false; | |
allowances[msg.sender][_spender] = _value; | |
return true; | |
} | |
} | |
/// Returns the amount which _spender is still allowed to withdraw from _owner | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | |
return allowances[_owner][_spender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment