Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ad0e34b990
|
|||
| 063a9c6b37 | |||
|
f05436e9b9
|
|||
| e305643f69 | |||
| 82a003ffeb | |||
|
fc0c113997
|
|||
|
5c6540580b
|
|||
| 078f78417c | |||
| d870099059 | |||
| b7482f2468 | |||
| 94c256e3d9 | |||
| 3b382eadb2 | |||
| ec63980cd3 | |||
|
|
2b86f37fcb | ||
| a8e29f2197 | |||
| b7ff55929c |
3
index.js
3
index.js
@@ -2,6 +2,7 @@ const fs = require('fs');
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const ethers = require('ethers');
|
const ethers = require('ethers');
|
||||||
|
const NonceManager = require('@ethersproject/experimental').NonceManager;
|
||||||
const Kredits = require('kredits-contracts');
|
const Kredits = require('kredits-contracts');
|
||||||
|
|
||||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||||
@@ -43,7 +44,7 @@ module.exports = async function(robot) {
|
|||||||
} else {
|
} else {
|
||||||
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||||
}
|
}
|
||||||
const signer = wallet.connect(ethProvider);
|
const signer = new NonceManager(wallet.connect(ethProvider));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Kredits contracts setup
|
// Kredits contracts setup
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const fetch = require('node-fetch');
|
|
||||||
const amountFromLabels = require('./utils/amount-from-labels');
|
const amountFromLabels = require('./utils/amount-from-labels');
|
||||||
const kindFromLabels = require('./utils/kind-from-labels');
|
const kindFromLabels = require('./utils/kind-from-labels');
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
|
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
|
||||||
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
||||||
|
|
||||||
return Contribution.addContribution(contributionAttr).catch(error => {
|
return Contribution.add(contributionAttr).catch(error => {
|
||||||
robot.logger.error(`[hubot-kredits] Error:`, error);
|
robot.logger.error(`[hubot-kredits] Error:`, error);
|
||||||
messageRoom(`I tried to add a contribution for ${giteaUser} for ${url}, but I encountered an error when submitting the tx:`);
|
messageRoom(`I tried to add a contribution for ${giteaUser} for ${url}, but I encountered an error when submitting the tx:`);
|
||||||
messageRoom(error.message);
|
messageRoom(error.message);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
|
robot.logger.debug(`[hubot-kredits] contribution attributes:`);
|
||||||
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
robot.logger.debug(util.inspect(contributionAttr, { depth: 1, colors: true }));
|
||||||
|
|
||||||
return Contribution.addContribution(contributionAttr).catch(error => {
|
return Contribution.add(contributionAttr).catch(error => {
|
||||||
robot.logger.error(`[hubot-kredits] Error:`, error);
|
robot.logger.error(`[hubot-kredits] Error:`, error);
|
||||||
messageRoom(`I tried to add a contribution for ${githubUser} for ${url}, but I encountered an error when submitting the tx:`);
|
messageRoom(`I tried to add a contribution for ${githubUser} for ${url}, but I encountered an error when submitting the tx:`);
|
||||||
messageRoom(error.message);
|
messageRoom(error.message);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
kind: 'docs'
|
kind: 'docs'
|
||||||
};
|
};
|
||||||
|
|
||||||
return Contribution.addContribution(contribution).catch(error => {
|
return Contribution.add(contribution).catch(error => {
|
||||||
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error);
|
robot.logger.error(`[hubot-kredits] Adding contribution failed:`, error);
|
||||||
});
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -126,6 +126,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
return [...new Set(changes.map(c => `"${c.title}"`))].join(', ');
|
return [...new Set(changes.map(c => `"${c.title}"`))].join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently not used
|
||||||
function calculateAmountForChanges(details) {
|
function calculateAmountForChanges(details) {
|
||||||
let amount;
|
let amount;
|
||||||
|
|
||||||
@@ -144,9 +145,8 @@ module.exports = async function(robot, kredits) {
|
|||||||
const dateNow = new Date();
|
const dateNow = new Date();
|
||||||
const dateYesterday = dateNow.setDate(dateNow.getDate() - 1);
|
const dateYesterday = dateNow.setDate(dateNow.getDate() - 1);
|
||||||
const date = (new Date(dateYesterday)).toISOString().split('T')[0];
|
const date = (new Date(dateYesterday)).toISOString().split('T')[0];
|
||||||
|
|
||||||
const details = analyzeUserChanges(user, changes);
|
const details = analyzeUserChanges(user, changes);
|
||||||
const amount = calculateAmountForChanges(details);
|
const amount = 500;
|
||||||
|
|
||||||
let desc = `Added ${details.charsAdded} characters of text.`;
|
let desc = `Added ${details.charsAdded} characters of text.`;
|
||||||
if (details.pagesChanged.length > 0) {
|
if (details.pagesChanged.length > 0) {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = async function(robot, kredits) {
|
module.exports = async function(robot, kredits) {
|
||||||
|
|
||||||
function messageRoom(message) {
|
function messageRoom(message) {
|
||||||
@@ -13,9 +17,6 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
const zoomAccessToken = process.env.KREDITS_ZOOM_JWT;
|
const zoomAccessToken = process.env.KREDITS_ZOOM_JWT;
|
||||||
|
|
||||||
const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address);
|
|
||||||
let nonce = walletTransactionCount;
|
|
||||||
|
|
||||||
async function createContributionFor (displayName, meeting) {
|
async function createContributionFor (displayName, meeting) {
|
||||||
const contributor = await getContributorByZoomDisplayName(displayName);
|
const contributor = await getContributorByZoomDisplayName(displayName);
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
time: meeting.end_time.split('T')[1]
|
time: meeting.end_time.split('T')[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
return Contribution.add(contribution, { nonce: nonce++ })
|
return Contribution.add(contribution)
|
||||||
.then(tx => {
|
.then(tx => {
|
||||||
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
|
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
|
||||||
})
|
})
|
||||||
@@ -78,6 +79,7 @@ module.exports = async function(robot, kredits) {
|
|||||||
|
|
||||||
for (const displayName of names) {
|
for (const displayName of names) {
|
||||||
await createContributionFor(displayName, meetingDetails);
|
await createContributionFor(displayName, meetingDetails);
|
||||||
|
await sleep(60000); // potentially to prevent too many transactions at the sametime. transactions need to be ordered because of the nonce. not sure though if this is needed.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2103
package-lock.json
generated
2103
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hubot-kredits",
|
"name": "hubot-kredits",
|
||||||
"version": "3.6.0",
|
"version": "3.8.0",
|
||||||
"description": "Kosmos Kredits functionality for chat bots",
|
"description": "Kosmos Kredits functionality for chat bots",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -12,13 +12,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"eth-provider": "^0.2.2",
|
"eth-provider": "^0.2.2",
|
||||||
"ethers": "^4.0.27",
|
"ethers": "^5.0.5",
|
||||||
|
"@ethersproject/experimental": "5.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-session": "^1.16.2",
|
"express-session": "^1.16.2",
|
||||||
"grant-express": "^4.6.1",
|
"grant-express": "^4.6.1",
|
||||||
"group-array": "^1.0.0",
|
"group-array": "^1.0.0",
|
||||||
"kosmos-schemas": "^1.1.2",
|
"kosmos-schemas": "^1.1.2",
|
||||||
"kredits-contracts": "^5.4.0",
|
"kredits-contracts": "^6.0.0",
|
||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"prompt": "^1.0.0"
|
"prompt": "^1.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user