Skip to content

Commit

Permalink
fix lndgrpc try except
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Sep 23, 2024
1 parent 33f92bc commit 6f53664
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
36 changes: 20 additions & 16 deletions cashu/lightning/lnd_grpc/lnd_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_mint_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6f53664

Please sign in to comment.