-
Notifications
You must be signed in to change notification settings - Fork 15
/
mempool.js
48 lines (48 loc) · 1.41 KB
/
mempool.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const Log = require('./log.js')
const fs = require('fs')
const es = require('event-stream')
const JSONStream = require('JSONStream')
const crawl = function(stream, o, path, hashpool, cb) {
let fileStream = fs.createWriteStream(path + "/mempool.json")
let str = stream;
if (o.l && o.l.map) {
str = str.pipe(JSONStream.parse("*"))
.on("error", (e) => {
console.log("* error:", e)
})
.pipe(es.map(function(data, callback) {
let parsed = o.l.map(data)
let e = {
$: parsed,
tx: data.tx
}
callback(null, e)
}))
.pipe(JSONStream.stringify("[\n", ",\n", "]"))
}
str = str.pipe(fileStream)
str.on('close', function() {
if (!process.env.DEV) {
Log.debug("BITBUS", "mempool crawl finished")
fileStream.close()
if (hashpool && hashpool.length > 0) {
// check if the hashes are in the new mempool.json
fs.readFile(path + "/mempool.json", function(err, content) {
Log.debug("BITBUS", "mempool = ", hashpool)
let filtered = hashpool.filter(function(h) {
return content.includes(h)
})
Log.debug("BITBUS", "filtered mempool= ", filtered)
filtered.forEach(function(h) {
let log = "MEMPOOL " + h + " " + Date.now() + "\n"
fs.appendFileSync(path + "/tape.txt", log);
})
})
}
}
cb();
})
}
module.exports = {
crawl: crawl
}