(trivial) wallet: rename parameter of a method
Re get_change_addresses_for_new_transaction, "allow_reuse" is a confusing parameter name: it means whether we allow reusing already used change addresses to send new change to. However, if the method returns [], we will instead reuse the "from address" and send change there. So it quite unclear without thinking it through what "allow_reuse" means as it could be either of the two (and they are ~opposite scenarios). The new name is long but at least it is clear.
This commit is contained in:
@@ -1258,7 +1258,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||
return candidate
|
||||
|
||||
def get_change_addresses_for_new_transaction(
|
||||
self, preferred_change_addr=None, *, allow_reuse: bool = True,
|
||||
self, preferred_change_addr=None, *, allow_reusing_used_change_addrs: bool = True,
|
||||
) -> List[str]:
|
||||
change_addrs = []
|
||||
if preferred_change_addr:
|
||||
@@ -1276,7 +1276,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||
change_addrs = addrs
|
||||
else:
|
||||
# if there are none, take one randomly from the last few
|
||||
if not allow_reuse:
|
||||
if not allow_reusing_used_change_addrs:
|
||||
return []
|
||||
addrs = self.get_change_addresses(slice_start=-self.gap_limit_for_change)
|
||||
change_addrs = [random.choice(addrs)] if addrs else []
|
||||
@@ -1289,11 +1289,11 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||
return change_addrs[:max_change]
|
||||
|
||||
def get_single_change_address_for_new_transaction(
|
||||
self, preferred_change_addr=None, *, allow_reuse: bool = True,
|
||||
self, preferred_change_addr=None, *, allow_reusing_used_change_addrs: bool = True,
|
||||
) -> Optional[str]:
|
||||
addrs = self.get_change_addresses_for_new_transaction(
|
||||
preferred_change_addr=preferred_change_addr,
|
||||
allow_reuse=allow_reuse,
|
||||
allow_reusing_used_change_addrs=allow_reusing_used_change_addrs,
|
||||
)
|
||||
if addrs:
|
||||
return addrs[0]
|
||||
@@ -1801,7 +1801,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||
if not item:
|
||||
raise CannotCPFP(_("Could not find coins for output"))
|
||||
inputs = [item]
|
||||
out_address = (self.get_single_change_address_for_new_transaction(allow_reuse=False)
|
||||
out_address = (self.get_single_change_address_for_new_transaction(allow_reusing_used_change_addrs=False)
|
||||
or self.get_unused_address()
|
||||
or address)
|
||||
output_value = value - fee
|
||||
|
||||
Reference in New Issue
Block a user