Last active
March 24, 2018 21:12
-
-
Save scyclow/d509f4b00d484067339f9b2bd54c803a to your computer and use it in GitHub Desktop.
Adding Permissions
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.17; | |
/* | |
Copyright 2017, FastCashMoneyPlus.biz | |
This contract is for educational purposes only, and is presented WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. | |
*/ | |
contract FastCashMoneyPlusPermissions { | |
address public centralBanker; | |
function FastCashMoneyPlusPermissions() { | |
centralBanker = msg.sender; | |
} | |
modifier onlyCentralBanker() { | |
require(msg.sender == centralBanker); | |
_; | |
} | |
function setCentralBanker(address newCentralBanker) external onlyCentralBanker { | |
require(newCentralBanker != address(0)); | |
centralBanker = newCentralBanker; | |
} | |
} | |
contract FastCashMoneyPlus is FastCashMoneyPlusPermissions { | |
uint public totalSupply; | |
uint256 public fastCashBank; | |
uint public decimals = 18; | |
string public symbol = "FASTCASH"; | |
string public name = "FastCashMoneyPlus"; | |
uint public exchangeRate = 2; | |
mapping (address => uint) public balanceOf; | |
mapping (address => mapping (address => uint)) internal allowed; | |
event Approval(address indexed _owner, address indexed _spender, uint _value); | |
event Transfer(address indexed _from, address indexed _to, uint _value); | |
function FastCashMoneyPlus() { | |
totalSupply = 1000000 * 10 ** uint256(decimals); | |
fastCashBank = totalSupply; | |
} | |
function updateExchangeRate(uint _newExchangeRate) external onlyCentralBanker { | |
require(_newExchangeRate > 0); | |
exchangeRate = _newExchangeRate; | |
} | |
function weiToMoneyBucks(uint _wei) returns (uint) { | |
return _wei * exchangeRate; | |
} | |
function buy() payable returns (uint) { | |
uint _wei = msg.value; | |
uint _moneyBucks = weiToMoneyBucks(_wei); | |
require(_moneyBucks > 0); | |
require(fastCashBank >= _moneyBucks); | |
balanceOf[msg.sender] += _moneyBucks; | |
fastCashBank -= _moneyBucks; | |
centralBanker.transfer(msg.value); | |
return _moneyBucks; | |
} | |
function _transfer( | |
address _from, | |
address _to, | |
uint _amount | |
) internal returns (bool success) { | |
require(_to != address(0)); | |
require(_to != address(this)); | |
require(_amount > 0); | |
require(balanceOf[_from] >= _amount); | |
require(balanceOf[_to] + _amount > balanceOf[_to]); | |
balanceOf[_from] -= _amount; | |
balanceOf[_to] += _amount; | |
Transfer(msg.sender, _to, _amount); | |
return true; | |
} | |
function transfer(address _to, uint _amount) public returns (bool success) { | |
return _transfer(msg.sender, _to, _amount); | |
} | |
function transferFrom(address _from, address _to, uint _amount) external returns (bool success) { | |
require(allowed[_from][msg.sender] >= _amount); | |
bool _tranferSuccess = _transfer(_from, _to, _amount); | |
if (_tranferSuccess) { | |
allowed[_from][msg.sender] -= _amount; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function transferFromBank(address _to, uint _amount) external onlyCentralBanker { | |
require(_to != address(0)); | |
require(_amount > 0); | |
require(fastCashBank >= _amount); | |
require(balanceOf[_to] + _amount > balanceOf[_to]); | |
fastCashBank -= _amount; | |
balanceOf[_to] += _amount; | |
} | |
function approve(address _spender, uint _value) external returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) external constant returns (uint remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment