add purge to tx prosposals
This commit is contained in:
parent
60d81e6b9f
commit
4931c9d618
6 changed files with 114 additions and 6 deletions
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue