Merge pull request #906 from embark-framework/bugfix/ens-require-default-account

Warning if no default account for ens
This commit is contained in:
Iuri Matias 2018-09-26 09:28:41 -04:00 committed by GitHub
commit 0848d81b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -131,6 +131,7 @@ __embarkENS.resolverInterface = [
}
];
const defaultAccountNotSetError = 'web3.eth.defaultAccount not set';
const providerNotSetError = 'ENS provider not set';
const NoDecodeAddrError = 'Error: Couldn\'t decode address from ABI: 0x';
const NoDecodeStringError = 'ERROR: The returned value is not a convertible string: 0x0';
@ -151,7 +152,6 @@ __embarkENS.setProvider = function (config) {
const ERROR_MESSAGE = 'ENS is not available in this chain';
self.registration = config.registration;
self.env = config.env;
EmbarkJS.onReady(() => {
web3.eth.net.getId()
.then((id) => {
@ -176,6 +176,10 @@ __embarkENS.resolve = function (name, callback) {
if (!this.ens) {
return callback(providerNotSetError);
}
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
let node = namehash.hash(name);
function cb(err, addr) {
@ -202,6 +206,9 @@ __embarkENS.lookup = function (address, callback) {
if (!this.ens) {
return callback(providerNotSetError);
}
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
if (address.startsWith("0x")) {
address = address.slice(2);
}
@ -229,6 +236,10 @@ __embarkENS.lookup = function (address, callback) {
__embarkENS.registerSubDomain = function (name, address, callback) {
callback = callback || function () {};
if (!web3.eth.defaultAccount) {
return callback(defaultAccountNotSetError);
}
if (this.env !== 'development' && this.env !== 'privatenet') {
return callback('Sub-domain registration is only available in development or privatenet mode');
}