-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworker.js
More file actions
61 lines (46 loc) · 1.75 KB
/
worker.js
File metadata and controls
61 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const Web3Wrap = require('./web3Wrapper')
const web3 = Web3Wrap.getWeb3()
const axios = require('axios')
const fs = require('fs')
const { rewardsDistributorAbi } = require("./merkleEncodeAbi")
const rewardsDistributorAddress = "0x3fEf090ED8C8b1Ad29C9F745464dFeCE47053345"
/*
async function getLastEndBlock() {
const contract = new web3.eth.Contract(rewardsDistributorAbi, rewardsDistributorAddress)
const merkleData = await contract.methods.getMerkleData().call()
const ipfsHash = merkleData[2]
const url = "https://cloudflare-ipfs.com/ipfs/" + ipfsHash
const json = await axios.get(url)
return json.data.endBlock
}*/
async function getLastJson() {
const contract = new web3.eth.Contract(rewardsDistributorAbi, rewardsDistributorAddress)
const merkleData = await contract.methods.getMerkleData().call()
const ipfsHash = merkleData[2]
const url = "https://cloudflare-ipfs.com/ipfs/" + ipfsHash
console.log(url)
const json = await axios.get(url)
//console.log(json.data)
return json.data
//return JSON.parse(json.data)
}
async function work(lastBlock) {
let endBlock = lastBlock || Number(await web3.eth.getBlockNumber() - 20)
const lastJson = await getLastJson()
const startBlock = Number(lastJson.endBlock) + 1
console.log(startBlock, endBlock)
const Main = require("./main")
const res = await Main.main(startBlock, endBlock, lastJson)
console.log("print")
if(!process.env.SERVERLESS) fs.writeFileSync('./snapshot.json', JSON.stringify(JSON.parse(res), null, 2) , 'utf-8')
return res
}
async function workAllNight() {
await work()
console.log("waiting for 10 minutes")
// run every 30 minutes
setTimeout(workAllNight, 1000 * 60 * 10)
}
module.exports = {
work
}