From 7975bb24996d34a66aac7dcf5aa393b69609ffdf Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 10 Feb 2015 16:30:58 -0300 Subject: [PATCH] remove pending tx --- lib/model/txproposal.js | 4 ++++ lib/server.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/model/txproposal.js b/lib/model/txproposal.js index b822999..cc81f26 100644 --- a/lib/model/txproposal.js +++ b/lib/model/txproposal.js @@ -93,6 +93,10 @@ TxProposal.prototype.getRawTx = function() { }; +TxProposal.prototype.getActors = function() { + return _.keys(this.actions); +}; + TxProposal.prototype.addAction = function(copayerId, type, signatures) { var action = new TxProposalAction({ copayerId: copayerId, diff --git a/lib/server.js b/lib/server.js index ef4e0c1..6284fb9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -482,6 +482,39 @@ CopayServer.prototype.removeWallet = function(opts, cb) { }); }; +/** + * removePendingTx + * + * @param opts + * @param {string} opts.id - The tx id. + * @return {undefined} + */ +CopayServer.prototype.removePendingTx = function(opts, cb) { + var self = this; + + if (!Utils.checkRequired(opts, ['id'])) + return cb(new ClientError('Required argument missing')); + + Utils.runLocked(self.id, cb, function(cb) { + + self.storage.fetchTx(self.walletId, opts.id, function(err, txp) { + if (err) return cb(err); + if (!txp) + return cb(new ClientError('Transaction proposal not found')); + + if (!txp.isPending()) + return cb(new ClientError('Transaction proposal not pending')); + + var actors = txp.getActors(); + + if (actors.length > 1 || actors[0] !== self.copayerId) + return cb(new ClientError('No allowed to erase this TX')); + + self.storage.removeTx(opts.id, cb); + }); + }); +}; + CopayServer.prototype._broadcastTx = function(txp, cb) { var raw = txp.getRawTx(); @@ -510,8 +543,9 @@ CopayServer.prototype.signTx = function(opts, cb) { }, function(err, txp) { if (err) return cb(err); if (!txp) return cb(new ClientError('Transaction proposal not found')); + var action = _.find(txp.actions, { - copayerId: opts.copayerId + copayerId: self.copayerId }); if (action) return cb(new ClientError('CVOTED', 'Copayer already voted on this transaction proposal'));