Grand_Factory.sol 4.3 KB

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