From 807fb13e9d9e32977ab0ffd8b528dd6fbe54af3c Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 9 Jan 2023 00:13:59 -0800 Subject: [PATCH] add cli. add rewind cmd --- src/cli.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/cli.js diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..78d3d0d --- /dev/null +++ b/src/cli.js @@ -0,0 +1,23 @@ +const fs = require('fs'); + +const ALL_CONTRACTS = require('../data/contracts'); +const BLOCKS_PER_HOUR = 300; +const ARGS = process.argv.slice(2); + +switch (ARGS[0]) { + case 'rewind': + if (isNaN(ARGS[1])) { + console.log('Invalid argument passed. Provide the number of hours you would like to rewind syncing to.'); + break; + } + const rewindBlocks = BLOCKS_PER_HOUR * Number(ARGS[1]); + for(const key in ALL_CONTRACTS) { + if (process.env.ONLY && process.env.ONLY != key) continue + const lastFile = `./storage/lastBlock.${key}.txt`; + const currentBlock = fs.readFileSync(lastFile); + const newBlock = Number(currentBlock) - rewindBlocks; + console.log(`Rewinding ${lastFile} ${rewindBlocks} blocks (${newBlock})`); + fs.writeFileSync(lastFile, newBlock.toString()); + } + break; +} \ No newline at end of file