-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathChannelSnapshot.py
More file actions
175 lines (153 loc) · 6.71 KB
/
ChannelSnapshot.py
File metadata and controls
175 lines (153 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
from dataclasses import dataclass
from datetime import datetime
from typing import Any, Mapping, Optional
from lightspark.requests.requester import Requester
from .CurrencyAmount import CurrencyAmount
from .CurrencyAmount import from_json as CurrencyAmount_from_json
from .Entity import Entity
@dataclass
class ChannelSnapshot(Entity):
requester: Requester
id: str
"""The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string."""
created_at: datetime
"""The date and time when the entity was first created."""
updated_at: datetime
"""The date and time when the entity was last updated."""
local_balance: Optional[CurrencyAmount]
local_unsettled_balance: Optional[CurrencyAmount]
remote_balance: Optional[CurrencyAmount]
remote_unsettled_balance: Optional[CurrencyAmount]
status: Optional[str]
channel_id: str
local_channel_reserve: Optional[CurrencyAmount]
timestamp: datetime
"""The timestamp that was used to query the snapshot of the channel"""
typename: str
def to_json(self) -> Mapping[str, Any]:
return {
"__typename": "ChannelSnapshot",
"channel_snapshot_id": self.id,
"channel_snapshot_created_at": self.created_at.isoformat(),
"channel_snapshot_updated_at": self.updated_at.isoformat(),
"channel_snapshot_local_balance": (
self.local_balance.to_json() if self.local_balance else None
),
"channel_snapshot_local_unsettled_balance": (
self.local_unsettled_balance.to_json()
if self.local_unsettled_balance
else None
),
"channel_snapshot_remote_balance": (
self.remote_balance.to_json() if self.remote_balance else None
),
"channel_snapshot_remote_unsettled_balance": (
self.remote_unsettled_balance.to_json()
if self.remote_unsettled_balance
else None
),
"channel_snapshot_status": self.status,
"channel_snapshot_channel": {"id": self.channel_id},
"channel_snapshot_local_channel_reserve": (
self.local_channel_reserve.to_json()
if self.local_channel_reserve
else None
),
"channel_snapshot_timestamp": self.timestamp.isoformat(),
}
FRAGMENT = """
fragment ChannelSnapshotFragment on ChannelSnapshot {
__typename
channel_snapshot_id: id
channel_snapshot_created_at: created_at
channel_snapshot_updated_at: updated_at
channel_snapshot_local_balance: local_balance {
__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
}
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
__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
}
channel_snapshot_remote_balance: remote_balance {
__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
}
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
__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
}
channel_snapshot_status: status
channel_snapshot_channel: channel {
id
}
channel_snapshot_local_channel_reserve: local_channel_reserve {
__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
}
channel_snapshot_timestamp: timestamp
}
"""
def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
return ChannelSnapshot(
requester=requester,
typename="ChannelSnapshot",
id=obj["channel_snapshot_id"],
created_at=datetime.fromisoformat(obj["channel_snapshot_created_at"]),
updated_at=datetime.fromisoformat(obj["channel_snapshot_updated_at"]),
local_balance=(
CurrencyAmount_from_json(requester, obj["channel_snapshot_local_balance"])
if obj["channel_snapshot_local_balance"]
else None
),
local_unsettled_balance=(
CurrencyAmount_from_json(
requester, obj["channel_snapshot_local_unsettled_balance"]
)
if obj["channel_snapshot_local_unsettled_balance"]
else None
),
remote_balance=(
CurrencyAmount_from_json(requester, obj["channel_snapshot_remote_balance"])
if obj["channel_snapshot_remote_balance"]
else None
),
remote_unsettled_balance=(
CurrencyAmount_from_json(
requester, obj["channel_snapshot_remote_unsettled_balance"]
)
if obj["channel_snapshot_remote_unsettled_balance"]
else None
),
status=obj["channel_snapshot_status"],
channel_id=obj["channel_snapshot_channel"]["id"],
local_channel_reserve=(
CurrencyAmount_from_json(
requester, obj["channel_snapshot_local_channel_reserve"]
)
if obj["channel_snapshot_local_channel_reserve"]
else None
),
timestamp=datetime.fromisoformat(obj["channel_snapshot_timestamp"]),
)