From 4c4501a06950b3fecf3713ddcbde957264a5483c Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Fri, 27 Jul 2018 12:21:52 +0100 Subject: [PATCH] Use promise on ipns namesystem --- lib/modules/ipfs/embarkjs/name.js | 25 +++++++++++++------------ templates/demo/config/namesystem.js | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/modules/ipfs/embarkjs/name.js b/lib/modules/ipfs/embarkjs/name.js index 2f4eecf03..6d11c2aa9 100644 --- a/lib/modules/ipfs/embarkjs/name.js +++ b/lib/modules/ipfs/embarkjs/name.js @@ -5,12 +5,13 @@ __embarkIPFS.resolve = function (name, callback) { return callback(connectionError); } - this._ipfsConnection.name.resolve(name, (err, res) => { - if (err) { + this._ipfsConnection.name.resolve(name) + .then(res => { + callback(null, res.Path); + }) + .catch(() => { return callback(name + " is not registered"); - } - callback(err, res.value); - }); + }); }; __embarkIPFS.register = function(addr, options) { @@ -18,13 +19,13 @@ __embarkIPFS.register = function(addr, options) { return new Error('No IPFS connection. Please ensure to call Embark.Names.setProvider()'); } - return this._ipfsConnection.name.publish(addr, options, function (err, res) { - if (err) { - return new Error('No IPFS connection. Please ensure to call Embark.Names.setProvider()'); - } - - return `https://gateway.ipfs.io/ipns/${res.name}`; - }); + this._ipfsConnection.name.publish("/ipfs/" + addr, options) + .then(res => { + return `https://gateway.ipfs.io/ipns/${res.name}`; + }) + .catch((err) => { + return new Error('Unexpected Error: ' + err); + }); }; __embarkIPFS.lookup = function () { diff --git a/templates/demo/config/namesystem.js b/templates/demo/config/namesystem.js index 62ed62620..4e9891ac1 100644 --- a/templates/demo/config/namesystem.js +++ b/templates/demo/config/namesystem.js @@ -1,6 +1,6 @@ module.exports = { default: { - available_providers: ["ens"], + available_providers: ["ens", "ipns"], provider: "ens", register: { rootDomain: "embark.eth",