1
0

submarine swaps: formatting

This commit is contained in:
ThomasV
2025-03-14 09:22:32 +01:00
parent fff90a1426
commit 42b072aca8

View File

@@ -10,7 +10,6 @@ import time
import attr import attr
import aiohttp import aiohttp
import electrum_ecc as ecc
from electrum_ecc import ECPrivkey from electrum_ecc import ECPrivkey
import electrum_aionostr as aionostr import electrum_aionostr as aionostr
@@ -316,7 +315,7 @@ class SwapManager(Logger):
if not swap.is_funded(): if not swap.is_funded():
self.swaps.pop(swap.payment_hash.hex()) self.swaps.pop(swap.payment_hash.hex())
def extract_preimage(self, swap, claim_tx): def extract_preimage(self, swap: SwapData, claim_tx: Transaction) -> Optional[bytes]:
for txin in claim_tx.inputs(): for txin in claim_tx.inputs():
preimage = txin.witness_elements()[1] preimage = txin.witness_elements()[1]
if sha256(preimage) == swap.payment_hash: if sha256(preimage) == swap.payment_hash:
@@ -538,18 +537,18 @@ class SwapManager(Logger):
receive_address = self.wallet.get_receiving_address() receive_address = self.wallet.get_receiving_address()
swap = SwapData( swap = SwapData(
redeem_script=redeem_script, redeem_script=redeem_script,
locktime = locktime, locktime=locktime,
privkey = our_privkey, privkey=our_privkey,
preimage = None, preimage=None,
prepay_hash = prepay_hash, prepay_hash=prepay_hash,
lockup_address = lockup_address, lockup_address=lockup_address,
onchain_amount = onchain_amount_sat, onchain_amount=onchain_amount_sat,
receive_address = receive_address, receive_address=receive_address,
lightning_amount = lightning_amount_sat, lightning_amount=lightning_amount_sat,
is_reverse = False, is_reverse=False,
is_redeemed = False, is_redeemed=False,
funding_txid = None, funding_txid=None,
spending_txid = None, spending_txid=None,
) )
swap._payment_hash = payment_hash swap._payment_hash = payment_hash
self._add_or_reindex_swap(swap) self._add_or_reindex_swap(swap)
@@ -595,19 +594,19 @@ class SwapManager(Logger):
lockup_address = script_to_p2wsh(redeem_script) lockup_address = script_to_p2wsh(redeem_script)
receive_address = self.wallet.get_receiving_address() receive_address = self.wallet.get_receiving_address()
swap = SwapData( swap = SwapData(
redeem_script = redeem_script, redeem_script=redeem_script,
locktime = locktime, locktime=locktime,
privkey = privkey, privkey=privkey,
preimage = preimage, preimage=preimage,
prepay_hash = prepay_hash, prepay_hash=prepay_hash,
lockup_address = lockup_address, lockup_address=lockup_address,
onchain_amount = onchain_amount_sat, onchain_amount=onchain_amount_sat,
receive_address = receive_address, receive_address=receive_address,
lightning_amount = lightning_amount_sat, lightning_amount=lightning_amount_sat,
is_reverse = True, is_reverse=True,
is_redeemed = False, is_redeemed=False,
funding_txid = None, funding_txid=None,
spending_txid = None, spending_txid=None,
) )
if prepay_hash: if prepay_hash:
self.prepayments[prepay_hash] = payment_hash self.prepayments[prepay_hash] = payment_hash
@@ -670,11 +669,10 @@ class SwapManager(Logger):
return await self.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx) return await self.wait_for_htlcs_and_broadcast(swap=swap, invoice=invoice, tx=tx)
async def request_normal_swap( async def request_normal_swap(
self, transport, self, transport, *,
*, lightning_amount_sat: int,
lightning_amount_sat: int, expected_onchain_amount_sat: int,
expected_onchain_amount_sat: int, channels: Optional[Sequence['Channel']] = None,
channels: Optional[Sequence['Channel']] = None,
) -> Tuple[SwapData, str]: ) -> Tuple[SwapData, str]:
await self.is_initialized.wait() # add timeout await self.is_initialized.wait() # add timeout
refund_privkey = os.urandom(32) refund_privkey = os.urandom(32)
@@ -729,11 +727,10 @@ class SwapManager(Logger):
return swap, invoice return swap, invoice
async def wait_for_htlcs_and_broadcast( async def wait_for_htlcs_and_broadcast(
self, transport, self, transport, *,
*, swap: SwapData,
swap: SwapData, invoice: str,
invoice: str, tx: Transaction,
tx: Transaction,
) -> Optional[str]: ) -> Optional[str]:
await transport.is_connected.wait() await transport.is_connected.wait()
payment_hash = swap.payment_hash payment_hash = swap.payment_hash
@@ -1255,10 +1252,10 @@ class HttpTransport(SwapServerTransport):
fees = response['pairs']['BTC/BTC']['fees'] fees = response['pairs']['BTC/BTC']['fees']
limits = response['pairs']['BTC/BTC']['limits'] limits = response['pairs']['BTC/BTC']['limits']
pairs = SwapFees( pairs = SwapFees(
percentage = fees['percentage'], percentage=fees['percentage'],
mining_fee = fees['minerFees']['baseAsset']['mining_fee'], mining_fee=fees['minerFees']['baseAsset']['mining_fee'],
min_amount = limits['minimal'], min_amount=limits['minimal'],
max_amount = limits['maximal'], max_amount=limits['maximal'],
) )
self.sm.update_pairs(pairs) self.sm.update_pairs(pairs)
@@ -1350,10 +1347,10 @@ class NostrTransport(SwapServerTransport):
def _parse_offer(self, offer): def _parse_offer(self, offer):
return SwapFees( return SwapFees(
percentage = offer['percentage_fee'], percentage=offer['percentage_fee'],
mining_fee = offer['mining_fee'], mining_fee=offer['mining_fee'],
min_amount = offer['min_amount'], min_amount=offer['min_amount'],
max_amount = offer['max_amount'], max_amount=offer['max_amount'],
) )
@ignore_exceptions @ignore_exceptions