35
35
from electrum .payment_identifier import PaymentIdentifierType
36
36
from electrum .plugin import hook
37
37
from electrum .i18n import _
38
- from electrum .transaction import PartialTxOutput
38
+ from electrum .transaction import PartialTxOutput , Transaction
39
39
from electrum .util import NotEnoughFunds , make_dir
40
40
from electrum .gui .qt .util import ColorScheme , WindowModalDialog , Buttons , HelpLabel
41
41
from electrum .gui .qt .util import read_QIcon_from_bytes , read_QPixmap_from_bytes , WaitingDialog
@@ -232,16 +232,26 @@ def update_transactions():
232
232
next_button .setToolTip ("" )
233
233
return
234
234
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
236
240
assert all (tx_input .is_segwit () for tx_input in context .alert_tx .inputs ())
237
241
alert_tx_complete_label .setText (_ ("✓ Signed" ) if context .alert_tx .is_complete () else "" )
238
242
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 ()
240
247
assert all (tx_input .is_segwit () for tx_input in context .recovery_tx .inputs ())
241
248
recovery_tx_complete_label .setText (_ ("✓ Signed" ) if context .recovery_tx .is_complete () else "" )
242
249
recovery_tx_fee_label .setText (_ ("Fee: {}" ).format (self .config .format_amount_and_units (context .recovery_tx .get_fee ())))
243
250
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 ()
245
255
assert all (tx_input .is_segwit () for tx_input in context .cancellation_tx .inputs ())
246
256
cancellation_tx_complete_label .setText (_ ("✓ Signed" ) if context .cancellation_tx .is_complete () else "" )
247
257
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():
338
348
plan_grid .addWidget (alert_tx_fee_label , grid_row , 1 , 1 , 2 )
339
349
plan_grid .addWidget (alert_tx_complete_label , grid_row , 3 )
340
350
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 ))
342
360
plan_grid .addWidget (view_alert_tx_button , grid_row , 4 )
343
361
grid_row += 1
344
362
345
363
plan_grid .addWidget (QLabel ('Recovery transaction' ), grid_row , 0 )
346
364
plan_grid .addWidget (recovery_tx_fee_label , grid_row , 1 , 1 , 2 )
347
365
plan_grid .addWidget (recovery_tx_complete_label , grid_row , 3 )
348
366
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 ))
350
372
plan_grid .addWidget (view_recovery_tx_button , grid_row , 4 )
351
373
grid_row += 1
352
374
@@ -355,7 +377,11 @@ def update_transactions():
355
377
plan_grid .addWidget (cancellation_tx_fee_label , grid_row , 1 , 1 , 2 )
356
378
plan_grid .addWidget (cancellation_tx_complete_label , grid_row , 3 )
357
379
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 ))
359
385
plan_grid .addWidget (view_cancellation_tx_button , grid_row , 4 )
360
386
grid_row += 1
361
387
@@ -440,9 +466,10 @@ def start_plan(self, context: TimelockRecoveryContext):
440
466
def task ():
441
467
if not context .alert_tx .is_complete ():
442
468
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 ()
443
471
if not context .alert_tx .is_complete ():
444
472
raise Exception (_ ("Alert transaction signing was not completed" ))
445
- context .add_input_info ()
446
473
if not context .recovery_tx .is_complete ():
447
474
wallet .sign_transaction (context .recovery_tx , password , ignore_warnings = True )
448
475
if not context .recovery_tx .is_complete ():
0 commit comments