From b1663af48558cece43d48abaad9df0bd8fbe7602 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 25 Jul 2018 13:08:03 -0400 Subject: [PATCH] if no register config, dont register anything --- lib/modules/ens/index.js | 67 ++++++++++++++++++++++++++++++++++++- lib/modules/ens/register.js | 4 +++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index eb5a6731..f55cbb7d 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -15,6 +15,7 @@ class ENS { this.registration = this.namesConfig.register || {}; this.embark = embark; +<<<<<<< HEAD if (this.namesConfig === {} || this.namesConfig.enabled !== true || this.namesConfig.available_providers.indexOf('ens') < 0) { @@ -22,6 +23,8 @@ class ENS { } this.doSetENSProvider = this.namesConfig.provider === 'ens'; +======= +>>>>>>> if no register config, dont register anything this.addENSToEmbarkJS(); this.configureContracts(); this.registerEvents(); @@ -74,10 +77,18 @@ class ENS { self.addSetProvider(config); } +<<<<<<< HEAD if ((!self.isDev && self.env !== 'privatenet') || !self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) { return cb(); } self.registerConfigDomains(config, cb); +======= + if (!self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) { + return cb(); + } + self.registerConfigDomains(config, cb); + }); +>>>>>>> if no register config, dont register anything }); } @@ -156,12 +167,32 @@ class ENS { const register = require('./register'); const secureSend = embarkJsUtils.secureSend; self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { +<<<<<<< HEAD async.parallel([ function createRegistryContract(paraCb) { self.events.request("blockchain:contract:create", {abi: config.registryAbi, address: config.registryAddress}, (registry) => { paraCb(null, registry); +======= + self.events.request("blockchain:contract:create", + {abi: config.registrarAbi, address: config.registrarAddress}, + (registrar) => { + async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => { + const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount); + + toSend.estimateGas().then(gasEstimated => { + return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => { + if (transaction.status !== "0x1" && transaction.status !== "0x01" && transaction.status !== true) { + return eachCb('Failed to register. Check gas cost.'); + } + eachCb(null, transaction); + }).catch(err => { + eachCb('Failed to register with error: ' + (err.message || err)); + }); + }).catch(err => { + eachCb("Register would error. Is it already registered? Do you have token balance? Is Allowance set? " + (err.message || err)); +>>>>>>> if no register config, dont register anything }); }, function createRegistrarContract(paraCb) { @@ -218,7 +249,9 @@ class ENS { configureContracts() { const config = { "default": { - "gas": "auto", + "gas": "auto" + }, + "development": { "contracts": { "ENS": { "deploy": false, @@ -248,6 +281,9 @@ class ENS { "Resolver": { "deploy": false }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } @@ -262,6 +298,9 @@ class ENS { "Resolver": { "deploy": false }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } @@ -276,13 +315,39 @@ class ENS { "Resolver": { "deploy": false }, + "Resolver": { + "deploy": false + }, "FIFSRegistrar": { "deploy": false } } } }; +<<<<<<< HEAD config.testnet = config.ropsten; +======= + + 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); +>>>>>>> if no register config, dont register anything if (this.registration && this.registration.rootDomain) { // Register root domain if it is defined diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index dd1a0d12..98267367 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -1,7 +1,11 @@ /*global web3*/ const namehash = require('eth-ens-namehash'); +<<<<<<< HEAD function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) { +======= +function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, callback) { +>>>>>>> if no register config, dont register anything const subnode = namehash.hash(subdomain); const rootNode = namehash.hash(rootDomain); const node = namehash.hash(`${subdomain}.${rootDomain}`);