Skip to content

Commit

Permalink
suggested changes pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lollerfirst committed Jul 29, 2024
1 parent 510d1f0 commit c9775d1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cashu/lightning/lnd_grpc/lnd_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@

# maps statuses to None, False, True:
# https://api.lightning.community/?python=#paymentpaymentstatus
STATUSES = {
PAYMENT_STATUSES = {
lnrpc.Payment.PaymentStatus.UNKNOWN: None,
lnrpc.Payment.PaymentStatus.IN_FLIGHT: None,
lnrpc.Payment.PaymentStatus.INITIATED: None,
lnrpc.Payment.PaymentStatus.SUCCEEDED: True,
lnrpc.Payment.PaymentStatus.FAILED: False,
}
INVOICE_STATUSES = {
lnrpc.Invoice.InvoiceState.OPEN: None,
lnrpc.Invoice.InvoiceState.SETTLED: True,
lnrpc.Invoice.InvoiceState.CANCELED: None,
lnrpc.Invoice.InvoiceState.ACCEPTED: None,
}

class LndRPCWallet(LightningBackend):

Expand Down Expand Up @@ -285,13 +291,7 @@ async def get_invoice_status(self, checking_id: str) -> PaymentStatus:
logger.error(error_message)
return PaymentStatus(paid=None)

# Invoice.settled is deprecated
if not r.settled:
# this must also work when checking_id is not a hex recognizable by lnd
# it will return an error and no "settled" attribute on the object
return PaymentStatus(paid=None)

return PaymentStatus(paid=True)
return PaymentStatus(paid=INVOICE_STATUSES[r.state])

async def get_payment_status(self, checking_id: str) -> PaymentStatus:
"""
Expand All @@ -312,7 +312,7 @@ async def get_payment_status(self, checking_id: str) -> PaymentStatus:
async for payment in router_stub.TrackPaymentV2(request):
if payment is not None and payment.status:
return PaymentStatus(
paid=STATUSES[payment.status],
paid=PAYMENT_STATUSES[payment.status],
fee=(
Amount(unit=Unit.msat, amount=payment.fee_msat)
if payment.fee_msat
Expand Down

0 comments on commit c9775d1

Please sign in to comment.