Merge pull request #59 from 67P/ethers-nonce-manager
Use new ethers.js NonceManager to handle transaction nonces
This commit is contained in:
commit
3b382eadb2
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,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.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2116
package-lock.json
generated
2116
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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.2",
|
||||||
|
"@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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user