Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity >=0.4.22 <0.6.0;
- contract tokens {
- address owner;
- uint256 rate;
- mapping (address => uint256) token;
- uint256 totalBalance;
- constructor(uint256 x) public
- {
- if (x==0)
- {
- x = 1;
- }
- rate = x;
- owner = msg.sender;
- }
- function () external payable
- {
- token[msg.sender] += msg.value * rate;
- totalBalance += msg.value * rate;
- }
- function showBalance(address tokenOwner) public returns (uint256)
- {
- return token[tokenOwner];
- }
- function changeRate(uint256 x) public
- {
- require (msg.sender == owner);
- if (x==0)
- {
- x = 1;
- }
- rate = x;
- }
- function getMoney() public
- {
- require (msg.sender == owner);
- (msg.sender).transfer(totalBalance);
- totalBalance = 0;
- }
- function totalSupply() public view returns (uint)
- {
- return totalBalance;
- }
- function balanceOf(address tokenOwner) public view returns (uint)
- {
- return token[tokenOwner];
- }
- function transferFrom(address from, address to, uint amount) public returns (bool success)
- {
- require(msg.sender == from);
- if (token[from] < amount)
- {
- return false;
- }
- else
- {
- token[to] += amount;
- token[from] -= amount;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement