add txproposal -i

This commit is contained in:
Matias Alejo Garcia 2015-02-22 01:51:24 -03:00
parent f08fedc4bc
commit 8d382c1e88
2 changed files with 49 additions and 5 deletions

View File

@ -3,22 +3,36 @@
var _ = require('lodash');
var fs = require('fs');
var program = require('commander');
var utils = require('./cli-utils');
var utils = require('./cli-utils');
program = utils.configureCommander(program);
program
.option('-i, --input [filename]', 'input file')
.option('-o, --output [filename]', 'output file')
.parse(process.argv);
var args = program.args;
var client = utils.getClient(program);
client.getTxProposals({}, function(err, txps) {
var txData;
function end(err, txps, rawtxps) {
utils.die(err);
if (program.input) {
console.log('\n* From File : %s\n', program.input);
}
utils.renderTxProposals(txps);
if (program.output) {
fs.writeFileSync(program.output, JSON.stringify(txps));
fs.writeFileSync(program.output, JSON.stringify(rawtxps));
console.log(' * Proposals Saved to: %s\n', program.output);
}
};
});
if (program.input) {
var txData = fs.readFileSync(program.input);
txData = JSON.parse(txData);
client.parseTxProposals(txData, end);
} else {
client.getTxProposals({getRawTxps: !!program.output}, end);
}

View File

@ -483,9 +483,35 @@ API.prototype.import = function(str, cb) {
});
};
/**
*
*/
API.prototype.parseTxProposals = function(txps, cb) {
var self = this;
this._loadAndCheck(function(err, data) {
if (err) return cb(err);
_processTxps(txps, data.sharedEncryptingKey);
var fake = _.any(txps, function(txp) {
return (!Verifier.checkTxProposal(data, txp));
});
if (fake)
return cb(new ServerCompromisedError('Server sent fake transaction proposal'));
return cb(null, txps);
});
};
/**
*
* opts.doNotVerify
* opts.getRawTxps
* @return {undefined}
*/
@ -498,6 +524,10 @@ API.prototype.getTxProposals = function(opts, cb) {
self._doGetRequest(url, data, function(err, txps) {
if (err) return cb(err);
var rawTxps;
if (opts.getRawTxps)
rawTxps = JSON.parse(JSON.stringify(txps));
_processTxps(txps, data.sharedEncryptingKey);
var fake = _.any(txps, function(txp) {
@ -507,7 +537,7 @@ API.prototype.getTxProposals = function(opts, cb) {
if (fake)
return cb(new ServerCompromisedError('Server sent fake transaction proposal'));
return cb(null, txps);
return cb(null, txps, rawTxps);
});
});
};