forked from forks/go-ethereum
contracts/ens: update public resolver solidity code
This commit is contained in:
parent
2a0e1bb32b
commit
f2aab02fcf
1 changed files with 114 additions and 114 deletions
|
|
@ -1,26 +1,27 @@
|
||||||
pragma solidity ^0.4.0;
|
pragma solidity >=0.4.25;
|
||||||
|
|
||||||
import './AbstractENS.sol';
|
import "@ensdomains/ens/contracts/ENS.sol";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple resolver anyone can use; only allows the owner of a node to set its
|
* A simple resolver anyone can use; only allows the owner of a node to set its
|
||||||
* address.
|
* address.
|
||||||
*/
|
*/
|
||||||
contract PublicResolver {
|
contract PublicResolver {
|
||||||
|
|
||||||
bytes4 constant INTERFACE_META_ID = 0x01ffc9a7;
|
bytes4 constant INTERFACE_META_ID = 0x01ffc9a7;
|
||||||
bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de;
|
bytes4 constant ADDR_INTERFACE_ID = 0x3b3b57de;
|
||||||
bytes4 constant CONTENT_INTERFACE_ID = 0xd8389dc5;
|
|
||||||
bytes4 constant NAME_INTERFACE_ID = 0x691f3431;
|
bytes4 constant NAME_INTERFACE_ID = 0x691f3431;
|
||||||
bytes4 constant ABI_INTERFACE_ID = 0x2203ab56;
|
bytes4 constant ABI_INTERFACE_ID = 0x2203ab56;
|
||||||
bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233;
|
bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233;
|
||||||
bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c;
|
bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c;
|
||||||
|
bytes4 constant CONTENTHASH_INTERFACE_ID = 0xbc1c58d1;
|
||||||
|
|
||||||
event AddrChanged(bytes32 indexed node, address a);
|
event AddrChanged(bytes32 indexed node, address a);
|
||||||
event ContentChanged(bytes32 indexed node, bytes32 hash);
|
|
||||||
event NameChanged(bytes32 indexed node, string name);
|
event NameChanged(bytes32 indexed node, string name);
|
||||||
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
|
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
|
||||||
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
|
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
|
||||||
event TextChanged(bytes32 indexed node, string indexed indexedKey, string key);
|
event TextChanged(bytes32 indexed node, string indexedKey, string key);
|
||||||
|
event ContenthashChanged(bytes32 indexed node, bytes hash);
|
||||||
|
|
||||||
struct PublicKey {
|
struct PublicKey {
|
||||||
bytes32 x;
|
bytes32 x;
|
||||||
|
|
@ -29,18 +30,19 @@ contract PublicResolver {
|
||||||
|
|
||||||
struct Record {
|
struct Record {
|
||||||
address addr;
|
address addr;
|
||||||
bytes32 content;
|
|
||||||
string name;
|
string name;
|
||||||
PublicKey pubkey;
|
PublicKey pubkey;
|
||||||
mapping(string=>string) text;
|
mapping(string=>string) text;
|
||||||
mapping(uint256=>bytes) abis;
|
mapping(uint256=>bytes) abis;
|
||||||
|
bytes contenthash;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractENS ens;
|
ENS ens;
|
||||||
mapping(bytes32=>Record) records;
|
|
||||||
|
|
||||||
modifier only_owner(bytes32 node) {
|
mapping (bytes32 => Record) records;
|
||||||
if (ens.owner(node) != msg.sender) throw;
|
|
||||||
|
modifier onlyOwner(bytes32 node) {
|
||||||
|
require(ens.owner(node) == msg.sender);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,77 +50,30 @@ contract PublicResolver {
|
||||||
* Constructor.
|
* Constructor.
|
||||||
* @param ensAddr The ENS registrar contract.
|
* @param ensAddr The ENS registrar contract.
|
||||||
*/
|
*/
|
||||||
function PublicResolver(AbstractENS ensAddr) {
|
constructor(ENS ensAddr) public {
|
||||||
ens = ensAddr;
|
ens = ensAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the resolver implements the interface specified by the provided hash.
|
|
||||||
* @param interfaceID The ID of the interface to check for.
|
|
||||||
* @return True if the contract implements the requested interface.
|
|
||||||
*/
|
|
||||||
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
|
|
||||||
return interfaceID == ADDR_INTERFACE_ID ||
|
|
||||||
interfaceID == CONTENT_INTERFACE_ID ||
|
|
||||||
interfaceID == NAME_INTERFACE_ID ||
|
|
||||||
interfaceID == ABI_INTERFACE_ID ||
|
|
||||||
interfaceID == PUBKEY_INTERFACE_ID ||
|
|
||||||
interfaceID == TEXT_INTERFACE_ID ||
|
|
||||||
interfaceID == INTERFACE_META_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the address associated with an ENS node.
|
|
||||||
* @param node The ENS node to query.
|
|
||||||
* @return The associated address.
|
|
||||||
*/
|
|
||||||
function addr(bytes32 node) constant returns (address ret) {
|
|
||||||
ret = records[node].addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the address associated with an ENS node.
|
* Sets the address associated with an ENS node.
|
||||||
* May only be called by the owner of that node in the ENS registry.
|
* May only be called by the owner of that node in the ENS registry.
|
||||||
* @param node The node to update.
|
* @param node The node to update.
|
||||||
* @param addr The address to set.
|
* @param addr The address to set.
|
||||||
*/
|
*/
|
||||||
function setAddr(bytes32 node, address addr) only_owner(node) {
|
function setAddr(bytes32 node, address addr) external onlyOwner(node) {
|
||||||
records[node].addr = addr;
|
records[node].addr = addr;
|
||||||
AddrChanged(node, addr);
|
emit AddrChanged(node, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the content hash associated with an ENS node.
|
* Sets the contenthash associated with an ENS node.
|
||||||
* Note that this resource type is not standardized, and will likely change
|
|
||||||
* in future to a resource type based on multihash.
|
|
||||||
* @param node The ENS node to query.
|
|
||||||
* @return The associated content hash.
|
|
||||||
*/
|
|
||||||
function content(bytes32 node) constant returns (bytes32 ret) {
|
|
||||||
ret = records[node].content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the content hash associated with an ENS node.
|
|
||||||
* May only be called by the owner of that node in the ENS registry.
|
* May only be called by the owner of that node in the ENS registry.
|
||||||
* Note that this resource type is not standardized, and will likely change
|
|
||||||
* in future to a resource type based on multihash.
|
|
||||||
* @param node The node to update.
|
* @param node The node to update.
|
||||||
* @param hash The content hash to set
|
* @param hash The contenthash to set
|
||||||
*/
|
*/
|
||||||
function setContent(bytes32 node, bytes32 hash) only_owner(node) {
|
function setContenthash(bytes32 node, bytes calldata hash) external onlyOwner(node) {
|
||||||
records[node].content = hash;
|
records[node].contenthash = hash;
|
||||||
ContentChanged(node, hash);
|
emit ContenthashChanged(node, hash);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name associated with an ENS node, for reverse records.
|
|
||||||
* Defined in EIP181.
|
|
||||||
* @param node The ENS node to query.
|
|
||||||
* @return The associated name.
|
|
||||||
*/
|
|
||||||
function name(bytes32 node) constant returns (string ret) {
|
|
||||||
ret = records[node].name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,28 +82,9 @@ contract PublicResolver {
|
||||||
* @param node The node to update.
|
* @param node The node to update.
|
||||||
* @param name The name to set.
|
* @param name The name to set.
|
||||||
*/
|
*/
|
||||||
function setName(bytes32 node, string name) only_owner(node) {
|
function setName(bytes32 node, string calldata name) external onlyOwner(node) {
|
||||||
records[node].name = name;
|
records[node].name = name;
|
||||||
NameChanged(node, name);
|
emit NameChanged(node, name);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ABI associated with an ENS node.
|
|
||||||
* Defined in EIP205.
|
|
||||||
* @param node The ENS node to query
|
|
||||||
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
|
|
||||||
* @return contentType The content type of the return value
|
|
||||||
* @return data The ABI data
|
|
||||||
*/
|
|
||||||
function ABI(bytes32 node, uint256 contentTypes) constant returns (uint256 contentType, bytes data) {
|
|
||||||
var record = records[node];
|
|
||||||
for(contentType = 1; contentType <= contentTypes; contentType <<= 1) {
|
|
||||||
if ((contentType & contentTypes) != 0 && record.abis[contentType].length > 0) {
|
|
||||||
data = record.abis[contentType];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contentType = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -159,22 +95,12 @@ contract PublicResolver {
|
||||||
* @param contentType The content type of the ABI
|
* @param contentType The content type of the ABI
|
||||||
* @param data The ABI data.
|
* @param data The ABI data.
|
||||||
*/
|
*/
|
||||||
function setABI(bytes32 node, uint256 contentType, bytes data) only_owner(node) {
|
function setABI(bytes32 node, uint256 contentType, bytes calldata data) external onlyOwner(node) {
|
||||||
// Content types must be powers of 2
|
// Content types must be powers of 2
|
||||||
if (((contentType - 1) & contentType) != 0) throw;
|
require(((contentType - 1) & contentType) == 0);
|
||||||
|
|
||||||
records[node].abis[contentType] = data;
|
records[node].abis[contentType] = data;
|
||||||
ABIChanged(node, contentType);
|
emit ABIChanged(node, contentType);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SECP256k1 public key associated with an ENS node.
|
|
||||||
* Defined in EIP 619.
|
|
||||||
* @param node The ENS node to query
|
|
||||||
* @return x, y the X and Y coordinates of the curve point for the public key.
|
|
||||||
*/
|
|
||||||
function pubkey(bytes32 node) constant returns (bytes32 x, bytes32 y) {
|
|
||||||
return (records[node].pubkey.x, records[node].pubkey.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -183,19 +109,9 @@ contract PublicResolver {
|
||||||
* @param x the X coordinate of the curve point for the public key.
|
* @param x the X coordinate of the curve point for the public key.
|
||||||
* @param y the Y coordinate of the curve point for the public key.
|
* @param y the Y coordinate of the curve point for the public key.
|
||||||
*/
|
*/
|
||||||
function setPubkey(bytes32 node, bytes32 x, bytes32 y) only_owner(node) {
|
function setPubkey(bytes32 node, bytes32 x, bytes32 y) external onlyOwner(node) {
|
||||||
records[node].pubkey = PublicKey(x, y);
|
records[node].pubkey = PublicKey(x, y);
|
||||||
PubkeyChanged(node, x, y);
|
emit PubkeyChanged(node, x, y);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the text data associated with an ENS node and key.
|
|
||||||
* @param node The ENS node to query.
|
|
||||||
* @param key The text data key to query.
|
|
||||||
* @return The associated text data.
|
|
||||||
*/
|
|
||||||
function text(bytes32 node, string key) constant returns (string ret) {
|
|
||||||
ret = records[node].text[key];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -205,8 +121,92 @@ contract PublicResolver {
|
||||||
* @param key The key to set.
|
* @param key The key to set.
|
||||||
* @param value The text data value to set.
|
* @param value The text data value to set.
|
||||||
*/
|
*/
|
||||||
function setText(bytes32 node, string key, string value) only_owner(node) {
|
function setText(bytes32 node, string calldata key, string calldata value) external onlyOwner(node) {
|
||||||
records[node].text[key] = value;
|
records[node].text[key] = value;
|
||||||
TextChanged(node, key, key);
|
emit TextChanged(node, key, key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Returns the text data associated with an ENS node and key.
|
||||||
|
* @param node The ENS node to query.
|
||||||
|
* @param key The text data key to query.
|
||||||
|
* @return The associated text data.
|
||||||
|
*/
|
||||||
|
function text(bytes32 node, string calldata key) external view returns (string memory) {
|
||||||
|
return records[node].text[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the SECP256k1 public key associated with an ENS node.
|
||||||
|
* Defined in EIP 619.
|
||||||
|
* @param node The ENS node to query
|
||||||
|
* @return x, y the X and Y coordinates of the curve point for the public key.
|
||||||
|
*/
|
||||||
|
function pubkey(bytes32 node) external view returns (bytes32 x, bytes32 y) {
|
||||||
|
return (records[node].pubkey.x, records[node].pubkey.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ABI associated with an ENS node.
|
||||||
|
* Defined in EIP205.
|
||||||
|
* @param node The ENS node to query
|
||||||
|
* @param contentTypes A bitwise OR of the ABI formats accepted by the caller.
|
||||||
|
* @return contentType The content type of the return value
|
||||||
|
* @return data The ABI data
|
||||||
|
*/
|
||||||
|
function ABI(bytes32 node, uint256 contentTypes) external view returns (uint256, bytes memory) {
|
||||||
|
Record storage record = records[node];
|
||||||
|
|
||||||
|
for (uint256 contentType = 1; contentType <= contentTypes; contentType <<= 1) {
|
||||||
|
if ((contentType & contentTypes) != 0 && record.abis[contentType].length > 0) {
|
||||||
|
return (contentType, record.abis[contentType]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes memory empty;
|
||||||
|
return (0, empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name associated with an ENS node, for reverse records.
|
||||||
|
* Defined in EIP181.
|
||||||
|
* @param node The ENS node to query.
|
||||||
|
* @return The associated name.
|
||||||
|
*/
|
||||||
|
function name(bytes32 node) external view returns (string memory) {
|
||||||
|
return records[node].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address associated with an ENS node.
|
||||||
|
* @param node The ENS node to query.
|
||||||
|
* @return The associated address.
|
||||||
|
*/
|
||||||
|
function addr(bytes32 node) external view returns (address) {
|
||||||
|
return records[node].addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the contenthash associated with an ENS node.
|
||||||
|
* @param node The ENS node to query.
|
||||||
|
* @return The associated contenthash.
|
||||||
|
*/
|
||||||
|
function contenthash(bytes32 node) external view returns (bytes memory) {
|
||||||
|
return records[node].contenthash;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the resolver implements the interface specified by the provided hash.
|
||||||
|
* @param interfaceID The ID of the interface to check for.
|
||||||
|
* @return True if the contract implements the requested interface.
|
||||||
|
*/
|
||||||
|
function supportsInterface(bytes4 interfaceID) external pure returns (bool) {
|
||||||
|
return interfaceID == ADDR_INTERFACE_ID ||
|
||||||
|
interfaceID == NAME_INTERFACE_ID ||
|
||||||
|
interfaceID == ABI_INTERFACE_ID ||
|
||||||
|
interfaceID == PUBKEY_INTERFACE_ID ||
|
||||||
|
interfaceID == TEXT_INTERFACE_ID ||
|
||||||
|
interfaceID == CONTENTHASH_INTERFACE_ID ||
|
||||||
|
interfaceID == INTERFACE_META_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue