commit 1703e0036a78888f73d896ac94ee34e6230ae8b8
parent 381de43cace42c8aa160205f32ad8584793f00ad
Author: ThomasV <thomasv@electrum.org>
Date: Wed, 21 Feb 2018 11:18:59 +0100
Merge pull request #3921 from SomberNight/fix_disabled_change_addrs
fix: disabling "use change addresses" did not work correctly
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/coinchooser.py b/lib/coinchooser.py
@@ -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)
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -1148,7 +1148,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: