Browse Source

wallet: (trivial) rename check_address

master
SomberNight 5 years ago
parent
commit
6457bb141d
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/qt/address_list.py
  2. 2
      electrum/gui/qt/main_window.py
  3. 26
      electrum/wallet.py

2
electrum/gui/qt/address_list.py

@ -271,7 +271,7 @@ class AddressList(MyTreeView):
def place_text_on_clipboard(self, text: str, *, title: str = None) -> None: def place_text_on_clipboard(self, text: str, *, title: str = None) -> None:
if is_address(text): if is_address(text):
try: try:
self.wallet.check_address(text) self.wallet.check_address_for_corruption(text)
except InternalAddressCorruption as e: except InternalAddressCorruption as e:
self.parent.show_error(str(e)) self.parent.show_error(str(e))
raise raise

2
electrum/gui/qt/main_window.py

@ -2822,7 +2822,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
# user pressed "sweep" # user pressed "sweep"
addr = get_address() addr = get_address()
try: try:
self.wallet.check_address(addr) self.wallet.check_address_for_corruption(addr)
except InternalAddressCorruption as e: except InternalAddressCorruption as e:
self.show_error(str(e)) self.show_error(str(e))
raise raise

26
electrum/wallet.py

@ -373,6 +373,13 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
raise WalletFileException(f'The addresses in this wallet are not bitcoin addresses.\n' raise WalletFileException(f'The addresses in this wallet are not bitcoin addresses.\n'
f'e.g. {neutered_addr} (length: {len(addr)})') f'e.g. {neutered_addr} (length: {len(addr)})')
def check_returned_address_for_corruption(func):
def wrapper(self, *args, **kwargs):
addr = func(self, *args, **kwargs)
self.check_address_for_corruption(addr)
return addr
return wrapper
def calc_unused_change_addresses(self): def calc_unused_change_addresses(self):
with self.lock: with self.lock:
if hasattr(self, '_unused_change_addresses'): if hasattr(self, '_unused_change_addresses'):
@ -1035,7 +1042,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
assert is_address(addr), f"not valid bitcoin address: {addr}" assert is_address(addr), f"not valid bitcoin address: {addr}"
# note that change addresses are not necessarily ismine # note that change addresses are not necessarily ismine
# in which case this is a no-op # in which case this is a no-op
self.check_address(addr) self.check_address_for_corruption(addr)
max_change = self.max_change_outputs if self.multiple_change else 1 max_change = self.max_change_outputs if self.multiple_change else 1
return change_addrs[:max_change] return change_addrs[:max_change]
@ -1490,29 +1497,22 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
def try_detecting_internal_addresses_corruption(self) -> None: def try_detecting_internal_addresses_corruption(self) -> None:
pass pass
def check_address(self, addr: str) -> None: def check_address_for_corruption(self, addr: str) -> None:
pass pass
def check_returned_address(func):
def wrapper(self, *args, **kwargs):
addr = func(self, *args, **kwargs)
self.check_address(addr)
return addr
return wrapper
def get_unused_addresses(self) -> Sequence[str]: def get_unused_addresses(self) -> Sequence[str]:
domain = self.get_receiving_addresses() domain = self.get_receiving_addresses()
in_use_by_request = [k for k in self.receive_requests.keys() if self.get_request_status(k)[0] != PR_EXPIRED] in_use_by_request = [k for k in self.receive_requests.keys() if self.get_request_status(k)[0] != PR_EXPIRED]
return [addr for addr in domain if not self.is_used(addr) return [addr for addr in domain if not self.is_used(addr)
and addr not in in_use_by_request] and addr not in in_use_by_request]
@check_returned_address @check_returned_address_for_corruption
def get_unused_address(self) -> Optional[str]: def get_unused_address(self) -> Optional[str]:
addrs = self.get_unused_addresses() addrs = self.get_unused_addresses()
if addrs: if addrs:
return addrs[0] return addrs[0]
@check_returned_address @check_returned_address_for_corruption
def get_receiving_address(self) -> str: def get_receiving_address(self) -> str:
# always return an address # always return an address
domain = self.get_receiving_addresses() domain = self.get_receiving_addresses()
@ -2175,9 +2175,9 @@ class Deterministic_Wallet(Abstract_Wallet):
addresses_rand = addresses_all[10:] addresses_rand = addresses_all[10:]
addresses_sample2 = random.sample(addresses_rand, min(len(addresses_rand), 10)) addresses_sample2 = random.sample(addresses_rand, min(len(addresses_rand), 10))
for addr_found in itertools.chain(addresses_sample1, addresses_sample2): for addr_found in itertools.chain(addresses_sample1, addresses_sample2):
self.check_address(addr_found) self.check_address_for_corruption(addr_found)
def check_address(self, addr): def check_address_for_corruption(self, addr):
if addr and self.is_mine(addr): if addr and self.is_mine(addr):
if addr != self.derive_address(*self.get_address_index(addr)): if addr != self.derive_address(*self.get_address_index(addr)):
raise InternalAddressCorruption() raise InternalAddressCorruption()

Loading…
Cancel
Save