Skip to content

Commit 855dca6

Browse files
authored
Generate new objects. (#16)
2 parents b8cc256 + 71acfab commit 855dca6

12 files changed

+459
-3
lines changed

lightspark/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from lightspark.objects.CreateUmaInvoiceInput import CreateUmaInvoiceInput
6666
from lightspark.objects.CurrencyAmount import CurrencyAmount
6767
from lightspark.objects.CurrencyUnit import CurrencyUnit
68+
from lightspark.objects.DailyLiquidityForecast import DailyLiquidityForecast
6869
from lightspark.objects.DeclineToSignMessagesInput import DeclineToSignMessagesInput
6970
from lightspark.objects.DeclineToSignMessagesOutput import DeclineToSignMessagesOutput
7071
from lightspark.objects.DeleteApiTokenInput import DeleteApiTokenInput
@@ -98,13 +99,17 @@
9899
LightningFeeEstimateForNodeInput,
99100
)
100101
from lightspark.objects.LightningFeeEstimateOutput import LightningFeeEstimateOutput
102+
from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection
101103
from lightspark.objects.LightningTransaction import LightningTransaction
102104
from lightspark.objects.LightsparkNode import LightsparkNode
103105
from lightspark.objects.LightsparkNodeOwner import LightsparkNodeOwner
104106
from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus
105107
from lightspark.objects.LightsparkNodeToChannelsConnection import (
106108
LightsparkNodeToChannelsConnection,
107109
)
110+
from lightspark.objects.LightsparkNodeToDailyLiquidityForecastsConnection import (
111+
LightsparkNodeToDailyLiquidityForecastsConnection,
112+
)
108113
from lightspark.objects.LightsparkNodeWithOSK import LightsparkNodeWithOSK
109114
from lightspark.objects.LightsparkNodeWithRemoteSigning import (
110115
LightsparkNodeWithRemoteSigning,
@@ -200,6 +205,8 @@
200205
)
201206
from lightspark.objects.WebhookEventType import WebhookEventType
202207
from lightspark.objects.Withdrawal import Withdrawal
208+
from lightspark.objects.WithdrawalFeeEstimateInput import WithdrawalFeeEstimateInput
209+
from lightspark.objects.WithdrawalFeeEstimateOutput import WithdrawalFeeEstimateOutput
203210
from lightspark.objects.WithdrawalMode import WithdrawalMode
204211
from lightspark.objects.WithdrawalRequest import WithdrawalRequest
205212
from lightspark.objects.WithdrawalRequestStatus import WithdrawalRequestStatus

lightspark/objects/Account.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,23 @@ def get_channels(
604604
after_date: Optional[datetime] = None,
605605
before_date: Optional[datetime] = None,
606606
first: Optional[int] = None,
607+
after: Optional[str] = None,
607608
) -> AccountToChannelsConnection:
608609
json = self.requester.execute_graphql(
609610
"""
610-
query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int) {
611+
query FetchAccountToChannelsConnection($entity_id: ID!, $bitcoin_network: BitcoinNetwork!, $lightning_node_id: ID, $after_date: DateTime, $before_date: DateTime, $first: Int, $after: String) {
611612
entity(id: $entity_id) {
612613
... on Account {
613-
channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first) {
614+
channels(, bitcoin_network: $bitcoin_network, lightning_node_id: $lightning_node_id, after_date: $after_date, before_date: $before_date, first: $first, after: $after) {
614615
__typename
615616
account_to_channels_connection_count: count
617+
account_to_channels_connection_page_info: page_info {
618+
__typename
619+
page_info_has_next_page: has_next_page
620+
page_info_has_previous_page: has_previous_page
621+
page_info_start_cursor: start_cursor
622+
page_info_end_cursor: end_cursor
623+
}
616624
account_to_channels_connection_entities: entities {
617625
__typename
618626
channel_id: id
@@ -719,6 +727,7 @@ def get_channels(
719727
"after_date": after_date,
720728
"before_date": before_date,
721729
"first": first,
730+
"after": after,
722731
},
723732
)
724733
connection = json["entity"]["channels"]

lightspark/objects/AccountToChannelsConnection.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,30 @@
77

88
from .Channel import Channel
99
from .Channel import from_json as Channel_from_json
10+
from .Connection import Connection
11+
from .PageInfo import PageInfo
12+
from .PageInfo import from_json as PageInfo_from_json
1013

1114

1215
@dataclass
13-
class AccountToChannelsConnection:
16+
class AccountToChannelsConnection(Connection):
1417
requester: Requester
1518

1619
count: int
1720
"""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)."""
1821

22+
page_info: PageInfo
23+
"""An object that holds pagination information about the objects in this connection."""
24+
1925
entities: List[Channel]
2026
"""The channels for the current page of this connection."""
27+
typename: str
2128

2229
def to_json(self) -> Mapping[str, Any]:
2330
return {
31+
"__typename": "AccountToChannelsConnection",
2432
"account_to_channels_connection_count": self.count,
33+
"account_to_channels_connection_page_info": self.page_info.to_json(),
2534
"account_to_channels_connection_entities": [
2635
e.to_json() for e in self.entities
2736
],
@@ -32,6 +41,13 @@ def to_json(self) -> Mapping[str, Any]:
3241
fragment AccountToChannelsConnectionFragment on AccountToChannelsConnection {
3342
__typename
3443
account_to_channels_connection_count: count
44+
account_to_channels_connection_page_info: page_info {
45+
__typename
46+
page_info_has_next_page: has_next_page
47+
page_info_has_previous_page: has_previous_page
48+
page_info_start_cursor: start_cursor
49+
page_info_end_cursor: end_cursor
50+
}
3551
account_to_channels_connection_entities: entities {
3652
id
3753
}
@@ -44,7 +60,11 @@ def from_json(
4460
) -> AccountToChannelsConnection:
4561
return AccountToChannelsConnection(
4662
requester=requester,
63+
typename="AccountToChannelsConnection",
4764
count=obj["account_to_channels_connection_count"],
65+
page_info=PageInfo_from_json(
66+
requester, obj["account_to_channels_connection_page_info"]
67+
),
4868
entities=list(
4969
map(
5070
# pylint: disable=unnecessary-lambda

lightspark/objects/Connection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ class Connection:
3636
id
3737
}
3838
}
39+
... on AccountToChannelsConnection {
40+
__typename
41+
account_to_channels_connection_count: count
42+
account_to_channels_connection_page_info: page_info {
43+
__typename
44+
page_info_has_next_page: has_next_page
45+
page_info_has_previous_page: has_previous_page
46+
page_info_start_cursor: start_cursor
47+
page_info_end_cursor: end_cursor
48+
}
49+
account_to_channels_connection_entities: entities {
50+
id
51+
}
52+
}
3953
... on AccountToNodesConnection {
4054
__typename
4155
account_to_nodes_connection_count: count
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from dataclasses import dataclass
4+
from datetime import datetime
5+
from typing import Any, Mapping
6+
7+
from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection
8+
from lightspark.requests.requester import Requester
9+
from lightspark.utils.enums import parse_enum
10+
11+
from .CurrencyAmount import CurrencyAmount
12+
from .CurrencyAmount import from_json as CurrencyAmount_from_json
13+
from .LightningPaymentDirection import LightningPaymentDirection
14+
15+
16+
@dataclass
17+
class DailyLiquidityForecast:
18+
requester: Requester
19+
20+
date: datetime
21+
"""The date for which this forecast was generated."""
22+
23+
direction: LightningPaymentDirection
24+
"""The direction for which this forecast was generated."""
25+
26+
amount: CurrencyAmount
27+
"""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."""
28+
29+
def to_json(self) -> Mapping[str, Any]:
30+
return {
31+
"daily_liquidity_forecast_date": self.date,
32+
"daily_liquidity_forecast_direction": self.direction.value,
33+
"daily_liquidity_forecast_amount": self.amount.to_json(),
34+
}
35+
36+
37+
FRAGMENT = """
38+
fragment DailyLiquidityForecastFragment on DailyLiquidityForecast {
39+
__typename
40+
daily_liquidity_forecast_date: date
41+
daily_liquidity_forecast_direction: direction
42+
daily_liquidity_forecast_amount: amount {
43+
__typename
44+
currency_amount_original_value: original_value
45+
currency_amount_original_unit: original_unit
46+
currency_amount_preferred_currency_unit: preferred_currency_unit
47+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
48+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
49+
}
50+
}
51+
"""
52+
53+
54+
def from_json(requester: Requester, obj: Mapping[str, Any]) -> DailyLiquidityForecast:
55+
return DailyLiquidityForecast(
56+
requester=requester,
57+
date=obj["daily_liquidity_forecast_date"],
58+
direction=parse_enum(
59+
LightningPaymentDirection, obj["daily_liquidity_forecast_direction"]
60+
),
61+
amount=CurrencyAmount_from_json(
62+
requester, obj["daily_liquidity_forecast_amount"]
63+
),
64+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from enum import Enum
4+
5+
6+
class LightningPaymentDirection(Enum):
7+
"""This is an enum identifying the payment direction."""
8+
9+
___FUTURE_VALUE___ = "___FUTURE_VALUE___"
10+
"""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."""
11+
INCOMING = "INCOMING"
12+
"""A payment that is received by the node."""
13+
OUTGOING = "OUTGOING"
14+
"""A payment that is sent by the node."""

lightspark/objects/LightsparkNode.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
from .CurrencyAmount import CurrencyAmount
2020
from .CurrencyAmount import from_json as CurrencyAmount_from_json
2121
from .Entity import Entity
22+
from .LightningPaymentDirection import LightningPaymentDirection
2223
from .LightsparkNodeStatus import LightsparkNodeStatus
2324
from .LightsparkNodeToChannelsConnection import LightsparkNodeToChannelsConnection
2425
from .LightsparkNodeToChannelsConnection import (
2526
from_json as LightsparkNodeToChannelsConnection_from_json,
2627
)
28+
from .LightsparkNodeToDailyLiquidityForecastsConnection import (
29+
LightsparkNodeToDailyLiquidityForecastsConnection,
30+
)
31+
from .LightsparkNodeToDailyLiquidityForecastsConnection import (
32+
from_json as LightsparkNodeToDailyLiquidityForecastsConnection_from_json,
33+
)
2734
from .Node import Node
2835
from .NodeAddressType import NodeAddressType
2936
from .NodeToAddressesConnection import NodeToAddressesConnection
@@ -248,6 +255,52 @@ def get_channels(
248255
connection = json["entity"]["channels"]
249256
return LightsparkNodeToChannelsConnection_from_json(self.requester, connection)
250257

258+
def get_daily_liquidity_forecasts(
259+
self,
260+
from_date: datetime,
261+
to_date: datetime,
262+
direction: LightningPaymentDirection,
263+
) -> LightsparkNodeToDailyLiquidityForecastsConnection:
264+
json = self.requester.execute_graphql(
265+
"""
266+
query FetchLightsparkNodeToDailyLiquidityForecastsConnection($entity_id: ID!, $from_date: Date!, $to_date: Date!, $direction: LightningPaymentDirection!) {
267+
entity(id: $entity_id) {
268+
... on LightsparkNode {
269+
daily_liquidity_forecasts(, from_date: $from_date, to_date: $to_date, direction: $direction) {
270+
__typename
271+
lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date
272+
lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date
273+
lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction
274+
lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities {
275+
__typename
276+
daily_liquidity_forecast_date: date
277+
daily_liquidity_forecast_direction: direction
278+
daily_liquidity_forecast_amount: amount {
279+
__typename
280+
currency_amount_original_value: original_value
281+
currency_amount_original_unit: original_unit
282+
currency_amount_preferred_currency_unit: preferred_currency_unit
283+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
284+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
285+
}
286+
}
287+
}
288+
}
289+
}
290+
}
291+
""",
292+
{
293+
"entity_id": self.id,
294+
"from_date": from_date,
295+
"to_date": to_date,
296+
"direction": direction,
297+
},
298+
)
299+
connection = json["entity"]["daily_liquidity_forecasts"]
300+
return LightsparkNodeToDailyLiquidityForecastsConnection_from_json(
301+
self.requester, connection
302+
)
303+
251304
def to_json(self) -> Mapping[str, Any]:
252305
return {
253306
"__typename": self.typename,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from dataclasses import dataclass
4+
from datetime import datetime
5+
from typing import Any, List, Mapping
6+
7+
from lightspark.objects.LightningPaymentDirection import LightningPaymentDirection
8+
from lightspark.requests.requester import Requester
9+
from lightspark.utils.enums import parse_enum
10+
11+
from .DailyLiquidityForecast import DailyLiquidityForecast
12+
from .DailyLiquidityForecast import from_json as DailyLiquidityForecast_from_json
13+
from .LightningPaymentDirection import LightningPaymentDirection
14+
15+
16+
@dataclass
17+
class LightsparkNodeToDailyLiquidityForecastsConnection:
18+
requester: Requester
19+
20+
from_date: datetime
21+
22+
to_date: datetime
23+
24+
direction: LightningPaymentDirection
25+
26+
entities: List[DailyLiquidityForecast]
27+
"""The daily liquidity forecasts for the current page of this connection."""
28+
29+
def to_json(self) -> Mapping[str, Any]:
30+
return {
31+
"lightspark_node_to_daily_liquidity_forecasts_connection_from_date": self.from_date,
32+
"lightspark_node_to_daily_liquidity_forecasts_connection_to_date": self.to_date,
33+
"lightspark_node_to_daily_liquidity_forecasts_connection_direction": self.direction.value,
34+
"lightspark_node_to_daily_liquidity_forecasts_connection_entities": [
35+
e.to_json() for e in self.entities
36+
],
37+
}
38+
39+
40+
FRAGMENT = """
41+
fragment LightsparkNodeToDailyLiquidityForecastsConnectionFragment on LightsparkNodeToDailyLiquidityForecastsConnection {
42+
__typename
43+
lightspark_node_to_daily_liquidity_forecasts_connection_from_date: from_date
44+
lightspark_node_to_daily_liquidity_forecasts_connection_to_date: to_date
45+
lightspark_node_to_daily_liquidity_forecasts_connection_direction: direction
46+
lightspark_node_to_daily_liquidity_forecasts_connection_entities: entities {
47+
__typename
48+
daily_liquidity_forecast_date: date
49+
daily_liquidity_forecast_direction: direction
50+
daily_liquidity_forecast_amount: amount {
51+
__typename
52+
currency_amount_original_value: original_value
53+
currency_amount_original_unit: original_unit
54+
currency_amount_preferred_currency_unit: preferred_currency_unit
55+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
56+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
57+
}
58+
}
59+
}
60+
"""
61+
62+
63+
def from_json(
64+
requester: Requester, obj: Mapping[str, Any]
65+
) -> LightsparkNodeToDailyLiquidityForecastsConnection:
66+
return LightsparkNodeToDailyLiquidityForecastsConnection(
67+
requester=requester,
68+
from_date=obj[
69+
"lightspark_node_to_daily_liquidity_forecasts_connection_from_date"
70+
],
71+
to_date=obj["lightspark_node_to_daily_liquidity_forecasts_connection_to_date"],
72+
direction=parse_enum(
73+
LightningPaymentDirection,
74+
obj["lightspark_node_to_daily_liquidity_forecasts_connection_direction"],
75+
),
76+
entities=list(
77+
map(
78+
# pylint: disable=unnecessary-lambda
79+
lambda e: DailyLiquidityForecast_from_json(requester, e),
80+
obj["lightspark_node_to_daily_liquidity_forecasts_connection_entities"],
81+
)
82+
),
83+
)

0 commit comments

Comments
 (0)