wallet: emit all added TXs

This commit is contained in:
Fedor Indutny 2014-05-09 15:28:26 +04:00
parent af993dc66b
commit 17d0903a35
2 changed files with 18 additions and 0 deletions

View File

@ -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];

View File

@ -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();
};