From 824a234d768f3889b1d1ad1b7cdeaec79c3d0316 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 16 Aug 2018 13:06:30 -0400 Subject: [PATCH] enable register in privatenet and patch weird errors --- lib/modules/ens/contracts/Resolver.sol | 6 ++++-- lib/modules/ens/index.js | 21 ++++++++------------- lib/modules/ens/register.js | 6 ++++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/modules/ens/contracts/Resolver.sol b/lib/modules/ens/contracts/Resolver.sol index 1d339cbd8..0902c4eed 100644 --- a/lib/modules/ens/contracts/Resolver.sol +++ b/lib/modules/ens/contracts/Resolver.sol @@ -33,8 +33,10 @@ contract Resolver { mapping (bytes32 => Record) records; modifier only_owner(bytes32 node) { - address currentOwner = ens.owner(node); - require(currentOwner == 0 || currentOwner == msg.sender); + // FIXME Calling ens.owner makes the transaction fail on privatenet for some reason + // address currentOwner = ens.owner(node); + // require(currentOwner == 0 || currentOwner == msg.sender); + require(true == true); _; } diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 9892da0a0..4d0bf70bf 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -22,12 +22,6 @@ class ENS { } this.doSetENSProvider = this.namesConfig.provider === 'ens'; - if (this.env === 'privatenet') { - this.logger.warn(__('ENS is disabled in privatenet')); - this.logger.info(__('To use ENS, use development, one of the testnets or mainnet')); - return; - } - this.addENSToEmbarkJS(); this.configureContracts(); this.registerEvents(); @@ -74,7 +68,7 @@ class ENS { self.addSetProvider(config); } - if (!self.isDev || !self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) { + if ((!self.isDev && self.env !== 'privatenet') || !self.registration || !self.registration.subdomains || !Object.keys(self.registration.subdomains).length) { return cb(); } self.registerConfigDomains(config, cb); @@ -296,19 +290,20 @@ class ENS { "silent": true, "args": ["$ENSRegistry", rootNode], "onDeploy": [ - `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send().then(() => { - ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send(); + `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => { + ENSRegistry.methods.setResolver('${rootNode}', "$Resolver").send({from: web3.eth.defaultAccount}); var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}'); - ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send(); - Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send(); - Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send(); + ENSRegistry.methods.setResolver(reverseNode, "$Resolver").send({from: web3.eth.defaultAccount}); + Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}); + Resolver.methods.setName(reverseNode, '${this.registration.rootDomain}').send({from: web3.eth.defaultAccount}); })` ] }; } + config.privatenet = config.development; this.embark.registerContractConfiguration(config); - if (this.isDev) { + if (this.isDev || this.env === 'privatenet') { 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')); this.embark.events.request("config:contractsFiles:add", this.embark.pathToFile('./contracts/Resolver.sol')); diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index 8ea9f9249..1ebf34783 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -3,11 +3,13 @@ const namehash = require('eth-ens-namehash'); function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, secureSend, callback) { const subnode = namehash.hash(subdomain); + const rootNode = namehash.hash(rootDomain); const node = namehash.hash(`${subdomain}.${rootDomain}`); - const toSend = registrar.methods.register(subnode, defaultAccount); + // FIXME Registrar calls a function in ENS and in privatenet it doesn't work for soem reason + // const toSend = registrar.methods.register(subnode, defaultAccount); + const toSend = ens.methods.setSubnodeOwner(rootNode, subnode, defaultAccount); let transaction; - secureSend(web3, toSend, {from: defaultAccount}, false) // Set resolver for the node .then(transac => {