From 6f53664b50ec6e4127c1e581e5327870d9bdca71 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:21:06 +0200 Subject: [PATCH] fix lndgrpc try except --- cashu/lightning/lnd_grpc/lnd_grpc.py | 36 +++++++++++++++------------- tests/test_mint_init.py | 4 ++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/cashu/lightning/lnd_grpc/lnd_grpc.py b/cashu/lightning/lnd_grpc/lnd_grpc.py index 9ecbc59d..6bea7b4c 100644 --- a/cashu/lightning/lnd_grpc/lnd_grpc.py +++ b/cashu/lightning/lnd_grpc/lnd_grpc.py @@ -325,23 +325,27 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus: self.endpoint, self.combined_creds ) as channel: router_stub = routerstub.RouterStub(channel) - async for payment in router_stub.TrackPaymentV2(request): - if payment is not None and payment.status: - preimage = ( - payment.payment_preimage - if payment.payment_preimage - != "0000000000000000000000000000000000000000000000000000000000000000" - else None - ) - return PaymentStatus( - result=PAYMENT_RESULT_MAP[payment.status], - fee=( - Amount(unit=Unit.msat, amount=payment.fee_msat) - if payment.fee_msat + try: + async for payment in router_stub.TrackPaymentV2(request): + if payment is not None and payment.status: + preimage = ( + payment.payment_preimage + if payment.payment_preimage != "0" * 64 else None - ), - preimage=preimage, - ) + ) + return PaymentStatus( + result=PAYMENT_RESULT_MAP[payment.status], + fee=( + Amount(unit=Unit.msat, amount=payment.fee_msat) + if payment.fee_msat + else None + ), + preimage=preimage, + ) + except AioRpcError as e: + # status = StatusCode.NOT_FOUND + if e.code() == grpc.StatusCode.NOT_FOUND: + return PaymentStatus(result=PaymentResult.UNKNOWN) return PaymentStatus(result=PaymentResult.UNKNOWN) diff --git a/tests/test_mint_init.py b/tests/test_mint_init.py index 4d7d4a51..71aa7021 100644 --- a/tests/test_mint_init.py +++ b/tests/test_mint_init.py @@ -444,8 +444,8 @@ async def test_startup_regtest_pending_quote_unknown(wallet: Wallet, ledger: Led assert melt_quote assert melt_quote.pending - # manipulate the checking_id - melt_quote.checking_id = "unknown_payment" + # manipulate the checking_id 32 bytes hexadecmial + melt_quote.checking_id = "a" * 64 await ledger.crud.update_melt_quote(quote=melt_quote, db=ledger.db) await asyncio.sleep(SLEEP_TIME)