WIP: IPFS cleanup #107

Closed
fsmanuel wants to merge 3 commits from fix/ipfs-config into master
2 changed files with 15 additions and 6 deletions
Showing only changes of commit 7a6b117876 - Show all commits

View File

@ -40,12 +40,15 @@ class Kredits {
this.abis = abis || ABIS; this.abis = abis || ABIS;
this.ipfs = new IPFS(ipfsConfig); this.ipfs = new IPFS(ipfsConfig);
this.contracts = {}; this.contracts = {};
this.networkId = null;
} }
init(names) { init(names) {
let contractsToLoad = names || APP_CONTRACTS; let contractsToLoad = names || APP_CONTRACTS;
return this.provider.getNetwork().then(network => { 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) => { let addressPromises = contractsToLoad.map((contractName) => {
return this.Kernel.getApp(contractName).then((address) => { return this.Kernel.getApp(contractName).then((address) => {
this.addresses[contractName] = address; this.addresses[contractName] = address;

View File

@ -4,22 +4,28 @@ class Preflight {
} }
check() { check() {
return this.kredits.ipfs._ipfsAPI.id() return this.kredits.ipfs.peerId()
.catch((error) => { .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(() => { .then(() => {
let promises = Object.keys(this.kredits.contracts).map((name) => { let promises = Object.keys(this.kredits.contracts).map((name) => {
let contractWrapper = this.kredits.contracts[name]; let address = this.kredits.contracts[name].contract.address;
return this.kredits.provider.getCode(contractWrapper.contract.address).then((code) => {
// 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 // not sure if we always get the same return value if the code is not available
// so checking if it is < 5 long // so checking if it is < 5 long
if (code === '0x00' || code.length < 5) { 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 true;
}); });
}); });
return Promise.all(promises); return Promise.all(promises);
}); });
} }