Skip to content

Commit

Permalink
Add invoice_for_payment_hash query.
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 committed Jun 12, 2024
1 parent bdd0da7 commit e7b38dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lightspark/lightspark_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
from lightspark.scripts.incoming_payments_for_invoice import (
INCOMING_PAYMENTS_FOR_INVOICE_QUERY,
)
from lightspark.scripts.invoice_for_payment_hash import INVOICE_FOR_PAYMENT_HASH_QUERY
from lightspark.scripts.lightning_fee_estimate_for_invoice import (
LIGHTNING_FEE_ESTIMATE_FOR_INVOICE_QUERY,
)
Expand Down Expand Up @@ -781,6 +782,26 @@ def incoming_payments_for_invoice(
)
return output.payments

def invoice_for_payment_hash(
self,
payment_hash: str,
) -> Optional[Invoice]:
"""
Fetches the invoice (if any) which have been created with a given payment hash.
"""

json = self._requester.execute_graphql(
INVOICE_FOR_PAYMENT_HASH_QUERY,
{"payment_hash": payment_hash},
)
if "invoice_for_payment_hash" not in json:
return None
if "invoice" not in json["invoice_for_payment_hash"]:
return None
return Invoice_from_json(
self._requester, json["invoice_for_payment_hash"]["invoice"]
)

def create_uma_invitation(
self,
inviter_uma: str,
Expand Down
17 changes: 17 additions & 0 deletions lightspark/scripts/invoice_for_payment_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from lightspark.objects.Invoice import FRAGMENT as InvoiceFragment

INVOICE_FOR_PAYMENT_HASH_QUERY = f"""
query InvoiceForPaymentHash($payment_hash: Hash32!) {{
invoice_for_payment_hash(input: {{
payment_hash: $payment_hash
}}) {{
invoice {{
...InvoiceFragment
}}
}}
}}
{InvoiceFragment}
"""

0 comments on commit e7b38dd

Please sign in to comment.