mirror of https://github.com/embarklabs/embark.git
pre-dploy using the same function as register
This commit is contained in:
parent
20c631434f
commit
346dd9de3a
|
@ -236,7 +236,7 @@ __embarkENS.registerSubDomain = function (name, address, callback) {
|
|||
|
||||
// Register function generated by the index
|
||||
registerSubDomain(this.ens, this.registrar, this.resolver, web3.eth.defaultAccount, name, this.registration.rootDomain,
|
||||
web3.utils.soliditySha3(address.toLowerCase().substr(2) + '.addr.reverse'), address, callback);
|
||||
web3.utils.soliditySha3(address.toLowerCase().substr(2) + '.addr.reverse'), address, console, callback);
|
||||
};
|
||||
|
||||
__embarkENS.isAvailable = function () {
|
||||
|
|
|
@ -58,27 +58,44 @@ class ENS {
|
|||
|
||||
registerConfigDomains(config, cb) {
|
||||
const self = this;
|
||||
const register = require('./register');
|
||||
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
||||
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));
|
||||
async.parallel([
|
||||
function createRegistryContract(paraCb) {
|
||||
self.events.request("blockchain:contract:create",
|
||||
{abi: config.registryAbi, address: config.registryAddress},
|
||||
(registry) => {
|
||||
paraCb(null, registry);
|
||||
});
|
||||
}, cb);
|
||||
});
|
||||
},
|
||||
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) + '.addr.reverse');
|
||||
register(ens, registrar, resolver, defaultAccount, subDomainName, self.registration.rootDomain,
|
||||
reverseNode, address, self.logger, eachCb);
|
||||
}, cb);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue