Skip to content

Commit

Permalink
l.map
Browse files Browse the repository at this point in the history
local map function
  • Loading branch information
unwriter committed Aug 11, 2019
1 parent 3d8a29a commit b48d9b8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
13 changes: 12 additions & 1 deletion block.js
Expand Up @@ -6,11 +6,22 @@ const writetape = function(current_block, path) {
let l = "BLOCK " + current_block + " " + Date.now() + "\n"
fs.appendFileSync(path + "/tape.txt", l);
}
const crawl = function(stream, path, cb) {
const crawl = function(stream, o, path, cb) {
let str = stream
.pipe(es.split())
.pipe(es.filterSync(function(data) { return !(["[", ",", "]"].includes(data.toString())) }))
.pipe(es.parse())
if (o.l && o.l.map) {
str = str.pipe(es.map(function(data, callback) {
let parsed = o.l.map(data)
let e = {
m: parsed,
tx: data.tx,
blk: data.blk
}
callback(null, e)
}))
}
let current_block;
let fileStream
str.on('data', function(data) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -182,7 +182,7 @@ const validate = function(config, vmode) {
return errors;
}
const start = function(options, cb) {
glob(process.cwd() + "/*.json", async function(er, files) {
glob(process.cwd() + "/*.@(js|json)", async function(er, files) {
let configs = files.map(function(f) {
return require(f)
}).filter(function(f) {
Expand Down
18 changes: 16 additions & 2 deletions mempool.js
@@ -1,9 +1,23 @@
const Log = require('./log.js')
const fs = require('fs')
const es = require('event-stream')
const crawl = function(stream, path, hashpool, cb) {
const JSONStream = require('JSONStream')
const crawl = function(stream, o, path, hashpool, cb) {
let fileStream = fs.createWriteStream(path + "/mempool.json")
let str = stream.pipe(fileStream)
let str = stream;
if (o.l && o.l.map) {
str = str.pipe(JSONStream.parse("*"))
.pipe(es.map(function(data, callback) {
let parsed = o.l.map(data)
let e = {
m: 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")
Expand Down
4 changes: 2 additions & 2 deletions net.js
Expand Up @@ -27,7 +27,7 @@ const block = function(host, o, path, cb) {
data: { tx: t },
responseType: "stream"
}).then(function(res) {
Block.crawl(res.data, path, cb)
Block.crawl(res.data, o, path, cb)
}).catch(function(err) {
Log.debug("BITBUS", err)
})
Expand All @@ -42,7 +42,7 @@ const mempool = function(host, o, path, hashpool, cb) {
data: { tx: t },
responseType: "stream"
}).then(function(res) {
Mempool.crawl(res.data, path, hashpool, cb)
Mempool.crawl(res.data, o, path, hashpool, cb)
}).catch(function(err) {
Log.debug("BITBUS", err)
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "bitbus",
"version": "0.0.112",
"name": "bitbusalpha",
"version": "0.0.123",
"description": "bitcoinless bitcoin computing",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion serve.js
Expand Up @@ -9,7 +9,7 @@ module.exports = function(buspath) {
app.use(express.static(__dirname + '/public'))
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views')
glob(process.cwd() + "/*.json", async function(er, files) {
glob(process.cwd() + "/*.@(js|json)", async function(er, files) {
let cfigs = files.map(function(f) {
return require(f)
}).filter(function(f) {
Expand Down

0 comments on commit b48d9b8

Please sign in to comment.