Skip to content

Commit

Permalink
[electrum] add the option to always add new addresses to wallet when …
Browse files Browse the repository at this point in the history
…scanning beyond gap

Summary:
Users have requested a better solution for generating more addresses without having to use console command.
This adds a checkbox to the "Scan More Addresses" tool. Users can optionnaly check it to save all the newly scanned addresses to the wallet, no matter if any tx history was found for any following address.

Note that as a result of this the wallet will monitor more unused addresses than the usual 20 (default gap limit), so it is not something I recommend doing for wallets with already a large history.

Depends on D15848

Test Plan:
use the Scan More Addresses tool  with the new checkbox toggled. Make sure the expected number of new addresses is added to the Address tab.
Try scanning for only receive addresses, only change addresses, and both.

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D15849
  • Loading branch information
PiRK authored and abc-bot committed Apr 3, 2024
1 parent bfc6e84 commit 874d49c
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions electrumabc_gui/qt/scan_beyond_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, main_window):
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
)
vbox.addWidget(label)

vbox.addStretch(1)
hbox = QtWidgets.QHBoxLayout()
label = QtWidgets.QLabel(_("Number of addresses to scan:"))
Expand All @@ -90,15 +91,31 @@ def __init__(self, main_window):
hbox.addWidget(self.which_cb)
hbox.addStretch(1)
vbox.addLayout(hbox)

self.always_add_addresses_cb = QtWidgets.QCheckBox(
_("Always add scanned addresses to the wallet")
)
self.always_add_addresses_cb.setToolTip(
_(
"Add the scanned addresses even if no new history is found. Leave this "
"unchecked if unsure, because subscribing to more addresses may "
"needlessly slow down your wallet."
)
)
vbox.addWidget(self.always_add_addresses_cb)

self.prog = QtWidgets.QProgressBar()
self.prog.setMinimum(0)
self.prog.setMaximum(100)
vbox.addWidget(self.prog)

self.prog_label = QtWidgets.QLabel()
vbox.addWidget(self.prog_label)

self.found_label = QtWidgets.QLabel()
vbox.addWidget(self.found_label)
vbox.addStretch(1)

self.cancel_but = QtWidgets.QPushButton(_("Cancel"))
self.scan_but = QtWidgets.QPushButton(_("Start Scan"))
vbox.addLayout(Buttons(self.cancel_but, self.scan_but))
Expand All @@ -107,7 +124,7 @@ def __init__(self, main_window):
self.scan_but.clicked.connect(self.scan)

self.thread = threading.Thread(target=self.scan_thread, daemon=True)
self._thread_args = (None,) * 2
self._thread_args = (None,) * 3
self.stop_flag = False
self.canceling = False
self.stage2 = False
Expand Down Expand Up @@ -157,9 +174,11 @@ def scan(self):
self.which_cb.setDisabled(True)
self.num_sb.setDisabled(True)
self.found_label.setText("")
total = self.num_sb.value()
which = self.which_cb.currentIndex()
self._thread_args = (total, which)
self._thread_args = (
self.num_sb.value(),
self.which_cb.currentIndex(),
self.always_add_addresses_cb.isChecked(),
)
self.thread.start()

def progress_slot(self, pct, scanned, total, found):
Expand Down Expand Up @@ -240,8 +259,8 @@ def _addr_has_history(self, address, network):
)

def scan_thread(self):
total, which = self._thread_args
assert total is not None and which is not None
total, which, always_add = self._thread_args
assert all(arg is not None for arg in self._thread_args)
wallet = self.main_window.wallet
network = wallet.network
assert network
Expand Down Expand Up @@ -270,14 +289,16 @@ def scan_thread(self):
)
if self.stop_flag:
return
if self._addr_has_history(addr, network):
has_history = self._addr_has_history(addr, network)
if has_history:
self.print_error(
"FOUND:",
addr,
"(Change)" if is_change else "(Receiving)",
n,
)
num_found += 1
if has_history or always_add:
if is_change:
change_end = n
else:
Expand All @@ -286,7 +307,7 @@ def scan_thread(self):
self.progress_sig.emit(ct * 100 // total, ct, total, num_found)
i += 1
num_added = 0
if num_found:
if num_found or (always_add and (recv_end or change_end)):
num_added = self._add_addresses(recv_end, change_end)
self.done_sig.emit(num_found, num_added)
except ServerError as e:
Expand Down

0 comments on commit 874d49c

Please sign in to comment.