Skip to content

Commit 32e77f3

Browse files
authored
Merge pull request #41 from lightsparkdev/feat/invoice_for_payment_hash
Add invoice_for_payment_hash query.
2 parents bdd0da7 + e7b38dd commit 32e77f3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lightspark/lightspark_client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
from lightspark.scripts.incoming_payments_for_invoice import (
9191
INCOMING_PAYMENTS_FOR_INVOICE_QUERY,
9292
)
93+
from lightspark.scripts.invoice_for_payment_hash import INVOICE_FOR_PAYMENT_HASH_QUERY
9394
from lightspark.scripts.lightning_fee_estimate_for_invoice import (
9495
LIGHTNING_FEE_ESTIMATE_FOR_INVOICE_QUERY,
9596
)
@@ -781,6 +782,26 @@ def incoming_payments_for_invoice(
781782
)
782783
return output.payments
783784

785+
def invoice_for_payment_hash(
786+
self,
787+
payment_hash: str,
788+
) -> Optional[Invoice]:
789+
"""
790+
Fetches the invoice (if any) which have been created with a given payment hash.
791+
"""
792+
793+
json = self._requester.execute_graphql(
794+
INVOICE_FOR_PAYMENT_HASH_QUERY,
795+
{"payment_hash": payment_hash},
796+
)
797+
if "invoice_for_payment_hash" not in json:
798+
return None
799+
if "invoice" not in json["invoice_for_payment_hash"]:
800+
return None
801+
return Invoice_from_json(
802+
self._requester, json["invoice_for_payment_hash"]["invoice"]
803+
)
804+
784805
def create_uma_invitation(
785806
self,
786807
inviter_uma: str,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from lightspark.objects.Invoice import FRAGMENT as InvoiceFragment
4+
5+
INVOICE_FOR_PAYMENT_HASH_QUERY = f"""
6+
query InvoiceForPaymentHash($payment_hash: Hash32!) {{
7+
invoice_for_payment_hash(input: {{
8+
payment_hash: $payment_hash
9+
}}) {{
10+
invoice {{
11+
...InvoiceFragment
12+
}}
13+
}}
14+
}}
15+
16+
{InvoiceFragment}
17+
"""

0 commit comments

Comments
 (0)