From fdd94a4e406e250f4b9b665c8b7bf713400eecbe Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 25 Sep 2014 14:04:59 -0700 Subject: [PATCH] more tx broadcast events. --- example/index.js | 3 ++- lib/bitcoind.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/example/index.js b/example/index.js index 35a5b020..963f8a37 100755 --- a/example/index.js +++ b/example/index.js @@ -25,9 +25,10 @@ bitcoind.start(function(err) { // }); bitcoind.once('tx', function(tx) { console.log('Broadcasting tx...'); - tx.broadcast(function(err, hash) { + tx.broadcast(function(err, hash, tx) { if (err) throw err; console.log('tx hash: %s', hash); + print(tx); }); }); bitcoind.on('mptx', function(mptx) { diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 7965bfc9..2ab2024f 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -474,7 +474,7 @@ Transaction.broadcast = function(tx, options, callback) { var own = options.ownOnly = options.ownOnly || false; if (!callback) { - callback = function() {}; + callback = utils.NOOP; } if (!tx.hex) { @@ -483,7 +483,12 @@ Transaction.broadcast = function(tx, options, callback) { } return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) { - if (err) return callback(err); + if (err) { + if (callback === utils.NOOP) { + bitcoin.global.emit('error', err); + } + return callback(err); + } tx = bitcoin.tx(tx); bitcoin.global.emit('broadcast', tx); return callback(null, hash, tx); @@ -609,6 +614,8 @@ utils.varint = function(arr, value, off) { } }; +utils.NOOP = function() {}; + /** * Expose */