bitcore-wallet-service/bit-wallet/bit-sign

53 lines
1.1 KiB
Plaintext
Raw Normal View History

2015-02-13 11:07:47 -08:00
#!/usr/bin/env node
2015-02-13 12:02:56 -08:00
var _ = require('lodash');
2015-02-13 11:07:47 -08:00
var program = require('commander');
var ClientLib = require('../lib/clientlib.js');
var common = require('./common');
program
2015-02-13 12:02:56 -08:00
.version('0.0.1')
.option('-c,--config [file]', 'Wallet config filename')
.option('-v,--verbose', 'be verbose')
.usage('[options] <txpid>')
.parse(process.argv);
2015-02-13 11:07:47 -08:00
var args = program.args;
2015-02-13 12:02:56 -08:00
if (!args[0])
2015-02-13 11:07:47 -08:00
program.help();
2015-02-13 12:02:56 -08:00
var txpid = args[0];
2015-02-13 11:07:47 -08:00
2015-02-13 12:02:56 -08:00
var cli = new ClientLib({
filename: program.config
2015-02-13 11:07:47 -08:00
});
2015-02-13 12:02:56 -08:00
cli.txProposals({}, function(err, x) {
common.die(err);
2015-02-13 11:07:47 -08:00
2015-02-13 12:02:56 -08:00
if (program.verbose)
console.log('* Raw Server Response:\n', x); //TODO
var txps = _.filter(x, function(x) {
2015-02-13 13:24:35 -08:00
return _.endsWith(common.shortID(x.id), txpid);
2015-02-13 12:02:56 -08:00
});
if (!txps.length)
2015-02-13 13:53:49 -08:00
common.die('Could not find TX Proposal:' + txpid);
2015-02-13 12:02:56 -08:00
if (txps.length > 1)
2015-02-13 17:51:40 -08:00
common.die('More than one TX Proposals match:' + txpid + ' : ' + _.map(txps, function(x) {
2015-02-13 12:02:56 -08:00
return x.id;
}).join(' '));;
var txp = txps[0];
2015-02-13 13:53:49 -08:00
cli.sign(txp, function(err, x) {
common.die(err);
if (program.verbose)
console.log('* Raw Server Response:\n', x); //TODO
console.log('Transaction signed.');
});
2015-02-13 11:07:47 -08:00
});