From 054215ce21fdf7a66a7a7a253d26b96f6e6ef627 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 10 Jul 2018 15:59:42 -0400 Subject: [PATCH] wip changes --- js/embark.js | 10 ++-- lib/cmds/blockchain/geth_commands.js | 2 +- lib/modules/ens/embarkjs.js | 71 ++++++++++++++++++---------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/js/embark.js b/js/embark.js index 78339a41..2a9416ca 100644 --- a/js/embark.js +++ b/js/embark.js @@ -393,19 +393,19 @@ EmbarkJS.Names.setProvider = function (provider, options) { }; // resolve resolves a name into an identifier of some kind -EmbarkJS.Names.resolve = function (name) { +EmbarkJS.Names.resolve = function (name, callback) { if (!this.currentNameSystems) { throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'); } - return this.currentNameSystems.resolve(name); + return this.currentNameSystems.resolve(name, callback); }; // the reverse of resolve, resolves using an identifier to get to a name -EmbarkJS.Names.lookup = function (identifier) { +EmbarkJS.Names.lookup = function (identifier, callback) { if (!this.currentNameSystems) { throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'); } - return this.currentNameSystems.lookup(identifier); + return this.currentNameSystems.lookup(identifier, callback); }; // To Implement @@ -417,7 +417,7 @@ EmbarkJS.Names.register = function(name, options) { throw new Error('Name system provider not set; e.g EmbarkJS.Names.setProvider("ens")'); } return this.currentNameSystems.register(name, options); -} +}; EmbarkJS.Utils = { fromAscii: function (str) { diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 573edf0e..58001b5c 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -21,7 +21,7 @@ class GethCommands { } if (config.syncMode || config.syncmode) { - cmd.push("--syncmode=" + config.syncmode || config.syncMode); + cmd.push("--syncmode=" + (config.syncmode || config.syncMode)); } if (config.account && config.account.password) { diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index a3736324..063b525d 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -162,6 +162,10 @@ __embarkENS.registryAddresses = { "4": "0xe7410170f87102DF0055eB195163A03B7F2Bff4A" }; +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'; + __embarkENS.setProvider = function () { const self = this; // get network id and then assign ENS contract based on that @@ -183,42 +187,61 @@ __embarkENS.setProvider = function () { }); }; -__embarkENS.resolve = function (name) { - const self = this; - - if (self.ens === undefined) return; +__embarkENS.resolve = function (name, callback) { + if (!this.ens) { + return callback(providerNotSetError); + } let node = namehash.hash(name); - - return self.ens.methods.resolver(node).call().then((resolverAddress) => { - let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); - return resolverContract.methods.addr(node).call(); - }).then((addr) => { - return addr; + + console.log('Name to check', name); + console.log('Node', node); + console.log(this.ens); + return this.ens.methods.resolver(node).call().then((resolverAddress) => { + console.log('address', resolverAddress); + let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress}); + return resolverContract.methods.addr(node).call() + .then((addr) => { + console.log('ADRESSS', addr); + callback(null, addr); + }) + .catch(err => { + if (err === NoDecodeAddrError) { + return callback(name + " is not registered", "0x"); + } + callback(err); + }); }).catch((err) => { if (err === NoDecodeAddrError) { - console.log(name + " is not registered"); - return "0x"; + return callback(name + " is not registered", "0x"); } - return err; + console.log('oldekwe^pfke'); + callback(err); }); }; -__embarkENS.lookup = function (address) { - const self = this; - - if (!self.ens) { - console.log("ENS provider not set. Exiting."); - return; +__embarkENS.lookup = function (address, callback) { + if (!this.ens) { + return callback(providerNotSetError); } - if (address.startsWith("0x")) address = address.slice(2); - + if (address.startsWith("0x")) { + address = address.slice(2); + } + console.log('Address', address); let node = namehash.hash(address.toLowerCase() + ".addr.reverse"); + console.log('Node', node); - return self.ens.methods.resolver(node).call().then((resolverAddress) => { - let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); - return resolverContract.methods.name(node).call(); + return this.ens.methods.resolver(node).call().then((resolverAddress) => { + console.log('Resolver address', resolverAddress); + let resolverContract = new EmbarkJS.Contract({abi: this.resolverInterface, address: resolverAddress}); + resolverContract.methods.name(node).call() + .then(name => { + console.log('Name'); + callback(null, name); + }) + .catch(callback); }).catch((err) => { + console.log('Got error', err); if (err === NoDecodeStringError || err === NoDecodeAddrError) { console.log('Address does not resolve to name. Try syncing chain.'); return "";