Skip to content

Commit 951ca76

Browse files
committed
allow signing transaction from View
1 parent fb40bbe commit 951ca76

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

electrum/plugins/timelock_recovery/qt.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from electrum.payment_identifier import PaymentIdentifierType
3636
from electrum.plugin import hook
3737
from electrum.i18n import _
38-
from electrum.transaction import PartialTxOutput
38+
from electrum.transaction import PartialTxOutput, Transaction
3939
from electrum.util import NotEnoughFunds, make_dir
4040
from electrum.gui.qt.util import ColorScheme, WindowModalDialog, Buttons, HelpLabel
4141
from electrum.gui.qt.util import read_QIcon_from_bytes, read_QPixmap_from_bytes, WaitingDialog
@@ -232,16 +232,26 @@ def update_transactions():
232232
next_button.setToolTip("")
233233
return
234234
try:
235-
context.alert_tx = context.make_unsigned_alert_tx(fee_policy)
235+
new_alert_tx = context.make_unsigned_alert_tx(fee_policy)
236+
alert_changed = False
237+
if not context.alert_tx or context.alert_tx.txid() != new_alert_tx.txid():
238+
context.alert_tx = new_alert_tx
239+
alert_changed = True
236240
assert all(tx_input.is_segwit() for tx_input in context.alert_tx.inputs())
237241
alert_tx_complete_label.setText(_("✓ Signed") if context.alert_tx.is_complete() else "")
238242
alert_tx_fee_label.setText(_("Fee: {}").format(self.config.format_amount_and_units(context.alert_tx.get_fee())))
239-
context.recovery_tx = context.make_unsigned_recovery_tx(fee_policy)
243+
new_recovery_tx = context.make_unsigned_recovery_tx(fee_policy)
244+
if alert_changed or not context.recovery_tx or context.recovery_tx.txid() != new_recovery_tx.txid():
245+
context.recovery_tx = new_recovery_tx
246+
context.add_input_info_to_recovery_tx()
240247
assert all(tx_input.is_segwit() for tx_input in context.recovery_tx.inputs())
241248
recovery_tx_complete_label.setText(_("✓ Signed") if context.recovery_tx.is_complete() else "")
242249
recovery_tx_fee_label.setText(_("Fee: {}").format(self.config.format_amount_and_units(context.recovery_tx.get_fee())))
243250
if create_cancel_cb.isChecked():
244-
context.cancellation_tx = context.make_unsigned_cancellation_tx(fee_policy)
251+
new_cancellation_tx = context.make_unsigned_cancellation_tx(fee_policy)
252+
if alert_changed or not context.cancellation_tx or context.cancellation_tx.txid() != new_cancellation_tx.txid():
253+
context.cancellation_tx = new_cancellation_tx
254+
context.add_input_info_to_cancellation_tx()
245255
assert all(tx_input.is_segwit() for tx_input in context.cancellation_tx.inputs())
246256
cancellation_tx_complete_label.setText(_("✓ Signed") if context.cancellation_tx.is_complete() else "")
247257
cancellation_tx_fee_label.setText(_("Fee: {}").format(self.config.format_amount_and_units(context.cancellation_tx.get_fee())))
@@ -338,15 +348,27 @@ def update_transactions():
338348
plan_grid.addWidget(alert_tx_fee_label, grid_row, 1, 1, 2)
339349
plan_grid.addWidget(alert_tx_complete_label, grid_row, 3)
340350
view_alert_tx_button = QPushButton(_('View'))
341-
view_alert_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.alert_tx, show_sign_button=False, show_broadcast_button=False))
351+
def on_alert_tx_closed(tx: Optional[Transaction]):
352+
if tx is not None and context.alert_tx is not None and tx.txid() == context.alert_tx.txid() and tx.is_complete():
353+
old_alert_tx_complete = context.alert_tx and context.alert_tx.is_complete()
354+
context.alert_tx = tx
355+
if not old_alert_tx_complete and context.alert_tx.is_complete():
356+
context.add_input_info_to_recovery_tx()
357+
context.add_input_info_to_cancellation_tx()
358+
update_transactions()
359+
view_alert_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.alert_tx, show_broadcast_button=False, on_closed=on_alert_tx_closed))
342360
plan_grid.addWidget(view_alert_tx_button, grid_row, 4)
343361
grid_row += 1
344362

345363
plan_grid.addWidget(QLabel('Recovery transaction'), grid_row, 0)
346364
plan_grid.addWidget(recovery_tx_fee_label, grid_row, 1, 1, 2)
347365
plan_grid.addWidget(recovery_tx_complete_label, grid_row, 3)
348366
view_recovery_tx_button = QPushButton(_('View'))
349-
view_recovery_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.recovery_tx, show_sign_button=False, show_broadcast_button=False))
367+
def on_recovery_tx_closed(tx: Optional[Transaction]):
368+
if tx is not None and context.recovery_tx is not None and tx.txid() == context.recovery_tx.txid() and tx.is_complete():
369+
context.recovery_tx = tx
370+
update_transactions()
371+
view_recovery_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.recovery_tx, show_broadcast_button=False, on_closed=on_recovery_tx_closed))
350372
plan_grid.addWidget(view_recovery_tx_button, grid_row, 4)
351373
grid_row += 1
352374

@@ -355,7 +377,11 @@ def update_transactions():
355377
plan_grid.addWidget(cancellation_tx_fee_label, grid_row, 1, 1, 2)
356378
plan_grid.addWidget(cancellation_tx_complete_label, grid_row, 3)
357379
view_cancellation_tx_button = QPushButton(_('View'))
358-
view_cancellation_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.cancellation_tx, show_sign_button=False, show_broadcast_button=False))
380+
def on_cancellation_tx_closed(tx: Optional[Transaction]):
381+
if tx is not None and context.cancellation_tx is not None and tx.txid() == context.cancellation_tx.txid() and tx.is_complete():
382+
context.cancellation_tx = tx
383+
update_transactions()
384+
view_cancellation_tx_button.clicked.connect(lambda: context.main_window.show_transaction(context.cancellation_tx, show_broadcast_button=False, on_closed=on_cancellation_tx_closed))
359385
plan_grid.addWidget(view_cancellation_tx_button, grid_row, 4)
360386
grid_row += 1
361387

@@ -440,9 +466,10 @@ def start_plan(self, context: TimelockRecoveryContext):
440466
def task():
441467
if not context.alert_tx.is_complete():
442468
wallet.sign_transaction(context.alert_tx, password, ignore_warnings=True)
469+
context.add_input_info_to_recovery_tx()
470+
context.add_input_info_to_cancellation_tx()
443471
if not context.alert_tx.is_complete():
444472
raise Exception(_("Alert transaction signing was not completed"))
445-
context.add_input_info()
446473
if not context.recovery_tx.is_complete():
447474
wallet.sign_transaction(context.recovery_tx, password, ignore_warnings=True)
448475
if not context.recovery_tx.is_complete():

electrum/plugins/timelock_recovery/timelock_recovery.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ def make_unsigned_recovery_tx(self, fee_policy) -> 'PartialTransaction':
126126
locktime=self.recovery_tx.locktime if self.recovery_tx else None,
127127
)
128128

129-
def add_input_info(self):
130-
self.recovery_tx.inputs()[0].utxo = self.alert_tx
131-
if self.cancellation_tx:
129+
def add_input_info_to_recovery_tx(self):
130+
if self.recovery_tx and self.alert_tx.is_complete():
131+
self.recovery_tx.inputs()[0].utxo = self.alert_tx
132+
133+
def add_input_info_to_cancellation_tx(self):
134+
if self.cancellation_tx and self.alert_tx.is_complete():
132135
self.cancellation_tx.inputs()[0].utxo = self.alert_tx
133136

134137
def make_unsigned_cancellation_tx(self, fee_policy) -> 'PartialTransaction':

0 commit comments

Comments
 (0)