Browse Source

Refactor bootstrap node connect, add CLI argument

Removes the superfluous wrapper function (as the API already returns a
Promise). Also adds a command line argument so you can choose a
different bootstrap node.
raucao 1 year ago
Signed by: raucao <> GPG Key ID: BE4634D632D39B67
1 changed files with 13 additions and 13 deletions
  1. +13

+ 13
- 13
index.js View File

@@ -5,7 +5,15 @@ 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 })
network: 'rinkeby',
apm: 'open.aragonpm.eth',
host: 'localhost',
port: '5001',
protocol: 'http',
monitor: true,
bootstrapNode: '/ip4/'
network: 'Ethereum network to connect to',
@@ -14,7 +22,8 @@ const argv = require('yargs')
host: 'IPFS API host',
port: 'IPFS API port',
protocol: 'IPFS API protocol',
monitor: 'Monitor contract events for new IPFS documents'
monitor: 'Monitor contract events for new IPFS documents',
bootstrapNode: 'IPFS node address to connect to before fetching documents'
.example('$0 --network rinkeby --host localhost', 'Pins all existing IPFS documents to the IPFS API running on localhost and monitors for new events.')
@@ -27,15 +36,6 @@ 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(
@@ -49,8 +49,8 @@ async function swarmConnect (ipfsApi, address) {


// TODO discover address dynamically from somewhere
await swarmConnect(ipfsApi, '/ip4/');
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
await ipfsApi.swarm.connect(argv.bootstrapNode);

const ipfsPinner = new IpfsPinner(kredits);