Fix: wallet include fees in swap outputs for inputs of successive melt (#630)

* wallet: add fees to outputs for melt that requires a split

* add test that requires a swap

* verify test fails, will revert

* revert true

* hopefully fix the tests

* fix default fee selection

* cleanup and renamings

* cleanup coinselect function, estimate fees

* fix test

* add comments

* weird error
This commit is contained in:
callebtc
2024-10-03 09:50:23 +02:00
committed by GitHub
parent f8f061f810
commit 700320a8c4
7 changed files with 112 additions and 56 deletions

View File

@@ -203,10 +203,12 @@ async def pay(
quote = await wallet.melt_quote(invoice, amount)
logger.debug(f"Quote: {quote}")
total_amount = quote.amount + quote.fee_reserve
# estimate ecash fee for the coinselected proofs
ecash_fees = wallet.coinselect_fee(wallet.proofs, total_amount)
if not yes:
potential = (
f" ({wallet.unit.str(total_amount)} with potential fees)"
if quote.fee_reserve
f" ({wallet.unit.str(total_amount + ecash_fees)} with potential fees)"
if quote.fee_reserve or ecash_fees
else ""
)
message = f"Pay {wallet.unit.str(quote.amount)}{potential}?"
@@ -215,15 +217,16 @@ async def pay(
abort=True,
default=True,
)
# we need to include fees so we can use the proofs for melting the `total_amount`
send_proofs, _ = await wallet.select_to_send(
wallet.proofs, total_amount, include_fees=True, set_reserved=True
)
print("Paying Lightning invoice ...", end="", flush=True)
assert total_amount > 0, "amount is not positive"
if wallet.available_balance < total_amount:
print(" Error: Balance too low.")
return
send_proofs, fees = await wallet.select_to_send(
wallet.proofs, total_amount, include_fees=True, set_reserved=True
)
try:
melt_response = await wallet.melt(
send_proofs, invoice, quote.fee_reserve, quote.quote