|
4 | 4 | from dataclasses import dataclass |
5 | 5 | from datetime import datetime, timedelta, timezone |
6 | 6 | from hashlib import sha256 |
7 | | -from typing import Any, Dict, Mapping, Optional, Tuple, Type, TypeVar |
| 7 | +from typing import Any, Dict, List, Mapping, Optional, Tuple, Type, TypeVar |
8 | 8 |
|
9 | 9 | import jwt |
10 | 10 | from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey |
|
46 | 46 | from lightspark.objects.PaymentRequestData import PaymentRequestData |
47 | 47 | from lightspark.objects.Permission import Permission |
48 | 48 | from lightspark.objects.RiskRating import RiskRating |
| 49 | +from lightspark.objects.TransactionStatus import TransactionStatus |
49 | 50 | from lightspark.objects.WithdrawalMode import WithdrawalMode |
50 | 51 | from lightspark.objects.WithdrawalRequest import WithdrawalRequest |
51 | 52 | from lightspark.objects.WithdrawalRequest import ( |
|
74 | 75 | from lightspark.scripts.lightning_fee_estimate_for_node import ( |
75 | 76 | LIGHTNING_FEE_ESTIMATE_FOR_NODE_QUERY, |
76 | 77 | ) |
| 78 | +from lightspark.scripts.outgoing_payments_for_invoice import ( |
| 79 | + OUTGOING_PAYMENTS_FOR_INVOICE_QUERY, |
| 80 | +) |
77 | 81 | from lightspark.scripts.pay_invoice import PAY_INVOICE_MUTATION |
78 | 82 | from lightspark.scripts.pay_uma_invoice import PAY_UMA_INVOICE_MUTATION |
79 | 83 | from lightspark.scripts.recover_node_signing_key import RECOVER_NODE_SIGNING_KEY_QUERY |
@@ -621,3 +625,31 @@ def register_payment( |
621 | 625 | return LightningTransaction_from_json( |
622 | 626 | self._requester, json["register_payment"]["payment"] |
623 | 627 | ) |
| 628 | + |
| 629 | + def outgoing_payments_for_invoice( |
| 630 | + self, |
| 631 | + encoded_invoice: str, |
| 632 | + transaction_statuses: Optional[List[TransactionStatus]] = None, |
| 633 | + ) -> List[OutgoingPayment]: |
| 634 | + """ |
| 635 | + Fetches the outgoing payments (if any) which have been made for a given invoice. |
| 636 | +
|
| 637 | + Args: |
| 638 | + encoded_invoice: The encoded invoice for which to fetch the outgoing payments. |
| 639 | + transaction_statuses: The statuses of the transactions to fetch. If not specified, all transactions will be fetched. |
| 640 | + """ |
| 641 | + |
| 642 | + variables: Dict[str, Any] = {"encoded_invoice": encoded_invoice} |
| 643 | + if transaction_statuses is not None: |
| 644 | + variables["transaction_statuses"] = transaction_statuses |
| 645 | + json = self._requester.execute_graphql( |
| 646 | + OUTGOING_PAYMENTS_FOR_INVOICE_QUERY, variables |
| 647 | + ) |
| 648 | + if "outgoing_payments_for_invoice" not in json: |
| 649 | + return [] |
| 650 | + if "payments" not in json["outgoing_payments_for_invoice"]: |
| 651 | + return [] |
| 652 | + return [ |
| 653 | + OutgoingPayment_from_json(self._requester, payment) |
| 654 | + for payment in json["outgoing_payments_for_invoice"]["payments"] |
| 655 | + ] |
0 commit comments