add reject to CLI

This commit is contained in:
Ivan Socolsky 2015-02-13 22:51:40 -03:00
parent b8532f662f
commit da6500e930
5 changed files with 83 additions and 12 deletions

View File

@ -12,6 +12,7 @@ program
.command('balance', 'wallet balance')
.command('send <address> <amount> <note>', 'send bitcoins')
.command('sign <txpId>', 'sign a Transaction Proposal')
.command('reject <txpId>', 'reject a Transaction Proposal')
.parse(process.argv);

52
bit-wallet/bit-reject Normal file
View File

@ -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] <txpid>')
.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.');
});
});

View File

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

View File

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

View File

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