Add method removeTxWithSpentInputs to wallet

This commit is contained in:
Ivan Socolsky 2014-08-27 16:42:07 -03:00
parent a0c7d2cb66
commit 8b55f69d40
2 changed files with 43 additions and 0 deletions

View File

@ -44,6 +44,13 @@ TxProposals.prototype.getNtxids = function() {
return Object.keys(this.txps);
};
TxProposals.prototype.deleteOne = function(ntxid) {
var txp = this.txps[ntxid];
if (!txp)
throw new Error('Unknown TXP: ' + ntxid);
delete this.txps[ntxid];
};
TxProposals.prototype.deleteAll = function() {
this.txps = {};
};

View File

@ -1525,6 +1525,42 @@ Wallet.prototype.getUnspent = function(cb) {
});
};
Wallet.prototype.removeTxWithSpentInputs = function(cb) {
var self = this;
var txps = this.getTxProposals();
var inputs = [];
txps.forEach(function (txp) {
txp.builder.utxos.forEach(function (utxo) {
inputs.push({ ntxid: txp.ntxid, txid: utxo.txid, vout: utxo.vout });
});
});
if (inputs.length === 0)
return;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
if (err) {
return cb(err);
}
unspentList.forEach(function (unspent) {
inputs.forEach(function (input) {
input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout);
});
});
inputs.forEach(function (input) {
if (!input.unspent) {
self.txProposals.deleteOne(input.ntxid);
}
});
self.emit('txProposalsUpdated');
self.store();
});
};
Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
var self = this;