Add ipns resolve

This commit is contained in:
Anthony Laibe 2018-07-26 14:03:35 +01:00 committed by Iuri Matias
parent 2e9fa345be
commit 1427b4596d
2 changed files with 19 additions and 0 deletions

View File

@ -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");
};

View File

@ -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);
}