diff --git a/bit-wallet/bit b/bit-wallet/bit index 1beaac6..06930e3 100755 --- a/bit-wallet/bit +++ b/bit-wallet/bit @@ -12,6 +12,7 @@ program .command('balance', 'wallet balance') .command('send
', 'send bitcoins') .command('sign ', 'sign a Transaction Proposal') + .command('reject ', 'reject a Transaction Proposal') .parse(process.argv); diff --git a/bit-wallet/bit-reject b/bit-wallet/bit-reject new file mode 100644 index 0000000..766f066 --- /dev/null +++ b/bit-wallet/bit-reject @@ -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.reject(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/bit-wallet/bit-sign b/bit-wallet/bit-sign index bad5658..c284490 100755 --- a/bit-wallet/bit-sign +++ b/bit-wallet/bit-sign @@ -36,7 +36,7 @@ cli.txProposals({}, function(err, x) { common.die('Could not find TX Proposal:' + txpid); if (txps.length > 1) - common.die('More that one TX Proposals match:' + txpid + ' : ' + _.map(txps, function(x) { + common.die('More than one TX Proposals match:' + txpid + ' : ' + _.map(txps, function(x) { return x.id; }).join(' '));; diff --git a/lib/clientlib.js b/lib/clientlib.js index e5ba809..a9b7bc1 100644 --- a/lib/clientlib.js +++ b/lib/clientlib.js @@ -278,15 +278,6 @@ ClientLib.prototype.send = function(inArgs, cb) { }; -// TODO check change address -ClientLib.prototype.sign = function(proposalId, cb) { - -}; - -ClientLib.prototype.reject = function(proposalId, cb) { - -}; - // Get addresses ClientLib.prototype.addresses = function(cb) { var self = this; @@ -439,7 +430,7 @@ ClientLib.prototype.sign = function(txp, cb) { signatures: signatures }; var reqSignature = _signRequest(url, args, data.signingPrivKey); -console.log('[clientlib.js.441:reqSignature:]',url, args, reqSignature); //TODO + console.log('[clientlib.js.441:reqSignature:]', url, args, reqSignature); //TODO request({ headers: { @@ -460,5 +451,33 @@ console.log('[clientlib.js.441:reqSignature:]',url, args, reqSignature); //TODO }); }; +ClientLib.prototype.reject = function(txp, reason, cb) { + var self = this; + var data = this._loadAndCheck(); + + var url = '/v1/txproposals/' + txp.id + '/rejections/'; + var args = { + reason: reason || '', + }; + var reqSignature = _signRequest(url, args, data.signingPrivKey); + + request({ + headers: { + 'x-identity': data.copayerId, + 'x-signature': reqSignature, + }, + method: 'post', + url: _getUrl(url), + body: args, + 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 = ClientLib; diff --git a/lib/server.js b/lib/server.js index 02558b2..d186758 100644 --- a/lib/server.js +++ b/lib/server.js @@ -584,7 +584,6 @@ CopayServer.prototype.removePendingTx = function(opts, cb) { CopayServer.prototype._broadcastTx = function(txp, cb) { var raw = txp.getRawTx(); -console.log('[server.js.586:raw:]',raw); //TODO var bc = this._getBlockExplorer('insight', txp.getNetworkName()); bc.broadcast(raw, function(err, txid) { return cb(err, txid);