From a16cd862f6354fc20537921f0517f2e36ca6a94a Mon Sep 17 00:00:00 2001 From: bumi Date: Thu, 19 Apr 2018 00:40:33 +0200 Subject: [PATCH] Better ipfs handling and default configs --- lib/kredits.js | 14 +++----------- lib/utils/ipfs.js | 3 +++ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/kredits.js b/lib/kredits.js index 33bbe8b..8182137 100644 --- a/lib/kredits.js +++ b/lib/kredits.js @@ -32,14 +32,13 @@ class Kredits { // Initialize our registry contract this.addresses = addresses; this.contracts = {}; + this.ipfs = new IPFS(); } - static setup(provider, signer, ipfsConfig) { - this.ipfsConfig = ipfsConfig; + static setup(provider, signer, ipfsConfig = null) { let ipfsAPI = new IPFS(ipfsConfig); - this.ipfs = ipfsAPI; - return this.ipfs._ipfsAPI.id().catch((error) => { + return ipfsAPI._ipfsAPI.id().catch((error) => { throw new Error(`IPFS node not available; config: ${JSON.stringify(ipfsConfig)} - ${error.message}`); }).then(() => { @@ -83,13 +82,6 @@ class Kredits { return new ethers.Contract(address, abi, provider); } - get ipfs() { - return this._ipfsAPI; - } - set ipfs(ipfs) { - this._ipfsAPI = ipfs; - } - get Contributor() { // TODO: rename to contributor return this.contractFor('contributors'); diff --git a/lib/utils/ipfs.js b/lib/utils/ipfs.js index 6dc1887..e0aecb6 100644 --- a/lib/utils/ipfs.js +++ b/lib/utils/ipfs.js @@ -4,6 +4,9 @@ const multihashes = require('multihashes'); class IPFS { constructor(config) { + if (!config) { + config = {host: 'localhost', port: '5001', protocol: 'http'}; + } this._ipfsAPI = ipfsAPI(config); this._config = config; }