Compare commits
7 Commits
v2.0.0
...
83b3045afd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83b3045afd
|
||
|
|
3c7bcf038e
|
||
|
|
0a21c57251
|
||
| 1401adbf0c | |||
|
|
2401d8dff2
|
||
|
|
45c0aed4a5
|
||
|
|
f25fcaa1b2
|
@@ -1,3 +1,5 @@
|
||||
[](https://www.npmjs.com/package/@kredits/ipfs-pinner)
|
||||
|
||||
# Kredits IPFS Pinner
|
||||
|
||||
This tool pins the IPFS documents of a Kredits organization on any IPFS node.
|
||||
|
||||
13
index.js
13
index.js
@@ -50,15 +50,22 @@ debug(`IPFS node:`, ipfsConfig);
|
||||
|
||||
// TODO redesign IPFS wrapper API and do not use an internal attribute
|
||||
const ipfsApi = kredits.ipfs._ipfsAPI;
|
||||
let connectBootstrapNode = true;
|
||||
|
||||
await ipfsApi.id().catch(e => {
|
||||
await ipfsApi.id().then(res => {
|
||||
if (res.id === argv.bootstrapNode.split('/')[argv.bootstrapNode.split('/').length-1]) {
|
||||
connectBootstrapNode = false;
|
||||
}
|
||||
}).catch(e => {
|
||||
console.log('Failed to initialize IPFS:');
|
||||
console.log(e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||
if (connectBootstrapNode) {
|
||||
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||
}
|
||||
|
||||
const ipfsPinner = new IpfsPinner(kredits, {
|
||||
progress: argv.progress
|
||||
|
||||
@@ -29,8 +29,7 @@ class IpfsPinner {
|
||||
const contracts = [
|
||||
this.kredits.Contributor,
|
||||
this.kredits.Contribution,
|
||||
// TODO uncomment once we have data here
|
||||
// this.kredits.Reimbursement
|
||||
this.kredits.Reimbursement
|
||||
]
|
||||
|
||||
for (const contract of contracts) {
|
||||
@@ -72,6 +71,11 @@ class IpfsPinner {
|
||||
.then(data => { return this.ipfsApi.pin(data); })
|
||||
.then(callback);
|
||||
});
|
||||
this.kredits.Reimbursement.on('ReimbursementAdded', (id) => {
|
||||
this.kredits.Reimbursement.getData(id)
|
||||
.then(data => { return this.ipfsApi.pin(data); })
|
||||
.then(callback);
|
||||
});
|
||||
}
|
||||
|
||||
async _pinAllFromContract (contract, itemCount, progressBar) {
|
||||
@@ -91,7 +95,7 @@ class IpfsPinner {
|
||||
cid = await ipfsApi.pin(data);
|
||||
debug(`Pinned ${contract.constructor.name} #${id} at ${cid}`);
|
||||
} catch(e) {
|
||||
debug(`Error while trying to load an pin ${contract.constructor.name} #${id}:`)
|
||||
debug(`Error while trying to load and pin ${contract.constructor.name} #${id}:`)
|
||||
debug(e);
|
||||
debug(`\nTrying again...`);
|
||||
loadAndPin(id);
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"@kredits/contracts": "^7.1.0",
|
||||
"cli-progress": "^3.11.2",
|
||||
"debug": "^4.3.4",
|
||||
"yargs": "^17.6.0"
|
||||
@@ -721,9 +721,9 @@
|
||||
"integrity": "sha512-yOTK5WiXFDNAitPByMabE365aEEzFHgSUSgAssbJWt7BZ80HQSVu8XWrQiTbFbCkoIBmXwPP/RoxgXJQVgZTFQ=="
|
||||
},
|
||||
"node_modules/@kredits/contracts": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.0.0.tgz",
|
||||
"integrity": "sha512-UITEkP3njFNI2WS7v5ivGE3ruFwdWPWuJZrhBXBEAZbtmr1t/p1K7jkmmjyLDUeKXJ/udMlH6oQMCgh7P/aHNg==",
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.1.0.tgz",
|
||||
"integrity": "sha512-RyZdKj6Ohr4UwoQ5Ne5CtShG/9j+v4EjDMvKmTwAU7uY1rbxpEWfMFo1xuYdAsT6ZVhiuMjVY3RG/8kPZVv9NQ==",
|
||||
"dependencies": {
|
||||
"@kosmos/schemas": "^3.1.0",
|
||||
"ethers": "^5.4.7",
|
||||
@@ -2245,9 +2245,9 @@
|
||||
"integrity": "sha512-yOTK5WiXFDNAitPByMabE365aEEzFHgSUSgAssbJWt7BZ80HQSVu8XWrQiTbFbCkoIBmXwPP/RoxgXJQVgZTFQ=="
|
||||
},
|
||||
"@kredits/contracts": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.0.0.tgz",
|
||||
"integrity": "sha512-UITEkP3njFNI2WS7v5ivGE3ruFwdWPWuJZrhBXBEAZbtmr1t/p1K7jkmmjyLDUeKXJ/udMlH6oQMCgh7P/aHNg==",
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@kredits/contracts/-/contracts-7.1.0.tgz",
|
||||
"integrity": "sha512-RyZdKj6Ohr4UwoQ5Ne5CtShG/9j+v4EjDMvKmTwAU7uY1rbxpEWfMFo1xuYdAsT6ZVhiuMjVY3RG/8kPZVv9NQ==",
|
||||
"requires": {
|
||||
"@kosmos/schemas": "^3.1.0",
|
||||
"ethers": "^5.4.7",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kredits/ipfs-pinner",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"description": "Pins IPFS data of a Kredits organization on an IPFS node",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -20,7 +20,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"@kredits/contracts": "^7.1.0",
|
||||
"cli-progress": "^3.11.2",
|
||||
"debug": "^4.3.4",
|
||||
"yargs": "^17.6.0"
|
||||
|
||||
Reference in New Issue
Block a user