From 285bf497b632d416fd7d31923903fbbbd2b2f0f6 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 12 Dec 2022 23:16:31 +0100 Subject: [PATCH 1/2] fix: log status check --- lnbits/extensions/cashu/views_api.py | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lnbits/extensions/cashu/views_api.py b/lnbits/extensions/cashu/views_api.py index ad253abf0..bf01dbff7 100644 --- a/lnbits/extensions/cashu/views_api.py +++ b/lnbits/extensions/cashu/views_api.py @@ -280,22 +280,33 @@ async def melt_coins( fees_msat = fee_reserve(invoice_obj.amount_msat) else: fees_msat = 0 - assert total_provided >= amount + fees_msat / 1000, Exception( + assert total_provided >= amount + math.ceil(fees_msat / 1000), Exception( f"Provided proofs ({total_provided} sats) not enough for Lightning payment ({amount + fees_msat} sats)." ) - + logger.debug(f"Cashu: Initiating payment of {total_provided} sats") await pay_invoice( wallet_id=cashu.wallet, payment_request=invoice, - description=f"pay cashu invoice", - extra={"tag": "cashu", "cahsu_name": cashu.name}, + description=f"Pay cashu invoice", + extra={"tag": "cashu", "cashu_name": cashu.name}, ) - status: PaymentStatus = await check_transaction_status( - cashu.wallet, invoice_obj.payment_hash - ) - if status.paid == True: + try: + logger.debug( + f"Cashu: Wallet {cashu.wallet} fetting PaymentStatus of {invoice_obj.payment_hash}" + ) + status: PaymentStatus = await check_transaction_status( + cashu.wallet, invoice_obj.payment_hash + ) + logger.debug(f"Cashu: Got status.paid: {status.paid}") + if status.paid == True: + logger.debug("Cashu: Payment successful, invalidating proofs") + await ledger._invalidate_proofs(proofs) + except Exception as e: + logger.error(e) + logger.error("Cashu: Error in payment status check, invalidating proofs") await ledger._invalidate_proofs(proofs) + return GetMeltResponse(paid=status.paid, preimage=status.preimage) @@ -333,7 +344,7 @@ async def check_fees( fees_msat = fee_reserve(invoice_obj.amount_msat) else: fees_msat = 0 - return CheckFeesResponse(fee=fees_msat / 1000) + return CheckFeesResponse(fee=math.ceil(fees_msat / 1000)) @cashu_ext.post("/api/v1/{cashu_id}/split") From a7f572f455d0bdee62a7a0167afb0ef375d42120 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 13 Dec 2022 17:15:44 +0100 Subject: [PATCH 2/2] typo --- lnbits/extensions/cashu/views_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/cashu/views_api.py b/lnbits/extensions/cashu/views_api.py index bf01dbff7..38cb0bba5 100644 --- a/lnbits/extensions/cashu/views_api.py +++ b/lnbits/extensions/cashu/views_api.py @@ -293,7 +293,7 @@ async def melt_coins( try: logger.debug( - f"Cashu: Wallet {cashu.wallet} fetting PaymentStatus of {invoice_obj.payment_hash}" + f"Cashu: Wallet {cashu.wallet} checking PaymentStatus of {invoice_obj.payment_hash}" ) status: PaymentStatus = await check_transaction_status( cashu.wallet, invoice_obj.payment_hash