Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. pragma solidity >=0.4.22 <0.6.0;
  2. contract tokens {
  3.  
  4. address owner;
  5. uint256 rate;
  6. mapping (address => uint256) token;
  7. uint256 totalBalance;
  8.  
  9. constructor(uint256 x) public
  10. {
  11. if (x==0)
  12. {
  13. x = 1;
  14. }
  15. rate = x;
  16. owner = msg.sender;
  17. }
  18.  
  19. function () external payable
  20. {
  21. token[msg.sender] += msg.value * rate;
  22. totalBalance += msg.value * rate;
  23. }
  24.  
  25. function showBalance(address tokenOwner) public returns (uint256)
  26. {
  27. return token[tokenOwner];
  28. }
  29.  
  30. function changeRate(uint256 x) public
  31. {
  32. require (msg.sender == owner);
  33. if (x==0)
  34. {
  35. x = 1;
  36. }
  37. rate = x;
  38. }
  39.  
  40. function getMoney() public
  41. {
  42. require (msg.sender == owner);
  43. (msg.sender).transfer(totalBalance);
  44. totalBalance = 0;
  45. }
  46.  
  47. function totalSupply() public view returns (uint)
  48. {
  49. return totalBalance;
  50. }
  51.  
  52. function balanceOf(address tokenOwner) public view returns (uint)
  53. {
  54. return token[tokenOwner];
  55. }
  56.  
  57. function transferFrom(address from, address to, uint amount) public returns (bool success)
  58. {
  59. require(msg.sender == from);
  60. if (token[from] < amount)
  61. {
  62. return false;
  63. }
  64. else
  65. {
  66. token[to] += amount;
  67. token[from] -= amount;
  68. }
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement