From 2ecf1cdcdffe0850fb64201a7452ef913086d101 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Thu, 18 Sep 2014 15:20:23 -0700 Subject: [PATCH] Block parsing example bitcoind saves blocks in files called blk*****.dat. Those files can be piped into this example, which will parse them and spit out a nice looking string of all the blocks, which also includes parsed transactions. --- examples/blockreader.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/blockreader.js diff --git a/examples/blockreader.js b/examples/blockreader.js new file mode 100644 index 0000000..3640ea0 --- /dev/null +++ b/examples/blockreader.js @@ -0,0 +1,20 @@ +var Block = require('../lib/block'); +var BufferReader = require('../lib/bufferreader'); +var BufferWriter = require('../lib/bufferwriter'); + +//This example will parse the blocks in a block file. +//To use, pipe in a blk*****.dat file. e.g.: +//cat blk00000.dat | node blockreader.js + +var bw = new BufferWriter(); + +process.stdin.on('data', function(buf) { + bw.write(buf); +}); + +process.stdin.on('end', function(buf) { + var blocksbuf = bw.concat(); + var br = new BufferReader(blocksbuf); + while (!br.eof()) + console.log(Block().fromBufferReader(br)); +});