Skip to content

Commit 9e166c2

Browse files
authored
Merge pull request #34 from lightsparkdev/feat/failhtlcandpaymenthash
Regenerate the SDK and add new queries.
2 parents 29ce0ff + 3c07a37 commit 9e166c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+424
-109
lines changed

examples/example.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@
258258
print(f" - {outgoing_payment.id}")
259259
print("")
260260

261+
decoded_request = client.get_decoded_payment_request(
262+
encoded_payment_request=test_invoice
263+
)
264+
assert isinstance(decoded_request, lightspark.InvoiceData)
265+
outgoing_payments = client.outgoing_payments_for_payment_hash(
266+
payment_hash=decoded_request.payment_hash
267+
)
268+
print(f"Outgoing payments for payment hash {decoded_request.payment_hash}:")
269+
for outgoing_payment in outgoing_payments:
270+
print(f" - {outgoing_payment.id}")
271+
print("")
272+
261273
# Key Send sample
262274
#
263275
# payment = client.send_payment(

lightspark/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
from lightspark.objects.DeleteApiTokenOutput import DeleteApiTokenOutput
7474
from lightspark.objects.Deposit import Deposit
7575
from lightspark.objects.Entity import Entity
76+
from lightspark.objects.FailHtlcsInput import FailHtlcsInput
77+
from lightspark.objects.FailHtlcsOutput import FailHtlcsOutput
7678
from lightspark.objects.FeeEstimate import FeeEstimate
7779
from lightspark.objects.FundNodeInput import FundNodeInput
7880
from lightspark.objects.FundNodeOutput import FundNodeOutput
@@ -226,6 +228,9 @@
226228
from lightspark.objects.WithdrawalRequestToChannelOpeningTransactionsConnection import (
227229
WithdrawalRequestToChannelOpeningTransactionsConnection,
228230
)
231+
from lightspark.objects.WithdrawalRequestToWithdrawalsConnection import (
232+
WithdrawalRequestToWithdrawalsConnection,
233+
)
229234
from lightspark.remote_signing import *
230235
from lightspark.version import __version__
231236
from lightspark.webhooks import SIGNATURE_HEADER, WebhookEvent

lightspark/lightspark_client.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
from lightspark.scripts.current_account import CURRENT_ACCOUNT_QUERY
8585
from lightspark.scripts.decoded_payment_request import DECODED_PAYMENT_REQUEST_QUERY
8686
from lightspark.scripts.delete_api_token import DELETE_API_TOKEN_MUTATION
87+
from lightspark.scripts.fail_htlcs import FAIL_HTLCS_MUTATION
8788
from lightspark.scripts.fetch_uma_invitation import FETCH_UMA_INVITATION_QUERY
8889
from lightspark.scripts.fund_node import FUND_NODE_MUTATION
8990
from lightspark.scripts.incoming_payments_for_invoice import (
@@ -98,6 +99,9 @@
9899
from lightspark.scripts.outgoing_payments_for_invoice import (
99100
OUTGOING_PAYMENTS_FOR_INVOICE_QUERY,
100101
)
102+
from lightspark.scripts.outgoing_payments_for_payment_hash import (
103+
OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY,
104+
)
101105
from lightspark.scripts.pay_invoice import PAY_INVOICE_MUTATION
102106
from lightspark.scripts.pay_uma_invoice import PAY_UMA_INVOICE_MUTATION
103107
from lightspark.scripts.recover_node_signing_key import RECOVER_NODE_SIGNING_KEY_QUERY
@@ -691,6 +695,34 @@ def outgoing_payments_for_invoice(
691695
for payment in json["outgoing_payments_for_invoice"]["payments"]
692696
]
693697

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+
694726
def incoming_payments_for_invoice(
695727
self,
696728
invoice_id: str,
@@ -848,6 +880,21 @@ def _hash_phone_number(self, phone_number_e164_format: str) -> str:
848880
)
849881
return sha256(phone_number_e164_format.encode()).hexdigest()
850882

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+
851898

852899
# pylint: disable=anomalous-backslash-in-string
853900
E614_REGEX = re.compile("^\+?[1-9]\d{1,14}$")

lightspark/objects/Account.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,14 @@ def get_withdrawal_requests(
17681768
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
17691769
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
17701770
}
1771+
withdrawal_request_total_fees: total_fees {
1772+
__typename
1773+
currency_amount_original_value: original_value
1774+
currency_amount_original_unit: original_unit
1775+
currency_amount_preferred_currency_unit: preferred_currency_unit
1776+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1777+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1778+
}
17711779
withdrawal_request_bitcoin_address: bitcoin_address
17721780
withdrawal_request_withdrawal_mode: withdrawal_mode
17731781
withdrawal_request_status: status

lightspark/objects/Channel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55
from typing import Any, List, Mapping, Optional
66

7-
from lightspark.objects.ChannelStatus import ChannelStatus
87
from lightspark.requests.requester import Requester
98
from lightspark.utils.enums import parse_enum_optional
109

lightspark/objects/ChannelClosingTransaction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55
from typing import Any, List, Mapping, Optional
66

7-
from lightspark.objects.TransactionStatus import TransactionStatus
87
from lightspark.requests.requester import Requester
98
from lightspark.utils.enums import parse_enum
109

@@ -44,7 +43,7 @@ class ChannelClosingTransaction(OnChainTransaction, Transaction, Entity):
4443
"""The hash of this transaction, so it can be uniquely identified on the Lightning Network."""
4544

4645
fees: Optional[CurrencyAmount]
47-
"""The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin blockchain."""
46+
"""The fees that were paid by the node for this transaction."""
4847

4948
block_hash: Optional[str]
5049
"""The hash of the block that included this transaction. This will be null for unconfirmed transactions."""

lightspark/objects/ChannelOpeningTransaction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55
from typing import Any, List, Mapping, Optional
66

7-
from lightspark.objects.TransactionStatus import TransactionStatus
87
from lightspark.requests.requester import Requester
98
from lightspark.utils.enums import parse_enum
109

@@ -44,7 +43,7 @@ class ChannelOpeningTransaction(OnChainTransaction, Transaction, Entity):
4443
"""The hash of this transaction, so it can be uniquely identified on the Lightning Network."""
4544

4645
fees: Optional[CurrencyAmount]
47-
"""The fees that were paid by the wallet sending the transaction to commit it to the Bitcoin blockchain."""
46+
"""The fees that were paid by the node for this transaction."""
4847

4948
block_hash: Optional[str]
5049
"""The hash of the block that included this transaction. This will be null for unconfirmed transactions."""

lightspark/objects/ClaimUmaInvitationWithIncentivesInput.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from dataclasses import dataclass
44
from typing import Any, Mapping
55

6-
from lightspark.objects.RegionCode import RegionCode
76
from lightspark.utils.enums import parse_enum
87

98
from .RegionCode import RegionCode

lightspark/objects/Connection.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,33 @@ class Connection:
242242
id
243243
}
244244
}
245+
... on WithdrawalRequestToChannelClosingTransactionsConnection {
246+
__typename
247+
withdrawal_request_to_channel_closing_transactions_connection_count: count
248+
withdrawal_request_to_channel_closing_transactions_connection_page_info: page_info {
249+
__typename
250+
page_info_has_next_page: has_next_page
251+
page_info_has_previous_page: has_previous_page
252+
page_info_start_cursor: start_cursor
253+
page_info_end_cursor: end_cursor
254+
}
255+
withdrawal_request_to_channel_closing_transactions_connection_entities: entities {
256+
id
257+
}
258+
}
259+
... on WithdrawalRequestToChannelOpeningTransactionsConnection {
260+
__typename
261+
withdrawal_request_to_channel_opening_transactions_connection_count: count
262+
withdrawal_request_to_channel_opening_transactions_connection_page_info: page_info {
263+
__typename
264+
page_info_has_next_page: has_next_page
265+
page_info_has_previous_page: has_previous_page
266+
page_info_start_cursor: start_cursor
267+
page_info_end_cursor: end_cursor
268+
}
269+
withdrawal_request_to_channel_opening_transactions_connection_entities: entities {
270+
id
271+
}
272+
}
245273
}
246274
"""

lightspark/objects/CreateInvitationWithIncentivesInput.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from dataclasses import dataclass
44
from typing import Any, Mapping
55

6-
from lightspark.objects.RegionCode import RegionCode
76
from lightspark.utils.enums import parse_enum
87

98
from .RegionCode import RegionCode

0 commit comments

Comments
 (0)