Make it work

This commit is contained in:
bumi 2019-07-02 16:35:53 +02:00
parent 746149e89a
commit 03438bb890
4 changed files with 18 additions and 9 deletions

View File

@ -2,7 +2,6 @@
This tool pins the IPFS hashes of a Kredits organisation on a IPFS node. This tool pins the IPFS hashes of a Kredits organisation on a IPFS node.
## Usage ## Usage
$ kredits-ipfs-pinner --help $ kredits-ipfs-pinner --help

View File

@ -7,7 +7,8 @@ class IpfsPinner {
pinAll () { pinAll () {
return Promise.all([ return Promise.all([
this._pinAllFromContract(this.kredits.Contributor), this._pinAllFromContract(this.kredits.Contributor),
this._pinAllFromContract(this.kredits.Contribution) this._pinAllFromContract(this.kredits.Contribution),
this._pinAllFromContract(this.kredits.Proposal)
]); ]);
} }
@ -30,10 +31,13 @@ class IpfsPinner {
} }
_pinAllFromContract (contract) { _pinAllFromContract (contract) {
console.log(`Pinning data from ${contract.constructor.name}...`);
return contract.count.then(count => { return contract.count.then(count => {
let promises = [...Array(count).keys()].map(i => { let promises = [...Array(count).keys()].map(i => {
let id = i + 1; // 0 => 1 - ids start with 1 and not with 0 let id = i + 1; // 0 => 1 - ids start with 1 and not with 0
console.log(`Loading ${contract.constructor.name} #${id}`);
return contract.getData(id).then(data => { return contract.getData(id).then(data => {
console.log(`Pinning ${contract.constructor.name} #${id}`);
return this.ipfsApi.pin(data); return this.ipfsApi.pin(data);
}); });
}); });

18
package-lock.json generated
View File

@ -1073,13 +1073,14 @@
} }
}, },
"kredits-contracts": { "kredits-contracts": {
"version": "5.3.0", "version": "5.4.0",
"resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.3.0.tgz", "resolved": "https://registry.npmjs.org/kredits-contracts/-/kredits-contracts-5.4.0.tgz",
"integrity": "sha512-Wz4zuA6yo0Q4WbVEO61fvFin+6VTNjkBqHPhHCqq6dIoGdFSjUZ3BCKan1ei0axIAda7ZDP+eebe2vCr+eqcHg==", "integrity": "sha512-Oz5c+wbuDhZ0uYKRWPxSpsNiUXdrZlJ6Vp/+IMMSjD/TmlHGwP2Pnmloyq4Xjim0JbA/bJSjyBdy62dCrqCLrw==",
"requires": { "requires": {
"ethers": "^4.0.27", "ethers": "^4.0.29",
"ipfs-http-client": "^30.1.1", "ipfs-http-client": "^30.1.3",
"kosmos-schemas": "^2.0.0", "kosmos-schemas": "^2.1.0",
"node-fetch": "^2.6.0",
"tv4": "^1.3.0" "tv4": "^1.3.0"
} }
}, },
@ -1338,6 +1339,11 @@
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
"integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ=="
}, },
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"node-forge": { "node-forge": {
"version": "0.7.6", "version": "0.7.6",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz",

View File

@ -12,7 +12,7 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"kredits-contracts": "^5.3.0", "kredits-contracts": "^5.4.0",
"yargs": "^13.2.4" "yargs": "^13.2.4"
} }
} }