-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 874 Bytes
/
index.js
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
import { preprocess } from './lib/preprocess.js'
import { evaluate } from './lib/evaluate.js'
import { ieContract } from './lib/contract.js'
const db = {
measurements: {},
cidsSeen: [],
roundsSeen: []
}
// Listen for events
ieContract.on('MeasurementsAdded', (cid, _roundIndex) => {
const roundIndex = Number(_roundIndex)
if (db.cidsSeen.includes(cid)) {
return
}
db.cidsSeen.push(cid)
console.log('Event: MeasurementsAdded', { roundIndex })
// Preprocess
preprocess({ db, cid, roundIndex }).catch(console.error)
})
ieContract.on('RoundStart', _roundIndex => {
const roundIndex = Number(_roundIndex)
if (db.roundsSeen.includes(roundIndex)) {
return
}
db.roundsSeen.push(roundIndex)
console.log('Event: RoundStart', { roundIndex })
// Evaluate previous round
evaluate({ db, roundIndex: roundIndex - 1 }).catch(console.error)
})