add purge to tx prosposals

This commit is contained in:
Matias Alejo Garcia 2014-08-21 13:12:55 -04:00
commit 4931c9d618
6 changed files with 114 additions and 6 deletions

View file

@ -65,6 +65,17 @@ TxProposal.prototype._check = function() {
}
};
TxProposal.prototype.rejectCount = function() {
return Object.keys(this.rejectedBy);
};
TxProposal.prototype.isPending = function(maxRejectCount) {
if (this.rejectCount() < maxRejectCount || p.sentTxid)
return false;
return true;
};
TxProposal.prototype._updateSignedBy = function() {
this._inputSignatures = [];

View file

@ -36,10 +36,25 @@ TxProposals.fromObj = function(o, forceOpts) {
return ret;
};
TxProposals.prototype.length = function() {
return Object.keys(this.txps).length;
};
TxProposals.prototype.getNtxids = function() {
return Object.keys(this.txps);
};
TxProposals.prototype.deleteAll = function() {
this.txps = {};
};
TxProposals.prototype.deletePending = function(maxRejectCount) {
for (var ntxid in this.txps) {
if (this.txps[ntxid].isPending(maxRejectCount))
delete this.txps[ntxid];
};
};
TxProposals.prototype.toObj = function() {
var ret = [];
for (var id in this.txps) {
@ -153,7 +168,8 @@ TxProposals.prototype.getUsedUnspent = function(maxRejectCount) {
for (var i in this.txps) {
var u = this.txps[i].builder.getSelectedUnspent();
var p = this.getTxProposal(i);
if (p.rejectCount > maxRejectCount || p.sentTxid)
if (!p.isPending(maxRejectCount))
continue;
for (var j in u) {

View file

@ -706,6 +706,18 @@ Wallet.prototype.getTxProposals = function() {
return ret;
};
Wallet.prototype.purgeTxProposals = function(deleteAll) {
var m = this.txProposals.length();
if (deleteAll) {
this.txProposals.deleteAll();
} else {
this.txProposals.deletePending(this.maxRejectCount());
}
var n = this.txProposals.length();
return m-n;
};
Wallet.prototype.reject = function(ntxid) {
var txp = this.txProposals.reject(ntxid, this.getMyCopayerId());
@ -1484,6 +1496,17 @@ Wallet.prototype.getBalance = function(cb) {
});
};
// See
// https://github.com/bitpay/copay/issues/1056
//
// maxRejectCount should equal requiredCopayers
// strictly.
//
Wallet.prototype.maxRejectCount = function(cb) {
return this.totalCopayers - this.requiredCopayers;
};
Wallet.prototype.getUnspent = function(cb) {
var self = this;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
@ -1493,8 +1516,7 @@ Wallet.prototype.getUnspent = function(cb) {
}
var safeUnspendList = [];
var maxRejectCount = self.totalCopayers - self.requiredCopayers;
var uu = self.txProposals.getUsedUnspent(maxRejectCount);
var uu = self.txProposals.getUsedUnspent(self.maxRejectCount());
for (var i in unspentList) {
var u = unspentList[i];