willexecutor manager improved

This commit is contained in:
2026-03-17 02:34:01 -04:00
parent 716d4dd5c5
commit a022c413cc
10 changed files with 329 additions and 258 deletions

115
qt.py
View File

@@ -31,10 +31,8 @@ if QT_VERSION == 5:
)
from PyQt5.QtGui import (
QColor,
QIcon,
QPainter,
QPalette,
QPixmap,
QStandardItem,
QStandardItemModel,
)
@@ -68,10 +66,8 @@ else: # QT6
)
from PyQt6.QtGui import (
QColor,
QIcon,
QPainter,
QPalette,
QPixmap,
QStandardItem,
QStandardItemModel,
)
@@ -124,7 +120,6 @@ from electrum.gui.qt.util import (
WindowModalDialog,
char_width_in_lineedit,
import_meta_gui,
read_QIcon,
read_QIcon_from_bytes,
read_QPixmap_from_bytes,
)
@@ -144,7 +139,6 @@ from electrum.util import (
)
from .bal import BalPlugin
from .bal_resources import DEFAULT_ICON, icon_path
from .heirs import Heirs, HEIR_REAL_AMOUNT, HEIR_DUST_AMOUNT
from .util import Util
from .will import (
@@ -197,8 +191,10 @@ class Plugin(BalPlugin, Logger):
w.init_menubar_tools(menu_child)
except Exception as e:
self.logger.error(
("init_qt except:", menu_child.text())
)
raise e
self.logger.error(("except:", menu_child.text()))
except Exception as e:
self.logger.error("Error loading plugini {}".format(e))
@@ -297,7 +293,7 @@ class Plugin(BalPlugin, Logger):
# heir_ping_willexecutors = bal_checkbox(self.PING_WILLEXECUTORS)
# heir_ask_ping_willexecutors = bal_checkbox(self.ASK_PING_WILLEXECUTORS)
heir_no_willexecutor = bal_checkbox(self.NO_WILLEXECUTOR)
# heir_no_willexecutor = bal_checkbox(self.NO_WILLEXECUTOR)
def on_multiverse_change():
self.update_all()
@@ -481,7 +477,7 @@ class BalWindow(Logger):
self.willitems = {}
try:
self.load_willitems()
except:
except Exception:
self.disable_plugin = True
self.show_warning(
_("Please restart Electrum to activate the BAL plugin"),
@@ -511,15 +507,15 @@ class BalWindow(Logger):
self.willexecutor_dialog.show()
def create_heirs_tab(self):
self.heir_list = l = HeirList(self, self.window)
self.heir_list = HeirList(self, self.window)
tab = self.window.create_list_tab(l)
tab = self.window.create_list_tab(self.heir_list)
tab.is_shown_cv = shown_cv(False)
return tab
def create_will_tab(self):
self.will_list = l = PreviewList(self, self.window, None)
tab = self.window.create_list_tab(l)
self.will_list = PreviewList(self, self.window, None)
tab = self.window.create_list_tab(self.will_list)
tab.is_shown_cv = shown_cv(True)
return tab
@@ -553,7 +549,7 @@ class BalWindow(Logger):
if heir:
self.heir_locktime.set_locktime(heir[2])
heir_is_xpub = QCheckBox()
# heir_is_xpub = QCheckBox()
new_heir_button = QPushButton(_("Add another heir"))
self.add_another_heir = False
@@ -661,8 +657,8 @@ class BalWindow(Logger):
def build_will(self, ignore_duplicate=True, keep_original=True):
_logger.debug("building will...")
will = {}
willtodelete = []
willtoappend = {}
# willtodelete = []
# willtoappend = {}
try:
self.init_class_variables()
self.willexecutors = Willexecutors.get_willexecutors(
@@ -691,7 +687,7 @@ class BalWindow(Logger):
creation_time = time.time()
if txs:
for txid in txs:
txtodelete = []
# txtodelete = []
_break = False
tx = {}
tx["tx"] = txs[txid]
@@ -758,7 +754,7 @@ class BalWindow(Logger):
self.date_to_check = Util.parse_locktime_string(
self.will_settings["threshold"]
)
found = False
# found = False
self.locktime_blocks = self.bal_plugin.LOCKTIME_BLOCKS.get()
self.current_block = Util.get_current_height(self.wallet.network)
self.block_to_check = self.current_block + self.locktime_blocks
@@ -769,7 +765,7 @@ class BalWindow(Logger):
self.init_heirs_to_locktime(self.bal_plugin.ENABLE_MULTIVERSE.get())
except Exception as e:
self.logger.error(e)
self.logger.error(f"init_class_variables: {e}")
raise e
def build_inheritance_transaction(self, ignore_duplicate=True, keep_original=True):
@@ -892,7 +888,7 @@ class BalWindow(Logger):
def show_transaction(self, tx=None, txid=None, parent=None):
if not parent:
parent = self.window
if txid != None and txid in self.willitems:
if txid is not None and txid in self.willitems:
tx = self.willitems[txid].tx
if not tx:
raise Exception(_("no tx"))
@@ -907,7 +903,7 @@ class BalWindow(Logger):
)
)
self.wallet.set_label(result.txid(), "BAL Invalidate")
a = self.show_transaction(result)
self.show_transaction(result)
else:
self.show_message(_("No transactions to invalidate"))
@@ -943,7 +939,7 @@ class BalWindow(Logger):
tosign = txid
try:
self.waiting_dialog.update(get_message())
except:
except Exception:
pass
for txin in tx.inputs():
prevout = txin.prevout.to_json()
@@ -952,7 +948,7 @@ class BalWindow(Logger):
txin._trusted_value_sats = change.value
try:
txin.script_descriptor = change.script_descriptor
except:
except Exception:
pass
txin.is_mine = True
txin._TxInput__address = change.address
@@ -961,9 +957,9 @@ class BalWindow(Logger):
self.wallet.sign_transaction(tx, password, ignore_warnings=True)
signed = tosign
is_complete = False
# is_complete = False
if tx.is_complete():
is_complete = True
# is_complete = True
wi.set_status("COMPLETE", True)
txs[txid] = tx
except Exception:
@@ -1040,7 +1036,7 @@ class BalWindow(Logger):
)
def on_failure(err):
self.logger.error(err)
self.logger.error(f"fail to broadcast transactions:{err}")
task = partial(self.push_transactions_to_willexecutors, force)
msg = _("Selecting Will-Executors")
@@ -1195,11 +1191,14 @@ class BalWindow(Logger):
try:
parent.willexecutor_list.update()
except Exception as e:
_logger.error(f"error updating willexecutors {e}")
pass
try:
parent.willexecutors_list.update()
except Exception as e:
pass
def on_failure(e):
self.logger.error(e)
self.logger.error(f"fail to ping willexecutors: {e}")
pass
self.logger.info("ping willexecutors")
@@ -1762,7 +1761,7 @@ class BalWizardWEDownloadWidget(BalWizardWidget):
import_meta_gui(
self.bal_window.window,
_("willexecutors.json"),
_("willexecutors"),
self.import_json_file,
doNothing,
)
@@ -1786,7 +1785,7 @@ class BalWizardWEDownloadWidget(BalWizardWidget):
_logger.debug(f"Failed to download willexecutors list {fail}")
pass
task = partial(Willexecutors.download_list, self.bal_window.bal_plugin)
task = partial(Willexecutors.download_list, self.bal_window.bal_plugin,self.bal_window.willexecutors)
msg = _("Downloading Will-Executors list")
self.waiting_dialog = BalWaitingDialog(
self.bal_window, msg, task, on_success, on_failure, exe=False
@@ -2045,11 +2044,11 @@ class BalBuildWillDialog(BalDialog):
def __init__(self, bal_window, parent=None):
if not parent:
parent = bal_window.window
BalDialog.__init__(self, parent, bal_window.bal_plugin, "Building Will")
BalDialog.__init__(self, parent, bal_window.bal_plugin, _("Building Will"))
self.parent = parent
self.updatemessage.connect(self.update)
self.bal_window = bal_window
self.message_label = QLabel("Building Will:")
self.message_label = QLabel(_("Building Will:"))
self.vbox = QVBoxLayout(self)
self.vbox.addWidget(self.message_label)
self.qwidget = QWidget()
@@ -2130,15 +2129,15 @@ class BalBuildWillDialog(BalDialog):
message = False
have_to_build = True
if isinstance(e, HeirChangeException):
message = "Heirs changed:"
message = _("Heirs changed:")
elif isinstance(e, WillExecutorNotPresent):
message = "Will-Executor not present"
message = _("Will-Executor not present")
elif isinstance(e, WillexecutorChangeException):
message = "Will-Executor changed"
message = _("Will-Executor changed")
elif isinstance(e, TxFeesChangedException):
message = "Txfees are changed"
message = _("Txfees are changed")
elif isinstance(e, HeirNotFoundException):
message = "Heir not found"
message = _("Heir not found")
if message:
_logger.debug(f"message: {message}")
self.msg_set_checking(message)
@@ -2160,7 +2159,7 @@ class BalBuildWillDialog(BalDialog):
for wid in Will.only_valid(self.bal_window.willitems):
self.bal_window.wallet.set_label(wid, "BAL Transaction")
self.msg_set_building(self.msg_ok())
except WillExecutorNotPresent as e:
except WillExecutorNotPresent:
self.msg_set_status(
_("Will-Executor excluded"), None, _("Skipped"), self.COLOR_ERROR
)
@@ -2169,7 +2168,7 @@ class BalBuildWillDialog(BalDialog):
self.msg_set_building(self.msg_error(e))
return False, None
excluded_heirs = []
# excluded_heirs = []
for wid in Will.only_valid(self.bal_window.willitems):
heirs = self.bal_window.willitems[wid].heirs
for hid, heir in heirs.items():
@@ -2202,7 +2201,7 @@ class BalBuildWillDialog(BalDialog):
for i in range(secs, 0, -1):
if self._stopping:
return
wait_row = self.msg_edit_row(f"Please wait {i}secs", wait_row)
wait_row = self.msg_edit_row(_(f"Please wait {i}secs"), wait_row)
time.sleep(1)
self.msg_del_row(wait_row)
@@ -2219,14 +2218,14 @@ class BalBuildWillDialog(BalDialog):
_logger.debug(f"should not be none txid: {txid}")
except TxBroadcastError as e:
_logger.error(e)
_logger.error(f"fail to broadcast transaction:{e}")
msg = e.get_message_for_gui()
self.msg_set_invalidating(self.msg_error(msg))
except BestEffortRequestFailed as e:
self.msg_set_invalidating(self.msg_error(e))
def loop_push(self):
self.msg_set_pushing("Broadcasting")
self.msg_set_pushing(_("Broadcasting"))
retry = False
try:
willexecutors = Willexecutors.get_willexecutor_transactions(
@@ -2270,7 +2269,7 @@ class BalBuildWillDialog(BalDialog):
except Exception as e:
_logger.error(e)
_logger.error(f"loop push error:{e}")
raise e
if retry:
raise Exception("retry")
@@ -2283,7 +2282,7 @@ class BalBuildWillDialog(BalDialog):
def invalidate_task(self, password, bal_window, tx):
_logger.debug(f"invalidate tx: {tx}")
fee_per_byte = bal_window.will_settings.get("baltx_fees", 1)
# fee_per_byte = bal_window.will_settings.get("baltx_fees", 1)
tx = self.bal_window.wallet.sign_transaction(tx, password)
try:
if tx:
@@ -2321,10 +2320,10 @@ class BalBuildWillDialog(BalDialog):
# need to sign invalidate and restart phase 1
password = self.bal_window.get_wallet_password(
"Invalidate your old will", parent=self
_("Invalidate your old will"), parent=self
)
if password is False:
self.msg_set_invalidating("Aborted")
self.msg_set_invalidating(_("Aborted"))
self.wait(3)
self.close()
return
@@ -2339,12 +2338,12 @@ class BalBuildWillDialog(BalDialog):
elif self.have_to_sign:
password = self.bal_window.get_wallet_password(
"Sign your will", parent=self
_("Sign your will"), parent=self
)
if password is False:
self.msg_set_signing("Aborted")
self.msg_set_signing(_("Aborted"))
else:
self.msg_set_signing("Nothing to do")
self.msg_set_signing(_("Nothing to do"))
self.thread.add(
partial(self.task_phase2, password),
on_success=self.on_success_phase2,
@@ -2356,7 +2355,7 @@ class BalBuildWillDialog(BalDialog):
def on_success_phase2(self, arg=False):
self.thread.stop()
self.bal_window.save_willitems()
self.msg_edit_row("Finished")
self.msg_edit_row(_("Finished"))
self.close()
def closeEvent(self, event):
@@ -2382,7 +2381,7 @@ class BalBuildWillDialog(BalDialog):
if w.we and w.get_status("COMPLETE") and not w.get_status("PUSHED"):
have_to_push = True
if not have_to_push:
self.msg_set_pushing("Nothing to do")
self.msg_set_pushing(_("Nothing to do"))
else:
try:
self.loop_push()
@@ -2397,16 +2396,16 @@ class BalBuildWillDialog(BalDialog):
_logger.error(f"error phase1: {error}")
def on_error_phase2(self, error):
_logger.error("error phase2: { error}")
_logger.error(f"error phase2: { error}")
def msg_set_checking(self, status="Waiting", row=None):
row = self.check_row if row is None else row
self.check_row = self.msg_set_status("Checking your will", row, status)
self.check_row = self.msg_set_status(_("Checking your will"), row, status)
def msg_set_invalidating(self, status=None, row=None):
row = self.inval_row if row is None else row
self.inval_row = self.msg_set_status(
"Invalidating old will", self.inval_row, status
_("Invalidating old will"), self.inval_row, status
)
def msg_set_building(self, status=None, row=None):
@@ -3456,7 +3455,6 @@ class WillExecutorList(MyTreeView):
pass
def update(self):
if self.parent.willexecutors_list is None:
return
try:
@@ -3541,7 +3539,8 @@ class WillExecutorList(MyTreeView):
self.parent.save_willexecutors()
except Exception as e:
_logger.error(e)
_logger.error(f"error updating willexcutor {e}")
raise e
class WillExecutorWidget(QWidget, MessageBoxMixin):
@@ -3609,7 +3608,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
self.willexecutor_list.update()
def download_list(self):
self.willexecutors_list.update(Willexecutors.download_list(self.bal_plugin))
self.willexecutors_list.update(Willexecutors.download_list(self.bal_plugin,self.bal_window.willexecutors))
self.willexecutor_list.update()
def export_file(self, path):
@@ -3623,7 +3622,7 @@ class WillExecutorWidget(QWidget, MessageBoxMixin):
def import_file(self):
import_meta_gui(
self.bal_window.window,
_("willexecutors.json"),
_("willexecutors"),
self.import_json_file,
self.willexecutors_list.update,
)