Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@
print(f" - {outgoing_payment.id}")
print("")

decoded_request = client.get_decoded_payment_request(
encoded_payment_request=test_invoice
)
assert isinstance(decoded_request, lightspark.InvoiceData)
outgoing_payments = client.outgoing_payments_for_payment_hash(
payment_hash=decoded_request.payment_hash
)
print(f"Outgoing payments for payment hash {decoded_request.payment_hash}:")
for outgoing_payment in outgoing_payments:
print(f" - {outgoing_payment.id}")
print("")

# Key Send sample
#
# payment = client.send_payment(
Expand Down
5 changes: 5 additions & 0 deletions lightspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
from lightspark.objects.DeleteApiTokenOutput import DeleteApiTokenOutput
from lightspark.objects.Deposit import Deposit
from lightspark.objects.Entity import Entity
from lightspark.objects.FailHtlcsInput import FailHtlcsInput
from lightspark.objects.FailHtlcsOutput import FailHtlcsOutput
from lightspark.objects.FeeEstimate import FeeEstimate
from lightspark.objects.FundNodeInput import FundNodeInput
from lightspark.objects.FundNodeOutput import FundNodeOutput
Expand Down Expand Up @@ -226,6 +228,9 @@
from lightspark.objects.WithdrawalRequestToChannelOpeningTransactionsConnection import (
WithdrawalRequestToChannelOpeningTransactionsConnection,
)
from lightspark.objects.WithdrawalRequestToWithdrawalsConnection import (
WithdrawalRequestToWithdrawalsConnection,
)
from lightspark.remote_signing import *
from lightspark.version import __version__
from lightspark.webhooks import SIGNATURE_HEADER, WebhookEvent
47 changes: 47 additions & 0 deletions lightspark/lightspark_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from lightspark.scripts.current_account import CURRENT_ACCOUNT_QUERY
from lightspark.scripts.decoded_payment_request import DECODED_PAYMENT_REQUEST_QUERY
from lightspark.scripts.delete_api_token import DELETE_API_TOKEN_MUTATION
from lightspark.scripts.fail_htlcs import FAIL_HTLCS_MUTATION
from lightspark.scripts.fetch_uma_invitation import FETCH_UMA_INVITATION_QUERY
from lightspark.scripts.fund_node import FUND_NODE_MUTATION
from lightspark.scripts.incoming_payments_for_invoice import (
Expand All @@ -98,6 +99,9 @@
from lightspark.scripts.outgoing_payments_for_invoice import (
OUTGOING_PAYMENTS_FOR_INVOICE_QUERY,
)
from lightspark.scripts.outgoing_payments_for_payment_hash import (
OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY,
)
from lightspark.scripts.pay_invoice import PAY_INVOICE_MUTATION
from lightspark.scripts.pay_uma_invoice import PAY_UMA_INVOICE_MUTATION
from lightspark.scripts.recover_node_signing_key import RECOVER_NODE_SIGNING_KEY_QUERY
Expand Down Expand Up @@ -691,6 +695,34 @@ def outgoing_payments_for_invoice(
for payment in json["outgoing_payments_for_invoice"]["payments"]
]

def outgoing_payments_for_payment_hash(
self,
payment_hash: str,
transaction_statuses: Optional[List[TransactionStatus]] = None,
) -> List[OutgoingPayment]:
"""
Fetches the outgoing payments (if any) which have been made for a given payment hash.

Args:
payment_hash: The payment hash for which to fetch the outgoing payments.
transaction_statuses: The statuses of the transactions to fetch. If not specified, all transactions will be fetched.
"""

variables: Dict[str, Any] = {"payment_hash": payment_hash}
if transaction_statuses is not None:
variables["transaction_statuses"] = transaction_statuses
json = self._requester.execute_graphql(
OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY, variables
)
if "outgoing_payments_for_payment_hash" not in json:
return []
if "payments" not in json["outgoing_payments_for_payment_hash"]:
return []
return [
OutgoingPayment_from_json(self._requester, payment)
for payment in json["outgoing_payments_for_payment_hash"]["payments"]
]

def incoming_payments_for_invoice(
self,
invoice_id: str,
Expand Down Expand Up @@ -848,6 +880,21 @@ def _hash_phone_number(self, phone_number_e164_format: str) -> str:
)
return sha256(phone_number_e164_format.encode()).hexdigest()

def fail_htlcs(self, invoice_id: str, cancel_invoice: bool = True) -> str:
"""
Fails all pending HTLCs associated with an invoice.

Args:
invoice_id: The ID of the invoice to fail.
cancel_invoice: Whether to cancel the invoice after failing the HTLCs.
"""
json = self._requester.execute_graphql(
FAIL_HTLCS_MUTATION,
{"invoice_id": invoice_id, "cancel_invoice": cancel_invoice},
)

return json["fail_htlcs"]["invoice"]["id"]


# pylint: disable=anomalous-backslash-in-string
E614_REGEX = re.compile("^\+?[1-9]\d{1,14}$")
8 changes: 8 additions & 0 deletions lightspark/objects/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,14 @@ def get_withdrawal_requests(
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_total_fees: total_fees {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_bitcoin_address: bitcoin_address
withdrawal_request_withdrawal_mode: withdrawal_mode
withdrawal_request_status: status
Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/Channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.ChannelStatus import ChannelStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum_optional

Expand Down
3 changes: 1 addition & 2 deletions lightspark/objects/ChannelClosingTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.TransactionStatus import TransactionStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

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

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

block_hash: Optional[str]
"""The hash of the block that included this transaction. This will be null for unconfirmed transactions."""
Expand Down
3 changes: 1 addition & 2 deletions lightspark/objects/ChannelOpeningTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.TransactionStatus import TransactionStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

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

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

block_hash: Optional[str]
"""The hash of the block that included this transaction. This will be null for unconfirmed transactions."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from typing import Any, Mapping

from lightspark.objects.RegionCode import RegionCode
from lightspark.utils.enums import parse_enum

from .RegionCode import RegionCode
Expand Down
28 changes: 28 additions & 0 deletions lightspark/objects/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,33 @@ class Connection:
id
}
}
... on WithdrawalRequestToChannelClosingTransactionsConnection {
__typename
withdrawal_request_to_channel_closing_transactions_connection_count: count
withdrawal_request_to_channel_closing_transactions_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
withdrawal_request_to_channel_closing_transactions_connection_entities: entities {
id
}
}
... on WithdrawalRequestToChannelOpeningTransactionsConnection {
__typename
withdrawal_request_to_channel_opening_transactions_connection_count: count
withdrawal_request_to_channel_opening_transactions_connection_page_info: page_info {
__typename
page_info_has_next_page: has_next_page
page_info_has_previous_page: has_previous_page
page_info_start_cursor: start_cursor
page_info_end_cursor: end_cursor
}
withdrawal_request_to_channel_opening_transactions_connection_entities: entities {
id
}
}
}
"""
1 change: 0 additions & 1 deletion lightspark/objects/CreateInvitationWithIncentivesInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from typing import Any, Mapping

from lightspark.objects.RegionCode import RegionCode
from lightspark.utils.enums import parse_enum

from .RegionCode import RegionCode
Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/CreateInvoiceInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from typing import Any, Mapping, Optional

from lightspark.objects.InvoiceType import InvoiceType
from lightspark.utils.enums import parse_enum_optional

from .InvoiceType import InvoiceType
Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/CreateTestModeInvoiceInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from typing import Any, Mapping, Optional

from lightspark.objects.InvoiceType import InvoiceType
from lightspark.utils.enums import parse_enum_optional

from .InvoiceType import InvoiceType
Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/CurrencyAmount.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Any, Mapping

from lightspark.exceptions import LightsparkException
from lightspark.objects.CurrencyUnit import CurrencyUnit
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/DailyLiquidityForecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, Mapping

from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
3 changes: 1 addition & 2 deletions lightspark/objects/Deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.TransactionStatus import TransactionStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

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

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

block_hash: Optional[str]
"""The hash of the block that included this transaction. This will be null for unconfirmed transactions."""
Expand Down
8 changes: 8 additions & 0 deletions lightspark/objects/Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,14 @@ class Entity:
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_total_fees: total_fees {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
withdrawal_request_bitcoin_address: bitcoin_address
withdrawal_request_withdrawal_mode: withdrawal_mode
withdrawal_request_status: status
Expand Down
26 changes: 26 additions & 0 deletions lightspark/objects/FailHtlcsInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from dataclasses import dataclass
from typing import Any, Mapping


@dataclass
class FailHtlcsInput:
invoice_id: str
"""The id of invoice which the pending HTLCs that need to be failed are paying for."""

cancel_invoice: bool
"""Whether the invoice needs to be canceled after failing the htlcs. If yes, the invoice cannot be paid anymore."""

def to_json(self) -> Mapping[str, Any]:
return {
"fail_htlcs_input_invoice_id": self.invoice_id,
"fail_htlcs_input_cancel_invoice": self.cancel_invoice,
}


def from_json(obj: Mapping[str, Any]) -> FailHtlcsInput:
return FailHtlcsInput(
invoice_id=obj["fail_htlcs_input_invoice_id"],
cancel_invoice=obj["fail_htlcs_input_cancel_invoice"],
)
35 changes: 35 additions & 0 deletions lightspark/objects/FailHtlcsOutput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved

from dataclasses import dataclass
from typing import Any, Mapping

from lightspark.requests.requester import Requester


@dataclass
class FailHtlcsOutput:
requester: Requester

invoice_id: str

def to_json(self) -> Mapping[str, Any]:
return {
"fail_htlcs_output_invoice": {"id": self.invoice_id},
}


FRAGMENT = """
fragment FailHtlcsOutputFragment on FailHtlcsOutput {
__typename
fail_htlcs_output_invoice: invoice {
id
}
}
"""


def from_json(requester: Requester, obj: Mapping[str, Any]) -> FailHtlcsOutput:
return FailHtlcsOutput(
requester=requester,
invoice_id=obj["fail_htlcs_output_invoice"]["id"],
)
1 change: 0 additions & 1 deletion lightspark/objects/GraphNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.BitcoinNetwork import BitcoinNetwork
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/IncomingPayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, List, Mapping, Optional

from lightspark.objects.TransactionStatus import TransactionStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/IncomingPaymentAttempt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, Mapping, Optional

from lightspark.objects.IncomingPaymentAttemptStatus import IncomingPaymentAttemptStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/Invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, Mapping, Optional

from lightspark.objects.PaymentRequestStatus import PaymentRequestStatus
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
1 change: 0 additions & 1 deletion lightspark/objects/InvoiceData.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from typing import Any, Mapping, Optional

from lightspark.objects.BitcoinNetwork import BitcoinNetwork
from lightspark.requests.requester import Requester
from lightspark.utils.enums import parse_enum

Expand Down
Loading