github.com/aerth/aquachain@v1.4.1/contracts/ens/contract/PublicResolver.sol (about) 1 pragma solidity ^0.4.0; 2 3 import './AbstractENS.sol'; 4 5 /** 6 * A simple resolver anyone can use; only allows the owner of a node to set its 7 * address. 8 */ 9 contract PublicResolver { 10 bytes4 constant INTERFACE_META_ID = 0x01ffc9a7; 11 bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de; 12 bytes4 constant CONTENT_INTERFACE_ID = 0xd8389dc5; 13 bytes4 constant NAME_INTERFACE_ID = 0x691f3431; 14 bytes4 constant ABI_INTERFACE_ID = 0x2203ab56; 15 bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233; 16 bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c; 17 18 event AddrChanged(bytes32 indexed node, address a); 19 event ContentChanged(bytes32 indexed node, bytes32 hash); 20 event NameChanged(bytes32 indexed node, string name); 21 event ABIChanged(bytes32 indexed node, uint256 indexed contentType); 22 event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y); 23 event TextChanged(bytes32 indexed node, string indexed indexedKey, string key); 24 25 struct PublicKey { 26 bytes32 x; 27 bytes32 y; 28 } 29 30 struct Record { 31 address addr; 32 bytes32 content; 33 string name; 34 PublicKey pubkey; 35 mapping(string=>string) text; 36 mapping(uint256=>bytes) abis; 37 } 38 39 AbstractENS ens; 40 mapping(bytes32=>Record) records; 41 42 modifier only_owner(bytes32 node) { 43 if (ens.owner(node) != msg.sender) throw; 44 _; 45 } 46 47 /** 48 * Constructor. 49 * @param ensAddr The ENS registrar contract. 50 */ 51 function PublicResolver(AbstractENS ensAddr) { 52 ens = ensAddr; 53 } 54 55 /** 56 * Returns true if the resolver implements the interface specified by the provided hash. 57 * @param interfaceID The ID of the interface to check for. 58 * @return True if the contract implements the requested interface. 59 */ 60 function supportsInterface(bytes4 interfaceID) constant returns (bool) { 61 return interfaceID == ADDR_INTERFACE_ID || 62 interfaceID == CONTENT_INTERFACE_ID || 63 interfaceID == NAME_INTERFACE_ID || 64 interfaceID == ABI_INTERFACE_ID || 65 interfaceID == PUBKEY_INTERFACE_ID || 66 interfaceID == TEXT_INTERFACE_ID || 67 interfaceID == INTERFACE_META_ID; 68 } 69 70 /** 71 * Returns the address associated with an ENS node. 72 * @param node The ENS node to query. 73 * @return The associated address. 74 */ 75 function addr(bytes32 node) constant returns (address ret) { 76 ret = records[node].addr; 77 } 78 79 /** 80 * Sets the address associated with an ENS node. 81 * May only be called by the owner of that node in the ENS registry. 82 * @param node The node to update. 83 * @param addr The address to set. 84 */ 85 function setAddr(bytes32 node, address addr) only_owner(node) { 86 records[node].addr = addr; 87 AddrChanged(node, addr); 88 } 89 90 /** 91 * Returns the content hash associated with an ENS node. 92 * Note that this resource type is not standardized, and will likely change 93 * in future to a resource type based on multihash. 94 * @param node The ENS node to query. 95 * @return The associated content hash. 96 */ 97 function content(bytes32 node) constant returns (bytes32 ret) { 98 ret = records[node].content; 99 } 100 101 /** 102 * Sets the content hash associated with an ENS node. 103 * May only be called by the owner of that node in the ENS registry. 104 * Note that this resource type is not standardized, and will likely change 105 * in future to a resource type based on multihash. 106 * @param node The node to update. 107 * @param hash The content hash to set 108 */ 109 function setContent(bytes32 node, bytes32 hash) only_owner(node) { 110 records[node].content = hash; 111 ContentChanged(node, hash); 112 } 113 114 /** 115 * Returns the name associated with an ENS node, for reverse records. 116 * Defined in EIP181. 117 * @param node The ENS node to query. 118 * @return The associated name. 119 */ 120 function name(bytes32 node) constant returns (string ret) { 121 ret = records[node].name; 122 } 123 124 /** 125 * Sets the name associated with an ENS node, for reverse records. 126 * May only be called by the owner of that node in the ENS registry. 127 * @param node The node to update. 128 * @param name The name to set. 129 */ 130 function setName(bytes32 node, string name) only_owner(node) { 131 records[node].name = name; 132 NameChanged(node, name); 133 } 134 135 /** 136 * Returns the ABI associated with an ENS node. 137 * Defined in EIP205. 138 * @param node The ENS node to query 139 * @param contentTypes A bitwise OR of the ABI formats accepted by the caller. 140 * @return contentType The content type of the return value 141 * @return data The ABI data 142 */ 143 function ABI(bytes32 node, uint256 contentTypes) constant returns (uint256 contentType, bytes data) { 144 var record = records[node]; 145 for(contentType = 1; contentType <= contentTypes; contentType <<= 1) { 146 if ((contentType & contentTypes) != 0 && record.abis[contentType].length > 0) { 147 data = record.abis[contentType]; 148 return; 149 } 150 } 151 contentType = 0; 152 } 153 154 /** 155 * Sets the ABI associated with an ENS node. 156 * Nodes may have one ABI of each content type. To remove an ABI, set it to 157 * the empty string. 158 * @param node The node to update. 159 * @param contentType The content type of the ABI 160 * @param data The ABI data. 161 */ 162 function setABI(bytes32 node, uint256 contentType, bytes data) only_owner(node) { 163 // Content types must be powers of 2 164 if (((contentType - 1) & contentType) != 0) throw; 165 166 records[node].abis[contentType] = data; 167 ABIChanged(node, contentType); 168 } 169 170 /** 171 * Returns the SECP256k1 public key associated with an ENS node. 172 * Defined in EIP 619. 173 * @param node The ENS node to query 174 * @return x, y the X and Y coordinates of the curve point for the public key. 175 */ 176 function pubkey(bytes32 node) constant returns (bytes32 x, bytes32 y) { 177 return (records[node].pubkey.x, records[node].pubkey.y); 178 } 179 180 /** 181 * Sets the SECP256k1 public key associated with an ENS node. 182 * @param node The ENS node to query 183 * @param x the X coordinate of the curve point for the public key. 184 * @param y the Y coordinate of the curve point for the public key. 185 */ 186 function setPubkey(bytes32 node, bytes32 x, bytes32 y) only_owner(node) { 187 records[node].pubkey = PublicKey(x, y); 188 PubkeyChanged(node, x, y); 189 } 190 191 /** 192 * Returns the text data associated with an ENS node and key. 193 * @param node The ENS node to query. 194 * @param key The text data key to query. 195 * @return The associated text data. 196 */ 197 function text(bytes32 node, string key) constant returns (string ret) { 198 ret = records[node].text[key]; 199 } 200 201 /** 202 * Sets the text data associated with an ENS node and key. 203 * May only be called by the owner of that node in the ENS registry. 204 * @param node The node to update. 205 * @param key The key to set. 206 * @param value The text data value to set. 207 */ 208 function setText(bytes32 node, string key, string value) only_owner(node) { 209 records[node].text[key] = value; 210 TextChanged(node, key, key); 211 } 212 }