From f945b378e2ed8f516c2b3e328e84ef2dfe1c1afc Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Thu, 18 Apr 2019 00:41:05 +0200 Subject: [PATCH 1/2] Add ipfs.config getters --- lib/utils/ipfs.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/utils/ipfs.js b/lib/utils/ipfs.js index 9b75462..f3b1017 100644 --- a/lib/utils/ipfs.js +++ b/lib/utils/ipfs.js @@ -11,6 +11,14 @@ class IPFS { this._config = config; } + get config() { + return this._config; + } + + get peerId() { + return this._ipfsAPI.id(); + } + catAndMerge(data, deserialize) { // if no hash details are found simply return the data; nothing to merge if (!data.hashSize || data.hashSize === 0) { -- 2.25.1 From 7a6b117876d8d95dd29343e692225084a2591ba2 Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Thu, 18 Apr 2019 00:41:21 +0200 Subject: [PATCH 2/2] Cleanup preflight --- lib/kredits.js | 5 ++++- lib/utils/preflight.js | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/kredits.js b/lib/kredits.js index fc1c168..a920ca9 100644 --- a/lib/kredits.js +++ b/lib/kredits.js @@ -40,12 +40,15 @@ class Kredits { this.abis = abis || ABIS; this.ipfs = new IPFS(ipfsConfig); this.contracts = {}; + this.networkId = null; } init(names) { let contractsToLoad = names || APP_CONTRACTS; return this.provider.getNetwork().then(network => { - this.addresses['Kernel'] = this.addresses['Kernel'] || DaoAddresses[network.chainId.toString()]; + this.networkId = network.chainId.toString(); + this.addresses['Kernel'] = this.addresses['Kernel'] || DaoAddresses[this.networkId]; + let addressPromises = contractsToLoad.map((contractName) => { return this.Kernel.getApp(contractName).then((address) => { this.addresses[contractName] = address; diff --git a/lib/utils/preflight.js b/lib/utils/preflight.js index aef3b64..13c563d 100644 --- a/lib/utils/preflight.js +++ b/lib/utils/preflight.js @@ -4,22 +4,28 @@ class Preflight { } check() { - return this.kredits.ipfs._ipfsAPI.id() + return this.kredits.ipfs.peerId() .catch((error) => { - throw new Error(`IPFS node not available; config: ${JSON.stringify(this.kredits.ipfs.config)} - ${error.message}`); + const ipfsConfig = JSON.stringify(this.kredits.ipfs.config); + throw new Error(`IPFS node not available; config: ${ipfsConfig} - ${error.message}`); }) .then(() => { let promises = Object.keys(this.kredits.contracts).map((name) => { - let contractWrapper = this.kredits.contracts[name]; - return this.kredits.provider.getCode(contractWrapper.contract.address).then((code) => { + let address = this.kredits.contracts[name].contract.address; + + // TODO: I think this throws the error: Error: contract not deployed + // I guess we don't need that if check anymore... + return this.kredits.provider.getCode(address).then((code) => { // not sure if we always get the same return value if the code is not available // so checking if it is < 5 long if (code === '0x00' || code.length < 5) { - throw new Error(`Contract for: ${name} not found at ${contractWrapper.contract.address} on network ${this.kredits.provider.chainId}`); + throw new Error(`Contract for: ${name} not found at ${address} on network ${this.kredits.networkId}`); } + return true; }); }); + return Promise.all(promises); }); } -- 2.25.1