fix(ens/embarkjs): fix using await with embarkjs functions

This commit is contained in:
Jonathan Rainville 2018-11-28 11:48:59 -05:00
parent ca212e3ffb
commit c64c093a48
1 changed files with 31 additions and 20 deletions

View File

@ -2,6 +2,7 @@
let __embarkENS = {}; let __embarkENS = {};
const NOT_REGISTERED_ERROR = 'Name not yet registered';
// resolver interface // resolver interface
__embarkENS.resolverInterface = [ __embarkENS.resolverInterface = [
{ {
@ -189,15 +190,20 @@ __embarkENS.resolve = function (name, callback) {
callback(err, addr); callback(err, addr);
} }
return this.ens.methods.resolver(node).call((err, resolverAddress) => { return this.ens.methods.resolver(node).call()
if (err) { .then(resolverAddress => {
return cb(err);
}
if (resolverAddress === voidAddress) { if (resolverAddress === voidAddress) {
return cb('Name not yet registered'); return cb(NOT_REGISTERED_ERROR);
} }
let resolverContract = new EmbarkJS.Blockchain.Contract({abi: this.resolverInterface, address: resolverAddress, web3: web3}); let resolverContract = new EmbarkJS.Blockchain.Contract({
resolverContract.methods.addr(node).call(cb); abi: this.resolverInterface,
address: resolverAddress,
web3: web3
});
return resolverContract.methods.addr(node).call(cb);
})
.catch(err => {
cb(err);
}); });
}; };
@ -221,15 +227,20 @@ __embarkENS.lookup = function (address, callback) {
return callback(err, name); return callback(err, name);
} }
return this.ens.methods.resolver(node).call((err, resolverAddress) => { return this.ens.methods.resolver(node).call()
if (err) { .then(resolverAddress => {
return cb(err);
}
if (resolverAddress === voidAddress) { if (resolverAddress === voidAddress) {
return cb('Address not associated to a resolver'); return cb('Address not associated to a resolver');
} }
let resolverContract = new EmbarkJS.Blockchain.Contract({abi: this.resolverInterface, address: resolverAddress, web3: web3}); const resolverContract = new EmbarkJS.Blockchain.Contract({
resolverContract.methods.name(node).call(cb); abi: this.resolverInterface,
address: resolverAddress,
web3: web3
});
return resolverContract.methods.name(node).call(cb);
})
.catch(err => {
cb(err);
}); });
}; };