From 71acfab7f443249e13a90eaf6eed0acf2f0c038d Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Tue, 2 Jan 2024 11:16:43 -0800 Subject: [PATCH] Generate new objects. --- lightspark/__init__.py | 7 ++ lightspark/objects/Account.py | 13 ++- .../objects/AccountToChannelsConnection.py | 22 ++++- lightspark/objects/Connection.py | 14 ++++ lightspark/objects/DailyLiquidityForecast.py | 64 ++++++++++++++ .../objects/LightningPaymentDirection.py | 14 ++++ lightspark/objects/LightsparkNode.py | 53 ++++++++++++ ...NodeToDailyLiquidityForecastsConnection.py | 83 +++++++++++++++++++ lightspark/objects/LightsparkNodeWithOSK.py | 53 ++++++++++++ .../LightsparkNodeWithRemoteSigning.py | 53 ++++++++++++ .../objects/WithdrawalFeeEstimateInput.py | 38 +++++++++ .../objects/WithdrawalFeeEstimateOutput.py | 48 +++++++++++ 12 files changed, 459 insertions(+), 3 deletions(-) create mode 100644 lightspark/objects/DailyLiquidityForecast.py create mode 100644 lightspark/objects/LightningPaymentDirection.py create mode 100644 lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py create mode 100644 lightspark/objects/WithdrawalFeeEstimateInput.py create mode 100644 lightspark/objects/WithdrawalFeeEstimateOutput.py diff --git a/lightspark/__init__.py b/lightspark/__init__.py index 1c97d4d..6dc7d68 100644 --- a/lightspark/__init__.py +++ b/lightspark/__init__.py @@ -65,6 +65,7 @@ from lightspark.objects.CreateUmaInvoiceInput import CreateUmaInvoiceInput from lightspark.objects.CurrencyAmount import CurrencyAmount from lightspark.objects.CurrencyUnit import CurrencyUnit +from lightspark.objects.DailyLiquidityForecast import DailyLiquidityForecast from lightspark.objects.DeclineToSignMessagesInput import DeclineToSignMessagesInput from lightspark.objects.DeclineToSignMessagesOutput import DeclineToSignMessagesOutput from lightspark.objects.DeleteApiTokenInput import DeleteApiTokenInput @@ -98,6 +99,7 @@ LightningFeeEstimateForNodeInput, ) from lightspark.objects.LightningFeeEstimateOutput import LightningFeeEstimateOutput +from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection from lightspark.objects.LightningTransaction import LightningTransaction from lightspark.objects.LightsparkNode import LightsparkNode from lightspark.objects.LightsparkNodeOwner import LightsparkNodeOwner @@ -105,6 +107,9 @@ from lightspark.objects.LightsparkNodeToChannelsConnection import ( LightsparkNodeToChannelsConnection, ) +from lightspark.objects.LightsparkNodeToDailyLiquidityForecastsConnection import ( + LightsparkNodeToDailyLiquidityForecastsConnection, +) from lightspark.objects.LightsparkNodeWithOSK import LightsparkNodeWithOSK from lightspark.objects.LightsparkNodeWithRemoteSigning import ( LightsparkNodeWithRemoteSigning, @@ -200,6 +205,8 @@ ) from lightspark.objects.WebhookEventType import WebhookEventType from lightspark.objects.Withdrawal import Withdrawal +from lightspark.objects.WithdrawalFeeEstimateInput import WithdrawalFeeEstimateInput +from lightspark.objects.WithdrawalFeeEstimateOutput import WithdrawalFeeEstimateOutput from lightspark.objects.WithdrawalMode import WithdrawalMode from lightspark.objects.WithdrawalRequest import WithdrawalRequest from lightspark.objects.WithdrawalRequestStatus import WithdrawalRequestStatus diff --git a/lightspark/objects/Account.py b/lightspark/objects/Account.py index e3ca431..a2794c1 100644 --- a/lightspark/objects/Account.py +++ b/lightspark/objects/Account.py @@ -604,15 +604,23 @@ def get_channels( after_date: Optional[datetime] = None, before_date: Optional[datetime] = None, first: Optional[int] = None, + after: Optional[str] = None, ) -> AccountToChannelsConnection: json = self.requester.execute_graphql( """ -query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int) { +query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int, $after: String) { entity(id: $entity_id) { ... on Account { - channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first) { + channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first, after: $after) { __typename account_to_channels_connection_count: count + account_to_channels_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 + } account_to_channels_connection_entities: entities { __typename channel_id: id @@ -719,6 +727,7 @@ def get_channels( "after_date": after_date, "before_date": before_date, "first": first, + "after": after, }, ) connection = json["entity"]["channels"] diff --git a/lightspark/objects/AccountToChannelsConnection.py b/lightspark/objects/AccountToChannelsConnection.py index fa8fb71..9e9493a 100644 --- a/lightspark/objects/AccountToChannelsConnection.py +++ b/lightspark/objects/AccountToChannelsConnection.py @@ -7,21 +7,30 @@ from .Channel import Channel from .Channel import from_json as Channel_from_json +from .Connection import Connection +from .PageInfo import PageInfo +from .PageInfo import from_json as PageInfo_from_json @dataclass -class AccountToChannelsConnection: +class AccountToChannelsConnection(Connection): 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).""" + page_info: PageInfo + """An object that holds pagination information about the objects in this connection.""" + entities: List[Channel] """The channels for the current page of this connection.""" + typename: str def to_json(self) -> Mapping[str, Any]: return { + "__typename": "AccountToChannelsConnection", "account_to_channels_connection_count": self.count, + "account_to_channels_connection_page_info": self.page_info.to_json(), "account_to_channels_connection_entities": [ e.to_json() for e in self.entities ], @@ -32,6 +41,13 @@ def to_json(self) -> Mapping[str, Any]: fragment AccountToChannelsConnectionFragment on AccountToChannelsConnection { __typename account_to_channels_connection_count: count + account_to_channels_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 + } account_to_channels_connection_entities: entities { id } @@ -44,7 +60,11 @@ def from_json( ) -> AccountToChannelsConnection: return AccountToChannelsConnection( requester=requester, + typename="AccountToChannelsConnection", count=obj["account_to_channels_connection_count"], + page_info=PageInfo_from_json( + requester, obj["account_to_channels_connection_page_info"] + ), entities=list( map( # pylint: disable=unnecessary-lambda diff --git a/lightspark/objects/Connection.py b/lightspark/objects/Connection.py index e55a28e..0e58c3e 100644 --- a/lightspark/objects/Connection.py +++ b/lightspark/objects/Connection.py @@ -36,6 +36,20 @@ class Connection: id } } + ... on AccountToChannelsConnection { + __typename + account_to_channels_connection_count: count + account_to_channels_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 + } + account_to_channels_connection_entities: entities { + id + } + } ... on AccountToNodesConnection { __typename account_to_nodes_connection_count: count diff --git a/lightspark/objects/DailyLiquidityForecast.py b/lightspark/objects/DailyLiquidityForecast.py new file mode 100644 index 0000000..ebb62c0 --- /dev/null +++ b/lightspark/objects/DailyLiquidityForecast.py @@ -0,0 +1,64 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from dataclasses import dataclass +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 + +from .CurrencyAmount import CurrencyAmount +from .CurrencyAmount import from_json as CurrencyAmount_from_json +from .LightningPaymentDirection import LightningPaymentDirection + + +@dataclass +class DailyLiquidityForecast: + requester: Requester + + date: datetime + """The date for which this forecast was generated.""" + + direction: LightningPaymentDirection + """The direction for which this forecast was generated.""" + + amount: CurrencyAmount + """The value of the forecast. It represents the amount of msats that we think will be moved for that specified direction, for that node, on that date.""" + + def to_json(self) -> Mapping[str, Any]: + return { + "daily_liquidity_forecast_date": self.date, + "daily_liquidity_forecast_direction": self.direction.value, + "daily_liquidity_forecast_amount": self.amount.to_json(), + } + + +FRAGMENT = """ +fragment DailyLiquidityForecastFragment on DailyLiquidityForecast { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_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 + } +} +""" + + +def from_json(requester: Requester, obj: Mapping[str, Any]) -> DailyLiquidityForecast: + return DailyLiquidityForecast( + requester=requester, + date=obj["daily_liquidity_forecast_date"], + direction=parse_enum( + LightningPaymentDirection, obj["daily_liquidity_forecast_direction"] + ), + amount=CurrencyAmount_from_json( + requester, obj["daily_liquidity_forecast_amount"] + ), + ) diff --git a/lightspark/objects/LightningPaymentDirection.py b/lightspark/objects/LightningPaymentDirection.py new file mode 100644 index 0000000..e096998 --- /dev/null +++ b/lightspark/objects/LightningPaymentDirection.py @@ -0,0 +1,14 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from enum import Enum + + +class LightningPaymentDirection(Enum): + """This is an enum identifying the payment direction.""" + + ___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.""" + INCOMING = "INCOMING" + """A payment that is received by the node.""" + OUTGOING = "OUTGOING" + """A payment that is sent by the node.""" diff --git a/lightspark/objects/LightsparkNode.py b/lightspark/objects/LightsparkNode.py index d726393..b140baa 100644 --- a/lightspark/objects/LightsparkNode.py +++ b/lightspark/objects/LightsparkNode.py @@ -19,11 +19,18 @@ from .CurrencyAmount import CurrencyAmount from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .LightningPaymentDirection import LightningPaymentDirection from .LightsparkNodeStatus import LightsparkNodeStatus from .LightsparkNodeToChannelsConnection import LightsparkNodeToChannelsConnection from .LightsparkNodeToChannelsConnection import ( from_json as LightsparkNodeToChannelsConnection_from_json, ) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + LightsparkNodeToDailyLiquidityForecastsConnection, +) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + from_json as LightsparkNodeToDailyLiquidityForecastsConnection_from_json, +) from .Node import Node from .NodeAddressType import NodeAddressType from .NodeToAddressesConnection import NodeToAddressesConnection @@ -248,6 +255,52 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def get_daily_liquidity_forecasts( + self, + from_date: datetime, + to_date: datetime, + direction: LightningPaymentDirection, + ) -> LightsparkNodeToDailyLiquidityForecastsConnection: + json = self.requester.execute_graphql( + """ +query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNode { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_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 + } + } + } + } + } +} + """, + { + "entity_id": self.id, + "from_date": from_date, + "to_date": to_date, + "direction": direction, + }, + ) + connection = json["entity"]["daily_liquidity_forecasts"] + return LightsparkNodeToDailyLiquidityForecastsConnection_from_json( + self.requester, connection + ) + def to_json(self) -> Mapping[str, Any]: return { "__typename": self.typename, diff --git a/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py b/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py new file mode 100644 index 0000000..b64f698 --- /dev/null +++ b/lightspark/objects/LightsparkNodeToDailyLiquidityForecastsConnection.py @@ -0,0 +1,83 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from dataclasses import dataclass +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 + +from .DailyLiquidityForecast import DailyLiquidityForecast +from .DailyLiquidityForecast import from_json as DailyLiquidityForecast_from_json +from .LightningPaymentDirection import LightningPaymentDirection + + +@dataclass +class LightsparkNodeToDailyLiquidityForecastsConnection: + requester: Requester + + from_date: datetime + + to_date: datetime + + direction: LightningPaymentDirection + + entities: List[DailyLiquidityForecast] + """The daily liquidity forecasts for the current page of this connection.""" + + def to_json(self) -> Mapping[str, Any]: + return { + "lightspark_node_to_daily_liquidity_forecasts_connection_from_date": self.from_date, + "lightspark_node_to_daily_liquidity_forecasts_connection_to_date": self.to_date, + "lightspark_node_to_daily_liquidity_forecasts_connection_direction": self.direction.value, + "lightspark_node_to_daily_liquidity_forecasts_connection_entities": [ + e.to_json() for e in self.entities + ], + } + + +FRAGMENT = """ +fragment LightsparkNodeToDailyLiquidityForecastsConnectionFragment on LightsparkNodeToDailyLiquidityForecastsConnection { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_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 + } + } +} +""" + + +def from_json( + requester: Requester, obj: Mapping[str, Any] +) -> LightsparkNodeToDailyLiquidityForecastsConnection: + return LightsparkNodeToDailyLiquidityForecastsConnection( + requester=requester, + from_date=obj[ + "lightspark_node_to_daily_liquidity_forecasts_connection_from_date" + ], + to_date=obj["lightspark_node_to_daily_liquidity_forecasts_connection_to_date"], + direction=parse_enum( + LightningPaymentDirection, + obj["lightspark_node_to_daily_liquidity_forecasts_connection_direction"], + ), + entities=list( + map( + # pylint: disable=unnecessary-lambda + lambda e: DailyLiquidityForecast_from_json(requester, e), + obj["lightspark_node_to_daily_liquidity_forecasts_connection_entities"], + ) + ), + ) diff --git a/lightspark/objects/LightsparkNodeWithOSK.py b/lightspark/objects/LightsparkNodeWithOSK.py index 4f1b366..c13becd 100644 --- a/lightspark/objects/LightsparkNodeWithOSK.py +++ b/lightspark/objects/LightsparkNodeWithOSK.py @@ -18,12 +18,19 @@ from .CurrencyAmount import CurrencyAmount from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .LightningPaymentDirection import LightningPaymentDirection from .LightsparkNode import LightsparkNode from .LightsparkNodeStatus import LightsparkNodeStatus from .LightsparkNodeToChannelsConnection import LightsparkNodeToChannelsConnection from .LightsparkNodeToChannelsConnection import ( from_json as LightsparkNodeToChannelsConnection_from_json, ) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + LightsparkNodeToDailyLiquidityForecastsConnection, +) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + from_json as LightsparkNodeToDailyLiquidityForecastsConnection_from_json, +) from .Node import Node from .NodeAddressType import NodeAddressType from .NodeToAddressesConnection import NodeToAddressesConnection @@ -252,6 +259,52 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def get_daily_liquidity_forecasts( + self, + from_date: datetime, + to_date: datetime, + direction: LightningPaymentDirection, + ) -> LightsparkNodeToDailyLiquidityForecastsConnection: + json = self.requester.execute_graphql( + """ +query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithOSK { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_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 + } + } + } + } + } +} + """, + { + "entity_id": self.id, + "from_date": from_date, + "to_date": to_date, + "direction": direction, + }, + ) + connection = json["entity"]["daily_liquidity_forecasts"] + return LightsparkNodeToDailyLiquidityForecastsConnection_from_json( + self.requester, connection + ) + def to_json(self) -> Mapping[str, Any]: return { "__typename": "LightsparkNodeWithOSK", diff --git a/lightspark/objects/LightsparkNodeWithRemoteSigning.py b/lightspark/objects/LightsparkNodeWithRemoteSigning.py index 493de76..cb3c700 100644 --- a/lightspark/objects/LightsparkNodeWithRemoteSigning.py +++ b/lightspark/objects/LightsparkNodeWithRemoteSigning.py @@ -18,12 +18,19 @@ from .CurrencyAmount import CurrencyAmount from .CurrencyAmount import from_json as CurrencyAmount_from_json from .Entity import Entity +from .LightningPaymentDirection import LightningPaymentDirection from .LightsparkNode import LightsparkNode from .LightsparkNodeStatus import LightsparkNodeStatus from .LightsparkNodeToChannelsConnection import LightsparkNodeToChannelsConnection from .LightsparkNodeToChannelsConnection import ( from_json as LightsparkNodeToChannelsConnection_from_json, ) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + LightsparkNodeToDailyLiquidityForecastsConnection, +) +from .LightsparkNodeToDailyLiquidityForecastsConnection import ( + from_json as LightsparkNodeToDailyLiquidityForecastsConnection_from_json, +) from .Node import Node from .NodeAddressType import NodeAddressType from .NodeToAddressesConnection import NodeToAddressesConnection @@ -247,6 +254,52 @@ def get_channels( connection = json["entity"]["channels"] return LightsparkNodeToChannelsConnection_from_json(self.requester, connection) + def get_daily_liquidity_forecasts( + self, + from_date: datetime, + to_date: datetime, + direction: LightningPaymentDirection, + ) -> LightsparkNodeToDailyLiquidityForecastsConnection: + json = self.requester.execute_graphql( + """ +query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) { + entity(id: $entity_id) { + ... on LightsparkNodeWithRemoteSigning { + daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) { + __typename + lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date + lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date + lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction + lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities { + __typename + daily_liquidity_forecast_date: date + daily_liquidity_forecast_direction: direction + daily_liquidity_forecast_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 + } + } + } + } + } +} + """, + { + "entity_id": self.id, + "from_date": from_date, + "to_date": to_date, + "direction": direction, + }, + ) + connection = json["entity"]["daily_liquidity_forecasts"] + return LightsparkNodeToDailyLiquidityForecastsConnection_from_json( + self.requester, connection + ) + def to_json(self) -> Mapping[str, Any]: return { "__typename": "LightsparkNodeWithRemoteSigning", diff --git a/lightspark/objects/WithdrawalFeeEstimateInput.py b/lightspark/objects/WithdrawalFeeEstimateInput.py new file mode 100644 index 0000000..07e0c82 --- /dev/null +++ b/lightspark/objects/WithdrawalFeeEstimateInput.py @@ -0,0 +1,38 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +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 + + +@dataclass +class WithdrawalFeeEstimateInput: + node_id: str + """The node from which you'd like to make the withdrawal.""" + + amount_sats: int + """The amount you want to withdraw from this node in Satoshis. Use the special value -1 to withdrawal all funds from this node.""" + + withdrawal_mode: WithdrawalMode + """The strategy that should be used to withdraw the funds from this node.""" + + def to_json(self) -> Mapping[str, Any]: + return { + "withdrawal_fee_estimate_input_node_id": self.node_id, + "withdrawal_fee_estimate_input_amount_sats": self.amount_sats, + "withdrawal_fee_estimate_input_withdrawal_mode": self.withdrawal_mode.value, + } + + +def from_json(obj: Mapping[str, Any]) -> WithdrawalFeeEstimateInput: + return WithdrawalFeeEstimateInput( + node_id=obj["withdrawal_fee_estimate_input_node_id"], + amount_sats=obj["withdrawal_fee_estimate_input_amount_sats"], + withdrawal_mode=parse_enum( + WithdrawalMode, obj["withdrawal_fee_estimate_input_withdrawal_mode"] + ), + ) diff --git a/lightspark/objects/WithdrawalFeeEstimateOutput.py b/lightspark/objects/WithdrawalFeeEstimateOutput.py new file mode 100644 index 0000000..659bebc --- /dev/null +++ b/lightspark/objects/WithdrawalFeeEstimateOutput.py @@ -0,0 +1,48 @@ +# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved + +from dataclasses import dataclass +from typing import Any, Mapping + +from lightspark.requests.requester import Requester + +from .CurrencyAmount import CurrencyAmount +from .CurrencyAmount import from_json as CurrencyAmount_from_json + + +@dataclass +class WithdrawalFeeEstimateOutput: + requester: Requester + + fee_estimate: CurrencyAmount + """The estimated fee for the withdrawal.""" + + def to_json(self) -> Mapping[str, Any]: + return { + "withdrawal_fee_estimate_output_fee_estimate": self.fee_estimate.to_json(), + } + + +FRAGMENT = """ +fragment WithdrawalFeeEstimateOutputFragment on WithdrawalFeeEstimateOutput { + __typename + withdrawal_fee_estimate_output_fee_estimate: fee_estimate { + __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 + } +} +""" + + +def from_json( + requester: Requester, obj: Mapping[str, Any] +) -> WithdrawalFeeEstimateOutput: + return WithdrawalFeeEstimateOutput( + requester=requester, + fee_estimate=CurrencyAmount_from_json( + requester, obj["withdrawal_fee_estimate_output_fee_estimate"] + ), + )