more tx broadcast events.

This commit is contained in:
Christopher Jeffrey 2014-09-25 14:04:59 -07:00
parent 5f21978a44
commit fdd94a4e40
2 changed files with 11 additions and 3 deletions

View File

@ -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) {

View File

@ -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
*/