update PublicResolver contract to support multihash

This commit is contained in:
Barry Gitarts 2018-08-23 11:34:42 -04:00
parent 23a53ec0f1
commit 2db113a390
2 changed files with 35 additions and 10 deletions

View File

@ -18,6 +18,7 @@
"deploy": true
},
"PublicResolver": {
"args": ["$ENSRegistry"],
"deploy": true
},
"ENSSubdomainRegistry": {
@ -77,7 +78,7 @@
"address": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
},
"PublicResolver": {
"address": "0x5FfC014343cd971B7eb70732021E26C35B744cc4"
"address": "0x29754bADB2640b98F6deF0f52D41418b0d2e0C51"
},
"TestToken": {
"address": "0xc55cF4B03948D7EBc8b9E8BAD92643703811d162"

View File

@ -1,6 +1,6 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.18;
import "./ENS.sol";
import './ENS.sol';
/**
* A simple resolver anyone can use; only allows the owner of a node to set its
@ -15,6 +15,7 @@ contract PublicResolver {
bytes4 constant ABI_INTERFACE_ID = 0x2203ab56;
bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233;
bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c;
bytes4 constant MULTIHASH_INTERFACE_ID = 0xe89401a1;
event AddrChanged(bytes32 indexed node, address a);
event ContentChanged(bytes32 indexed node, bytes32 hash);
@ -22,6 +23,7 @@ contract PublicResolver {
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
event TextChanged(bytes32 indexed node, string indexedKey, string key);
event MultihashChanged(bytes32 indexed node, bytes hash);
struct PublicKey {
bytes32 x;
@ -35,6 +37,7 @@ contract PublicResolver {
PublicKey pubkey;
mapping(string=>string) text;
mapping(uint256=>bytes) abis;
bytes multihash;
}
ENS ens;
@ -50,7 +53,7 @@ contract PublicResolver {
* Constructor.
* @param ensAddr The ENS registrar contract.
*/
constructor(ENS ensAddr) public {
function PublicResolver(ENS ensAddr) public {
ens = ensAddr;
}
@ -62,7 +65,7 @@ contract PublicResolver {
*/
function setAddr(bytes32 node, address addr) public only_owner(node) {
records[node].addr = addr;
emit AddrChanged(node, addr);
AddrChanged(node, addr);
}
/**
@ -75,7 +78,18 @@ contract PublicResolver {
*/
function setContent(bytes32 node, bytes32 hash) public only_owner(node) {
records[node].content = hash;
emit ContentChanged(node, hash);
ContentChanged(node, hash);
}
/**
* Sets the multihash associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param hash The multihash to set
*/
function setMultihash(bytes32 node, bytes hash) public only_owner(node) {
records[node].multihash = hash;
MultihashChanged(node, hash);
}
/**
@ -86,7 +100,7 @@ contract PublicResolver {
*/
function setName(bytes32 node, string name) public only_owner(node) {
records[node].name = name;
emit NameChanged(node, name);
NameChanged(node, name);
}
/**
@ -102,7 +116,7 @@ contract PublicResolver {
require(((contentType - 1) & contentType) == 0);
records[node].abis[contentType] = data;
emit ABIChanged(node, contentType);
ABIChanged(node, contentType);
}
/**
@ -113,7 +127,7 @@ contract PublicResolver {
*/
function setPubkey(bytes32 node, bytes32 x, bytes32 y) public only_owner(node) {
records[node].pubkey = PublicKey(x, y);
emit PubkeyChanged(node, x, y);
PubkeyChanged(node, x, y);
}
/**
@ -125,7 +139,7 @@ contract PublicResolver {
*/
function setText(bytes32 node, string key, string value) public only_owner(node) {
records[node].text[key] = value;
emit TextChanged(node, key, key);
TextChanged(node, key, key);
}
/**
@ -188,6 +202,15 @@ contract PublicResolver {
return records[node].content;
}
/**
* Returns the multihash associated with an ENS node.
* @param node The ENS node to query.
* @return The associated multihash.
*/
function multihash(bytes32 node) public view returns (bytes) {
return records[node].multihash;
}
/**
* Returns the address associated with an ENS node.
* @param node The ENS node to query.
@ -209,6 +232,7 @@ contract PublicResolver {
interfaceID == ABI_INTERFACE_ID ||
interfaceID == PUBKEY_INTERFACE_ID ||
interfaceID == TEXT_INTERFACE_ID ||
interfaceID == MULTIHASH_INTERFACE_ID ||
interfaceID == INTERFACE_META_ID;
}
}