From 93359ab1a8554be96a3ae2f69e4c147de2c119e6 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 10 May 2024 19:11:39 -0700 Subject: [PATCH 1/3] Regenerate the SDK and add new queries. Adding fail_htlcs and outgoing_payments_for_payment_hash. --- examples/example.py | 12 ++ lightspark/__init__.py | 5 + lightspark/lightspark_client.py | 47 ++++++++ lightspark/objects/Account.py | 8 ++ lightspark/objects/Channel.py | 1 - .../objects/ChannelClosingTransaction.py | 3 +- .../objects/ChannelOpeningTransaction.py | 3 +- .../ClaimUmaInvitationWithIncentivesInput.py | 1 - lightspark/objects/Connection.py | 28 +++++ .../CreateInvitationWithIncentivesInput.py | 1 - lightspark/objects/CreateInvoiceInput.py | 1 - .../objects/CreateTestModeInvoiceInput.py | 1 - lightspark/objects/CurrencyAmount.py | 1 - lightspark/objects/DailyLiquidityForecast.py | 1 - lightspark/objects/Deposit.py | 3 +- lightspark/objects/Entity.py | 8 ++ lightspark/objects/GraphNode.py | 1 - lightspark/objects/IncomingPayment.py | 1 - lightspark/objects/IncomingPaymentAttempt.py | 1 - lightspark/objects/Invoice.py | 1 - lightspark/objects/InvoiceData.py | 1 - lightspark/objects/LightningTransaction.py | 7 +- lightspark/objects/LightsparkNode.py | 14 ++- lightspark/objects/LightsparkNodeOwner.py | 2 +- ...NodeToDailyLiquidityForecastsConnection.py | 1 - lightspark/objects/LightsparkNodeWithOSK.py | 14 ++- .../LightsparkNodeWithRemoteSigning.py | 14 ++- lightspark/objects/Node.py | 3 +- lightspark/objects/NodeAddress.py | 1 - lightspark/objects/OnChainTransaction.py | 3 +- lightspark/objects/OutgoingPayment.py | 2 - lightspark/objects/OutgoingPaymentAttempt.py | 2 - lightspark/objects/PaymentRequest.py | 1 - lightspark/objects/PaymentRequestData.py | 1 - lightspark/objects/RegisterPaymentInput.py | 2 - .../objects/RemoteSigningSubEventType.py | 1 + lightspark/objects/RequestWithdrawalInput.py | 8 +- lightspark/objects/RoutingTransaction.py | 4 - lightspark/objects/ScreenNodeInput.py | 1 - lightspark/objects/ScreenNodeOutput.py | 1 - lightspark/objects/SignablePayload.py | 1 - lightspark/objects/Transaction.py | 7 +- lightspark/objects/UmaInvitation.py | 4 - lightspark/objects/Wallet.py | 9 +- lightspark/objects/Withdrawal.py | 3 +- .../objects/WithdrawalFeeEstimateInput.py | 1 - lightspark/objects/WithdrawalRequest.py | 104 +++++++++++++++--- lightspark/objects/WithdrawalRequestStatus.py | 1 + ...tToChannelClosingTransactionsConnection.py | 22 ++-- ...tToChannelOpeningTransactionsConnection.py | 22 ++-- 50 files changed, 276 insertions(+), 109 deletions(-) diff --git a/examples/example.py b/examples/example.py index e1640a6..14bb98e 100644 --- a/examples/example.py +++ b/examples/example.py @@ -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( diff --git a/lightspark/__init__.py b/lightspark/__init__.py index 8052f62..995a89a 100644 --- a/lightspark/__init__.py +++ b/lightspark/__init__.py @@ -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 @@ -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 diff --git a/lightspark/lightspark_client.py b/lightspark/lightspark_client.py index 250c46c..057dc66 100644 --- a/lightspark/lightspark_client.py +++ b/lightspark/lightspark_client.py @@ -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 ( @@ -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 @@ -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, @@ -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}$") diff --git a/lightspark/objects/Account.py b/lightspark/objects/Account.py index 32cb594..04562f0 100644 --- a/lightspark/objects/Account.py +++ b/lightspark/objects/Account.py @@ -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 diff --git a/lightspark/objects/Channel.py b/lightspark/objects/Channel.py index ecf0adc..2cc4a96 100644 --- a/lightspark/objects/Channel.py +++ b/lightspark/objects/Channel.py @@ -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 diff --git a/lightspark/objects/ChannelClosingTransaction.py b/lightspark/objects/ChannelClosingTransaction.py index cc141a9..187dcda 100644 --- a/lightspark/objects/ChannelClosingTransaction.py +++ b/lightspark/objects/ChannelClosingTransaction.py @@ -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 @@ -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.""" diff --git a/lightspark/objects/ChannelOpeningTransaction.py b/lightspark/objects/ChannelOpeningTransaction.py index 8ce5cb5..e108801 100644 --- a/lightspark/objects/ChannelOpeningTransaction.py +++ b/lightspark/objects/ChannelOpeningTransaction.py @@ -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 @@ -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.""" diff --git a/lightspark/objects/ClaimUmaInvitationWithIncentivesInput.py b/lightspark/objects/ClaimUmaInvitationWithIncentivesInput.py index a512cbb..8503677 100644 --- a/lightspark/objects/ClaimUmaInvitationWithIncentivesInput.py +++ b/lightspark/objects/ClaimUmaInvitationWithIncentivesInput.py @@ -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 diff --git a/lightspark/objects/Connection.py b/lightspark/objects/Connection.py index 0e58c3e..0dc46fd 100644 --- a/lightspark/objects/Connection.py +++ b/lightspark/objects/Connection.py @@ -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 + } + } } """ diff --git a/lightspark/objects/CreateInvitationWithIncentivesInput.py b/lightspark/objects/CreateInvitationWithIncentivesInput.py index 578b495..a596174 100644 --- a/lightspark/objects/CreateInvitationWithIncentivesInput.py +++ b/lightspark/objects/CreateInvitationWithIncentivesInput.py @@ -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 diff --git a/lightspark/objects/CreateInvoiceInput.py b/lightspark/objects/CreateInvoiceInput.py index d0f319b..5ce966a 100644 --- a/lightspark/objects/CreateInvoiceInput.py +++ b/lightspark/objects/CreateInvoiceInput.py @@ -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 diff --git a/lightspark/objects/CreateTestModeInvoiceInput.py b/lightspark/objects/CreateTestModeInvoiceInput.py index 546669d..1462e86 100644 --- a/lightspark/objects/CreateTestModeInvoiceInput.py +++ b/lightspark/objects/CreateTestModeInvoiceInput.py @@ -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 diff --git a/lightspark/objects/CurrencyAmount.py b/lightspark/objects/CurrencyAmount.py index e9bb092..92bc2f6 100644 --- a/lightspark/objects/CurrencyAmount.py +++ b/lightspark/objects/CurrencyAmount.py @@ -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 diff --git a/lightspark/objects/DailyLiquidityForecast.py b/lightspark/objects/DailyLiquidityForecast.py index ebb62c0..ab76177 100644 --- a/lightspark/objects/DailyLiquidityForecast.py +++ b/lightspark/objects/DailyLiquidityForecast.py @@ -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 diff --git a/lightspark/objects/Deposit.py b/lightspark/objects/Deposit.py index 1df9426..6768ff9 100644 --- a/lightspark/objects/Deposit.py +++ b/lightspark/objects/Deposit.py @@ -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 @@ -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.""" diff --git a/lightspark/objects/Entity.py b/lightspark/objects/Entity.py index b01843e..fa0fbb2 100644 --- a/lightspark/objects/Entity.py +++ b/lightspark/objects/Entity.py @@ -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 diff --git a/lightspark/objects/GraphNode.py b/lightspark/objects/GraphNode.py index 6e823ef..587a6da 100644 --- a/lightspark/objects/GraphNode.py +++ b/lightspark/objects/GraphNode.py @@ -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 diff --git a/lightspark/objects/IncomingPayment.py b/lightspark/objects/IncomingPayment.py index 50e50c2..ef35369 100644 --- a/lightspark/objects/IncomingPayment.py +++ b/lightspark/objects/IncomingPayment.py @@ -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 diff --git a/lightspark/objects/IncomingPaymentAttempt.py b/lightspark/objects/IncomingPaymentAttempt.py index 650aa0b..1d6d819 100644 --- a/lightspark/objects/IncomingPaymentAttempt.py +++ b/lightspark/objects/IncomingPaymentAttempt.py @@ -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 diff --git a/lightspark/objects/Invoice.py b/lightspark/objects/Invoice.py index 87cb225..cc876d7 100644 --- a/lightspark/objects/Invoice.py +++ b/lightspark/objects/Invoice.py @@ -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 diff --git a/lightspark/objects/InvoiceData.py b/lightspark/objects/InvoiceData.py index ac89e25..b0665b1 100644 --- a/lightspark/objects/InvoiceData.py +++ b/lightspark/objects/InvoiceData.py @@ -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 diff --git a/lightspark/objects/LightningTransaction.py b/lightspark/objects/LightningTransaction.py index 33688d3..858611d 100644 --- a/lightspark/objects/LightningTransaction.py +++ b/lightspark/objects/LightningTransaction.py @@ -5,20 +5,17 @@ from typing import Any, Mapping, Optional from lightspark.exceptions import LightsparkException -from lightspark.objects.PaymentFailureReason import PaymentFailureReason -from lightspark.objects.RoutingTransactionFailureReason import ( - RoutingTransactionFailureReason, -) -from lightspark.objects.TransactionStatus import TransactionStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional from .CurrencyAmount import CurrencyAmount from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .PaymentFailureReason import PaymentFailureReason from .PaymentRequestData import from_json as PaymentRequestData_from_json from .PostTransactionData import from_json as PostTransactionData_from_json from .RichText import from_json as RichText_from_json +from .RoutingTransactionFailureReason import RoutingTransactionFailureReason from .Transaction import Transaction from .TransactionStatus import TransactionStatus diff --git a/lightspark/objects/LightsparkNode.py b/lightspark/objects/LightsparkNode.py index b140baa..5cc2d27 100644 --- a/lightspark/objects/LightsparkNode.py +++ b/lightspark/objects/LightsparkNode.py @@ -5,8 +5,6 @@ from typing import Any, List, Mapping, Optional from lightspark.exceptions import LightsparkException -from lightspark.objects.BitcoinNetwork import BitcoinNetwork -from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional @@ -128,15 +126,17 @@ def get_addresses( def get_channels( self, first: Optional[int] = None, - statuses: Optional[List[ChannelStatus]] = None, after: Optional[str] = None, + before_date: Optional[datetime] = None, + after_date: Optional[datetime] = None, + statuses: Optional[List[ChannelStatus]] = None, ) -> LightsparkNodeToChannelsConnection: json = self.requester.execute_graphql( """ -query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $statuses: [ChannelStatus!], $after: String) { +query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $after: String, $before_date: DateTime, $after_date: DateTime, $statuses: [ChannelStatus!]) { entity(id: $entity_id) { ... on LightsparkNode { - channels(, first: $first, statuses: $statuses, after: $after) { + channels(, first: $first, after: $after, before_date: $before_date, after_date: $after_date, statuses: $statuses) { __typename lightspark_node_to_channels_connection_count: count lightspark_node_to_channels_connection_page_info: page_info { @@ -248,8 +248,10 @@ def get_channels( { "entity_id": self.id, "first": first, - "statuses": statuses, "after": after, + "before_date": before_date, + "after_date": after_date, + "statuses": statuses, }, ) connection = json["entity"]["channels"] diff --git a/lightspark/objects/LightsparkNodeOwner.py b/lightspark/objects/LightsparkNodeOwner.py index 8930933..c0d9134 100644 --- a/lightspark/objects/LightsparkNodeOwner.py +++ b/lightspark/objects/LightsparkNodeOwner.py @@ -5,12 +5,12 @@ from typing import Any, Mapping from lightspark.exceptions import LightsparkException -from lightspark.objects.WalletStatus import WalletStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum from .Balances import from_json as Balances_from_json from .Entity import Entity +from .WalletStatus import WalletStatus @dataclass diff --git a/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py b/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py index b64f698..7ace8a0 100644 --- a/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py +++ b/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py @@ -4,7 +4,6 @@ from datetime import datetime from typing import Any, List, Mapping -from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/LightsparkNodeWithOSK.py b/lightspark/objects/LightsparkNodeWithOSK.py index c13becd..cd758dc 100644 --- a/lightspark/objects/LightsparkNodeWithOSK.py +++ b/lightspark/objects/LightsparkNodeWithOSK.py @@ -4,8 +4,6 @@ from datetime import datetime from typing import Any, List, Mapping, Optional -from lightspark.objects.BitcoinNetwork import BitcoinNetwork -from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional @@ -132,15 +130,17 @@ def get_addresses( def get_channels( self, first: Optional[int] = None, - statuses: Optional[List[ChannelStatus]] = None, after: Optional[str] = None, + before_date: Optional[datetime] = None, + after_date: Optional[datetime] = None, + statuses: Optional[List[ChannelStatus]] = None, ) -> LightsparkNodeToChannelsConnection: json = self.requester.execute_graphql( """ -query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $statuses: [ChannelStatus!], $after: String) { +query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $after: String, $before_date: DateTime, $after_date: DateTime, $statuses: [ChannelStatus!]) { entity(id: $entity_id) { ... on LightsparkNodeWithOSK { - channels(, first: $first, statuses: $statuses, after: $after) { + channels(, first: $first, after: $after, before_date: $before_date, after_date: $after_date, statuses: $statuses) { __typename lightspark_node_to_channels_connection_count: count lightspark_node_to_channels_connection_page_info: page_info { @@ -252,8 +252,10 @@ def get_channels( { "entity_id": self.id, "first": first, - "statuses": statuses, "after": after, + "before_date": before_date, + "after_date": after_date, + "statuses": statuses, }, ) connection = json["entity"]["channels"] diff --git a/lightspark/objects/LightsparkNodeWithRemoteSigning.py b/lightspark/objects/LightsparkNodeWithRemoteSigning.py index cb3c700..47a451c 100644 --- a/lightspark/objects/LightsparkNodeWithRemoteSigning.py +++ b/lightspark/objects/LightsparkNodeWithRemoteSigning.py @@ -4,8 +4,6 @@ from datetime import datetime from typing import Any, List, Mapping, Optional -from lightspark.objects.BitcoinNetwork import BitcoinNetwork -from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional @@ -127,15 +125,17 @@ def get_addresses( def get_channels( self, first: Optional[int] = None, - statuses: Optional[List[ChannelStatus]] = None, after: Optional[str] = None, + before_date: Optional[datetime] = None, + after_date: Optional[datetime] = None, + statuses: Optional[List[ChannelStatus]] = None, ) -> LightsparkNodeToChannelsConnection: json = self.requester.execute_graphql( """ -query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $statuses: [ChannelStatus!], $after: String) { +query FetchLightsparkNodeToChannelsConnection($entity_id: ID!, $first: Int, $after: String, $before_date: DateTime, $after_date: DateTime, $statuses: [ChannelStatus!]) { entity(id: $entity_id) { ... on LightsparkNodeWithRemoteSigning { - channels(, first: $first, statuses: $statuses, after: $after) { + channels(, first: $first, after: $after, before_date: $before_date, after_date: $after_date, statuses: $statuses) { __typename lightspark_node_to_channels_connection_count: count lightspark_node_to_channels_connection_page_info: page_info { @@ -247,8 +247,10 @@ def get_channels( { "entity_id": self.id, "first": first, - "statuses": statuses, "after": after, + "before_date": before_date, + "after_date": after_date, + "statuses": statuses, }, ) connection = json["entity"]["channels"] diff --git a/lightspark/objects/Node.py b/lightspark/objects/Node.py index 75d29b5..881ad81 100644 --- a/lightspark/objects/Node.py +++ b/lightspark/objects/Node.py @@ -5,8 +5,6 @@ from typing import Any, List, Mapping, Optional from lightspark.exceptions import LightsparkException -from lightspark.objects.BitcoinNetwork import BitcoinNetwork -from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional @@ -15,6 +13,7 @@ from .BlockchainBalance import from_json as BlockchainBalance_from_json from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .LightsparkNodeStatus import LightsparkNodeStatus from .NodeAddressType import NodeAddressType from .NodeToAddressesConnection import NodeToAddressesConnection from .NodeToAddressesConnection import from_json as NodeToAddressesConnection_from_json diff --git a/lightspark/objects/NodeAddress.py b/lightspark/objects/NodeAddress.py index cc37f59..62c5bb5 100644 --- a/lightspark/objects/NodeAddress.py +++ b/lightspark/objects/NodeAddress.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from typing import Any, Mapping -from lightspark.objects.NodeAddressType import NodeAddressType from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/OnChainTransaction.py b/lightspark/objects/OnChainTransaction.py index b302f1a..18381ec 100644 --- a/lightspark/objects/OnChainTransaction.py +++ b/lightspark/objects/OnChainTransaction.py @@ -5,7 +5,6 @@ from typing import Any, List, Mapping, Optional from lightspark.exceptions import LightsparkException -from lightspark.objects.TransactionStatus import TransactionStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum @@ -44,7 +43,7 @@ class 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.""" diff --git a/lightspark/objects/OutgoingPayment.py b/lightspark/objects/OutgoingPayment.py index c02efae..17cef0b 100644 --- a/lightspark/objects/OutgoingPayment.py +++ b/lightspark/objects/OutgoingPayment.py @@ -4,8 +4,6 @@ from datetime import datetime from typing import Any, List, Mapping, Optional -from lightspark.objects.PaymentFailureReason import PaymentFailureReason -from lightspark.objects.TransactionStatus import TransactionStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional diff --git a/lightspark/objects/OutgoingPaymentAttempt.py b/lightspark/objects/OutgoingPaymentAttempt.py index 1a2261f..1d1a2a7 100644 --- a/lightspark/objects/OutgoingPaymentAttempt.py +++ b/lightspark/objects/OutgoingPaymentAttempt.py @@ -4,8 +4,6 @@ from datetime import datetime from typing import Any, Mapping, Optional -from lightspark.objects.HtlcAttemptFailureCode import HtlcAttemptFailureCode -from lightspark.objects.OutgoingPaymentAttemptStatus import OutgoingPaymentAttemptStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional diff --git a/lightspark/objects/PaymentRequest.py b/lightspark/objects/PaymentRequest.py index dc0a9f6..4770b16 100644 --- a/lightspark/objects/PaymentRequest.py +++ b/lightspark/objects/PaymentRequest.py @@ -5,7 +5,6 @@ from typing import Any, Mapping from lightspark.exceptions import LightsparkException -from lightspark.objects.PaymentRequestStatus import PaymentRequestStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/PaymentRequestData.py b/lightspark/objects/PaymentRequestData.py index f407348..fa14211 100644 --- a/lightspark/objects/PaymentRequestData.py +++ b/lightspark/objects/PaymentRequestData.py @@ -5,7 +5,6 @@ from typing import Any, Mapping from lightspark.exceptions import LightsparkException -from lightspark.objects.BitcoinNetwork import BitcoinNetwork from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/RegisterPaymentInput.py b/lightspark/objects/RegisterPaymentInput.py index bb51676..62539f4 100644 --- a/lightspark/objects/RegisterPaymentInput.py +++ b/lightspark/objects/RegisterPaymentInput.py @@ -3,8 +3,6 @@ from dataclasses import dataclass from typing import Any, Mapping -from lightspark.objects.ComplianceProvider import ComplianceProvider -from lightspark.objects.PaymentDirection import PaymentDirection from lightspark.utils.enums import parse_enum from .ComplianceProvider import ComplianceProvider diff --git a/lightspark/objects/RemoteSigningSubEventType.py b/lightspark/objects/RemoteSigningSubEventType.py index 182bd31..e6e553a 100644 --- a/lightspark/objects/RemoteSigningSubEventType.py +++ b/lightspark/objects/RemoteSigningSubEventType.py @@ -18,3 +18,4 @@ class RemoteSigningSubEventType(Enum): REVEAL_COUNTERPARTY_PER_COMMITMENT_SECRET = ( "REVEAL_COUNTERPARTY_PER_COMMITMENT_SECRET" ) + VLS_MESSAGE = "VLS_MESSAGE" diff --git a/lightspark/objects/RequestWithdrawalInput.py b/lightspark/objects/RequestWithdrawalInput.py index 21583cf..c3423c8 100644 --- a/lightspark/objects/RequestWithdrawalInput.py +++ b/lightspark/objects/RequestWithdrawalInput.py @@ -1,9 +1,8 @@ # Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved from dataclasses import dataclass -from typing import Any, Mapping +from typing import Any, Mapping, Optional -from lightspark.objects.WithdrawalMode import WithdrawalMode from lightspark.utils.enums import parse_enum from .WithdrawalMode import WithdrawalMode @@ -23,12 +22,16 @@ class RequestWithdrawalInput: withdrawal_mode: WithdrawalMode """The strategy that should be used to withdraw the funds from this node.""" + idempotency_key: Optional[str] + """The idempotency key of the request. The same result will be returned for the same idempotency key.""" + def to_json(self) -> Mapping[str, Any]: return { "request_withdrawal_input_node_id": self.node_id, "request_withdrawal_input_bitcoin_address": self.bitcoin_address, "request_withdrawal_input_amount_sats": self.amount_sats, "request_withdrawal_input_withdrawal_mode": self.withdrawal_mode.value, + "request_withdrawal_input_idempotency_key": self.idempotency_key, } @@ -40,4 +43,5 @@ def from_json(obj: Mapping[str, Any]) -> RequestWithdrawalInput: withdrawal_mode=parse_enum( WithdrawalMode, obj["request_withdrawal_input_withdrawal_mode"] ), + idempotency_key=obj["request_withdrawal_input_idempotency_key"], ) diff --git a/lightspark/objects/RoutingTransaction.py b/lightspark/objects/RoutingTransaction.py index f6dd390..4cd25f3 100644 --- a/lightspark/objects/RoutingTransaction.py +++ b/lightspark/objects/RoutingTransaction.py @@ -4,10 +4,6 @@ from datetime import datetime from typing import Any, Mapping, Optional -from lightspark.objects.RoutingTransactionFailureReason import ( - RoutingTransactionFailureReason, -) -from lightspark.objects.TransactionStatus import TransactionStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional diff --git a/lightspark/objects/ScreenNodeInput.py b/lightspark/objects/ScreenNodeInput.py index f78621a..d38e234 100644 --- a/lightspark/objects/ScreenNodeInput.py +++ b/lightspark/objects/ScreenNodeInput.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from typing import Any, Mapping -from lightspark.objects.ComplianceProvider import ComplianceProvider from lightspark.utils.enums import parse_enum from .ComplianceProvider import ComplianceProvider diff --git a/lightspark/objects/ScreenNodeOutput.py b/lightspark/objects/ScreenNodeOutput.py index d167e41..fb0863a 100644 --- a/lightspark/objects/ScreenNodeOutput.py +++ b/lightspark/objects/ScreenNodeOutput.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from typing import Any, Mapping -from lightspark.objects.RiskRating import RiskRating from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/SignablePayload.py b/lightspark/objects/SignablePayload.py index b7acbee..9122895 100644 --- a/lightspark/objects/SignablePayload.py +++ b/lightspark/objects/SignablePayload.py @@ -4,7 +4,6 @@ from datetime import datetime from typing import Any, Mapping, Optional -from lightspark.objects.SignablePayloadStatus import SignablePayloadStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum diff --git a/lightspark/objects/Transaction.py b/lightspark/objects/Transaction.py index f2440e3..4b98dd0 100644 --- a/lightspark/objects/Transaction.py +++ b/lightspark/objects/Transaction.py @@ -5,20 +5,17 @@ from typing import Any, Mapping, Optional from lightspark.exceptions import LightsparkException -from lightspark.objects.PaymentFailureReason import PaymentFailureReason -from lightspark.objects.RoutingTransactionFailureReason import ( - RoutingTransactionFailureReason, -) -from lightspark.objects.TransactionStatus import TransactionStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional from .CurrencyAmount import CurrencyAmount from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .PaymentFailureReason import PaymentFailureReason from .PaymentRequestData import from_json as PaymentRequestData_from_json from .PostTransactionData import from_json as PostTransactionData_from_json from .RichText import from_json as RichText_from_json +from .RoutingTransactionFailureReason import RoutingTransactionFailureReason from .TransactionStatus import TransactionStatus diff --git a/lightspark/objects/UmaInvitation.py b/lightspark/objects/UmaInvitation.py index 1476971..76ea194 100644 --- a/lightspark/objects/UmaInvitation.py +++ b/lightspark/objects/UmaInvitation.py @@ -4,10 +4,6 @@ from datetime import datetime from typing import Any, Mapping, Optional -from lightspark.objects.IncentivesIneligibilityReason import ( - IncentivesIneligibilityReason, -) -from lightspark.objects.IncentivesStatus import IncentivesStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum, parse_enum_optional diff --git a/lightspark/objects/Wallet.py b/lightspark/objects/Wallet.py index 5056af7..9050f49 100644 --- a/lightspark/objects/Wallet.py +++ b/lightspark/objects/Wallet.py @@ -4,7 +4,6 @@ from datetime import datetime from typing import Any, List, Mapping, Optional -from lightspark.objects.WalletStatus import WalletStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum @@ -1092,6 +1091,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 diff --git a/lightspark/objects/Withdrawal.py b/lightspark/objects/Withdrawal.py index f783a26..236b5d7 100644 --- a/lightspark/objects/Withdrawal.py +++ b/lightspark/objects/Withdrawal.py @@ -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 @@ -44,7 +43,7 @@ class Withdrawal(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.""" diff --git a/lightspark/objects/WithdrawalFeeEstimateInput.py b/lightspark/objects/WithdrawalFeeEstimateInput.py index 07e0c82..24ee7b8 100644 --- a/lightspark/objects/WithdrawalFeeEstimateInput.py +++ b/lightspark/objects/WithdrawalFeeEstimateInput.py @@ -3,7 +3,6 @@ from dataclasses import dataclass from typing import Any, Mapping -from lightspark.objects.WithdrawalMode import WithdrawalMode from lightspark.utils.enums import parse_enum from .WithdrawalMode import WithdrawalMode diff --git a/lightspark/objects/WithdrawalRequest.py b/lightspark/objects/WithdrawalRequest.py index 3b64b52..e6d2dd7 100644 --- a/lightspark/objects/WithdrawalRequest.py +++ b/lightspark/objects/WithdrawalRequest.py @@ -4,8 +4,6 @@ from datetime import datetime from typing import Any, Mapping, Optional -from lightspark.objects.WithdrawalMode import WithdrawalMode -from lightspark.objects.WithdrawalRequestStatus import WithdrawalRequestStatus from lightspark.requests.requester import Requester from lightspark.utils.enums import parse_enum @@ -26,6 +24,12 @@ from .WithdrawalRequestToChannelOpeningTransactionsConnection import ( from_json as WithdrawalRequestToChannelOpeningTransactionsConnection_from_json, ) +from .WithdrawalRequestToWithdrawalsConnection import ( + WithdrawalRequestToWithdrawalsConnection, +) +from .WithdrawalRequestToWithdrawalsConnection import ( + from_json as WithdrawalRequestToWithdrawalsConnection_from_json, +) @dataclass @@ -53,7 +57,10 @@ class WithdrawalRequest(Entity): """If the requested amount is `-1` (i.e. everything), this field may contain an estimate of the amount for the withdrawal.""" amount_withdrawn: Optional[CurrencyAmount] - """The actual amount that is withdrawn. It will be set once the request is completed.""" + """The actual amount that is withdrawn to the bitcoin address. It will be set once the request is completed.""" + + total_fees: Optional[CurrencyAmount] + """The total fees the node paid for the withdrawal. It will be set once the request is completed.""" bitcoin_address: str """The bitcoin address where the funds should be sent.""" @@ -72,15 +79,16 @@ class WithdrawalRequest(Entity): typename: str def get_channel_closing_transactions( - self, first: Optional[int] = None + self, first: Optional[int] = None, after: Optional[str] = None ) -> WithdrawalRequestToChannelClosingTransactionsConnection: json = self.requester.execute_graphql( """ -query FetchWithdrawalRequestToChannelClosingTransactionsConnection($entity_id: ID!, $first: Int) { +query FetchWithdrawalRequestToChannelClosingTransactionsConnection($entity_id: ID!, $first: Int, $after: String) { entity(id: $entity_id) { ... on WithdrawalRequest { - channel_closing_transactions(, first: $first) { + channel_closing_transactions(, first: $first, after: $after) { __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 @@ -88,7 +96,6 @@ def get_channel_closing_transactions( page_info_start_cursor: start_cursor page_info_end_cursor: end_cursor } - withdrawal_request_to_channel_closing_transactions_connection_count: count withdrawal_request_to_channel_closing_transactions_connection_entities: entities { __typename channel_closing_transaction_id: id @@ -126,7 +133,7 @@ def get_channel_closing_transactions( } } """, - {"entity_id": self.id, "first": first}, + {"entity_id": self.id, "first": first, "after": after}, ) connection = json["entity"]["channel_closing_transactions"] return WithdrawalRequestToChannelClosingTransactionsConnection_from_json( @@ -134,15 +141,16 @@ def get_channel_closing_transactions( ) def get_channel_opening_transactions( - self, first: Optional[int] = None + self, first: Optional[int] = None, after: Optional[str] = None ) -> WithdrawalRequestToChannelOpeningTransactionsConnection: json = self.requester.execute_graphql( """ -query FetchWithdrawalRequestToChannelOpeningTransactionsConnection($entity_id: ID!, $first: Int) { +query FetchWithdrawalRequestToChannelOpeningTransactionsConnection($entity_id: ID!, $first: Int, $after: String) { entity(id: $entity_id) { ... on WithdrawalRequest { - channel_opening_transactions(, first: $first) { + channel_opening_transactions(, first: $first, after: $after) { __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 @@ -150,7 +158,6 @@ def get_channel_opening_transactions( page_info_start_cursor: start_cursor page_info_end_cursor: end_cursor } - withdrawal_request_to_channel_opening_transactions_connection_count: count withdrawal_request_to_channel_opening_transactions_connection_entities: entities { __typename channel_opening_transaction_id: id @@ -188,13 +195,68 @@ def get_channel_opening_transactions( } } """, - {"entity_id": self.id, "first": first}, + {"entity_id": self.id, "first": first, "after": after}, ) connection = json["entity"]["channel_opening_transactions"] return WithdrawalRequestToChannelOpeningTransactionsConnection_from_json( self.requester, connection ) + def get_withdrawals( + self, first: Optional[int] = None + ) -> WithdrawalRequestToWithdrawalsConnection: + json = self.requester.execute_graphql( + """ +query FetchWithdrawalRequestToWithdrawalsConnection($entity_id: ID!, $first: Int) { + entity(id: $entity_id) { + ... on WithdrawalRequest { + withdrawals(, first: $first) { + __typename + withdrawal_request_to_withdrawals_connection_count: count + withdrawal_request_to_withdrawals_connection_entities: entities { + __typename + withdrawal_id: id + withdrawal_created_at: created_at + withdrawal_updated_at: updated_at + withdrawal_status: status + withdrawal_resolved_at: resolved_at + withdrawal_amount: amount { + __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_transaction_hash: transaction_hash + withdrawal_fees: 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_block_hash: block_hash + withdrawal_block_height: block_height + withdrawal_destination_addresses: destination_addresses + withdrawal_num_confirmations: num_confirmations + withdrawal_origin: origin { + id + } + } + } + } + } +} + """, + {"entity_id": self.id, "first": first}, + ) + connection = json["entity"]["withdrawals"] + return WithdrawalRequestToWithdrawalsConnection_from_json( + self.requester, connection + ) + def to_json(self) -> Mapping[str, Any]: return { "__typename": "WithdrawalRequest", @@ -209,6 +271,9 @@ def to_json(self) -> Mapping[str, Any]: "withdrawal_request_amount_withdrawn": self.amount_withdrawn.to_json() if self.amount_withdrawn else None, + "withdrawal_request_total_fees": self.total_fees.to_json() + if self.total_fees + else None, "withdrawal_request_bitcoin_address": self.bitcoin_address, "withdrawal_request_withdrawal_mode": self.withdrawal_mode.value, "withdrawal_request_status": self.status.value, @@ -259,6 +324,14 @@ def to_json(self) -> Mapping[str, Any]: 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 @@ -291,6 +364,11 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> WithdrawalRequest ) if obj["withdrawal_request_amount_withdrawn"] else None, + total_fees=CurrencyAmount_from_json( + requester, obj["withdrawal_request_total_fees"] + ) + if obj["withdrawal_request_total_fees"] + else None, bitcoin_address=obj["withdrawal_request_bitcoin_address"], withdrawal_mode=parse_enum( WithdrawalMode, obj["withdrawal_request_withdrawal_mode"] diff --git a/lightspark/objects/WithdrawalRequestStatus.py b/lightspark/objects/WithdrawalRequestStatus.py index cb063ad..874212e 100644 --- a/lightspark/objects/WithdrawalRequestStatus.py +++ b/lightspark/objects/WithdrawalRequestStatus.py @@ -8,6 +8,7 @@ class WithdrawalRequestStatus(Enum): ___FUTURE_VALUE___ = "___FUTURE_VALUE___" """This is an enum value that represents future values that could be added in the future. Clients should support unknown values as more of them could be added without notice.""" + CREATING = "CREATING" CREATED = "CREATED" FAILED = "FAILED" IN_PROGRESS = "IN_PROGRESS" diff --git a/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py b/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py index 367b7e8..07ba02a 100644 --- a/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py +++ b/lightspark/objects/WithdrawalRequestToChannelClosingTransactionsConnection.py @@ -7,27 +7,30 @@ from .ChannelClosingTransaction import ChannelClosingTransaction from .ChannelClosingTransaction import from_json as ChannelClosingTransaction_from_json +from .Connection import Connection from .PageInfo import PageInfo from .PageInfo import from_json as PageInfo_from_json @dataclass -class WithdrawalRequestToChannelClosingTransactionsConnection: +class WithdrawalRequestToChannelClosingTransactionsConnection(Connection): requester: Requester - page_info: PageInfo - """An object that holds pagination information about the objects in this connection.""" - count: int """The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field).""" + page_info: PageInfo + """An object that holds pagination information about the objects in this connection.""" + entities: List[ChannelClosingTransaction] """The channel closing transactions for the current page of this connection.""" + typename: str def to_json(self) -> Mapping[str, Any]: return { - "withdrawal_request_to_channel_closing_transactions_connection_page_info": self.page_info.to_json(), + "__typename": "WithdrawalRequestToChannelClosingTransactionsConnection", "withdrawal_request_to_channel_closing_transactions_connection_count": self.count, + "withdrawal_request_to_channel_closing_transactions_connection_page_info": self.page_info.to_json(), "withdrawal_request_to_channel_closing_transactions_connection_entities": [ e.to_json() for e in self.entities ], @@ -37,6 +40,7 @@ def to_json(self) -> Mapping[str, Any]: FRAGMENT = """ fragment WithdrawalRequestToChannelClosingTransactionsConnectionFragment 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 @@ -44,7 +48,6 @@ def to_json(self) -> Mapping[str, Any]: page_info_start_cursor: start_cursor page_info_end_cursor: end_cursor } - withdrawal_request_to_channel_closing_transactions_connection_count: count withdrawal_request_to_channel_closing_transactions_connection_entities: entities { id } @@ -57,15 +60,16 @@ def from_json( ) -> WithdrawalRequestToChannelClosingTransactionsConnection: return WithdrawalRequestToChannelClosingTransactionsConnection( requester=requester, + typename="WithdrawalRequestToChannelClosingTransactionsConnection", + count=obj[ + "withdrawal_request_to_channel_closing_transactions_connection_count" + ], page_info=PageInfo_from_json( requester, obj[ "withdrawal_request_to_channel_closing_transactions_connection_page_info" ], ), - count=obj[ - "withdrawal_request_to_channel_closing_transactions_connection_count" - ], entities=list( map( # pylint: disable=unnecessary-lambda diff --git a/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py b/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py index 8d01078..a68e1b4 100644 --- a/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py +++ b/lightspark/objects/WithdrawalRequestToChannelOpeningTransactionsConnection.py @@ -7,27 +7,30 @@ from .ChannelOpeningTransaction import ChannelOpeningTransaction from .ChannelOpeningTransaction import from_json as ChannelOpeningTransaction_from_json +from .Connection import Connection from .PageInfo import PageInfo from .PageInfo import from_json as PageInfo_from_json @dataclass -class WithdrawalRequestToChannelOpeningTransactionsConnection: +class WithdrawalRequestToChannelOpeningTransactionsConnection(Connection): requester: Requester - page_info: PageInfo - """An object that holds pagination information about the objects in this connection.""" - count: int """The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field).""" + page_info: PageInfo + """An object that holds pagination information about the objects in this connection.""" + entities: List[ChannelOpeningTransaction] """The channel opening transactions for the current page of this connection.""" + typename: str def to_json(self) -> Mapping[str, Any]: return { - "withdrawal_request_to_channel_opening_transactions_connection_page_info": self.page_info.to_json(), + "__typename": "WithdrawalRequestToChannelOpeningTransactionsConnection", "withdrawal_request_to_channel_opening_transactions_connection_count": self.count, + "withdrawal_request_to_channel_opening_transactions_connection_page_info": self.page_info.to_json(), "withdrawal_request_to_channel_opening_transactions_connection_entities": [ e.to_json() for e in self.entities ], @@ -37,6 +40,7 @@ def to_json(self) -> Mapping[str, Any]: FRAGMENT = """ fragment WithdrawalRequestToChannelOpeningTransactionsConnectionFragment 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 @@ -44,7 +48,6 @@ def to_json(self) -> Mapping[str, Any]: page_info_start_cursor: start_cursor page_info_end_cursor: end_cursor } - withdrawal_request_to_channel_opening_transactions_connection_count: count withdrawal_request_to_channel_opening_transactions_connection_entities: entities { id } @@ -57,15 +60,16 @@ def from_json( ) -> WithdrawalRequestToChannelOpeningTransactionsConnection: return WithdrawalRequestToChannelOpeningTransactionsConnection( requester=requester, + typename="WithdrawalRequestToChannelOpeningTransactionsConnection", + count=obj[ + "withdrawal_request_to_channel_opening_transactions_connection_count" + ], page_info=PageInfo_from_json( requester, obj[ "withdrawal_request_to_channel_opening_transactions_connection_page_info" ], ), - count=obj[ - "withdrawal_request_to_channel_opening_transactions_connection_count" - ], entities=list( map( # pylint: disable=unnecessary-lambda From 4e47bba2d857e3e2149e9eda064f1421deefb9c8 Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 10 May 2024 19:20:08 -0700 Subject: [PATCH 2/3] Forgot to git add --- lightspark/objects/FailHtlcsInput.py | 26 +++++++++ lightspark/objects/FailHtlcsOutput.py | 35 ++++++++++++ ...ithdrawalRequestToWithdrawalsConnection.py | 55 +++++++++++++++++++ lightspark/scripts/fail_htlcs.py | 11 ++++ .../outgoing_payments_for_payment_hash.py | 21 +++++++ 5 files changed, 148 insertions(+) create mode 100644 lightspark/objects/FailHtlcsInput.py create mode 100644 lightspark/objects/FailHtlcsOutput.py create mode 100644 lightspark/objects/WithdrawalRequestToWithdrawalsConnection.py create mode 100644 lightspark/scripts/fail_htlcs.py create mode 100644 lightspark/scripts/outgoing_payments_for_payment_hash.py diff --git a/lightspark/objects/FailHtlcsInput.py b/lightspark/objects/FailHtlcsInput.py new file mode 100644 index 0000000..07b3d1a --- /dev/null +++ b/lightspark/objects/FailHtlcsInput.py @@ -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"], + ) diff --git a/lightspark/objects/FailHtlcsOutput.py b/lightspark/objects/FailHtlcsOutput.py new file mode 100644 index 0000000..1bdf34b --- /dev/null +++ b/lightspark/objects/FailHtlcsOutput.py @@ -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"], + ) diff --git a/lightspark/objects/WithdrawalRequestToWithdrawalsConnection.py b/lightspark/objects/WithdrawalRequestToWithdrawalsConnection.py new file mode 100644 index 0000000..6f2844f --- /dev/null +++ b/lightspark/objects/WithdrawalRequestToWithdrawalsConnection.py @@ -0,0 +1,55 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from dataclasses import dataclass +from typing import Any, List, Mapping + +from lightspark.requests.requester import Requester + +from .Withdrawal import Withdrawal +from .Withdrawal import from_json as Withdrawal_from_json + + +@dataclass +class WithdrawalRequestToWithdrawalsConnection: + requester: Requester + + count: int + """The total count of objects in this connection, using the current filters. It is different from the number of objects returned in the current page (in the `entities` field).""" + + entities: List[Withdrawal] + """The withdrawals for the current page of this connection.""" + + def to_json(self) -> Mapping[str, Any]: + return { + "withdrawal_request_to_withdrawals_connection_count": self.count, + "withdrawal_request_to_withdrawals_connection_entities": [ + e.to_json() for e in self.entities + ], + } + + +FRAGMENT = """ +fragment WithdrawalRequestToWithdrawalsConnectionFragment on WithdrawalRequestToWithdrawalsConnection { + __typename + withdrawal_request_to_withdrawals_connection_count: count + withdrawal_request_to_withdrawals_connection_entities: entities { + id + } +} +""" + + +def from_json( + requester: Requester, obj: Mapping[str, Any] +) -> WithdrawalRequestToWithdrawalsConnection: + return WithdrawalRequestToWithdrawalsConnection( + requester=requester, + count=obj["withdrawal_request_to_withdrawals_connection_count"], + entities=list( + map( + # pylint: disable=unnecessary-lambda + lambda e: Withdrawal_from_json(requester, e), + obj["withdrawal_request_to_withdrawals_connection_entities"], + ) + ), + ) diff --git a/lightspark/scripts/fail_htlcs.py b/lightspark/scripts/fail_htlcs.py new file mode 100644 index 0000000..b0aff22 --- /dev/null +++ b/lightspark/scripts/fail_htlcs.py @@ -0,0 +1,11 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +FAIL_HTLCS_MUTATION = f""" +mutation FailHtlcs($invoice_id: ID!, $cancel_invoice: Boolean!) {{ + fail_htlcs(input: {{ invoice_id: $invoice_id, cancel_invoice: $cancel_invoice }}) {{ + invoice {{ + id + }} + }} +}} +""" diff --git a/lightspark/scripts/outgoing_payments_for_payment_hash.py b/lightspark/scripts/outgoing_payments_for_payment_hash.py new file mode 100644 index 0000000..25a2e42 --- /dev/null +++ b/lightspark/scripts/outgoing_payments_for_payment_hash.py @@ -0,0 +1,21 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from lightspark.objects.OutgoingPayment import FRAGMENT as OutgoingPaymentFragment + +OUTGOING_PAYMENTS_FOR_PAYMENT_HASH_QUERY = f""" +query OutgoingPaymentsForPaymentHash( + $payment_hash: String!, + $transaction_statuses: [TransactionStatus!] = null +) {{ + outgoing_payments_for_payment_hash(input: {{ + payment_hash: $payment_hash, + statuses: $transaction_statuses + }}) {{ + payments {{ + ...OutgoingPaymentFragment + }} + }} +}} + +{OutgoingPaymentFragment} +""" From 3c07a378e8279a7a00682e0852439e720067bdad Mon Sep 17 00:00:00 2001 From: Jeremy Klein Date: Fri, 10 May 2024 19:22:05 -0700 Subject: [PATCH 3/3] lint --- lightspark/scripts/fail_htlcs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lightspark/scripts/fail_htlcs.py b/lightspark/scripts/fail_htlcs.py index b0aff22..9299347 100644 --- a/lightspark/scripts/fail_htlcs.py +++ b/lightspark/scripts/fail_htlcs.py @@ -1,11 +1,11 @@ # Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved -FAIL_HTLCS_MUTATION = f""" -mutation FailHtlcs($invoice_id: ID!, $cancel_invoice: Boolean!) {{ - fail_htlcs(input: {{ invoice_id: $invoice_id, cancel_invoice: $cancel_invoice }}) {{ - invoice {{ +FAIL_HTLCS_MUTATION = """ +mutation FailHtlcs($invoice_id: ID!, $cancel_invoice: Boolean!) { + fail_htlcs(input: { invoice_id: $invoice_id, cancel_invoice: $cancel_invoice }) { + invoice { id - }} - }} -}} + } + } +} """