Standard_With_Owner_And_Create.sol 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Adds possibility for owner to mint new tokens.
  3. */
  4. contract Coin {
  5. function sendCoin(uint _value, address _to) returns (bool _success) {}
  6. function sendCoinFrom(address _from, uint _value, address _to) returns (bool _success) {}
  7. function coinBalance() constant returns (uint _r) {}
  8. function coinBalanceOf(address _addr) constant returns (uint _r) {}
  9. function approve(address _addr) {}
  10. function approveOnce(address _addr, uint256 _maxValue) {}
  11. function unapprove(address _addr) {}
  12. function isApproved(address _proxy) constant returns (bool _r) {}
  13. function isApprovedFor(address _target, address _proxy) constant returns (bool _r) {}
  14. }
  15. contract Token is Coin {
  16. function Token(uint _initialAmount) {
  17. balances[msg.sender] = _initialAmount;
  18. }
  19. event CoinTransfer(address indexed from, address indexed to, uint256 value);
  20. event AddressApproval(address indexed from, address indexed to, bool result);
  21. event AddressApprovalOnce(address indexed from, address indexed to, uint256 value);
  22. function sendCoin(uint _value, address _to) returns (bool _success) {
  23. if (balances[msg.sender] >= _value) {
  24. balances[msg.sender] -= _value;
  25. balances[_to] += _value;
  26. CoinTransfer(msg.sender, _to, _value);
  27. return true;
  28. } else { return false; }
  29. }
  30. function sendCoinFrom(address _from, uint _value, address _to) returns (bool _success) {
  31. if (balances[_from] >= _value) {
  32. bool transfer = false;
  33. if(approved[_from][msg.sender]) {
  34. transfer = true;
  35. } else {
  36. if(_value < approved_once[_from][msg.sender]) {
  37. transfer = true;
  38. approved_once[_from][msg.sender] = 0; //reset
  39. }
  40. }
  41. if(transfer == true) {
  42. balances[_from] -= _value;
  43. balances[_to] += _value;
  44. CoinTransfer(_from, _to, _value);
  45. return true;
  46. } else { return false; }
  47. }
  48. }
  49. function coinBalance() constant returns (uint _r) {
  50. return balances[msg.sender];
  51. }
  52. function coinBalanceOf(address _addr) constant returns (uint _r) {
  53. return balances[_addr];
  54. }
  55. function approve(address _addr) {
  56. approved[msg.sender][_addr] = true;
  57. AddressApproval(msg.sender, _addr, true);
  58. }
  59. function approveOnce(address _addr, uint256 _maxValue) {
  60. approved_once[msg.sender][_addr] = _maxValue;
  61. AddressApprovalOnce(msg.sender, _addr, _maxValue);
  62. }
  63. function unapprove(address _addr) {
  64. approved[msg.sender][_addr] = false;
  65. approved_once[msg.sender][_addr] = 0;
  66. AddressApproval(msg.sender, _addr, false);
  67. AddressApprovalOnce(msg.sender, _addr, 0);
  68. }
  69. function isApproved(address _proxy) constant returns (bool _r) {
  70. if(approved[msg.sender][_proxy] == true || approved_once[msg.sender][_proxy] > 0) {
  71. return true;
  72. }
  73. }
  74. function isApprovedFor(address _target, address _proxy) constant returns (bool _r) {
  75. if(approved[_target][_proxy] == true || approved_once[_target][_proxy] > 0) {
  76. return true;
  77. }
  78. }
  79. mapping (address => uint) public balances;
  80. mapping (address => mapping (address => bool)) public approved;
  81. mapping (address => mapping (address => uint256)) public approved_once;
  82. }
  83. import "owned"; //standard library
  84. contract Token_With_Owner_And_Create is Token, owned {
  85. modifier isOwner {
  86. if(msg.sender == owner) {
  87. _
  88. }
  89. }
  90. function createToken(address _for, uint256 _value) isOwner {
  91. balances[_for] += _value;
  92. }
  93. }