@kredits/hubot-kredits
Advanced tools
Comparing version 4.0.1 to 4.0.2
{ | ||
"name": "@kredits/hubot-kredits", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Kosmos Kredits functionality for chat bots", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
[![npm](https://img.shields.io/npm/v/hubot-kredits.svg)](https://www.npmjs.com/package/hubot-kredits) | ||
[![npm](https://img.shields.io/npm/v/@kredits/hubot-kredits.svg)](https://www.npmjs.com/package/@kredits/hubot-kredits) | ||
@@ -3,0 +3,0 @@ # Hubot Kredits |
#!/usr/bin/env node | ||
require('dotenv').config({ path: '../.env' }); | ||
require('dotenv').config({ path: '.env' }); | ||
const GiteaReviews = require('./lib/gitea-reviews'); | ||
@@ -8,8 +8,12 @@ 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 yargs = require('yargs/yargs'); | ||
const { hideBin } = require('yargs/helpers'); | ||
const fs = require('fs'); | ||
const walletPath = process.env.KREDITS_WALLET_PATH || '../wallet.json'; | ||
const walletJson = fs.readFileSync(walletPath); | ||
const providerUrl = process.env.KREDITS_PROVIDER_URL; | ||
@@ -88,3 +92,2 @@ const daoAddress = process.env.KREDITS_DAO_ADDRESS; | ||
]).then(reviews => { | ||
// console.log(util.inspect(reviews[0], { depth: 3, colors: true })); | ||
return { github: reviews[0], gitea: reviews[1] } | ||
@@ -96,2 +99,14 @@ }); | ||
// | ||
// 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 | ||
@@ -106,2 +121,3 @@ // | ||
} | ||
const signer = new NonceManager(wallet.connect(ethProvider)); | ||
@@ -119,3 +135,3 @@ // | ||
try { | ||
kredits = await new Kredits(ethProvider, null, opts).init(); | ||
kredits = await new Kredits(signer.provider, signer, opts).init(); | ||
} catch(error) { | ||
@@ -129,2 +145,13 @@ console.log('Could not set up kredits:', error); | ||
function createContribution(contributorName, contributionAttributes, Contribution) { | ||
console.log(`Creating contribution token for ${contributionAttributes.amount}₭S to ${contributorName} for ${contributionAttributes.description}...`); | ||
return Contribution.add(contributionAttributes).catch(error => { | ||
console.log(`I tried to add a contribution for ${contributorName}, but I encountered an error when submitting the tx:`); | ||
console.log(`Error:`, error); | ||
console.log('Contribution attributes:'); | ||
console.log(util.inspect(contributionAttributes, { depth: 2, colors: true })); | ||
}); | ||
} | ||
async function generateContributionData(reviews, Contributor, startDate, endDate) { | ||
@@ -188,9 +215,12 @@ const dateFormatOptions = { year: 'numeric', month: 'long', day: 'numeric' }; | ||
if (argv.dry) { | ||
console.log('contributions:'); | ||
console.log('Contributions:'); | ||
console.log(util.inspect(contributionData, { depth: 3, colors: true })); | ||
} else { | ||
// create contributions | ||
for (const [username, contributionAttributes] of Object.entries(contributionData)) { | ||
createContribution(username, contributionAttributes, kredits.Contribution); | ||
} | ||
} | ||
// TODO create contributions | ||
}); | ||
}); | ||
51849
1133
48