WIP: Create Kredits contributions for reviews #1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/node_modules/
|
||||
.env
|
||||
wallet.json
|
||||
|
61
index.js
61
index.js
@ -5,12 +5,15 @@ const GiteaReviews = require('./lib/gitea-reviews');
|
||||
const GithubReviews = require('./lib/github-reviews');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const NonceManager = require('@ethersproject/experimental').NonceManager;
|
||||
const Kredits = require('kredits-contracts');
|
||||
const util = require('util');
|
||||
|
||||
const yargs = require('yargs/yargs');
|
||||
const { hideBin } = require('yargs/helpers');
|
||||
|
||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||
const walletJson = require(walletPath);
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
||||
|
||||
@ -94,6 +97,21 @@ async function getAllReviews(repos, startDate, endDate) {
|
||||
}
|
||||
|
||||
async function initializeKredits() {
|
||||
//
|
||||
// Ethereum wallet setup
|
||||
//
|
||||
|
||||
let wallet;
|
||||
try {
|
||||
wallet = await ethers.Wallet.fromEncryptedJson(
|
||||
walletJson,
|
||||
process.env.KREDITS_WALLET_PASSWORD
|
||||
);
|
||||
} catch (error) {
|
||||
console.log('Could not load wallet:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Ethereum provider/node setup
|
||||
//
|
||||
@ -104,6 +122,7 @@ async function initializeKredits() {
|
||||
} else {
|
||||
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||
}
|
||||
const signer = new NonceManager(wallet.connect(ethProvider));
|
||||
|
||||
//
|
||||
// Kredits contracts setup
|
||||
@ -116,15 +135,55 @@ async function initializeKredits() {
|
||||
let kredits;
|
||||
|
||||
try {
|
||||
kredits = await new Kredits(ethProvider, null, opts).init();
|
||||
kredits = await new Kredits(signer.provider, signer, opts).init();
|
||||
} catch (error) {
|
||||
console.log('Could not set up kredits:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
const Contributor = kredits.Contributor;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
return kredits;
|
||||
}
|
||||
|
||||
function createContribution(
|
||||
giteaUser,
|
||||
date,
|
||||
time,
|
||||
amount,
|
||||
kind,
|
||||
description,
|
||||
url,
|
||||
details
|
||||
) {
|
||||
return getContributorByGiteaUser(giteaUser).then((contributor) => {
|
||||
console.log(
|
||||
`Creating contribution token for ${amount}₭S to ${giteaUser} for ${url}...`
|
||||
);
|
||||
|
||||
const contributionAttr = {
|
||||
contributorId: contributor.id,
|
||||
contributorIpfsHash: contributor.ipfsHash,
|
||||
date,
|
||||
time,
|
||||
amount,
|
||||
kind,
|
||||
description,
|
||||
url,
|
||||
details,
|
||||
};
|
||||
|
||||
console.log(`contribution attributes:`);
|
||||
console.log(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
||||
|
||||
// return Contribution.add(contributionAttr).catch(error => {
|
||||
// console.log(`I tried to add a contribution for ${giteaUser} for ${url}, but I encountered an error when submitting the tx:`);
|
||||
// console.log(`Error:`, error);
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
async function generateContributionData(reviews, Contributor) {
|
||||
const contributors = await Contributor.all();
|
||||
const contributionData = {};
|
||||
|
Reference in New Issue
Block a user