mirror of https://github.com/embarklabs/embark.git
fix lookup and also enable lookup for new subdomains
This commit is contained in:
parent
9baf11f555
commit
d789abf056
|
@ -34,13 +34,13 @@ contract FIFSRegistrar {
|
||||||
* @param subnode The hash of the label to register.
|
* @param subnode The hash of the label to register.
|
||||||
* @param owner The address of the new owner.
|
* @param owner The address of the new owner.
|
||||||
*/
|
*/
|
||||||
function register(bytes32 subnode, address owner, address _account) public only_owner(subnode) {
|
function register(bytes32 subnode, address owner, address nodeAddress) public only_owner(subnode) {
|
||||||
bytes32 subdomainHash = sha3(rootNode, subnode);
|
bytes32 subdomainHash = sha3(rootNode, subnode);
|
||||||
ens.setSubnodeOwner(rootNode, subnode, owner);
|
ens.setSubnodeOwner(rootNode, subnode, owner);
|
||||||
ens.setResolver(subdomainHash, resolver); //default resolver
|
ens.setResolver(subdomainHash, resolver); //default resolver
|
||||||
bool resolveAccount = _account != address(0);
|
bool resolveAccount = nodeAddress != address(0);
|
||||||
if (resolveAccount) {
|
if (resolveAccount) {
|
||||||
resolver.setAddr(subdomainHash, _account);
|
resolver.setAddr(subdomainHash, nodeAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,198 @@
|
||||||
pragma solidity ^0.4.18;
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
import './ENS.sol';
|
import "./ENS.sol";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple resolver anyone can use; only allows the owner of a node to set its
|
||||||
|
* address.
|
||||||
|
*/
|
||||||
contract Resolver {
|
contract Resolver {
|
||||||
event AddrChanged(bytes32 indexed node, address a);
|
event AddrChanged(bytes32 indexed node, address a);
|
||||||
event ContentChanged(bytes32 indexed node, bytes32 hash);
|
event ContentChanged(bytes32 indexed node, bytes32 hash);
|
||||||
|
event NameChanged(bytes32 indexed node, string name);
|
||||||
|
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);
|
||||||
|
|
||||||
|
struct PublicKey {
|
||||||
|
bytes32 x;
|
||||||
|
bytes32 y;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Record {
|
||||||
|
address addr;
|
||||||
|
bytes32 content;
|
||||||
|
string name;
|
||||||
|
PublicKey pubkey;
|
||||||
|
mapping(string=>string) text;
|
||||||
|
mapping(uint256=>bytes) abis;
|
||||||
|
}
|
||||||
|
|
||||||
ENS ens;
|
ENS ens;
|
||||||
mapping(bytes32 => address) addresses;
|
|
||||||
|
mapping (bytes32 => Record) records;
|
||||||
|
|
||||||
modifier only_owner(bytes32 node) {
|
modifier only_owner(bytes32 node) {
|
||||||
require(ens.owner(node) == msg.sender);
|
require(ens.owner(node) == msg.sender);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Resolver(address ensAddr) {
|
/**
|
||||||
ens = ENS(ensAddr);
|
* Constructor.
|
||||||
|
* @param ensAddr The ENS registrar contract.
|
||||||
|
*/
|
||||||
|
constructor(ENS ensAddr) public {
|
||||||
|
ens = ensAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addr(bytes32 node) constant returns (address ret) {
|
/**
|
||||||
ret = addresses[node];
|
* Sets the address 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.
|
||||||
// function setAddr(bytes32 node, address addr) only_owner(node) {
|
* @param addr The address to set.
|
||||||
// addresses[node] = addr;
|
*/
|
||||||
// AddrChanged(node, addr);
|
// function setAddr(bytes32 node, address addr) public only_owner(node) {
|
||||||
|
// records[node].addr = addr;
|
||||||
|
// emit AddrChanged(node, addr);
|
||||||
// }
|
// }
|
||||||
|
function setAddr(bytes32 node, address addr) public {
|
||||||
function setAddr(bytes32 node, address addr) {
|
records[node].addr = addr;
|
||||||
addresses[node] = addr;
|
emit AddrChanged(node, addr);
|
||||||
AddrChanged(node, addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function supportsInterface(bytes4 interfaceID) constant returns (bool) {
|
/**
|
||||||
return interfaceID == 0x3b3b57de || interfaceID == 0x01ffc9a7;
|
* Sets the content hash associated with an ENS node.
|
||||||
|
* 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 hash The content hash to set
|
||||||
|
*/
|
||||||
|
function setContent(bytes32 node, bytes32 hash) public only_owner(node) {
|
||||||
|
records[node].content = hash;
|
||||||
|
emit ContentChanged(node, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function() {
|
/**
|
||||||
throw;
|
* Sets the name associated with an ENS node, for reverse records.
|
||||||
|
* May only be called by the owner of that node in the ENS registry.
|
||||||
|
* @param node The node to update.
|
||||||
|
* @param name The name to set.
|
||||||
|
*/
|
||||||
|
// function setName(bytes32 node, string name) public only_owner(node) {
|
||||||
|
// records[node].name = name;
|
||||||
|
// emit NameChanged(node, name);
|
||||||
|
// }
|
||||||
|
function setName(bytes32 node, string name) public {
|
||||||
|
records[node].name = name;
|
||||||
|
emit NameChanged(node, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the ABI associated with an ENS node.
|
||||||
|
* Nodes may have one ABI of each content type. To remove an ABI, set it to
|
||||||
|
* the empty string.
|
||||||
|
* @param node The node to update.
|
||||||
|
* @param contentType The content type of the ABI
|
||||||
|
* @param data The ABI data.
|
||||||
|
*/
|
||||||
|
function setABI(bytes32 node, uint256 contentType, bytes data) public only_owner(node) {
|
||||||
|
// Content types must be powers of 2
|
||||||
|
require(((contentType - 1) & contentType) == 0);
|
||||||
|
|
||||||
|
records[node].abis[contentType] = data;
|
||||||
|
emit ABIChanged(node, contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the SECP256k1 public key associated with an ENS node.
|
||||||
|
* @param node The ENS node to query
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
function setPubkey(bytes32 node, bytes32 x, bytes32 y) public only_owner(node) {
|
||||||
|
records[node].pubkey = PublicKey(x, y);
|
||||||
|
emit PubkeyChanged(node, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the text data associated with an ENS node and key.
|
||||||
|
* May only be called by the owner of that node in the ENS registry.
|
||||||
|
* @param node The node to update.
|
||||||
|
* @param key The key to set.
|
||||||
|
* @param value The text data value to set.
|
||||||
|
*/
|
||||||
|
function setText(bytes32 node, string key, string value) public only_owner(node) {
|
||||||
|
records[node].text[key] = value;
|
||||||
|
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 key) public view returns (string) {
|
||||||
|
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) public 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) public view returns (uint256 contentType, bytes data) {
|
||||||
|
Record storage 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) public view returns (string) {
|
||||||
|
return records[node].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content hash 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) public view returns (bytes32) {
|
||||||
|
return records[node].content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the address associated with an ENS node.
|
||||||
|
* @param node The ENS node to query.
|
||||||
|
* @return The associated address.
|
||||||
|
*/
|
||||||
|
function addr(bytes32 node) public view returns (address) {
|
||||||
|
return records[node].addr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,27 +57,6 @@ __embarkENS.resolverInterface = [
|
||||||
],
|
],
|
||||||
"type": "function"
|
"type": "function"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"constant": true,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"name": "node",
|
|
||||||
"type": "bytes32"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "kind",
|
|
||||||
"type": "bytes32"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"name": "has",
|
|
||||||
"outputs": [
|
|
||||||
{
|
|
||||||
"name": "",
|
|
||||||
"type": "bool"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": "function"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
@ -177,6 +156,7 @@ __embarkENS.setProvider = function (config) {
|
||||||
self.isAvailable = true;
|
self.isAvailable = true;
|
||||||
self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress});
|
self.ens = new EmbarkJS.Contract({abi: config.registryAbi, address: registryAddress});
|
||||||
self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress});
|
self.registrar = new EmbarkJS.Contract({abi: config.registrarAbi, address: config.registrarAddress});
|
||||||
|
self.resolver = new EmbarkJS.Contract({abi: config.resolverAbi, address: config.resolverAddress});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.message.indexOf('Provider not set or invalid') > -1) {
|
if (err.message.indexOf('Provider not set or invalid') > -1) {
|
||||||
|
@ -222,7 +202,7 @@ __embarkENS.lookup = function (address, callback) {
|
||||||
if (address.startsWith("0x")) {
|
if (address.startsWith("0x")) {
|
||||||
address = address.slice(2);
|
address = address.slice(2);
|
||||||
}
|
}
|
||||||
let node = namehash.hash(address.toLowerCase() + ".addr.reverse");
|
let node = web3.utils.sha3(address.toLowerCase() + ".addr.reverse");
|
||||||
|
|
||||||
function cb(err, name) {
|
function cb(err, name) {
|
||||||
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
|
if (err === NoDecodeStringError || err === NoDecodeAddrError) {
|
||||||
|
@ -235,12 +215,16 @@ __embarkENS.lookup = function (address, callback) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
if (resolverAddress === '0x0000000000000000000000000000000000000000') {
|
||||||
|
return cb('Address not associated to a resolver');
|
||||||
|
}
|
||||||
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
|
let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress});
|
||||||
resolverContract.methods.name(node).call(cb);
|
resolverContract.methods.name(node).call(cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkENS.registerSubDomain = function (name, address, callback) {
|
__embarkENS.registerSubDomain = function (name, address, callback) {
|
||||||
|
const self = this;
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
|
|
||||||
const resolveAddr = address || '0x0000000000000000000000000000000000000000';
|
const resolveAddr = address || '0x0000000000000000000000000000000000000000';
|
||||||
|
@ -252,7 +236,16 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
|
||||||
console.warn('Failed transaction', transaction);
|
console.warn('Failed transaction', transaction);
|
||||||
return callback('Failed to register. Check gas cost.');
|
return callback('Failed to register. Check gas cost.');
|
||||||
}
|
}
|
||||||
callback(null, transaction);
|
|
||||||
|
const reverseNode = web3.utils.sha3(resolveAddr.toLowerCase().substr(2) + '.addr.reverse');
|
||||||
|
return self.ens.methods.setResolver(reverseNode, this.resolver.options.address).send((function (err, _result) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
return self.resolver.methods.setName(reverseNode, name + '.embark.eth').send(function (err, _result) {
|
||||||
|
callback(err, transaction);
|
||||||
|
});
|
||||||
|
}));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
callback('Failed to register with error: ' + (err.message || err));
|
callback('Failed to register with error: ' + (err.message || err));
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
|
@ -29,14 +29,21 @@ class ENS {
|
||||||
self.events.request('contracts:contract', "FIFSRegistrar", (contract) => {
|
self.events.request('contracts:contract', "FIFSRegistrar", (contract) => {
|
||||||
paraCb(null, contract);
|
paraCb(null, contract);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
function getResolver(paraCb) {
|
||||||
|
self.events.request('contracts:contract', "Resolver", (contract) => {
|
||||||
|
paraCb(null, contract);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
], (err, results) => {
|
], (err, results) => {
|
||||||
// result[0] => ENSRegistry; result[1] => FIFSRegistrar
|
// result[0] => ENSRegistry; result[1] => FIFSRegistrar; result[2] => FIFSRegistrar
|
||||||
let config = {
|
let config = {
|
||||||
registryAbi: results[0].abiDefinition,
|
registryAbi: results[0].abiDefinition,
|
||||||
registryAddress: results[0].deployedAddress,
|
registryAddress: results[0].deployedAddress,
|
||||||
registrarAbi: results[1].abiDefinition,
|
registrarAbi: results[1].abiDefinition,
|
||||||
registrarAddress: results[1].deployedAddress
|
registrarAddress: results[1].deployedAddress,
|
||||||
|
resolverAbi: results[2].abiDefinition,
|
||||||
|
resolverAddress: results[2].deployedAddress
|
||||||
};
|
};
|
||||||
self.addSetProvider(config);
|
self.addSetProvider(config);
|
||||||
|
|
||||||
|
@ -124,7 +131,10 @@ class ENS {
|
||||||
"onDeploy": [
|
"onDeploy": [
|
||||||
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
`ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => {
|
||||||
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send();
|
||||||
|
var reverseNode = web3.utils.sha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');
|
||||||
|
ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send();
|
||||||
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send();
|
||||||
|
Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send();
|
||||||
})`
|
})`
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue