Skip to content

Commit 53e4b0c

Browse files
committed
refactor for _voteTransaction and better revertedTxns.json file handling
1 parent d83c98c commit 53e4b0c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

federator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"scripts": {
1515
"start": "node ./src/main.js",
1616
"test": "jest --detectOpenHandles test/",
17-
"integrationTest": "rm ./db/lastBlock.txt --force && rm ./db/side-fed/lastBlock.txt --force && node ./integrationTest/integrationTest.js",
17+
"integrationTest": "rm -rf ./db/* && node ./integrationTest/integrationTest.js",
1818
"integrationHeartbeatTest": "rm -rf ./db/* && node ./integrationTest/integrationHeartbeatTest.js && rm heartbeat.log",
1919
"clean": "rm -rf ./db/*"
2020
},

federator/src/lib/Federator.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,20 @@ module.exports = class Federator {
281281
typeId
282282
}).encodeABI();
283283

284-
let revertedTxns = JSON.parse(fs.readFileSync(this.revertedTxnsPath, 'utf8'));
285-
this.logger.info(`read these transactions from reverted transactions file`, revertedTxns);
284+
let revertedTxns = {};
285+
if (fs.existsSync(this.revertedTxnsPath)) {
286+
revertedTxns = JSON.parse(fs.readFileSync(this.revertedTxnsPath, 'utf8'));
287+
this.logger.info(`read these transactions from reverted transactions file`, revertedTxns);
288+
}
286289

287-
let receipt;
288290
if (revertedTxns[txId]) {
289291
this.logger.info(`Skipping Voting Transfer ${txId} since it's marked as reverted.`, revertedTxns[txId])
290-
} else {
291-
receipt = await transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
292+
return false;
292293
}
294+
const receipt = await transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
293295

294-
if(receipt && receipt.status == false) {
295-
this._saveRevertedTxns(
296+
if(receipt.status == false) {
297+
fs.writeFileSync(
296298
this.revertedTxnsPath,
297299
JSON.stringify({
298300
...revertedTxns,
@@ -323,10 +325,4 @@ module.exports = class Federator {
323325
fs.writeFileSync(path, value.toString());
324326
}
325327
}
326-
327-
_saveRevertedTxns(path, value) {
328-
if (value) {
329-
fs.writeFileSync(path, value.toString());
330-
}
331-
}
332328
}

0 commit comments

Comments
 (0)