contracts.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package registrar
  17. const ( // built-in contracts address source code and evm code
  18. UrlHintCode = "0x60c180600c6000396000f30060003560e060020a90048063300a3bbf14601557005b6024600435602435604435602a565b60006000f35b6000600084815260200190815260200160002054600160a060020a0316600014806078575033600160a060020a03166000600085815260200190815260200160002054600160a060020a0316145b607f5760bc565b336000600085815260200190815260200160002081905550806001600085815260200190815260200160002083610100811060b657005b01819055505b50505056"
  19. UrlHintSrc = `
  20. contract URLhint {
  21. function register(uint256 _hash, uint8 idx, uint256 _url) {
  22. if (owner[_hash] == 0 || owner[_hash] == msg.sender) {
  23. owner[_hash] = msg.sender;
  24. url[_hash][idx] = _url;
  25. }
  26. }
  27. mapping (uint256 => address) owner;
  28. (uint256 => uint256[256]) url;
  29. }
  30. `
  31. HashRegCode = "0x609880600c6000396000f30060003560e060020a9004806331e12c2014601f578063d66d6c1014602b57005b6025603d565b60006000f35b6037600435602435605d565b60006000f35b600054600160a060020a0316600014605357605b565b336000819055505b565b600054600160a060020a031633600160a060020a031614607b576094565b8060016000848152602001908152602001600020819055505b505056"
  32. HashRegSrc = `
  33. contract HashReg {
  34. function setowner() {
  35. if (owner == 0) {
  36. owner = msg.sender;
  37. }
  38. }
  39. function register(uint256 _key, uint256 _content) {
  40. if (msg.sender == owner) {
  41. content[_key] = _content;
  42. }
  43. }
  44. address owner;
  45. mapping (uint256 => uint256) content;
  46. }
  47. `
  48. GlobalRegistrarSrc = `
  49. //sol
  50. import "owned";
  51. contract NameRegister {
  52. function addr(bytes32 _name) constant returns (address o_owner) {}
  53. function name(address _owner) constant returns (bytes32 o_name) {}
  54. }
  55. contract Registrar is NameRegister {
  56. event Changed(bytes32 indexed name);
  57. event PrimaryChanged(bytes32 indexed name, address indexed addr);
  58. function owner(bytes32 _name) constant returns (address o_owner) {}
  59. function addr(bytes32 _name) constant returns (address o_address) {}
  60. function subRegistrar(bytes32 _name) constant returns (address o_subRegistrar) {}
  61. function content(bytes32 _name) constant returns (bytes32 o_content) {}
  62. function name(address _owner) constant returns (bytes32 o_name) {}
  63. }
  64. contract GlobalRegistrar is Registrar {
  65. struct Record {
  66. address owner;
  67. address primary;
  68. address subRegistrar;
  69. bytes32 content;
  70. uint value;
  71. uint renewalDate;
  72. }
  73. function Registrar() {
  74. // TODO: Populate with hall-of-fame.
  75. }
  76. function reserve(bytes32 _name) {
  77. // Don't allow the same name to be overwritten.
  78. // TODO: bidding mechanism
  79. if (m_toRecord[_name].owner == 0) {
  80. m_toRecord[_name].owner = msg.sender;
  81. Changed(_name);
  82. }
  83. }
  84. /*
  85. TODO
  86. > 12 chars: free
  87. <= 12 chars: auction:
  88. 1. new names are auctioned
  89. - 7 day period to collect all bid bytes32es + deposits
  90. - 1 day period to collect all bids to be considered (validity requires associated deposit to be >10% of bid)
  91. - all valid bids are burnt except highest - difference between that and second highest is returned to winner
  92. 2. remember when last auctioned/renewed
  93. 3. anyone can force renewal process:
  94. - 7 day period to collect all bid bytes32es + deposits
  95. - 1 day period to collect all bids & full amounts - bids only uncovered if sufficiently high.
  96. - 1% of winner burnt; original owner paid rest.
  97. */
  98. modifier onlyrecordowner(bytes32 _name) { if (m_toRecord[_name].owner == msg.sender) _ }
  99. function transfer(bytes32 _name, address _newOwner) onlyrecordowner(_name) {
  100. m_toRecord[_name].owner = _newOwner;
  101. Changed(_name);
  102. }
  103. function disown(bytes32 _name) onlyrecordowner(_name) {
  104. if (m_toName[m_toRecord[_name].primary] == _name)
  105. {
  106. PrimaryChanged(_name, m_toRecord[_name].primary);
  107. m_toName[m_toRecord[_name].primary] = "";
  108. }
  109. delete m_toRecord[_name];
  110. Changed(_name);
  111. }
  112. function setAddress(bytes32 _name, address _a, bool _primary) onlyrecordowner(_name) {
  113. m_toRecord[_name].primary = _a;
  114. if (_primary)
  115. {
  116. PrimaryChanged(_name, _a);
  117. m_toName[_a] = _name;
  118. }
  119. Changed(_name);
  120. }
  121. function setSubRegistrar(bytes32 _name, address _registrar) onlyrecordowner(_name) {
  122. m_toRecord[_name].subRegistrar = _registrar;
  123. Changed(_name);
  124. }
  125. function setContent(bytes32 _name, bytes32 _content) onlyrecordowner(_name) {
  126. m_toRecord[_name].content = _content;
  127. Changed(_name);
  128. }
  129. function owner(bytes32 _name) constant returns (address) { return m_toRecord[_name].owner; }
  130. function addr(bytes32 _name) constant returns (address) { return m_toRecord[_name].primary; }
  131. // function subRegistrar(bytes32 _name) constant returns (address) { return m_toRecord[_name].subRegistrar; } // TODO: bring in on next iteration.
  132. function register(bytes32 _name) constant returns (address) { return m_toRecord[_name].subRegistrar; } // only possible for now
  133. function content(bytes32 _name) constant returns (bytes32) { return m_toRecord[_name].content; }
  134. function name(address _owner) constant returns (bytes32 o_name) { return m_toName[_owner]; }
  135. mapping (address => bytes32) m_toName;
  136. mapping (bytes32 => Record) m_toRecord;
  137. }
  138. `
  139. GlobalRegistrarAbi = `[{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"content","outputs":[{"name":"","type":"bytes32"}],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_registrar","type":"address"}],"name":"setSubRegistrar","outputs":[],"type":"function"},{"constant":false,"inputs":[],"name":"Registrar","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_a","type":"address"},{"name":"_primary","type":"bool"}],"name":"setAddress","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_content","type":"bytes32"}],"name":"setContent","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"disown","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"register","outputs":[{"name":"","type":"address"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"}],"name":"Changed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"addr","type":"address"}],"name":"PrimaryChanged","type":"event"}]`
  140. GlobalRegistrarCode = `0x610b408061000e6000396000f3006000357c01000000000000000000000000000000000000000000000000000000009004806301984892146100b357806302571be3146100ce5780632dff6941146100ff5780633b3b57de1461011a578063432ced041461014b5780635a3a05bd1461016257806379ce9fac1461019357806389a69c0e146101b0578063b9f37c86146101cd578063be99a980146101de578063c3d014d614610201578063d93e75731461021e578063e1fa8e841461023557005b6100c4600480359060200150610b02565b8060005260206000f35b6100df6004803590602001506109f3565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b610110600480359060200150610ad4565b8060005260206000f35b61012b600480359060200150610a3e565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b61015c600480359060200150610271565b60006000f35b610173600480359060200150610266565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6101aa600480359060200180359060200150610341565b60006000f35b6101c7600480359060200180359060200150610844565b60006000f35b6101d860045061026e565b60006000f35b6101fb6004803590602001803590602001803590602001506106de565b60006000f35b61021860048035906020018035906020015061092c565b60006000f35b61022f600480359060200150610429565b60006000f35b610246600480359060200150610a89565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b60005b919050565b5b565b60006001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561033d57336001600050600083815260200190815260200160002060005060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550807fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b5b50565b813373ffffffffffffffffffffffffffffffffffffffff166001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561042357816001600050600085815260200190815260200160002060005060000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550827fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b505b5050565b803373ffffffffffffffffffffffffffffffffffffffff166001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156106d95781600060005060006001600050600086815260200190815260200160002060005060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000505414156105fd576001600050600083815260200190815260200160002060005060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16827ff63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a85456040604090036040a36000600060005060006001600050600086815260200190815260200160002060005060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055505b6001600050600083815260200190815260200160002060006000820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160005060009055600482016000506000905560058201600050600090555050817fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b505b50565b823373ffffffffffffffffffffffffffffffffffffffff166001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561083d57826001600050600086815260200190815260200160002060005060010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055508115610811578273ffffffffffffffffffffffffffffffffffffffff16847ff63780e752c6a54a94fc52715dbc5518a3b4c3c2833d301a204226548a2a85456040604090036040a383600060005060008573ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050819055505b837fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b505b505050565b813373ffffffffffffffffffffffffffffffffffffffff166001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561092657816001600050600085815260200190815260200160002060005060020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550827fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b505b5050565b813373ffffffffffffffffffffffffffffffffffffffff166001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156109ed57816001600050600085815260200190815260200160002060005060030160005081905550827fa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc6040604090036040a25b505b5050565b60006001600050600083815260200190815260200160002060005060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050610a39565b919050565b60006001600050600083815260200190815260200160002060005060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050610a84565b919050565b60006001600050600083815260200190815260200160002060005060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050610acf565b919050565b600060016000506000838152602001908152602001600020600050600301600050549050610afd565b919050565b6000600060005060008373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050549050610b3b565b91905056`
  141. )