Compare commits

..

2 Commits

Author SHA1 Message Date
Râu Cao
96a18d3c5c Bundle import txs into blocks, wait for confirmations
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-24 12:41:40 +02:00
Râu Cao
b3dabb41e1 Add RSK testnet contract addresses
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-23 18:46:57 +02:00
7 changed files with 49 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
{
"31": {
"Contributor": "0xf1073Dab6e305583F95e451Cba449bB867a6e3Fd",
"Contribution": "0x1C531F824e339cD37D75B7F391cB8E42e0E0d4bd",
"Token": "0x56F64C3BB45e6a248F4C783f5a1633E53D6A2371",
"Reimbursement": "0x9C5fFBFba2570A9b31D60338453C5480Ce74B342"
"Contributor": "0x9C66a36fa6296EBb81d8F5D4642B05dF2CE85a8D",
"Contribution": "0xa12630a995337e45bDD746B6baedc1Ce2a1DCC9D",
"Token": "0x12Eb86338076450f86E5B552556028c7D21eaf1F",
"Reimbursement": "0xe2FE7cb00e2f94b8bA0AE526dfbe313f34c66E3C"
},
"1337": {
"Contributor": "0xCc66f9A3cA2670972938FAD91d0865c4a62DFB25",

View File

@@ -69,10 +69,7 @@ class Kredits {
if (wallet) {
signer = wallet.connect(ethProvider);
} else if (ethProvider.getSigner) {
// Only useful for reading data, not writing. The (unused) address is
// necessary because without an address, ethers.js will try to look up
// the provider's account 0, which doesn't work on our public RSK nodes.
signer = ethProvider.getSigner('0xfa77675540E550b911a6AABF3805ac17C6641ec1');
signer = ethProvider.getSigner();
}
return new Kredits(ethProvider, signer, kreditsOptions);
}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "kredits-contracts",
"version": "7.0.0",
"version": "7.0.0-beta.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "kredits-contracts",
"version": "7.0.0",
"version": "7.0.0-beta.0",
"license": "MIT",
"dependencies": {
"@kosmos/schemas": "^3.1.0",

View File

@@ -1,7 +1,7 @@
{
"name": "@kredits/contracts",
"version": "7.0.0",
"description": "Smart contracts and JavaScript API for Kredits",
"name": "kredits-contracts",
"version": "7.0.0-beta.0",
"description": "Ethereum contracts and npm wrapper for Kredits",
"main": "./lib/kredits.js",
"directories": {
"test": "test"

View File

@@ -1,13 +1,13 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits');
const PARALLEL_TXS = 5;
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;
console.log(`Currently ${count} entries`);
try {
const data = fs.readFileSync("./data/contributions.json");
@@ -20,21 +20,42 @@ async function main() {
const confirmationPeriod = 40320 // blocks
const unconfirmedHeight = currentBlockHeight + confirmationPeriod;
for (const contributionId of ids) {
const c = contributions[contributionId.toString()];
const txBundlesAmount = Math.ceil(ids.length / PARALLEL_TXS);
let txBundles = [];
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
for (let i = 0; i < txBundlesAmount; i++) {
txBundles.push(ids.slice((i * PARALLEL_TXS), (i * PARALLEL_TXS) + PARALLEL_TXS));
}
const result = await kredits.Contribution.contract.add(
c.amount, c.contributorId,
c.hashDigest, c.hashFunction, c.hashSize,
confirmedAtBlock, c.vetoed
);
console.log(`Adding contribution #${contributionId}: ${result.hash}`);
await result.wait();
};
for (const txBundle of txBundles) {
console.log(`Adding contributions #${txBundle[0]} to #${txBundle[txBundle.length - 1]}`)
let resultPromises = [];
for (const contributionId of txBundle) {
const c = contributions[contributionId.toString()];
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
const result = await kredits.Contribution.contract.add(
c.amount, c.contributorId,
c.hashDigest, c.hashFunction, c.hashSize,
confirmedAtBlock, c.vetoed
);
resultPromises.push(result.wait());
console.log(`Added contribution #${contributionId}: ${result.hash}`);
}
console.log(`Waiting for confirmations...`);
await Promise.all(resultPromises);
console.log('Transactions confirmed');
}
} catch(e) {
console.error(e);
console.log(e);
}
}

View File

@@ -6,8 +6,7 @@ async function main() {
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const count = await kredits.Contributor.count;
console.log(`Currently ${count} entries`);
try {
const data = fs.readFileSync("./data/contributors.json");
const contributors = JSON.parse(data);
@@ -23,11 +22,11 @@ async function main() {
contributor.hashFunction,
contributor.hashSize,
);
console.log(`Adding contributor #${contributorId}: ${result.hash}`);
await result.wait();
// await result.wait();
console.log(`Added contributor #${contributorId}: ${result.hash}`);
};
} catch(e) {
console.error(e);
console.log(e);
}
}

View File

@@ -6,8 +6,6 @@ async function main() {
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const count = await kredits.Contributors.count;
console.log(`Currently ${count} entries`);
const table = new Table({
head: ['ID', 'Account', 'Name', 'Core?', 'Balance', 'Kredits earned', 'Contributions count', 'IPFS']