-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from rohitverma007/rewards
adding hourly script, modifying script a bit
- Loading branch information
Showing
4 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import TezosRpc from '../src/services/rpc/rpc' | ||
import Helper from '../src/services/utils/helper' | ||
const fs = require('fs'); | ||
const { promisify } = require("util"); | ||
const writeFile = promisify(fs.writeFile); | ||
const { fork } = require('child_process'); | ||
|
||
(async () => { | ||
const tezosConfig = require('../static/config.json') | ||
const tezosRpc = new TezosRpc(tezosConfig.tezosRpcAddress) | ||
const block = 'head' | ||
const mostRecentCompletedCycle = await tezosRpc.getHeadCycle() | ||
let cycle = mostRecentCompletedCycle + 6 | ||
await tezosRpc.setCycle(cycle) | ||
const rawSnapshotData = require('../static/snapshotData.json') | ||
const cycleDataFromJson = require('../static/allCyclesData.json') | ||
|
||
// save rights data + snapshot data for latest future cycle | ||
const latestCycleFromSnapshotJson = rawSnapshotData[rawSnapshotData.length-1]['cycleNumber'] | ||
if(latestCycleFromSnapshotJson != cycle) { | ||
const snapshotBlockNumber = await tezosRpc.getSnapshotBlockForCycle('head') | ||
const snapshotNumber = tezosRpc.snapshotNumber | ||
rawSnapshotData.push({ | ||
'cycleNumber': cycle, | ||
'snapshotBlockNumber': snapshotBlockNumber, | ||
'snapshotNumber': tezosRpc.snapshotNumber | ||
}) | ||
await writeFile('../static/snapshotData.json', JSON.stringify(rawSnapshotData)); | ||
console.log('cycle: ', cycle, ', snapshotNumber: ', snapshotNumber, ', snapshotBlockNumber: ', snapshotBlockNumber) | ||
console.log('Saved: snapshotData.json'); | ||
|
||
const process = fork('./saveCycleDataToJson.js'); | ||
let snapshotData = {} | ||
snapshotData[cycle] = snapshotBlockNumber | ||
process.send({mostRecentCompletedCycle, block, snapshotData, cycle}) | ||
process.on('message', async (data) => { | ||
cycleDataFromJson[cycle] = data[cycle] | ||
await writeFile('../static/allCyclesData.json', JSON.stringify(cycleDataFromJson)) | ||
console.log('Saved: allCyclesData.json with latest future cycle'); | ||
}) | ||
} | ||
|
||
// save rewards data for latest baked cycle | ||
const mostRecentCompletedCycleDatFromJson = cycleDataFromJson[mostRecentCompletedCycle] | ||
if (mostRecentCompletedCycleDatFromJson['prediction']) { | ||
cycle = mostRecentCompletedCycle | ||
await tezosRpc.setCycle(mostRecentCompletedCycle) | ||
const process = fork('./saveCycleDataToJson.js'); | ||
const snapshotData = new Helper().parseSnapshotData(rawSnapshotData)['snapshotblockNumberData'] | ||
process.send({mostRecentCompletedCycle, block, snapshotData, cycle}) | ||
process.on('message', async (data) => { | ||
cycleDataFromJson[cycle] = data[cycle] | ||
await writeFile('../static/allCyclesData.json', JSON.stringify(cycleDataFromJson)) | ||
console.log('Saved: allCyclesData.json with latest baked cycle'); | ||
}) | ||
} | ||
|
||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import TezosRpc from '../src/services/rpc/rpc' | ||
const fs = require('fs'); | ||
const util = require('util'); | ||
const readFile = util.promisify(fs.readFile); | ||
const writeFile = util.promisify(fs.writeFile); | ||
|
||
(async () => { | ||
const tezosConfig = require('../static/config.json') | ||
const tezosRpc = new TezosRpc(tezosConfig.tezosRpcAddress) | ||
const mostRecentCompletedCycle = await tezosRpc.getHeadCycle() | ||
let allCyclesData = {} | ||
for(let i = 7; i <= mostRecentCompletedCycle + 6; i++){ | ||
const cycleData = await readFile(i+'.json') | ||
allCyclesData = { ...allCyclesData, ...JSON.parse(cycleData.toString('utf8'))} | ||
} | ||
await writeFile('../static/allCyclesData.json', JSON.stringify(allCyclesData)) | ||
console.log('Saved: allCyclesData.json') | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters