diff --git a/app.js b/app.js index 7cd3ccb..ceb23df 100644 --- a/app.js +++ b/app.js @@ -207,7 +207,17 @@ router.post('/v1/txproposals/:id/signatures/', function(req, res) { router.post('/v1/txproposals/:id/rejections', function(req, res) { getServerWithAuth(req, res, function(server) { req.body.txProposalId = req.params['id']; - server.signTx(req.body, function(err, txp) { + server.rejectTx(req.body, function(err, txp) { + if (err) return returnError(err, res, req); + res.end(); + }); + }); +}); + +router.delete('/v1/txproposals/:id/', function(req, res) { + getServerWithAuth(req, res, function(server) { + req.body.txProposalId = req.params['id']; + server.removePendingTx(req.body, function(err, txp) { if (err) return returnError(err, res, req); res.end(); }); diff --git a/bit-wallet/bit b/bit-wallet/bit index 06930e3..cffe423 100755 --- a/bit-wallet/bit +++ b/bit-wallet/bit @@ -11,8 +11,9 @@ program .command('addresses', 'list addresses') .command('balance', 'wallet balance') .command('send
', 'send bitcoins') - .command('sign ', 'sign a Transaction Proposal') - .command('reject ', 'reject a Transaction Proposal') + .command('sign ', 'sign a transaction proposal') + .command('reject [reason]', 'reject a transaction proposal') + .command('rm ', 'remove a transaction proposal') .parse(process.argv); diff --git a/bit-wallet/bit-reject b/bit-wallet/bit-reject index b4bb33f..4e2f127 100644 --- a/bit-wallet/bit-reject +++ b/bit-wallet/bit-reject @@ -9,14 +9,14 @@ program .version('0.0.1') .option('-c,--config [file]', 'Wallet config filename') .option('-v,--verbose', 'be verbose') - .usage('[options] ') + .usage('[options] [reason]') .parse(process.argv); var args = program.args; if (!args[0]) program.help(); - var txpid = args[0]; +var reason = args[1] || ''; var cli = new Client({ filename: program.config @@ -41,7 +41,7 @@ cli.getTxProposals({}, function(err, x) { }).join(' '));; var txp = txps[0]; - cli.rejectTxProposal(txp, function(err, x) { + cli.rejectTxProposal(txp, reason, function(err, x) { common.die(err); if (program.verbose) diff --git a/bit-wallet/bit-rm b/bit-wallet/bit-rm new file mode 100644 index 0000000..9a864e8 --- /dev/null +++ b/bit-wallet/bit-rm @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +var _ = require('lodash'); +var program = require('commander'); +var ClientLib = require('../lib/clientlib.js'); +var common = require('./common'); + +program + .version('0.0.1') + .option('-c,--config [file]', 'Wallet config filename') + .option('-v,--verbose', 'be verbose') + .usage('[options] ') + .parse(process.argv); + +var args = program.args; +if (!args[0]) + program.help(); + +var txpid = args[0]; + +var cli = new ClientLib({ + filename: program.config +}); + +cli.txProposals({}, function(err, x) { + common.die(err); + + if (program.verbose) + console.log('* Raw Server Response:\n', x); //TODO + + var txps = _.filter(x, function(x) { + return _.endsWith(common.shortID(x.id), txpid); + }); + + if (!txps.length) + common.die('Could not find TX Proposal:' + txpid); + + if (txps.length > 1) + common.die('More than one TX Proposals match:' + txpid + ' : ' + _.map(txps, function(x) { + return x.id; + }).join(' '));; + + var txp = txps[0]; + cli.rm(txp, function(err, x) { + common.die(err); + + if (program.verbose) + console.log('* Raw Server Response:\n', x); //TODO + + console.log('Transaction rejected.'); + }); +}); diff --git a/lib/client/API.js b/lib/client/API.js index 615c58c..8f1ca41 100644 --- a/lib/client/API.js +++ b/lib/client/API.js @@ -359,4 +359,29 @@ API.prototype.rejectTxProposal = function(txp, reason, cb) { this._doPostRequest(url, args, data, cb); }; +ClientLib.prototype.rm = function(txp, cb) { + var self = this; + var data = this._loadAndCheck(); + + var url = '/v1/txproposals/' + txp.id; + var reqSignature = _signRequest(url, {}, data.signingPrivKey); + + request({ + headers: { + 'x-identity': data.copayerId, + 'x-signature': reqSignature, + }, + method: 'delete', + url: _getUrl(url), + json: true, + }, function(err, res, body) { + if (err) return cb(err); + if (res.statusCode != 200) { + _parseError(body); + return cb('Request error'); + } + return cb(null, body); + }); +}; + module.exports = API;