pre-dploy using the same function as register

This commit is contained in:
Jonathan Rainville 2018-07-25 13:57:03 -04:00 committed by Iuri Matias
parent eee2f66a22
commit 24fe768e70
2 changed files with 45 additions and 28 deletions

View File

@ -58,26 +58,43 @@ class ENS {
registerConfigDomains(config, cb) { registerConfigDomains(config, cb) {
const self = this; const self = this;
const register = require('./register');
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { 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", self.events.request("blockchain:contract:create",
{abi: config.registrarAbi, address: config.registrarAddress}, {abi: config.registrarAbi, address: config.registrarAddress},
(registrar) => { (registrar) => {
async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => { paraCb(null, registrar);
const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount); });
},
toSend.estimateGas().then(gasEstimated => { function createResolverContract(paraCb) {
return toSend.send({gas: gasEstimated + 1000, from: defaultAccount}).then(transaction => { self.events.request("blockchain:contract:create",
if (transaction.status !== "0x1" && transaction.status !== "0x01" && transaction.status !== true) { {abi: config.resolverAbi, address: config.resolverAddress},
return eachCb('Failed to register. Check gas cost.'); (resolver) => {
paraCb(null, resolver);
});
} }
eachCb(null, transaction); ], function (err, contracts) {
}).catch(err => { if (err) {
eachCb('Failed to register with error: ' + (err.message || err)); return cb(err);
}); }
}).catch(err => { const [ens, registrar, resolver] = contracts;
eachCb("Register would error. Is it already registered? Do you have token balance? Is Allowance set? " + (err.message || err));
}); async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => {
const address = self.registration.subdomains[subDomainName];
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + '.addr.reverse');
register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain,
reverseNode, address, self.logger, eachCb);
}, cb); }, cb);
}); });
}); });
} }

View File

@ -1,6 +1,6 @@
const namehash = require('eth-ens-namehash'); const namehash = require('eth-ens-namehash');
function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, callback) { function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain, rootDomain, reverseNode, address, logger, callback) {
const subnode = namehash.hash(subdomain); const subnode = namehash.hash(subdomain);
const node = namehash.hash(`${subdomain}.${rootDomain}`); const node = namehash.hash(`${subdomain}.${rootDomain}`);
const toSend = registrar.methods.register(subnode, defaultAccount); const toSend = registrar.methods.register(subnode, defaultAccount);
@ -9,35 +9,35 @@ function registerSubDomain(ens, registrar, resolver, defaultAccount, subdomain,
toSend.estimateGas() toSend.estimateGas()
// Register domain // Register domain
.then(gasEstimated => { .then(gasEstimated => {
return toSend.send({gas: gasEstimated + 1000}); return toSend.send({gas: gasEstimated + 1000, from: defaultAccount});
}) })
// Set resolver for the node // Set resolver for the node
.then(transac => { .then(transac => {
if (transac.status !== "0x1" && transac.status !== "0x01") { if (transac.status !== "0x1" && transac.status !== "0x01" && transac.status !== true) {
console.warn('Failed transaction', transac); logger.warn('Failed transaction', transac);
return callback('Failed to register. Check gas cost.'); return callback('Failed to register. Check gas cost.');
} }
transaction = transac; transaction = transac;
return ens.methods.setResolver(node, resolver.options.address).send(); return ens.methods.setResolver(node, resolver.options.address).send({from: defaultAccount});
}) })
// Set address for node // Set address for node
.then(_result => { .then(_result => {
return resolver.methods.setAddr(node, address).send(); return resolver.methods.setAddr(node, address).send({from: defaultAccount});
}) })
// Set resolver for the reverse node // Set resolver for the reverse node
.then(_result => { .then(_result => {
return ens.methods.setResolver(reverseNode, resolver.options.address).send(); return ens.methods.setResolver(reverseNode, resolver.options.address).send({from: defaultAccount});
}) })
// Set name for reverse node // Set name for reverse node
.then(_result => { .then(_result => {
return resolver.methods.setName(reverseNode, subdomain + '.embark.eth').send(); return resolver.methods.setName(reverseNode, subdomain + '.embark.eth').send({from: defaultAccount});
}) })
.then(_result => { .then(_result => {
callback(null, transaction); callback(null, transaction);
}) })
.catch(err => { .catch(err => {
logger.error(err);
callback('Failed to register with error: ' + (err.message || err)); callback('Failed to register with error: ' + (err.message || err));
console.error(err);
}); });
} }