From f324fd80cd8b447199b2b049e718386a83b3f3a4 Mon Sep 17 00:00:00 2001 From: Gregg Zigler Date: Tue, 23 Jun 2015 17:11:14 -0400 Subject: [PATCH] replace missing and unsupported flags with output.valid, similar to each loops below --- lib/server.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/server.js b/lib/server.js index 40a44d1..a87ac98 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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'));