minor refactor in output validation

This commit is contained in:
Ivan Socolsky 2016-06-14 12:22:26 -03:00
parent ab8ee233e0
commit 6190348200
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
1 changed files with 3 additions and 10 deletions

View File

@ -1681,6 +1681,8 @@ WalletService.prototype._canCreateTx = function(cb) {
};
WalletService.prototype._validateOutputs = function(opts, wallet, cb) {
var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore.Transaction.DUST_AMOUNT);
for (var i = 0; i < opts.outputs.length; i++) {
var output = opts.outputs[i];
output.valid = false;
@ -1702,7 +1704,7 @@ WalletService.prototype._validateOutputs = function(opts, wallet, cb) {
if (!_.isNumber(output.amount) || _.isNaN(output.amount) || output.amount <= 0) {
return new ClientError('Invalid amount');
}
if (output.amount < Bitcore.Transaction.DUST_AMOUNT) {
if (output.amount < dustThreshold) {
return Errors.DUST_AMOUNT;
}
@ -1903,15 +1905,6 @@ WalletService.prototype._validateAndSanitizeTxOpts = function(wallet, opts, cb)
return next();
});
},
function(next) {
var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore.Transaction.DUST_AMOUNT);
if (_.any(opts.outputs, function(output) {
return output.amount < dustThreshold;
})) {
return next(Errors.DUST_AMOUNT);
}
next();
},
function(next) {
if (opts.validateOutputs === false) return next();
var validationError = self._validateOutputs(opts, wallet, next);