|
84 | 84 | from lightspark.scripts.current_account import CURRENT_ACCOUNT_QUERY |
85 | 85 | from lightspark.scripts.decoded_payment_request import DECODED_PAYMENT_REQUEST_QUERY |
86 | 86 | from lightspark.scripts.delete_api_token import DELETE_API_TOKEN_MUTATION |
| 87 | +from lightspark.scripts.fail_htlcs import FAIL_HTLCS_MUTATION |
87 | 88 | from lightspark.scripts.fetch_uma_invitation import FETCH_UMA_INVITATION_QUERY |
88 | 89 | from lightspark.scripts.fund_node import FUND_NODE_MUTATION |
89 | 90 | from lightspark.scripts.incoming_payments_for_invoice import ( |
|
98 | 99 | from lightspark.scripts.outgoing_payments_for_invoice import ( |
99 | 100 | OUTGOING_PAYMENTS_FOR_INVOICE_QUERY, |
100 | 101 | ) |
| 102 | +from lightspark.scripts.outgoing_payments_for_payment_hash import ( |
| 103 | + OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY, |
| 104 | +) |
101 | 105 | from lightspark.scripts.pay_invoice import PAY_INVOICE_MUTATION |
102 | 106 | from lightspark.scripts.pay_uma_invoice import PAY_UMA_INVOICE_MUTATION |
103 | 107 | from lightspark.scripts.recover_node_signing_key import RECOVER_NODE_SIGNING_KEY_QUERY |
@@ -691,6 +695,34 @@ def outgoing_payments_for_invoice( |
691 | 695 | for payment in json["outgoing_payments_for_invoice"]["payments"] |
692 | 696 | ] |
693 | 697 |
|
| 698 | + def outgoing_payments_for_payment_hash( |
| 699 | + self, |
| 700 | + payment_hash: str, |
| 701 | + transaction_statuses: Optional[List[TransactionStatus]] = None, |
| 702 | + ) -> List[OutgoingPayment]: |
| 703 | + """ |
| 704 | + Fetches the outgoing payments (if any) which have been made for a given payment hash. |
| 705 | +
|
| 706 | + Args: |
| 707 | + payment_hash: The payment hash for which to fetch the outgoing payments. |
| 708 | + transaction_statuses: The statuses of the transactions to fetch. If not specified, all transactions will be fetched. |
| 709 | + """ |
| 710 | + |
| 711 | + variables: Dict[str, Any] = {"payment_hash": payment_hash} |
| 712 | + if transaction_statuses is not None: |
| 713 | + variables["transaction_statuses"] = transaction_statuses |
| 714 | + json = self._requester.execute_graphql( |
| 715 | + OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY, variables |
| 716 | + ) |
| 717 | + if "outgoing_payments_for_payment_hash" not in json: |
| 718 | + return [] |
| 719 | + if "payments" not in json["outgoing_payments_for_payment_hash"]: |
| 720 | + return [] |
| 721 | + return [ |
| 722 | + OutgoingPayment_from_json(self._requester, payment) |
| 723 | + for payment in json["outgoing_payments_for_payment_hash"]["payments"] |
| 724 | + ] |
| 725 | + |
694 | 726 | def incoming_payments_for_invoice( |
695 | 727 | self, |
696 | 728 | invoice_id: str, |
@@ -848,6 +880,21 @@ def _hash_phone_number(self, phone_number_e164_format: str) -> str: |
848 | 880 | ) |
849 | 881 | return sha256(phone_number_e164_format.encode()).hexdigest() |
850 | 882 |
|
| 883 | + def fail_htlcs(self, invoice_id: str, cancel_invoice: bool = True) -> str: |
| 884 | + """ |
| 885 | + Fails all pending HTLCs associated with an invoice. |
| 886 | +
|
| 887 | + Args: |
| 888 | + invoice_id: The ID of the invoice to fail. |
| 889 | + cancel_invoice: Whether to cancel the invoice after failing the HTLCs. |
| 890 | + """ |
| 891 | + json = self._requester.execute_graphql( |
| 892 | + FAIL_HTLCS_MUTATION, |
| 893 | + {"invoice_id": invoice_id, "cancel_invoice": cancel_invoice}, |
| 894 | + ) |
| 895 | + |
| 896 | + return json["fail_htlcs"]["invoice"]["id"] |
| 897 | + |
851 | 898 |
|
852 | 899 | # pylint: disable=anomalous-backslash-in-string |
853 | 900 | E614_REGEX = re.compile("^\+?[1-9]\d{1,14}$") |
0 commit comments