mirror of https://github.com/embarklabs/embark.git
fix(ens): fix error message by checking for directives before
This commit is contained in:
parent
50858dc063
commit
06553b5981
|
@ -235,41 +235,51 @@ class ENS {
|
||||||
}
|
}
|
||||||
|
|
||||||
registerConfigDomains(config, cb) {
|
registerConfigDomains(config, cb) {
|
||||||
const secureSend = embarkJsUtils.secureSend;
|
|
||||||
|
|
||||||
this.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
this.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
|
||||||
async.each(Object.keys(this.registration.subdomains), (subDomainName, eachCb) => {
|
async.each(Object.keys(this.registration.subdomains), (subDomainName, eachCb) => {
|
||||||
const address = this.registration.subdomains[subDomainName];
|
const address = this.registration.subdomains[subDomainName];
|
||||||
const directivesRegExp = new RegExp(/\$(\w+\[?\d?\]?)/g);
|
const directivesRegExp = new RegExp(/\$(\w+\[?\d?\]?)/g);
|
||||||
this.ensResolve(`${subDomainName}.${this.registration.rootDomain}`, (error, currentAddress) => {
|
|
||||||
if (currentAddress && currentAddress.toLowerCase() === address.toLowerCase()) {
|
|
||||||
return eachCb();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error !== NOT_REGISTERED_ERROR) {
|
|
||||||
this.logger.error(__('Error resolving %s', `${subDomainName}.${this.registration.rootDomain}`));
|
|
||||||
return eachCb(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const directives = directivesRegExp.exec(address);
|
const directives = directivesRegExp.exec(address);
|
||||||
if (directives && directives.length) {
|
if (directives && directives.length) {
|
||||||
this.embark.registerActionForEvent("contracts:deploy:afterAll", async (deployActionCb) => {
|
this.embark.registerActionForEvent("contracts:deploy:afterAll", async (deployActionCb) => {
|
||||||
this.events.request("contracts:contract", directives[1], (contract) => {
|
this.events.request("contracts:contract", directives[1], (contract) => {
|
||||||
if(!contract) return deployActionCb(); // if the contract is not registered in the config, it will be undefined here
|
if(!contract) {
|
||||||
const reverseNode = utils.soliditySha3(contract.deployedAddress.toLowerCase().substr(2) + reverseAddrSuffix);
|
// if the contract is not registered in the config, it will be undefined here
|
||||||
this.registerSubDomain(defaultAccount, subDomainName, reverseNode, contract.deployedAddress, secureSend, deployActionCb);
|
this.logger.error(__('Tried to register the subdomain "{{subdomain}}" as contract "{{contractName}}", ' +
|
||||||
});
|
'but "{{contractName}}" does not exist. Is it configured in your contract configuration?', {contractName: directives[1], subdomain: subDomainName}));
|
||||||
|
return deployActionCb();
|
||||||
|
}
|
||||||
|
this.safeRegisterSubDomain(subDomainName, contract.deployedAddress, defaultAccount, deployActionCb);
|
||||||
});
|
});
|
||||||
return eachCb();
|
});
|
||||||
}
|
return eachCb();
|
||||||
|
}
|
||||||
|
|
||||||
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
|
this.safeRegisterSubDomain(subDomainName, address, defaultAccount, eachCb);
|
||||||
this.registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, eachCb);
|
|
||||||
});
|
|
||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safeRegisterSubDomain(subDomainName, address, defaultAccount, callback) {
|
||||||
|
const secureSend = embarkJsUtils.secureSend;
|
||||||
|
this.ensResolve(`${subDomainName}.${this.registration.rootDomain}`, (error, currentAddress) => {
|
||||||
|
if (currentAddress && currentAddress.toLowerCase() === address.toLowerCase()) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error && error !== NOT_REGISTERED_ERROR) {
|
||||||
|
this.logger.error(__('Error resolving %s', `${subDomainName}.${this.registration.rootDomain}`));
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reverseNode = utils.soliditySha3(address.toLowerCase().substr(2) + reverseAddrSuffix);
|
||||||
|
this.registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, cb) {
|
registerSubDomain(defaultAccount, subDomainName, reverseNode, address, secureSend, cb) {
|
||||||
ENSFunctions.registerSubDomain(this.ensContract, this.registrarContract, this.resolverContract, defaultAccount,
|
ENSFunctions.registerSubDomain(this.ensContract, this.registrarContract, this.resolverContract, defaultAccount,
|
||||||
subDomainName, this.registration.rootDomain, reverseNode, address, this.logger, secureSend, cb);
|
subDomainName, this.registration.rootDomain, reverseNode, address, this.logger, secureSend, cb);
|
||||||
|
|
Loading…
Reference in New Issue