Browse Source

add reject to CLI

activeAddress
Ivan Socolsky 10 years ago
parent
commit
da6500e930
  1. 1
      bit-wallet/bit
  2. 52
      bit-wallet/bit-reject
  3. 2
      bit-wallet/bit-sign
  4. 39
      lib/clientlib.js
  5. 1
      lib/server.js

1
bit-wallet/bit

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

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

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

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

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

Loading…
Cancel
Save