Skip to content

Commit

Permalink
get coinbase tx in spv mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Sep 21, 2017
1 parent 1a48ba7 commit b65e499
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bin/spvnode
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const assert = require('assert');
const SPVNode = require('../lib/node/spvnode');
const util = require('../lib/utils/util');
const Outpoint = require('../lib/primitives/outpoint');
const fs = require('fs');

const node = SPVNode({
config: true,
Expand Down Expand Up @@ -48,6 +49,23 @@ process.on('unhandledRejection', (err, promise) => {
});
}

// attempt to collect coinbase transactions by adding null outpoint to bloom filter
node.pool.watchOutpoint(new Outpoint());
node.on('block', (block) => {
console.log(" ---- new coinbase tx received ----");
var cbScriptSig = block.txs[0]['inputs'][0]['script'].toJSON();
// reverse byte order of little endian hash
var blockHash = block.hash('hex').match(/[a-fA-F0-9]{2}/g).reverse().join('');
console.log("Block hash: " + blockHash + "\n" + "Coinbase scriptSig: " + cbScriptSig);
fs.writeFile("/home/pi/.bcoin/spv_cb_" + blockHash, cbScriptSig, function(err){
if(err)
return console.log(err);
console.log("coinbase file saved\n--------");
});
});



node.startSync();
})().catch((err) => {
console.error(err.stack);
Expand Down

0 comments on commit b65e499

Please sign in to comment.