diff --git a/lib/core/config.js b/lib/core/config.js index 925e77fe8..1ad0c8f2c 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -282,10 +282,7 @@ Config.prototype.loadNameSystemConfigFile = function() { "default": { "available_providers": ["ens"], "provider": "ens", - "enabled": true, - "register": { - "rootDomain": "embark" - } + "enabled": true } }; diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index f0f036a25..4cc691dc6 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -8,10 +8,9 @@ class ENS { this.logger = embark.logger; this.events = embark.events; this.namesConfig = embark.config.namesystemConfig; - this.registration = this.namesConfig.register; + this.registration = this.namesConfig.register || {}; this.embark = embark; - // TODO add checks to see if config is ok this.addENSToEmbarkJS(); this.configureContracts(); this.registerEvents(); @@ -49,7 +48,7 @@ class ENS { }; self.addSetProvider(config); - if (!self.registration || !self.registration.domains || !Object.keys(self.registration.domains).length) { + if (!self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) { return cb(); } self.registerConfigDomains(config, cb); @@ -63,7 +62,7 @@ class ENS { self.events.request("blockchain:contract:create", {abi: config.registrarAbi, address: config.registrarAddress}, (registrar) => { - async.each(Object.keys(self.registration.domains), (subDomainName, eachCb) => { + async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => { const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount); toSend.estimateGas().then(gasEstimated => { @@ -112,11 +111,11 @@ class ENS { } configureContracts() { - let rootNode = namehash.hash(this.registration.rootDomain); - - this.embark.registerContractConfiguration({ + const config = { "default": { - "gas": "auto", + "gas": "auto" + }, + "development": { "contracts": { "ENSRegistry": { "deploy": true, @@ -127,17 +126,7 @@ class ENS { "args": ["$ENSRegistry"] }, "FIFSRegistrar": { - "deploy": true, - "args": ["$ENSRegistry", rootNode], - "onDeploy": [ - `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => { - ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send(); - var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse'); - ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send(); - Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send(); - Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send(); - })` - ] + "deploy": false } } }, @@ -146,6 +135,9 @@ class ENS { "ENSRegistry": { "address": "0x112234455c3a32fd11230c42e7bccd4a84e02010" }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } @@ -156,6 +148,9 @@ class ENS { "ENSRegistry": { "address": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } @@ -166,12 +161,35 @@ class ENS { "ENSRegistry": { "address": "0x314159265dd8dbb310642f98f50c066173c1259b" }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } } } - }); + }; + + if (this.registration && this.registration.rootDomain) { + // Register root domain if it is defined + const rootNode = namehash.hash(this.registration.rootDomain); + config.development.contracts['FIFSRegistrar'] = { + "deploy": true, + "args": ["$ENSRegistry", rootNode], + "onDeploy": [ + `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => { + ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send(); + var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse'); + ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send(); + Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send(); + Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send(); + })` + ] + }; + } + + this.embark.registerContractConfiguration(config); this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/ENSRegistry.sol')); this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/FIFSRegistrar.sol')); diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index 6b10d4cea..b7a1d6b06 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -1,7 +1,6 @@ const namehash = require('eth-ens-namehash'); function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, callback) { - console.log('Register', arguments); const subnode = namehash.hash(subdomain); const node = namehash.hash(`${subdomain}.${rootDomain}`); const toSend = registrar.methods.register(subnode, defaultAccount); diff --git a/templates/demo/config/namesystem.js b/templates/demo/config/namesystem.js index 1b2958434..62ed62620 100644 --- a/templates/demo/config/namesystem.js +++ b/templates/demo/config/namesystem.js @@ -4,7 +4,7 @@ module.exports = { provider: "ens", register: { rootDomain: "embark.eth", - domains: { + subdomains: { 'status': '0x1a2f3b98e434c02363f3dac3174af93c1d690914' } }