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) {
const self = this;
const register = require('./register');
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) => {
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.');
paraCb(null, registrar);
});
},
function createResolverContract(paraCb) {
self.events.request("blockchain:contract:create",
{abi: config.resolverAbi, address: config.resolverAddress},
(resolver) => {
paraCb(null, resolver);
});
}
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));
});
], 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) + '.addr.reverse');
register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain,
reverseNode, address, self.logger, eachCb);
}, cb);
});
});
}

View File

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