diff --git a/lib/modules/ens/ensContractConfigs.json b/lib/modules/ens/ensContractConfigs.json index 714886c99..97ce2c258 100644 --- a/lib/modules/ens/ensContractConfigs.json +++ b/lib/modules/ens/ensContractConfigs.json @@ -678,13 +678,6 @@ "FIFSRegistrar": { "deploy": true, "silent": true, - "args": [ - "$ENSRegistry", - "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae" - ], - "onDeploy": [ - "ENSRegistry.methods.setOwner('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => {\n ENSRegistry.methods.setResolver('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', \"$Resolver\").send({from: web3.eth.defaultAccount});\n var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '.addr.reverse');\n ENSRegistry.methods.setResolver(reverseNode, \"$Resolver\").send({from: web3.eth.defaultAccount});\n Resolver.methods.setAddr('0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount});\n Resolver.methods.setName(reverseNode, 'eth').send({from: web3.eth.defaultAccount});\n })" - ], "className": "FIFSRegistrar", "code": "608060405234801561001057600080fd5b5060405160408061030883398101604052805160209091015160008054600160a060020a031916600160a060020a039093169290921782556001556102ad90819061005b90396000f3006080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663d22057a98114610045575b600080fd5b34801561005157600080fd5b5061007660043573ffffffffffffffffffffffffffffffffffffffff60243516610078565b005b600154604080516020808201939093528082018590528151808203830181526060909101918290528051859360009384939290918291908401908083835b602083106100d55780518252601f1990920191602091820191016100b6565b51815160209384036101000a600019018019909216911617905260408051929094018290038220600080547f02571be300000000000000000000000000000000000000000000000000000000855260048501839052955191995073ffffffffffffffffffffffffffffffffffffffff90951696506302571be3955060248084019592945090928390030190829087803b15801561017157600080fd5b505af1158015610185573d6000803e3d6000fd5b505050506040513d602081101561019b57600080fd5b5051905073ffffffffffffffffffffffffffffffffffffffff811615806101d7575073ffffffffffffffffffffffffffffffffffffffff811633145b15156101e257600080fd5b60008054600154604080517f06ab592300000000000000000000000000000000000000000000000000000000815260048101929092526024820189905273ffffffffffffffffffffffffffffffffffffffff888116604484015290519216926306ab59239260648084019382900301818387803b15801561026257600080fd5b505af1158015610276573d6000803e3d6000fd5b5050505050505050505600a165627a7a72305820ebb89ba93428b8bd5b039b76284cd01bc18764cffcb64cfd58163125d169441a0029", "runtimeBytecode": "6080604052600436106100405763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663d22057a98114610045575b600080fd5b34801561005157600080fd5b5061007660043573ffffffffffffffffffffffffffffffffffffffff60243516610078565b005b600154604080516020808201939093528082018590528151808203830181526060909101918290528051859360009384939290918291908401908083835b602083106100d55780518252601f1990920191602091820191016100b6565b51815160209384036101000a600019018019909216911617905260408051929094018290038220600080547f02571be300000000000000000000000000000000000000000000000000000000855260048501839052955191995073ffffffffffffffffffffffffffffffffffffffff90951696506302571be3955060248084019592945090928390030190829087803b15801561017157600080fd5b505af1158015610185573d6000803e3d6000fd5b505050506040513d602081101561019b57600080fd5b5051905073ffffffffffffffffffffffffffffffffffffffff811615806101d7575073ffffffffffffffffffffffffffffffffffffffff811633145b15156101e257600080fd5b60008054600154604080517f06ab592300000000000000000000000000000000000000000000000000000000815260048101929092526024820189905273ffffffffffffffffffffffffffffffffffffffff888116604484015290519216926306ab59239260648084019382900301818387803b15801561026257600080fd5b505af1158015610276573d6000803e3d6000fd5b5050505050505050505600a165627a7a72305820ebb89ba93428b8bd5b039b76284cd01bc18764cffcb64cfd58163125d169441a0029", diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 05b80e54f..0d249dc9d 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -206,43 +206,14 @@ class ENS { const self = this; const register = require('./register'); const secureSend = embarkJsUtils.secureSend; + self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { - async.parallel([ - function createRegistryContract(paraCb) { - self.events.request("blockchain:contract:create", - {abi: config.registryAbi, address: config.registryAddress}, - (registry) => { - paraCb(null, registry); - }); - }, - function createRegistrarContract(paraCb) { - self.events.request("blockchain:contract:create", - {abi: config.registrarAbi, address: config.registrarAddress}, - (registrar) => { - paraCb(null, registrar); - }); - }, - function createResolverContract(paraCb) { - self.events.request("blockchain:contract:create", - {abi: config.resolverAbi, address: config.resolverAddress}, - (resolver) => { - paraCb(null, resolver); - }); - } - ], function(err, contracts) { - if (err) { - return cb(err); - } - const [ens, registrar, resolver] = contracts; - - async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => { - const address = self.registration.subdomains[subDomainName]; - const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix); - register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain, - reverseNode, address, self.logger, secureSend, eachCb); - }, cb); - - }); + async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => { + const address = self.registration.subdomains[subDomainName]; + const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix); + register(self.ensContract, self.registrarContract, self.resolverContract, defaultAccount, subDomainName, self.registration.rootDomain, + reverseNode, address, self.logger, secureSend, eachCb); + }, cb); }); } @@ -293,29 +264,77 @@ class ENS { return next(); } const registryAddress = self.ensConfig.ENSRegistry.deployedAddress; - const resolverAddress = self.ensConfig.Resolver.deployedAddress; const rootNode = namehash.hash(self.registration.rootDomain); const contract = self.ensConfig.FIFSRegistrar; contract.args = [registryAddress, rootNode]; - contract.onDeploy = [ - `ENSRegistry.methods.setOwner('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}).then(() => { - ENSRegistry.methods.setResolver('${rootNode}', "${resolverAddress}").send({from: web3.eth.defaultAccount}); - var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + '${reverseAddrSuffix}'); - ENSRegistry.methods.setResolver(reverseNode, "${resolverAddress}").send({from: web3.eth.defaultAccount}); - Resolver.methods.setAddr('${rootNode}', web3.eth.defaultAccount).send({from: web3.eth.defaultAccount}); - Resolver.methods.setName(reverseNode, '${self.registration.rootDomain}').send({from: web3.eth.defaultAccount}); - })` - ]; + self.events.request('deploy:contract', contract, (err, _receipt) => { return next(err); }); + }, + function registerRoot(next) { + let config = { + registryAbi: self.ensConfig.ENSRegistry.abiDefinition, + registryAddress: self.ensConfig.ENSRegistry.deployedAddress, + registrarAbi: self.ensConfig.FIFSRegistrar.abiDefinition, + registrarAddress: self.ensConfig.FIFSRegistrar.deployedAddress, + resolverAbi: self.ensConfig.Resolver.abiDefinition, + resolverAddress: self.ensConfig.Resolver.deployedAddress + }; + async.parallel([ + function createRegistryContract(paraCb) { + self.events.request("blockchain:contract:create", + {abi: config.registryAbi, address: config.registryAddress}, + (registry) => { + paraCb(null, registry); + }); + }, + function createRegistrarContract(paraCb) { + self.events.request("blockchain:contract:create", + {abi: config.registrarAbi, address: config.registrarAddress}, + (registrar) => { + paraCb(null, registrar); + }); + }, + function createResolverContract(paraCb) { + self.events.request("blockchain:contract:create", + {abi: config.resolverAbi, address: config.resolverAddress}, + (resolver) => { + paraCb(null, resolver); + }); + } + ], (err, contracts) => { + self.ensContract = contracts[0]; + self.registrarContract = contracts[1]; + self.resolverContract = contracts[2]; + + /*global web3*/ + const rootNode = namehash.hash(self.registration.rootDomain); + var reverseNode = web3.utils.soliditySha3(web3.eth.defaultAccount.toLowerCase().substr(2) + reverseAddrSuffix); + self.ensContract.methods.setOwner(rootNode, web3.eth.defaultAccount).send({from: web3.eth.defaultAccount, gas: 700000}).then(() => { + return self.ensContract.methods.setResolver(rootNode, config.resolverAddress).send({from: web3.eth.defaultAccount, gas: 700000}); + }).then(() => { + return self.ensContract.methods.setResolver(reverseNode, config.resolverAddress).send({from: web3.eth.defaultAccount, gas: 700000}); + }).then(() => { + return self.resolverContract.methods.setAddr(rootNode, web3.eth.defaultAccount).send({from: web3.eth.defaultAccount, gas: 700000}); + }).then(() => { + return self.resolverContract.methods.setName(reverseNode, self.registration.rootDomain).send({from: web3.eth.defaultAccount, gas: 700000}); + }).then((_result) => { + next(); + }) + .catch(err => { + console.error('Error while registering the root domain'); + console.error(err); + next(err); + }); + }); } ], (err) => { self.configured = true; if (err) { self.logger.error('Error while deploying ENS contracts'); self.logger.error(err.message || err); - return; + return cb(err); } self.setProviderAndRegisterDomains(cb); }); diff --git a/lib/modules/ens/register.js b/lib/modules/ens/register.js index dd1a0d128..55a1bd2e5 100644 --- a/lib/modules/ens/register.js +++ b/lib/modules/ens/register.js @@ -10,7 +10,7 @@ function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, const toSend = ens.methods.setSubnodeOwner(rootNode, subnode, defaultAccount); let transaction; - secureSend(web3, toSend, {from: defaultAccount}, false) + secureSend(web3, toSend, {from: defaultAccount, gas: 700000}, false) // Set resolver for the node .then(transac => { if (transac.status !== "0x1" && transac.status !== "0x01" && transac.status !== true) { @@ -18,19 +18,19 @@ function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, return callback('Failed to register. Check gas cost.'); } transaction = transac; - return secureSend(web3, ens.methods.setResolver(node, resolver.options.address), {from: defaultAccount}, false); + return secureSend(web3, ens.methods.setResolver(node, resolver.options.address), {from: defaultAccount, gas: 700000}, false); }) // Set address for node .then(_result => { - return secureSend(web3, resolver.methods.setAddr(node, address), {from: defaultAccount}, false); + return secureSend(web3, resolver.methods.setAddr(node, address), {from: defaultAccount, gas: 700000}, false); }) // Set resolver for the reverse node .then(_result => { - return secureSend(web3, ens.methods.setResolver(reverseNode, resolver.options.address), {from: defaultAccount}, false); + return secureSend(web3, ens.methods.setResolver(reverseNode, resolver.options.address), {from: defaultAccount, gas: 700000}, false); }) // Set name for reverse node .then(_result => { - return secureSend(web3, resolver.methods.setName(reverseNode, `${subdomain}.${rootDomain}`), {from: defaultAccount}, false); + return secureSend(web3, resolver.methods.setName(reverseNode, `${subdomain}.${rootDomain}`), {from: defaultAccount, gas: 700000}, false); }) .then(_result => { callback(null, transaction);