1
0

submarine_swaps: fix bugs and create method for max_amount_forward_swap

This commit is contained in:
ThomasV
2023-02-11 10:21:01 +01:00
parent 095b6dab0f
commit 215629235d
2 changed files with 14 additions and 4 deletions

View File

@@ -639,3 +639,12 @@ class SwapManager(Logger):
sig = bytes.fromhex(tx.sign_txin(0, swap.privkey))
witness = [sig, preimage, witness_script]
txin.witness = bytes.fromhex(construct_witness(witness))
def max_amount_forward_swap(self) -> Optional[int]:
""" returns None if we cannot swap """
max_swap_amt_ln = self.get_max_amount()
max_recv_amt_ln = int(self.num_sats_can_receive())
max_amt_ln = int(min(max_swap_amt_ln, max_recv_amt_ln))
max_amt_oc = self.get_send_amount(max_amt_ln, is_reverse=False) or 0
min_amt_oc = self.get_send_amount(self.min_amount, is_reverse=False) or 0
return max_amt_oc if max_amt_oc >= min_amt_oc else None