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');
|
var hash = tx.hash('hex');
|
||||||
|
|
||||||
// Do not add TX two times
|
// 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;
|
return false;
|
||||||
|
}
|
||||||
this._all[hash] = tx;
|
this._all[hash] = tx;
|
||||||
|
|
||||||
var own = this._wallet.own(tx);
|
var own = this._wallet.own(tx);
|
||||||
@ -103,25 +109,34 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
if (updated)
|
if (updated)
|
||||||
this.emit('update', this._lastTs);
|
this.emit('update', this._lastTs);
|
||||||
|
|
||||||
if (!noWrite && this._storage) {
|
if (!noWrite && this._storage)
|
||||||
var self = this;
|
this._storeTX(hash, tx);
|
||||||
this._storage.put(this._prefix + hash, tx.toJSON(), function(err) {
|
|
||||||
if (err)
|
|
||||||
self.emit('error', err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
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() {
|
TXPool.prototype.unspent = function unspent() {
|
||||||
return Object.keys(this._unspent).map(function(key) {
|
return Object.keys(this._unspent).map(function(key) {
|
||||||
return this._unspent[key];
|
return this._unspent[key];
|
||||||
}, this).filter(function(item) {
|
|
||||||
return this._wallet.own(item.tx, item.index);
|
|
||||||
}, this);
|
}, 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() {
|
TXPool.prototype.balance = function balance() {
|
||||||
var acc = new bn(0);
|
var acc = new bn(0);
|
||||||
var unspent = this.unspent();
|
var unspent = this.unspent();
|
||||||
|
|||||||
@ -199,6 +199,10 @@ Wallet.prototype.unspent = function unspent() {
|
|||||||
return this.tx.unspent();
|
return this.tx.unspent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.pending = function pending() {
|
||||||
|
return this.tx.pending();
|
||||||
|
};
|
||||||
|
|
||||||
Wallet.prototype.balance = function balance() {
|
Wallet.prototype.balance = function balance() {
|
||||||
return this.tx.balance();
|
return this.tx.balance();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user