From 17d0903a35b1f9fb10e94e175a35b14798efb6e7 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 9 May 2014 15:28:26 +0400 Subject: [PATCH] wallet: emit all added TXs --- lib/bcoin/tx-pool.js | 10 ++++++++++ lib/bcoin/wallet.js | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/bcoin/tx-pool.js b/lib/bcoin/tx-pool.js index f64d4883..d4906f69 100644 --- a/lib/bcoin/tx-pool.js +++ b/lib/bcoin/tx-pool.js @@ -114,6 +114,8 @@ TXPool.prototype.add = function add(tx, noWrite) { if (!noWrite && this._storage) this._storeTX(hash, tx); + this.emit('tx', tx); + return true; }; @@ -125,6 +127,14 @@ TXPool.prototype._storeTX = function _storeTX(hash, tx) { }); }; +TXPool.prototype.all = function all() { + return Object.keys(this._all).map(function(key) { + return this._all[key]; + }, this).filter(function(item) { + return this._wallet.own(item.tx, item.index); + }, this); +}; + TXPool.prototype.unspent = function unspent() { return Object.keys(this._unspent).map(function(key) { return this._unspent[key]; diff --git a/lib/bcoin/wallet.js b/lib/bcoin/wallet.js index acb6c078..bb41f2a8 100644 --- a/lib/bcoin/wallet.js +++ b/lib/bcoin/wallet.js @@ -55,6 +55,10 @@ Wallet.prototype._init = function init() { prevBalance = b; }); + this.tx.on('tx', function(tx) { + self.emit('tx', tx); + }); + this.tx.once('load', function(ts) { self.emit('load', ts); }); @@ -195,6 +199,10 @@ Wallet.prototype.addTX = function addTX(tx, block) { return this.tx.add(tx); }; +Wallet.prototype.all = function all() { + return this.tx.all(); +}; + Wallet.prototype.unspent = function unspent() { return this.tx.unspent(); };