wallet: .pending()
This commit is contained in:
parent
26516085f2
commit
90ea2e24d1
@ -49,8 +49,14 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
||||
var hash = tx.hash('hex');
|
||||
|
||||
// Do not add TX two times
|
||||
if (this._all[hash])
|
||||
if (this._all[hash]) {
|
||||
// Transaction was confirmed, update it in storage
|
||||
if (tx.ts !== 0 && this._all[hash].ts === 0) {
|
||||
this._all[hash].ts = tx.ts;
|
||||
this._storeTX(hash, tx);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this._all[hash] = tx;
|
||||
|
||||
var own = this._wallet.own(tx);
|
||||
@ -103,25 +109,34 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
||||
if (updated)
|
||||
this.emit('update', this._lastTs);
|
||||
|
||||
if (!noWrite && this._storage) {
|
||||
var self = this;
|
||||
this._storage.put(this._prefix + hash, tx.toJSON(), function(err) {
|
||||
if (err)
|
||||
self.emit('error', err);
|
||||
});
|
||||
}
|
||||
if (!noWrite && this._storage)
|
||||
this._storeTX(hash, tx);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
TXPool.prototype._storeTX = function _storeTX(hash, tx) {
|
||||
var self = this;
|
||||
this._storage.put(this._prefix + hash, tx.toJSON(), function(err) {
|
||||
if (err)
|
||||
self.emit('error', err);
|
||||
});
|
||||
};
|
||||
|
||||
TXPool.prototype.unspent = function unspent() {
|
||||
return Object.keys(this._unspent).map(function(key) {
|
||||
return this._unspent[key];
|
||||
}, this).filter(function(item) {
|
||||
return this._wallet.own(item.tx, item.index);
|
||||
}, this);
|
||||
};
|
||||
|
||||
TXPool.prototype.pending = function pending() {
|
||||
return Object.keys(this._all).map(function(key) {
|
||||
return this._all[key];
|
||||
}, this).filter(function(tx) {
|
||||
return tx.ts === 0;
|
||||
});
|
||||
};
|
||||
|
||||
TXPool.prototype.balance = function balance() {
|
||||
var acc = new bn(0);
|
||||
var unspent = this.unspent();
|
||||
|
||||
@ -199,6 +199,10 @@ Wallet.prototype.unspent = function unspent() {
|
||||
return this.tx.unspent();
|
||||
};
|
||||
|
||||
Wallet.prototype.pending = function pending() {
|
||||
return this.tx.pending();
|
||||
};
|
||||
|
||||
Wallet.prototype.balance = function balance() {
|
||||
return this.tx.balance();
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user