added some logic for error handling in lookup and fixed some linting issues

Signed-off-by: VoR0220 <catalanor0220@gmail.com>
This commit is contained in:
VoR0220 2018-05-23 23:34:19 -05:00
parent 8b07039907
commit 16e7fe9fde
1 changed files with 4 additions and 5 deletions

View File

@ -278,22 +278,21 @@ __embarkENS.resolve = function(name) {
}).catch(err => err); }).catch(err => err);
}; };
__embarkENS.NameNotFound = Error("ENS name not found");
__embarkENS.lookup = function(address) { __embarkENS.lookup = function(address) {
const self = this; const self = this;
if (self.ens === undefined) return undefined; if (self.ens === undefined) return undefined;
if(address.startsWith("0x")) if (address.startsWith("0x"))
address = address.slice(2); address = address.slice(2);
let node = namehash(address.toLowerCase() + ".addr.reverse") let node = namehash(address.toLowerCase() + ".addr.reverse");
self.ens.methods.resolver(node).call().then((resolverAddress) => { self.ens.methods.resolver(node).call().then((resolverAddress) => {
let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress); let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress);
return resolverContract.methods.name(node).call(); return resolverContract.methods.name(node).call();
}).then((name) => { }).then((name) => {
if (name === "" || name === undefined) throw Error("ENS name not found");
return name; return name;
}).catch(err => err); }).catch(err => err);
} };