51 lines
1.7 KiB
JavaScript
Executable File
51 lines
1.7 KiB
JavaScript
Executable File
#! /usr/bin/env node
|
|
|
|
const Kredits = require('kredits-contracts');
|
|
const IpfsPinner = require('./lib/ipfs-pinner');
|
|
|
|
const argv = require('yargs')
|
|
.default({ network: 'rinkeby', apm: 'open.aragonpm.eth', host: 'localhost', port: '5001', protocol: 'http', monitor: true })
|
|
.boolean('monitor')
|
|
.describe({
|
|
network: 'Ethereum network to connect to',
|
|
rpcUrl: 'Ethereum node RPC URL; alternative to --network',
|
|
daoAddress: 'Optional Kredits DAO address',
|
|
host: 'IPFS API host',
|
|
port: 'IPFS API port',
|
|
protocol: 'IPFS API protocol',
|
|
monitor: 'Monitor contract events for new IPFS documents'
|
|
})
|
|
.example('$0 --network rinkeby --host localhost', 'Pins all existing IPFS documents to the IPFS API running on localhost and monitors for new events.')
|
|
.argv;
|
|
|
|
const ipfsConfig = {
|
|
host: argv.host,
|
|
port: argv.port,
|
|
protocol: argv.protocol
|
|
};
|
|
|
|
console.log(`Using IPFS:`, ipfsConfig);
|
|
|
|
(async () => {
|
|
try {
|
|
const kredits = await Kredits.for(
|
|
{ network: argv.network, rpcUrl: argv.rpcUrl },
|
|
{ apm: argv.apm, ipfsConfig: ipfsConfig, addresses: { Kernel: argv.daoAddress } }
|
|
).init();
|
|
await kredits.ipfs._ipfsAPI.id(); // check the connection to the IPFS client TODO: redesign IPFS wrapper API and not use an internal attribute
|
|
const ipfsPinner = new IpfsPinner(kredits);
|
|
|
|
ipfsPinner.pinAll().then(pins => {
|
|
console.log('Pinned', JSON.stringify(pins, null, 2));
|
|
});
|
|
ipfsPinner.monitor((pin) => {
|
|
console.log('Pinned', JSON.stringify(pin));
|
|
});
|
|
console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
|
|
} catch(e) {
|
|
console.log('Failed to start pinner');
|
|
console.log(e);
|
|
process.exit(1);
|
|
}
|
|
})();
|