Add export/import functionality #224

Merged
raucao merged 23 commits from feature/export-import into master 2022-09-02 20:31:28 +00:00
Showing only changes of commit 1521e272f9 - Show all commits

View File

@ -1,3 +1,4 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits'); const Kredits = require('../../lib/kredits');
async function main() { async function main() {
@ -6,21 +7,27 @@ async function main() {
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`); console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
try {
const data = fs.readFileSync("./data/contributors.json"); const data = fs.readFileSync("./data/contributors.json");
const contributors = JSON.parse(data); const contributors = JSON.parse(data);
const ids = Object.keys(contributors)
.map(k => parseInt(k))
.sort(function(a, b){return a-b});
const ids = Object.keys(contributors).map(k => parseInt(k)).sort();
for (const contributorId of ids) { for (const contributorId of ids) {
const contributor = contributors[contributorId.toString()]; const contributor = contributors[contributorId.toString()];
const result = kredits.Contributor.contract.addContributor({ const result = await kredits.Contributor.contract.addContributor(
account: contributor.account, contributor.account,
hashDigest: contirbutor.hashDigest, contributor.hashDigest,
hashFunction: contributor.hashFunction, contributor.hashFunction,
hashSize: contributr.hashSize, contributor.hashSize,
}); );
// await result.wait(); // await result.wait();
console.log(`Added contributor #${id}: ${result.hash}`); console.log(`Added contributor #${contributorId}: ${result.hash}`);
}; };
} catch(e) {
console.log(e);
}
} }
main(); main();