From 1427b4596d411d1403e1e5f85b3e2bc4f5be850f Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 26 Jul 2018 14:03:35 +0100 Subject: [PATCH] Add ipns resolve --- lib/modules/ipfs/embarkjs.js | 18 ++++++++++++++++++ lib/modules/ipfs/index.js | 1 + 2 files changed, 19 insertions(+) diff --git a/lib/modules/ipfs/embarkjs.js b/lib/modules/ipfs/embarkjs.js index 82bf19324..e95a8eb09 100644 --- a/lib/modules/ipfs/embarkjs.js +++ b/lib/modules/ipfs/embarkjs.js @@ -120,4 +120,22 @@ __embarkIPFS.getUrl = function (hash) { return (this._getUrl || "http://localhost:8080/ipfs/") + hash; }; +__embarkIPFS.resolve = function (name, callback) { + callback = callback || function () {}; + if (!this._ipfsConnection) { + var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Names.setProvider()'); + return callback(connectionError); + } + + this._ipfsConnection.name.resolve(name, (err, res) => { + if (err) { + return callback(name + " is not registered"); + } + callback(err, res.value); + }) +}; + +__embarkIPFS.lookup = function () { + console.error("Not Available"); +}; diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index 7d36d5e0d..76f11baef 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -95,6 +95,7 @@ class IPFS { let code = ""; code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);"; + code += "\nEmbarkJS.Names.registerProvider('ipns', __embarkIPFS);"; this.embark.addCodeToEmbarkJS(code); }