Added export/import function for contributors
This commit is contained in:
parent
2b05be1897
commit
2fca436fa8
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,8 @@ node_modules
|
|||||||
yarn-error.log
|
yarn-error.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
data
|
||||||
|
|
||||||
cache
|
cache
|
||||||
artifacts
|
artifacts
|
||||||
.openzeppelin
|
.openzeppelin
|
||||||
|
45
scripts/export/contributions.js
Normal file
45
scripts/export/contributions.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
|
||||||
|
|
||||||
|
const count = await kredits.Contribution.count;
|
||||||
|
const currentBlockHeight = await XMLHttpRequest.ethers.provider.getBlockNumber();
|
||||||
|
|
||||||
|
const backup = {};
|
||||||
|
const promises = [];
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log(`Loading contribution ${i}`);
|
||||||
|
await kredits.Contribution.contract.getContribution(i).then(contractData => {
|
||||||
|
if (contractData.vetoed) {
|
||||||
|
console.log(`Ignoring vetoed contribution #${contractData.id}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
backup[i] = {
|
||||||
|
amount: contractData.amount,
|
||||||
|
contributorId: contractData.contributorId,
|
||||||
|
hashDigest: contractData.hashDigest,
|
||||||
|
hashFunction: contractData.hashFunction,
|
||||||
|
hashSize: contractData.hashSize,
|
||||||
|
confirmedAtBlock: contractData.confirmedAtBlock,
|
||||||
|
confirmed: contractData.confirmedAtBlock <= currentBlockHeight,
|
||||||
|
id: contractData.id,
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}, 100 * i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises).then(() => {
|
||||||
|
fs.writeFileSync("./data/contributions.json", JSON.stringify(backup, null, 2));
|
||||||
|
console.log("Exported");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
38
scripts/export/contributors.js
Normal file
38
scripts/export/contributors.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
const count = await kredits.Contributor.count;
|
||||||
|
|
||||||
|
const backup = {};
|
||||||
|
const promises = [];
|
||||||
|
for (let i = 1; i <= count; i++) {
|
||||||
|
promises.push(new Promise((resolve, reject) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
console.log(`Loading contributor ${i}`);
|
||||||
|
await kredits.Contributor.contract.getContributorById(i).then(contractData => {
|
||||||
|
backup[i] = {
|
||||||
|
account: contractData.account,
|
||||||
|
hashDigest: contractData.hashDigest,
|
||||||
|
hashFunction: contractData.hashFunction,
|
||||||
|
hashSize: contractData.hashSize,
|
||||||
|
id: contractData.id,
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}, 100 * i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises).then(() => {
|
||||||
|
fs.writeFileSync("./data/contributors.json", JSON.stringify(backup, null, 2));
|
||||||
|
console.log("Exported");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
26
scripts/import/contributors.js
Normal file
26
scripts/import/contributors.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const Kredits = require('../../lib/kredits');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
|
||||||
|
await kredits.init();
|
||||||
|
|
||||||
|
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
|
||||||
|
|
||||||
|
const data = fs.readFileSync("./data/contributors.json");
|
||||||
|
const contributors = JSON.parse(data);
|
||||||
|
|
||||||
|
const ids = Object.keys(contributors).map(k => parseInt(k)).sort();
|
||||||
|
for (const contributorId of ids) {
|
||||||
|
const contributor = contributors[contributorId.toString()];
|
||||||
|
const result = kredits.Contributor.contract.addContributor({
|
||||||
|
account: contributor.account,
|
||||||
|
hashDigest: contirbutor.hashDigest,
|
||||||
|
hashFunction: contributor.hashFunction,
|
||||||
|
hashSize: contributr.hashSize,
|
||||||
|
});
|
||||||
|
// await result.wait();
|
||||||
|
console.log(`Added contributor #${id}: ${result.hash}`);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
Loading…
x
Reference in New Issue
Block a user