Merge pull request #501 from isocolsky/fix/build-tx-change
Include change address when building tx
This commit is contained in:
commit
0bd06921dd
|
@ -164,10 +164,7 @@ TxProposal.prototype._buildTx = function() {
|
|||
|
||||
t.fee(self.fee);
|
||||
|
||||
var totalInputs = _.sum(self.inputs, 'satoshis');
|
||||
var totalOutputs = _.sum(self.outputs, 'amount');
|
||||
|
||||
if (totalInputs - totalOutputs - self.fee > 0 && self.changeAddress) {
|
||||
if (self.changeAddress) {
|
||||
t.change(self.changeAddress.address);
|
||||
}
|
||||
|
||||
|
|
|
@ -1593,7 +1593,8 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
|
|||
var err = self._checkTx(txp);
|
||||
|
||||
if (!err) {
|
||||
log.debug('Successfully built transaction. Total fees: ' + Utils.formatAmountInBtc(txp.fee) + ', total change: ' + Utils.formatAmountInBtc(_.sum(txp.inputs, 'satoshis') - txp.fee));
|
||||
var change = _.sum(txp.inputs, 'satoshis') - _.sum(txp.outputs, 'amount') - txp.fee;
|
||||
log.debug('Successfully built transaction. Total fees: ' + Utils.formatAmountInBtc(txp.fee) + ', total change: ' + Utils.formatAmountInBtc(change));
|
||||
} else {
|
||||
log.warn('Error building transaction', err);
|
||||
}
|
||||
|
|
26
package.json
26
package.json
|
@ -2,7 +2,7 @@
|
|||
"name": "bitcore-wallet-service",
|
||||
"description": "A service for Mutisig HD Bitcoin Wallets",
|
||||
"author": "BitPay Inc",
|
||||
"version": "1.6.1",
|
||||
"version": "1.7.0",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"copay",
|
||||
|
@ -65,18 +65,14 @@
|
|||
"coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
"bitcoreNode": "./bitcorenode",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Braydon Fuller",
|
||||
"email": "braydon@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Ivan Socolsky",
|
||||
"email": "ivan@bitpay.com"
|
||||
},
|
||||
{
|
||||
"name": "Matias Alejo Garcia",
|
||||
"email": "ematiu@gmail.com"
|
||||
}
|
||||
]
|
||||
"contributors": [{
|
||||
"name": "Braydon Fuller",
|
||||
"email": "braydon@bitpay.com"
|
||||
}, {
|
||||
"name": "Ivan Socolsky",
|
||||
"email": "ivan@bitpay.com"
|
||||
}, {
|
||||
"name": "Matias Alejo Garcia",
|
||||
"email": "ematiu@gmail.com"
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -2132,7 +2132,6 @@ describe('Wallet service', function() {
|
|||
});
|
||||
|
||||
it('should use unconfirmed utxos only when no more confirmed utxos are available', function(done) {
|
||||
// log.level = 'debug';
|
||||
helpers.stubUtxos(server, wallet, [1.3, 'u0.5', 'u0.1', 1.2], function(utxos) {
|
||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 2.55, TestData.copayers[0].privKey_1H_0, {
|
||||
message: 'some message'
|
||||
|
@ -2355,7 +2354,6 @@ describe('Wallet service', function() {
|
|||
});
|
||||
|
||||
it('should fail to create a tx exceeding max size in kb', function(done) {
|
||||
// log.level = 'debug';
|
||||
var _oldDefault = Defaults.MAX_TX_SIZE_IN_KB;
|
||||
Defaults.MAX_TX_SIZE_IN_KB = 1;
|
||||
helpers.stubUtxos(server, wallet, _.range(1, 10, 0), function() {
|
||||
|
@ -3399,7 +3397,6 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
it('should account for fee when selecting smallest big utxo', function(done) {
|
||||
// log.level = 'debug';
|
||||
var _old = Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR;
|
||||
Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR = 2;
|
||||
// The 605 bits input cannot be selected even if it is > 2 * tx amount
|
||||
|
@ -3564,7 +3561,6 @@ describe('Wallet service', function() {
|
|||
});
|
||||
});
|
||||
it('should select unconfirmed utxos if not enough confirmed utxos', function(done) {
|
||||
// log.level = 'debug';
|
||||
helpers.stubUtxos(server, wallet, ['u 1btc', '0.5btc'], function() {
|
||||
var txOpts = {
|
||||
outputs: [{
|
||||
|
|
Loading…
Reference in New Issue