forked from rohenaz/bmap-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.ts
37 lines (33 loc) · 954 Bytes
/
state.ts
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
import { config } from './config.js'
import { getDbo } from './db.js'
const getCurrentBlock = () => {
return new Promise(async (resolve, reject) => {
try {
let dbo = await getDbo()
dbo
.collection('c')
.find({ 'blk.i': { $gt: 0 } })
.sort({ 'blk.i': -1 })
.limit(1)
.toArray(async function (err, result) {
if (err) {
// await closeDb()
reject(err)
}
if (result && result.length > 0) {
// only clear unconfirmed when block is higher than last item from socket too latest_block
// await closeDb()
resolve(result[0].blk.i)
} else {
console.log('No existing records. Crawling from the beginning.')
// await closeDb()
resolve(config.from)
}
})
} catch (e) {
// await closeDb()
reject(e)
}
})
}
export { getCurrentBlock }