Created
April 12, 2018 00:26
-
-
Save falehenrique/837608b61711c9e78d8c0987bd8b325f 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.18; | |
contract ERC20Interface { | |
function totalSupply() public constant returns (uint); | |
function balanceOf(address tokenOwner) public constant returns (uint balance); | |
function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
function transfer(address to, uint tokens) public returns (bool success); | |
function approve(address spender, uint tokens) public returns (bool success); | |
function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
event Transfer(address indexed from, address indexed to, uint tokens); | |
event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
} | |
contract GoBlockchainERC20 is ERC20Interface { | |
address public dono; | |
string public symbol; | |
string public name; | |
uint8 public decimals; | |
uint256 public _totalSupply; | |
//Henrique = 200 tokens; | |
mapping(address => uint256) balances; | |
//Henrique = (Joao = 100); | |
mapping(address => mapping(address => uint256)) allowed; | |
function GoBlockchainERC20() public { | |
symbol = "$GB"; | |
name = "Go"; | |
dono = msg.sender; | |
decimals = 0; | |
_totalSupply = 0; | |
balances[dono] = _totalSupply; | |
} | |
function () public payable { | |
uint tokens; | |
tokens = msg.value * 2; | |
balances[msg.sender] += tokens; | |
_totalSupply += tokens; | |
dono.transfer(msg.value); | |
emit Transfer(this, msg.sender, tokens); | |
} | |
function totalSupply() public view returns(uint256) { | |
return _totalSupply; | |
} | |
function balanceOf(address tokensDono) public view returns(uint256) { | |
return balances[tokensDono]; | |
} | |
// exercicio/ | |
// verificar se o msg.sender tem o saldo suficiente para liberar os tokens para o amigo | |
function approve(address _amigo, uint _qtdTokens) public returns (bool) { | |
// if (balanceOf[msg.sender] > _qtdTokens) | |
allowed[msg.sender][_amigo] = _qtdTokens; | |
return true; | |
} | |
// aplicar regras necessárias | |
function transferFrom(address _from, address _to, uint _qtdTokens) public returns (bool) { | |
balances[_from] -= _qtdTokens; | |
allowed[_from][msg.sender] -= _qtdTokens; | |
balances[_to] += _qtdTokens; | |
return true; | |
} | |
function transfer(address to, uint tokens) public returns (bool success) { | |
balances[msg.sender] -= tokens; | |
balances[to] += tokens; | |
return true; | |
} | |
function allowance (address _dono, address _amigo) public view returns(uint256 saldo) { | |
return allowed[_dono][_amigo]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment