Merge branch 'feature/connect_to_kosmos_ipfs_node' of kosmos/kredits-ipfs-pinner into master
This commit is contained in:
commit
bfb51d48bc
17
index.js
17
index.js
|
@ -2,6 +2,7 @@
|
|||
|
||||
const Kredits = require('kredits-contracts');
|
||||
const IpfsPinner = require('./lib/ipfs-pinner');
|
||||
const debug = require('debug')('ipfs-pinner');
|
||||
|
||||
const argv = require('yargs')
|
||||
.default({ network: 'rinkeby', apm: 'open.aragonpm.eth', host: 'localhost', port: '5001', protocol: 'http', monitor: true })
|
||||
|
@ -26,6 +27,15 @@ const ipfsConfig = {
|
|||
|
||||
console.log(`Using IPFS:`, ipfsConfig);
|
||||
|
||||
async function swarmConnect (ipfsApi, address) {
|
||||
return new Promise((resolve, reject) => {
|
||||
debug(`Connecting to known IPFS node: ${address}`);
|
||||
ipfsApi.swarm.connect(address, err => {
|
||||
return err ? reject(err) : resolve();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const kredits = await Kredits.for(
|
||||
|
@ -35,7 +45,12 @@ console.log(`Using IPFS:`, ipfsConfig);
|
|||
|
||||
// check the connection to the IPFS client
|
||||
// TODO redesign IPFS wrapper API and do not use an internal attribute
|
||||
await kredits.ipfs._ipfsAPI.id();
|
||||
const ipfsApi = kredits.ipfs._ipfsAPI;
|
||||
|
||||
await ipfsApi.id();
|
||||
|
||||
// TODO discover address dynamically from somewhere
|
||||
await swarmConnect(ipfsApi, '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7');
|
||||
|
||||
const ipfsPinner = new IpfsPinner(kredits);
|
||||
|
||||
|
|
Loading…
Reference in New Issue