replace missing and unsupported flags with output.valid, similar to each loops below

This commit is contained in:
Gregg Zigler 2015-06-23 17:11:14 -04:00
parent e9a90f5560
commit f324fd80cd
1 changed files with 15 additions and 9 deletions

View File

@ -836,19 +836,25 @@ WalletService.prototype.createTx = function(opts, cb) {
if (opts.type == Model.TxProposal.Types.MULTIPLEOUTPUTS) {
if (!Utils.checkRequired(opts, ['outputs']))
return cb(new ClientError('Required argument missing'));
var missing = false, unsupported = false;
_.each(opts.outputs, function(o) {
if (!Utils.checkRequired(o, ['toAddress', 'amount']))
missing = true;
o.valid = true;
if (!Utils.checkRequired(o, ['toAddress', 'amount'])) {
o.valid = false;
cb(new ClientError('Required outputs argument missing'));
return false;
}
_.each(_.keys(o), function(key) {
if (!_.contains(['toAddress', 'amount', 'message'], key))
unsupported = true;
if (!_.contains(['toAddress', 'amount', 'message', 'valid'], key)) {
o.valid = false;
cb(new ClientError('Invalid outputs argument found'));
return false;
}
});
if (!o.valid) return false;
});
if (missing)
return cb(new ClientError('Required outputs argument missing'));
if (unsupported)
return cb(new ClientError('Invalid outputs argument found'));
if (_.any(opts.outputs, 'valid', false)) return;
_.each(opts.outputs, function(o) { delete o.valid; });
} else {
if (!Utils.checkRequired(opts, ['toAddress', 'amount']))
return cb(new ClientError('Required argument missing'));