Compare commits
5 Commits
914d4d9585
...
new-final-
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ba9a95fcd | |||
| f9e2312846 | |||
| cda84fa2ce | |||
| 97e2db93be | |||
| 17c582f6df |
@@ -31,18 +31,35 @@ contract Reimbursement is Initializable {
|
|||||||
|
|
||||||
uint32 public blocksToWait;
|
uint32 public blocksToWait;
|
||||||
|
|
||||||
|
// The address that deployed the contract
|
||||||
|
address public deployer;
|
||||||
|
|
||||||
|
// Data migration flag
|
||||||
|
bool public migrationDone;
|
||||||
|
|
||||||
event ReimbursementAdded(uint32 id, address indexed addedByAccount, uint256 amount);
|
event ReimbursementAdded(uint32 id, address indexed addedByAccount, uint256 amount);
|
||||||
event ReimbursementVetoed(uint32 id, address vetoedByAccount);
|
event ReimbursementVetoed(uint32 id, address vetoedByAccount);
|
||||||
|
|
||||||
function initialize() public initializer {
|
|
||||||
blocksToWait = 40320; // 7 days; 15 seconds block time
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier onlyCore {
|
modifier onlyCore {
|
||||||
require(contributorContract.addressIsCore(tx.origin), "Core only");
|
require(contributorContract.addressIsCore(tx.origin), "Core only");
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier onlyDeployer {
|
||||||
|
require(msg.sender == deployer, "Deployer only");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialize() public initializer {
|
||||||
|
deployer = msg.sender;
|
||||||
|
migrationDone = false;
|
||||||
|
blocksToWait = 40320; // 7 days; 15 seconds block time
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishMigration() public onlyDeployer {
|
||||||
|
migrationDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
function setContributorContract(address contributor) public {
|
function setContributorContract(address contributor) public {
|
||||||
require(address(contributorContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
|
require(address(contributorContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
|
||||||
contributorContract = ContributorInterface(contributor);
|
contributorContract = ContributorInterface(contributor);
|
||||||
@@ -82,7 +99,8 @@ contract Reimbursement is Initializable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(uint256 amount, address token, uint32 recipientId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
|
function add(uint256 amount, address token, uint32 recipientId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool vetoed) public onlyCore {
|
||||||
|
require((confirmedAtBlock == 0 && vetoed == false) || migrationDone == false, "Extra arguments not allowed");
|
||||||
uint32 reimbursementId = reimbursementsCount + 1;
|
uint32 reimbursementId = reimbursementsCount + 1;
|
||||||
ReimbursementData storage r = reimbursements[reimbursementId];
|
ReimbursementData storage r = reimbursements[reimbursementId];
|
||||||
r.exists = true;
|
r.exists = true;
|
||||||
@@ -92,7 +110,14 @@ contract Reimbursement is Initializable {
|
|||||||
r.hashDigest = hashDigest;
|
r.hashDigest = hashDigest;
|
||||||
r.hashFunction = hashFunction;
|
r.hashFunction = hashFunction;
|
||||||
r.hashSize = hashSize;
|
r.hashSize = hashSize;
|
||||||
r.confirmedAtBlock = block.number + blocksToWait;
|
|
||||||
|
if (confirmedAtBlock > 0) {
|
||||||
|
r.confirmedAtBlock = confirmedAtBlock;
|
||||||
|
} else {
|
||||||
|
r.confirmedAtBlock = block.number + 1 + blocksToWait;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vetoed) { r.vetoed = true; }
|
||||||
|
|
||||||
reimbursementsCount++;
|
reimbursementsCount++;
|
||||||
|
|
||||||
|
|||||||
44
scripts/export/reimbursements.js
Normal file
44
scripts/export/reimbursements.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
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 Reimbursement at: ${kredits.Reimbursement.contract.address}`);
|
||||||
|
|
||||||
|
const count = await kredits.Reimbursement.count;
|
||||||
|
const currentBlockHeight = await hre.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 reimbursement #${i}`);
|
||||||
|
await kredits.Reimbursement.contract.get(i).then(contractData => {
|
||||||
|
backup[i] = {
|
||||||
|
recipientId: contractData.recipientId,
|
||||||
|
amount: contractData.amount,
|
||||||
|
token: contractData.token,
|
||||||
|
hashDigest: contractData.hashDigest,
|
||||||
|
hashFunction: contractData.hashFunction,
|
||||||
|
hashSize: contractData.hashSize,
|
||||||
|
confirmedAtBlock: contractData.confirmedAtBlock,
|
||||||
|
confirmed: contractData.confirmedAtBlock <= currentBlockHeight,
|
||||||
|
vetoed: contractData.vetoed,
|
||||||
|
id: contractData.id,
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}, 100 * i);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises).then(() => {
|
||||||
|
fs.writeFileSync("./data/reimbursements.json", JSON.stringify(backup, null, 2));
|
||||||
|
console.log("Exported");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -14,13 +14,17 @@ async function main() {
|
|||||||
const contributions = JSON.parse(data);
|
const contributions = JSON.parse(data);
|
||||||
const ids = Object.keys(contributions)
|
const ids = Object.keys(contributions)
|
||||||
.map(k => parseInt(k))
|
.map(k => parseInt(k))
|
||||||
.sort(function(a, b){return a-b});
|
.sort(function(a, b) { return a - b });
|
||||||
|
|
||||||
const currentBlockHeight = await kredits.provider.getBlockNumber();
|
const currentBlockHeight = await kredits.provider.getBlockNumber();
|
||||||
const confirmationPeriod = 40320 // blocks
|
const confirmationPeriod = 40320 // blocks
|
||||||
const unconfirmedHeight = currentBlockHeight + confirmationPeriod;
|
const unconfirmedHeight = currentBlockHeight + confirmationPeriod;
|
||||||
|
|
||||||
|
const startId = parseInt(process.env.START_AT || "0");
|
||||||
for (const contributionId of ids) {
|
for (const contributionId of ids) {
|
||||||
|
if (contributionId < startId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const c = contributions[contributionId.toString()];
|
const c = contributions[contributionId.toString()];
|
||||||
|
|
||||||
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
|
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
|
||||||
@@ -33,7 +37,7 @@ async function main() {
|
|||||||
console.log(`Adding contribution #${contributionId}: ${result.hash}`);
|
console.log(`Adding contribution #${contributionId}: ${result.hash}`);
|
||||||
await result.wait();
|
await result.wait();
|
||||||
};
|
};
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
scripts/import/reimbursements.js
Normal file
36
scripts/import/reimbursements.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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 Reimbursement at: ${kredits.Reimbursement.contract.address}`);
|
||||||
|
const count = await kredits.Reimbursement.count;
|
||||||
|
console.log(`Currently ${count} entries`);
|
||||||
|
try {
|
||||||
|
const data = fs.readFileSync("./data/reimbursements.json");
|
||||||
|
const reimbursements = JSON.parse(data);
|
||||||
|
const ids = Object.keys(reimbursements)
|
||||||
|
.map(k => parseInt(k))
|
||||||
|
.sort(function(a, b) { return a - b });
|
||||||
|
|
||||||
|
for (const reimbursementId of ids) {
|
||||||
|
const reimbursement = reimbursements[reimbursementId.toString()];
|
||||||
|
const result = await kredits.Reimbursement.contract.add(
|
||||||
|
reimbursement.amount,
|
||||||
|
reimbursement.token,
|
||||||
|
reimbursement.recipientId,
|
||||||
|
reimbursement.hashDigest,
|
||||||
|
reimbursement.hashFunction,
|
||||||
|
reimbursement.hashSize,
|
||||||
|
);
|
||||||
|
console.log(`Adding reimbursement #${reimbursementId}: ${result.hash}`);
|
||||||
|
await result.wait();
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
Reference in New Issue
Block a user