Browse Source

Merge pull request #561 from isocolsky/fix/args-check

More robust validation of createTx params
activeAddress
Matias Alejo Garcia 9 years ago
committed by GitHub
parent
commit
9812a0d53b
  1. 4
      lib/server.js
  2. 7
      test/integration/server.js

4
lib/server.js

@ -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) {

7
test/integration/server.js

@ -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…
Cancel
Save