Skip to content

Commit 2889159

Browse files
committed
Making main_window optional
So we can run test functions without a main window
1 parent 1312031 commit 2889159

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

electrum/plugins/timelock_recovery/qt.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
if TYPE_CHECKING:
5050
from electrum.gui.qt import ElectrumGui
5151
from electrum.transaction import PartialTransaction
52+
from electrum.gui.qt.main_window import ElectrumWindow
5253
from PyQt6.QtWidgets import QStatusBar
5354

5455

@@ -120,7 +121,9 @@ def requires_settings(self) -> bool:
120121
return False
121122

122123
def setup_dialog(self, status_bar: 'QStatusBar') -> bool:
123-
context = TimelockRecoveryContext(status_bar.parent())
124+
main_window: 'ElectrumWindow' = status_bar.parent()
125+
context = TimelockRecoveryContext(main_window.wallet)
126+
context.main_window = main_window
124127

125128
if constants.net.NET_NAME == 'regtest':
126129
return self.create_plan_dialog(context)

electrum/plugins/timelock_recovery/timelock_recovery.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from typing import TYPE_CHECKING, List, Optional, Tuple
2+
from typing import TYPE_CHECKING, Callable, List, Optional, Sequence, Tuple
33
from electrum.bitcoin import address_to_script
44
from electrum.plugin import BasePlugin
55
from electrum.transaction import PartialTxOutput, PartialTxInput, TxOutpoint
@@ -29,9 +29,9 @@ def nsequence(self, value: int):
2929
pass # ignore override attempts
3030

3131
class TimelockRecoveryContext:
32-
main_window: 'ElectrumWindow'
3332
wallet: 'Abstract_Wallet'
3433
wallet_name: str
34+
main_window: Optional['ElectrumWindow'] = None
3535
timelock_days: Optional[int] = None
3636
cancellation_address: Optional[str] = None
3737
outputs: Optional[List['PartialTxOutput']] = None
@@ -48,9 +48,8 @@ class TimelockRecoveryContext:
4848

4949
ANCHOR_OUTPUT_AMOUNT_SATS = 600
5050

51-
def __init__(self, main_window: 'ElectrumWindow'):
52-
self.main_window = main_window
53-
self.wallet = main_window.wallet
51+
def __init__(self, wallet: 'Abstract_Wallet'):
52+
self.wallet = wallet
5453
self.wallet_name = str(self.wallet)
5554

5655
def _get_address_by_label(self, label: str) -> str:
@@ -88,7 +87,7 @@ def make_unsigned_alert_tx(self, fee_est, *, confirmed_only=False) -> 'PartialTr
8887
for output in self.outputs
8988
]
9089
return self.wallet.make_unsigned_transaction(
91-
coins=self.main_window.get_coins(confirmed_only=confirmed_only),
90+
coins=self.wallet.get_spendable_coins(confirmed_only=confirmed_only),
9291
outputs=self._alert_tx_outputs,
9392
fee=fee_est,
9493
is_sweep=False,

0 commit comments

Comments
 (0)