Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2. import "./ERC20interface.sol";
  3.  
  4. contract FixedSupplyToken is ERC20Interface {
  5. string public constant symbol = "FIXED";
  6. string public constant name = "EXE token";
  7. uint8 public constant decimals = 18;
  8. uint constant MAX_UINT = 2**256 - 1;
  9. uint256 _totalSupply = MAX_UINT;
  10. // Owner of this contract
  11. address public owner;
  12. // Balances for each account
  13. mapping(address => uint256) balances;
  14. // Owner of account approves the transfer of an amount to another account
  15. mapping(address => mapping (address => uint256)) allowed;
  16. // Functions with this modifier can only be executed by the owner
  17. modifier onlyOwner() {
  18. // if (msg.sender != owner) {
  19. // revert(); ony available in 4.x version truffle
  20. // }
  21. if (msg.sender != owner) throw;
  22. _;
  23. }
  24. // Constructor
  25. function FixedSupplyToken() public {
  26. owner = msg.sender;
  27. balances[owner] = _totalSupply;
  28. }
  29. function totalSupply() public constant returns (uint256 totalSupplyReturn) {
  30. totalSupplyReturn = _totalSupply;
  31. }
  32. // What is the balance of a particular account?
  33. function balanceOf(address _owner) public constant returns (uint256 balance) {
  34. return balances[_owner];
  35. }
  36. // Transfer the balance from owner's account to another account
  37. function transfer(address _to, uint256 _amount) public returns (bool success) {
  38. if (balances[msg.sender] >= _amount
  39. && _amount > 0
  40. && balances[_to] + _amount > balances[_to]) {
  41. balances[msg.sender] -= _amount;
  42. balances[_to] += _amount;
  43. Transfer(msg.sender, _to, _amount);
  44. return true;
  45. } else {
  46. return false;
  47. }
  48. }
  49. // Send _value amount of tokens from address _from to address _to
  50. // The transferFrom method is used for a withdraw workflow, allowing contracts to send
  51. // tokens on your behalf, for example to "deposit" to a contract address and/or to charge
  52. // fees in sub-currencies; the command should fail unless the _from account has
  53. // deliberately authorized the sender of the message via some mechanism; we propose
  54. // these standardized APIs for approval:
  55. function transferFrom(
  56. address _from,
  57. address _to,
  58. uint256 _amount
  59. ) public onlyOwner returns (bool success) { //&& allowed[_from][msg.sender] >= _amount. And without onlyOwner
  60. if (balances[_from] >= _amount
  61. && _amount > 0
  62. && balances[_to] + _amount > balances[_to]) {
  63. balances[_from] -= _amount;
  64. // allowed[_from][msg.sender] -= _amount;
  65. balances[_to] += _amount;
  66. Transfer(_from, _to, _amount);
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
  73. // If this function is called again it overwrites the current allowance with _value.
  74. function approve(address _spender, uint256 _amount) public returns (bool success) {
  75. allowed[msg.sender][_spender] = _amount;
  76. Approval(msg.sender, _spender, _amount);
  77. return true;
  78. }
  79. function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
  80. return allowed[_owner][_spender];
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement