From af993dc66ba7d01b8bdf497c148cdeca437a9016 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 9 May 2014 15:13:20 +0400 Subject: [PATCH] tx-pool: emit updates only at end of .add() --- lib/bcoin/tx-pool.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index 493ee3b8..f64d4883 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -60,6 +60,7 @@ TXPool.prototype.add = function add(tx, noWrite) { this._all[hash] = tx; var own = this._wallet.own(tx); + var update = false; // Consume unspent money or add orphans for (var i = 0; i < tx.inputs.length; i++) { @@ -71,7 +72,7 @@ TXPool.prototype.add = function add(tx, noWrite) { // Add TX to inputs and spend money tx.input(unspent.tx, unspent.index); delete this._unspent[key]; - this.emit('update'); + updated = true; continue; } @@ -83,10 +84,11 @@ TXPool.prototype.add = function add(tx, noWrite) { this._orphans[key] = { tx: tx, index: input.out.index }; } - if (!own) + if (!own) { + if (updated) + this.emit('update', this._lastTs); return; - - var updated = false; + } // Add unspent outputs or fullfill orphans for (var i = 0; i < tx.outputs.length; i++) {