From 4de830ca298bfe8a9e986aeeb52e049ebca26b0b Mon Sep 17 00:00:00 2001 From: VoR0220 Date: Wed, 23 May 2018 09:58:18 -0500 Subject: [PATCH] resolve appears to be done, now I just need some help wiring the module together Signed-off-by: VoR0220 --- lib/modules/ens/embarkjs.js | 19 ++++++++++++++----- lib/modules/ens/index.js | 10 ++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 lib/modules/ens/index.js diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 4d20f74f2..bb4079cac 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -1,7 +1,8 @@ +const namehash = require('eth-ens-namehash'); + /*global web3*/ let __embarkENS = {}; -/* // registry interface for later var registryInterface = [ { @@ -91,7 +92,6 @@ var registryInterface = [ "type": "function" } ]; -*/ var resolverInterface = [ { @@ -260,12 +260,12 @@ __embarkENS.setProvider = function (options) { provider = options.server + ':' + options.port; } // TODO: take into account type - var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); - + let web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); + self.web3 = web3; // get network id and then assign ENS contract based on that self.ens = web3.eth.net.getId().then(id => { if (registryAddresses[id] !== undefined) { - return new web3.eth.Contract(resolverInterface, registryAddresses[id]); + return new web3.eth.Contract(registryInterface, registryAddresses[id]); } // todo: deploy at this point return undefined; @@ -273,6 +273,15 @@ __embarkENS.setProvider = function (options) { } __embarkENS.resolve = function(name) { + const self = this; + const web3 = this.web3; if (this.ens === undefined) return undefined; + let node = namehash(name) + this.ens.methods.resolver(node).call().then((resolverAddress) => { + let resolverContract = new web3.eth.Contract(resolverInterface, resolverAddress); + return resolverContract.methods.addr(node).call() + }).then((addr) => { + return addr + }).catch(err => err); } \ No newline at end of file diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js new file mode 100644 index 000000000..0bc0df4e9 --- /dev/null +++ b/lib/modules/ens/index.js @@ -0,0 +1,10 @@ +const fs = require('../../core/fs.js'); + +class ENS { + constructor(embark, options) { + this.logger = embark.logger; + this.events = embark.events; + this.web3 = options.web3; + this.embark = embark; + } +} \ No newline at end of file