7
7
QModelIndex )
8
8
from PyQt6 .QtGui import QColor
9
9
10
- from electrum .gui .qml .qetxfinalizer import QETxFinalizer
11
10
from electrum .i18n import _
12
11
from electrum .bitcoin import DummyAddress
13
12
from electrum .logging import get_logger
17
16
from electrum .submarine_swaps import NostrTransport , SwapServerTransport , pubkey_to_rgb_color
18
17
from electrum .fee_policy import FeePolicy
19
18
20
- from electrum .gui import messages
21
-
22
19
from .auth import AuthMixin , auth_protect
23
20
from .qetypes import QEAmount
24
21
from .qewallet import QEWallet
25
22
from .util import QtEventListener , qt_event_listener
23
+ from .qetxfinalizer import QETxFinalizer
26
24
27
25
if TYPE_CHECKING :
28
- from electrum .submarine_swaps import SwapOffer
26
+ from electrum .submarine_swaps import SwapOffer , SwapData
29
27
30
28
31
29
class InvalidSwapParameters (Exception ): pass
@@ -158,13 +156,13 @@ class State(IntEnum):
158
156
def __init__ (self , parent = None ):
159
157
super ().__init__ (parent )
160
158
161
- self ._wallet = None # type : Optional[QEWallet]
162
- self ._finalizer = None # type : Optional[QETxFinalizer]
163
- self ._sliderPos = 0
164
- self ._rangeMin = - 1
165
- self ._rangeMax = 1
166
- self ._tx = None # updated on feeslider move and fee histogram updates, used for estimation
167
- self ._finalized_tx = None # updated by finalizer, used for actual forward swap
159
+ self ._wallet : Optional [QEWallet ] = None
160
+ self ._finalizer : Optional [QETxFinalizer ] = None
161
+ self ._sliderPos : float = 0
162
+ self ._rangeMin : float = - 1
163
+ self ._rangeMax : float = 1
164
+ self ._preview_tx : Optional [ PartialTransaction ] = None # updated on feeslider move and fee histogram updates, used for estimation
165
+ self ._finalized_tx : Optional [ PartialTransaction ] = None # updated by finalizer, used for actual forward swap
168
166
self ._valid = False
169
167
self ._state = QESwapHelper .State .Initialized
170
168
self ._userinfo = QESwapHelper .MESSAGE_SWAP_HOWTO
@@ -175,17 +173,21 @@ def __init__(self, parent=None):
175
173
self ._miningfee = QEAmount ()
176
174
self ._isReverse = False
177
175
self ._canCancel = False
178
- self ._swap = None
179
- self ._fut_htlc_wait = None
176
+ self ._swap : Optional [ 'SwapData' ] = None
177
+ self ._fut_htlc_wait : Optional [ asyncio . Task ] = None
180
178
181
179
self ._service_available = False
182
- self ._send_amount = 0
183
- self ._receive_amount = 0
180
+ self ._send_amount : int = 0
181
+ self ._receive_amount : int = 0
182
+
183
+ self ._leftVoid : float = 0
184
+ self ._rightVoid : float = 0
184
185
185
- self ._leftVoid = 0
186
- self ._rightVoid = 0
186
+ self ._available_swapservers : Optional [QESwapServerNPubListModel ] = None
187
187
188
- self ._available_swapservers = None
188
+ self .transport_task : Optional [asyncio .Task ] = None
189
+ self .swap_transport : Optional [SwapServerTransport ] = None
190
+ self .recent_offers : Sequence [SwapOffer ] = []
189
191
190
192
self .register_callbacks ()
191
193
self .destroyed .connect (lambda : self .on_destroy ())
@@ -194,11 +196,7 @@ def __init__(self, parent=None):
194
196
self ._fwd_swap_updatetx_timer .setSingleShot (True )
195
197
self ._fwd_swap_updatetx_timer .timeout .connect (self .fwd_swap_updatetx )
196
198
self .requestTxUpdate .connect (self .tx_update_pushback_timer )
197
-
198
199
self .offersUpdated .connect (self .on_offers_updated )
199
- self .transport_task : Optional [asyncio .Task ] = None
200
- self .swap_transport : Optional [SwapServerTransport ] = None
201
- self .recent_offers = []
202
200
203
201
def on_destroy (self ):
204
202
if self .transport_task is not None :
@@ -517,7 +515,7 @@ def initSwapSliderRange(self):
517
515
# this is just to estimate the maximal spendable onchain amount for HTLC
518
516
self .update_tx ('!' )
519
517
try :
520
- max_onchain_spend = self ._tx .output_value_for_address (DummyAddress .SWAP )
518
+ max_onchain_spend = self ._preview_tx .output_value_for_address (DummyAddress .SWAP )
521
519
except AttributeError : # happens if there are no utxos
522
520
max_onchain_spend = 0
523
521
reverse = int (min (lnworker .num_sats_can_send (),
@@ -558,13 +556,13 @@ def initSwapSliderRange(self):
558
556
def update_tx (self , onchain_amount : Union [int , str ], fee_policy : Optional [FeePolicy ] = None ):
559
557
"""Updates the transaction associated with a forward swap."""
560
558
if onchain_amount is None :
561
- self ._tx = None
559
+ self ._preview_tx = None
562
560
self .valid = False
563
561
return
564
562
try :
565
- self ._tx = self ._create_swap_tx (onchain_amount , fee_policy )
563
+ self ._preview_tx = self ._create_swap_tx (onchain_amount , fee_policy )
566
564
except (NotEnoughFunds , NoDynamicFeeEstimates ):
567
- self ._tx = None
565
+ self ._preview_tx = None
568
566
self .valid = False
569
567
570
568
def _create_swap_tx (self , onchain_amount : int | str , fee_policy : Optional [FeePolicy ] = None ):
@@ -614,7 +612,7 @@ def swap_slider_moved(self):
614
612
def tx_update_pushback_timer (self ):
615
613
self ._fwd_swap_updatetx_timer .start (250 )
616
614
617
- def check_valid (self , send_amount , receive_amount ):
615
+ def check_valid (self , send_amount : int | None , receive_amount : int | None ):
618
616
if send_amount and receive_amount :
619
617
self .valid = True
620
618
else :
@@ -627,12 +625,11 @@ def fwd_swap_updatetx(self):
627
625
return
628
626
self .update_tx (self ._send_amount )
629
627
# add lockup fees, but the swap amount is position
630
- pay_amount = self ._send_amount + self ._tx .get_fee () if self ._tx else 0
631
- self .miningfee = QEAmount (amount_sat = self ._tx .get_fee ()) if self ._tx else QEAmount ()
628
+ pay_amount = self ._send_amount + self ._preview_tx .get_fee () if self ._preview_tx else 0
629
+ self .miningfee = QEAmount (amount_sat = self ._preview_tx .get_fee ()) if self ._preview_tx else QEAmount ()
632
630
self .check_valid (pay_amount , self ._receive_amount )
633
631
634
632
def do_normal_swap (self , lightning_amount , onchain_amount ):
635
- assert self ._tx
636
633
assert self ._finalized_tx
637
634
if lightning_amount is None or onchain_amount is None :
638
635
return
@@ -689,7 +686,9 @@ async def swap_task():
689
686
asyncio .run_coroutine_threadsafe (swap_task (), get_asyncio_loop ())
690
687
691
688
@pyqtSlot ()
692
- def prepNormalSwap (self ):
689
+ def prepareNormalSwap (self ):
690
+ """prepare for normal swap by instantiating a finalizer for the requested amount.
691
+ self._finalized_tx will contain the finalized tx using the fees set by the user"""
693
692
def mktx (amt , fee_policy : FeePolicy ):
694
693
try :
695
694
self ._finalized_tx = self ._create_swap_tx (amt , fee_policy )
0 commit comments