bitcore-wallet-service/bit-wallet/bit-txproposals

46 lines
1.1 KiB
Plaintext
Raw Normal View History

2015-02-21 20:04:51 -08:00
#!/usr/bin/env node
var _ = require('lodash');
var fs = require('fs');
var program = require('commander');
2015-02-21 20:51:24 -08:00
var utils = require('./cli-utils');
2015-02-21 20:04:51 -08:00
program = utils.configureCommander(program);
program
2015-02-21 22:46:47 -08:00
.option('-i, --input [filename]', 'use input file instead of server\'s')
.option('-o, --output [filename]', 'write tx to output file')
2015-02-21 20:04:51 -08:00
.parse(process.argv);
var args = program.args;
var client = utils.getClient(program);
2015-02-21 20:51:24 -08:00
var txData;
function end(err, txps, rawtxps) {
2015-02-21 20:04:51 -08:00
utils.die(err);
2015-02-21 20:51:24 -08:00
if (program.input) {
console.log('\n* From File : %s\n', program.input);
}
2015-02-21 20:04:51 -08:00
utils.renderTxProposals(txps);
if (program.output) {
2015-02-22 19:43:39 -08:00
2015-02-22 21:19:23 -08:00
client.getEncryptedWalletData(function (err, toComplete) {
2015-02-22 19:43:39 -08:00
var txData = {
2015-02-22 21:19:23 -08:00
toComplete: toComplete,
2015-02-22 19:43:39 -08:00
txps: txps,
};
fs.writeFileSync(program.output, JSON.stringify(txData));
console.log(' * Proposals Saved to: %s\n', program.output);
});
2015-02-21 20:04:51 -08:00
}
2015-02-21 20:51:24 -08:00
};
2015-02-21 20:04:51 -08:00
2015-02-21 20:51:24 -08:00
if (program.input) {
var txData = fs.readFileSync(program.input);
txData = JSON.parse(txData);
client.parseTxProposals(txData, end);
} else {
client.getTxProposals({getRawTxps: !!program.output}, end);
}