Better ipfs handling and default configs
This commit is contained in:
parent
424a2c4d02
commit
a16cd862f6
@ -32,14 +32,13 @@ class Kredits {
|
|||||||
// Initialize our registry contract
|
// Initialize our registry contract
|
||||||
this.addresses = addresses;
|
this.addresses = addresses;
|
||||||
this.contracts = {};
|
this.contracts = {};
|
||||||
|
this.ipfs = new IPFS();
|
||||||
}
|
}
|
||||||
|
|
||||||
static setup(provider, signer, ipfsConfig) {
|
static setup(provider, signer, ipfsConfig = null) {
|
||||||
this.ipfsConfig = ipfsConfig;
|
|
||||||
let ipfsAPI = new IPFS(ipfsConfig);
|
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}`);
|
throw new Error(`IPFS node not available; config: ${JSON.stringify(ipfsConfig)} - ${error.message}`);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
||||||
@ -83,13 +82,6 @@ class Kredits {
|
|||||||
return new ethers.Contract(address, abi, provider);
|
return new ethers.Contract(address, abi, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
get ipfs() {
|
|
||||||
return this._ipfsAPI;
|
|
||||||
}
|
|
||||||
set ipfs(ipfs) {
|
|
||||||
this._ipfsAPI = ipfs;
|
|
||||||
}
|
|
||||||
|
|
||||||
get Contributor() {
|
get Contributor() {
|
||||||
// TODO: rename to contributor
|
// TODO: rename to contributor
|
||||||
return this.contractFor('contributors');
|
return this.contractFor('contributors');
|
||||||
|
@ -4,6 +4,9 @@ const multihashes = require('multihashes');
|
|||||||
class IPFS {
|
class IPFS {
|
||||||
|
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
if (!config) {
|
||||||
|
config = {host: 'localhost', port: '5001', protocol: 'http'};
|
||||||
|
}
|
||||||
this._ipfsAPI = ipfsAPI(config);
|
this._ipfsAPI = ipfsAPI(config);
|
||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user