diff --git a/js/models/core/TxProposals.js b/js/models/core/TxProposals.js index 11d9ad3b8..2481b3a72 100644 --- a/js/models/core/TxProposals.js +++ b/js/models/core/TxProposals.js @@ -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 = {}; }; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 0a9785516..8de654705 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -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;