Skip to content

Commit

Permalink
Generate new objects. (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu authored Jan 2, 2024
2 parents b8cc256 + 71acfab commit 855dca6
Show file tree
Hide file tree
Showing 12 changed files with 459 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lightspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,13 +99,17 @@
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
from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus
from lightspark.objects.LightsparkNodeToChannelsConnection import (
LightsparkNodeToChannelsConnection,
)
from lightspark.objects.LightsparkNodeToDailyLiquidityForecastsConnection import (
LightsparkNodeToDailyLiquidityForecastsConnection,
)
from lightspark.objects.LightsparkNodeWithOSK import LightsparkNodeWithOSK
from lightspark.objects.LightsparkNodeWithRemoteSigning import (
LightsparkNodeWithRemoteSigning,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions lightspark/objects/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -719,6 +727,7 @@ def get_channels(
"after_date": after_date,
"before_date": before_date,
"first": first,
"after": after,
},
)
connection = json["entity"]["channels"]
Expand Down
22 changes: 21 additions & 1 deletion lightspark/objects/AccountToChannelsConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
Expand All @@ -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
}
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lightspark/objects/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions lightspark/objects/DailyLiquidityForecast.py
Original file line number Diff line number Diff line change
@@ -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"]
),
)
14 changes: 14 additions & 0 deletions lightspark/objects/LightningPaymentDirection.py
Original file line number Diff line number Diff line change
@@ -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."""
53 changes: 53 additions & 0 deletions lightspark/objects/LightsparkNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"],
)
),
)
Loading

0 comments on commit 855dca6

Please sign in to comment.