mirror of https://github.com/BTCPrivate/copay.git
Add method removeTxWithSpentInputs to wallet
This commit is contained in:
parent
a0c7d2cb66
commit
8b55f69d40
|
@ -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 = {};
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue