Merge pull request #59 from 67P/ethers-nonce-manager

Use new ethers.js NonceManager to handle transaction nonces
This commit is contained in:
bumi 2020-07-18 12:58:45 +02:00 committed by GitHub
commit 3b382eadb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1519 additions and 615 deletions

View File

@ -2,6 +2,7 @@ const fs = require('fs');
const util = require('util');
const fetch = require('node-fetch');
const ethers = require('ethers');
const NonceManager = require('@ethersproject/experimental').NonceManager;
const Kredits = require('kredits-contracts');
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
@ -43,7 +44,7 @@ module.exports = async function(robot) {
} else {
ethProvider = new ethers.getDefaultProvider('rinkeby');
}
const signer = wallet.connect(ethProvider);
const signer = new NonceManager(wallet.connect(ethProvider));
//
// Kredits contracts setup

View File

@ -1,5 +1,9 @@
const fetch = require('node-fetch');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports = async function(robot, kredits) {
function messageRoom(message) {
@ -13,9 +17,6 @@ module.exports = async function(robot, kredits) {
const zoomAccessToken = process.env.KREDITS_ZOOM_JWT;
const walletTransactionCount = await kredits.provider.getTransactionCount(kredits.signer.address);
let nonce = walletTransactionCount;
async function createContributionFor (displayName, meeting) {
const contributor = await getContributorByZoomDisplayName(displayName);
@ -35,7 +36,7 @@ module.exports = async function(robot, kredits) {
time: meeting.end_time.split('T')[1]
}
return Contribution.add(contribution, { nonce: nonce++ })
return Contribution.add(contribution)
.then(tx => {
robot.logger.info(`[hubot-kredits] Contribution created: ${tx.hash}`);
})
@ -78,6 +79,7 @@ module.exports = async function(robot, kredits) {
for (const displayName of names) {
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.
};
}

2116
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,13 +12,14 @@
"dependencies": {
"cors": "^2.8.5",
"eth-provider": "^0.2.2",
"ethers": "^4.0.27",
"ethers": "^5.0.2",
"@ethersproject/experimental": "5.0.0",
"express": "^4.17.1",
"express-session": "^1.16.2",
"grant-express": "^4.6.1",
"group-array": "^1.0.0",
"kosmos-schemas": "^1.1.2",
"kredits-contracts": "^5.4.0",
"kredits-contracts": "^6.0.0",
"node-cron": "^2.0.3",
"node-fetch": "^2.3.0",
"prompt": "^1.0.0"