Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #814 from matiu/bug/fix-change-address-check
Browse files Browse the repository at this point in the history
fix changeAddress check, fail before
  • Loading branch information
matiu committed Dec 7, 2018
2 parents 438e068 + dfebf3e commit 94b2c85
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/expressapp.js
Expand Up @@ -692,7 +692,7 @@ ExpressApp.prototype.start = function(opts, cb) {
router.get('/v1/txnotes/', function(req, res) {
getServerWithAuth(req, res, function(server) {
var opts = {};
if (_.isNumber(+req.query.minTs)) {
if (req.query.minTs && _.isNumber(+req.query.minTs)) {
opts.minTs = +req.query.minTs;
}
server.getTxNotes(opts, function(err, notes) {
Expand Down
4 changes: 2 additions & 2 deletions lib/model/txproposal.js
Expand Up @@ -193,8 +193,8 @@ TxProposal.prototype._buildTx = function() {
var totalInputs = _.sumBy(t.inputs, 'output.satoshis');
var totalOutputs = _.sumBy(t.outputs, 'satoshis');

$.checkState(totalInputs > 0 && totalOutputs > 0 && totalInputs >= totalOutputs);
$.checkState(totalInputs - totalOutputs <= Defaults.MAX_TX_FEE);
$.checkState(totalInputs > 0 && totalOutputs > 0 && totalInputs >= totalOutputs, 'not-enought-inputs');
$.checkState(totalInputs - totalOutputs <= Defaults.MAX_TX_FEE, 'fee-too-high');

return t;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Expand Up @@ -2286,7 +2286,7 @@ WalletService.prototype.createTx = function(opts, cb) {
} else {
if (opts.changeAddress) {
self.storage.fetchAddressByWalletId(wallet.id, opts.changeAddress, function(err, address) {
if (err) return cb(Errors.INVALID_CHANGE_ADDRESS);
if (err || !address) return cb(Errors.INVALID_CHANGE_ADDRESS);
return cb(null, address);
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "bitcore-wallet-service",
"description": "A service for Mutisig HD Bitcoin Wallets",
"author": "BitPay Inc",
"version": "2.5.0",
"version": "2.5.1",
"license": "MIT",
"keywords": [
"bitcoin",
Expand Down
21 changes: 21 additions & 0 deletions test/integration/server.js
Expand Up @@ -3388,6 +3388,27 @@ console.log('[server.js.425:err:]',err); //TODO
});
});
});
it('should be fail if specified change address is not from the wallet', function(done) {

helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {

var addr = (new Bitcore_[coin].PrivateKey()).toAddress();
var txOpts = {
outputs: [{
toAddress: addressStr,
amount: 0.8e8,
}],
feePerKb: 100e2,
changeAddress: addr.toString(),
};
server.createTx(txOpts, function(err, tx) {
should.exist(err);
err.code.should.equal('INVALID_CHANGE_ADDRESS');
done();
});
});
});

it('should be able to specify inputs & absolute fee', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function(utxos) {
var txOpts = {
Expand Down

0 comments on commit 94b2c85

Please sign in to comment.