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
|
// Register function generated by the index
|
||||||
registerSubDomain(this.ens, this.registrar, this.resolver, web3.eth.defaultAccount, name, this.registration.rootDomain,
|
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 () {
|
__embarkENS.isAvailable = function () {
|
||||||
|
|
|
@ -58,27 +58,44 @@ 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) => {
|
||||||
self.events.request("blockchain:contract:create",
|
async.parallel([
|
||||||
{abi: config.registrarAbi, address: config.registrarAddress},
|
function createRegistryContract(paraCb) {
|
||||||
(registrar) => {
|
self.events.request("blockchain:contract:create",
|
||||||
async.each(Object.keys(self.registration.subdomains), (subDomainName, eachCb) => {
|
{abi: config.registryAbi, address: config.registryAddress},
|
||||||
const toSend = registrar.methods.register(utils.soliditySha3(subDomainName), defaultAccount);
|
(registry) => {
|
||||||
|
paraCb(null, registry);
|
||||||
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));
|
|
||||||
});
|
});
|
||||||
}, 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');
|
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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue