adds .deleteLockTime to getTxproposals
This commit is contained in:
parent
5d943a4b27
commit
139deac770
|
@ -843,6 +843,26 @@ WalletService.prototype.removeWallet = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WalletService.prototype.getRemainingDeleteLockTime = function(txp) {
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
var lockTimeRemaining = txp.createdOn + WalletService.deleteLockTime - now;
|
||||||
|
if (lockTimeRemaining < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// not the creator? need to wait
|
||||||
|
if (txp.creatorId !== this.copayerId)
|
||||||
|
return lockTimeRemaining;
|
||||||
|
|
||||||
|
// has other approvers? need to wait
|
||||||
|
var approvers = txp.getApprovers();
|
||||||
|
if (approvers.length > 1 || (approvers.length == 1 && approvers[0] !== this.copayerId))
|
||||||
|
return lockTimeRemaining;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removePendingTx
|
* removePendingTx
|
||||||
*
|
*
|
||||||
|
@ -866,14 +886,10 @@ WalletService.prototype.removePendingTx = function(opts, cb) {
|
||||||
if (!txp.isPending())
|
if (!txp.isPending())
|
||||||
return cb(new ClientError('TXNOTPENDING', 'Transaction proposal not pending'));
|
return cb(new ClientError('TXNOTPENDING', 'Transaction proposal not pending'));
|
||||||
|
|
||||||
var now = Math.floor(Date.now() / 1000);
|
|
||||||
if (now - txp.createdOn < WalletService.lockTimeoutHours * 3600) {
|
|
||||||
if (txp.creatorId !== self.copayerId)
|
|
||||||
return cb(new ClientError('Only creators can remove pending proposals during locktime'));
|
|
||||||
|
|
||||||
var approvers = txp.getApprovers();
|
var deleteLockTime = self.getRemainingDeleteLockTime(txp);
|
||||||
if (approvers.length > 1 || (approvers.length == 1 && approvers[0] !== self.copayerId))
|
if (deleteLockTime > 0) {
|
||||||
return cb(new ClientError('TXACTIONED', 'Cannot remove a proposal signed/rejected by other copayers during locktime'));
|
return cb(new ClientError('TXCANNOTREMOVE', 'Cannot remove this tx proposal during locktime. Time remaining:' + deleteLockTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
self._notify('TxProposalRemoved', {}, function() {
|
self._notify('TxProposalRemoved', {}, function() {
|
||||||
|
@ -1104,6 +1120,10 @@ WalletService.prototype.getPendingTxs = function(opts, cb) {
|
||||||
self.storage.fetchPendingTxs(self.walletId, function(err, txps) {
|
self.storage.fetchPendingTxs(self.walletId, function(err, txps) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
_.each(txps,function(txp){
|
||||||
|
txp.deleteLockTime = self.getRemainingDeleteLockTime(txp);
|
||||||
|
});
|
||||||
|
|
||||||
return cb(null, txps);
|
return cb(null, txps);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -1320,7 +1340,8 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletService.lockTimeoutHours = 24;
|
// in seconds
|
||||||
|
WalletService.deleteLockTime = 24 * 3600;
|
||||||
|
|
||||||
WalletService.scanConfig = {
|
WalletService.scanConfig = {
|
||||||
SCAN_WINDOW: 20,
|
SCAN_WINDOW: 20,
|
||||||
|
|
|
@ -1269,6 +1269,8 @@ describe('Wallet service', function() {
|
||||||
server.getPendingTxs({}, function(err, txs) {
|
server.getPendingTxs({}, function(err, txs) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
txs.length.should.equal(1);
|
txs.length.should.equal(1);
|
||||||
|
// creator
|
||||||
|
txs[0].deleteLockTime.should.equal(0);
|
||||||
server.getBalance({}, function(err, balance) {
|
server.getBalance({}, function(err, balance) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
balance.totalAmount.should.equal(helpers.toSatoshi(300));
|
balance.totalAmount.should.equal(helpers.toSatoshi(300));
|
||||||
|
@ -2746,6 +2748,7 @@ describe('Wallet service', function() {
|
||||||
server2.removePendingTx({
|
server2.removePendingTx({
|
||||||
txProposalId: txp.id
|
txProposalId: txp.id
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
should.exist(err);
|
||||||
err.message.should.contain('creators');
|
err.message.should.contain('creators');
|
||||||
server2.getPendingTxs({}, function(err, txs) {
|
server2.getPendingTxs({}, function(err, txs) {
|
||||||
txs.length.should.equal(1);
|
txs.length.should.equal(1);
|
||||||
|
@ -2766,8 +2769,8 @@ describe('Wallet service', function() {
|
||||||
server.removePendingTx({
|
server.removePendingTx({
|
||||||
txProposalId: txp.id
|
txProposalId: txp.id
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
err.code.should.equal('TXACTIONED');
|
err.code.should.equal('TXCANNOTREMOVE');
|
||||||
err.message.should.contain('other copayers');
|
err.message.should.contain('Cannot remove');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2803,7 +2806,11 @@ describe('Wallet service', function() {
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
|
||||||
var clock = sinon.useFakeTimers(Date.now()+1+24*3600*1000);
|
server.getPendingTxs({}, function(err, txs) {
|
||||||
|
should.not.exist(err);
|
||||||
|
txs[0].deleteLockTime.should.be.above(WalletService.deleteLockTime-10);
|
||||||
|
|
||||||
|
var clock = sinon.useFakeTimers(Date.now() + 1 + 24 * 3600 * 1000);
|
||||||
server.removePendingTx({
|
server.removePendingTx({
|
||||||
txProposalId: txp.id
|
txProposalId: txp.id
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
@ -2814,6 +2821,7 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should allow other copayer to remove a TX signed, after 24hrs', function(done) {
|
it('should allow other copayer to remove a TX signed, after 24hrs', function(done) {
|
||||||
|
@ -2825,7 +2833,7 @@ describe('Wallet service', function() {
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
|
||||||
var clock = sinon.useFakeTimers(Date.now()+1+24*3600*1000);
|
var clock = sinon.useFakeTimers(Date.now() + 1 + 24 * 3600 * 1000);
|
||||||
server2.removePendingTx({
|
server2.removePendingTx({
|
||||||
txProposalId: txp.id
|
txProposalId: txp.id
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
|
Loading…
Reference in New Issue