fixes. emit broadcast event.

This commit is contained in:
Christopher Jeffrey 2014-09-25 13:58:54 -07:00
parent 2b2d56dfea
commit b681642132

View File

@ -20,6 +20,10 @@ var bitcoin = Bitcoin;
function Bitcoin(options) {
var self = this;
if (Bitcoin.global) {
throw new Error('bitcoindjs cannot be instantiated more than once.');
}
if (!(this instanceof Bitcoin)) {
return new Bitcoin(options);
}
@ -27,6 +31,8 @@ function Bitcoin(options) {
EventEmitter.call(this);
this.options = options;
Bitcoin.global = this;
}
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
@ -464,22 +470,31 @@ Transaction.broadcast = function(tx, options, callback) {
options = {};
}
options.overrideFees = options.overrideFees || false;
options.ownOnly = options.ownOnly || false;
var fee = options.overrideFees = options.overrideFees || false;
var own = options.ownOnly = options.ownOnly || false;
if (!callback) {
callback = function() {};
}
if (!tx.hex) {
tx = bitcoin.tx(tx);
tx.toHex();
}
return bitcoindjs.broadcastTx(tx,
options.overrideFees,
options.ownOnly,
callback);
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash) {
if (err) return callback(err);
bitcoin.global.emit('broadcast', hash);
return callback(null, err);
});
};
Transaction.prototype.broadcast = function(callback) {
return Transaction.broadcast(this, callback);
Transaction.prototype.broadcast = function(options, callback) {
if (!callback) {
callback = options;
options = null;
}
return Transaction.broadcast(this, options, callback);
};
/**