mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-23 03:34:19 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user