|
|
@ -142,7 +142,7 @@ class Abstract_Wallet(object): |
|
|
|
def __init__(self, storage): |
|
|
|
self.storage = storage |
|
|
|
self.electrum_version = ELECTRUM_VERSION |
|
|
|
self.gap_limit_for_change = 3 # constant |
|
|
|
self.gap_limit_for_change = 6 # constant |
|
|
|
# saved fields |
|
|
|
self.seed_version = storage.get('seed_version', NEW_SEED_VERSION) |
|
|
|
self.use_change = storage.get('use_change',True) |
|
|
@ -887,10 +887,17 @@ class Abstract_Wallet(object): |
|
|
|
# send change to one of the accounts involved in the tx |
|
|
|
address = inputs[0].get('address') |
|
|
|
account, _ = self.get_address_index(address) |
|
|
|
if not self.use_change or not self.accounts[account].has_change(): |
|
|
|
change_addr = address |
|
|
|
if self.use_change and self.accounts[account].has_change(): |
|
|
|
# New change addresses are created only after a few confirmations. |
|
|
|
# Choose an unused change address if any, otherwise take one at random |
|
|
|
change_addrs = self.accounts[account].get_addresses(1)[-self.gap_limit_for_change:] |
|
|
|
for change_addr in change_addrs: |
|
|
|
if self.get_num_tx(change_addr) == 0: |
|
|
|
break |
|
|
|
else: |
|
|
|
change_addr = self.accounts[account].get_addresses(1)[-self.gap_limit_for_change] |
|
|
|
change_addr = random.choice(change_addrs) |
|
|
|
else: |
|
|
|
change_addr = address |
|
|
|
|
|
|
|
# if change is above dust threshold, add a change output. |
|
|
|
change_amount = total - ( amount + fee ) |
|
|
|