fix: disabling "use change addresses" did not work correctly

This commit is contained in:
SomberNight 2018-02-18 20:13:27 +01:00
parent c4d31674ab
commit 72a443b688
2 changed files with 10 additions and 2 deletions

View File

@ -25,7 +25,7 @@
from collections import defaultdict, namedtuple
from math import floor, log10
from .bitcoin import sha256, COIN, TYPE_ADDRESS
from .bitcoin import sha256, COIN, TYPE_ADDRESS, is_address
from .transaction import Transaction
from .util import NotEnoughFunds, PrintError
@ -240,6 +240,13 @@ class CoinChooserBase(PrintError):
tx.add_inputs([coin for b in buckets for coin in b.coins])
tx_weight = get_tx_weight(buckets)
# change is sent back to sending address unless specified
if not change_addrs:
change_addrs = [tx.inputs()[0]['address']]
# note: this is not necessarily the final "first input address"
# because the inputs had not been sorted at this point
assert is_address(change_addrs[0])
# This takes a count of change outputs and returns a tx fee
output_weight = 4 * Transaction.estimated_output_size(change_addrs[0])
fee = lambda count: fee_estimator_w(tx_weight + count * output_weight)

View File

@ -1123,7 +1123,8 @@ class Abstract_Wallet(PrintError):
if not change_addrs:
change_addrs = [random.choice(addrs)]
else:
change_addrs = [inputs[0]['address']]
# coin_chooser will set change address
change_addrs = []
# Fee estimator
if fixed_fee is None: