more robust validation of createTx params
This commit is contained in:
parent
4dc010cf0c
commit
82bd588834
|
@ -1645,6 +1645,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);
|
||||
|
||||
if (_.isEmpty(opts.outputs)) return new ClientError('No outputs were specified');
|
||||
|
||||
for (var i = 0; i < opts.outputs.length; i++) {
|
||||
var output = opts.outputs[i];
|
||||
output.valid = false;
|
||||
|
@ -1753,8 +1755,6 @@ WalletService.prototype.createTx = function(opts, cb) {
|
|||
|
||||
opts = opts || {};
|
||||
|
||||
if (!checkRequired(opts, ['outputs'], cb)) return;
|
||||
|
||||
function getChangeAddress(wallet, cb) {
|
||||
if (wallet.singleAddress) {
|
||||
self.storage.fetchAddresses(self.walletId, function(err, addresses) {
|
||||
|
|
|
@ -2294,17 +2294,16 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
it('should fail to create a tx without outputs param', function(done) {
|
||||
it('should fail to create a tx without outputs', function(done) {
|
||||
helpers.stubUtxos(server, wallet, [1, 2], function() {
|
||||
var txOpts = {
|
||||
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||
amount: 0.8 * 1e8,
|
||||
message: 'some message',
|
||||
outputs: [],
|
||||
feePerKb: 123e2,
|
||||
};
|
||||
server.createTx(txOpts, function(err, tx) {
|
||||
should.exist(err);
|
||||
should.not.exist(tx);
|
||||
err.message.should.equal('No outputs were specified');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue