remove pending tx

This commit is contained in:
Matias Alejo Garcia 2015-02-10 16:30:58 -03:00
parent 11a7a65bc5
commit 7975bb2499
2 changed files with 39 additions and 1 deletions

View File

@ -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,

View File

@ -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'));