Skip to content

Commit c6cdd88

Browse files
authored
Add the is_uma flag to payments. (#22)
2 parents a4c16c9 + 9d1dd53 commit c6cdd88

File tree

12 files changed

+145
-167
lines changed

12 files changed

+145
-167
lines changed

lightspark/objects/Account.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ def get_transactions(
898898
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
899899
}
900900
incoming_payment_transaction_hash: transaction_hash
901+
incoming_payment_is_uma: is_uma
901902
incoming_payment_destination: destination {
902903
id
903904
}
@@ -933,6 +934,7 @@ def get_transactions(
933934
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
934935
}
935936
outgoing_payment_transaction_hash: transaction_hash
937+
outgoing_payment_is_uma: is_uma
936938
outgoing_payment_origin: origin {
937939
id
938940
}

lightspark/objects/CancelInvoiceInput.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
@dataclass
88
class CancelInvoiceInput:
9+
"""The unique identifier of the Invoice that should be cancelled. The invoice is supposed to be open, not settled and not expired."""
10+
911
invoice_id: str
1012

1113
def to_json(self) -> Mapping[str, Any]:

lightspark/objects/CancelInvoiceOutput.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
@dataclass
1010
class CancelInvoiceOutput:
11+
"""The Invoice that was cancelled. If the invoice was already cancelled, the same invoice is returned."""
12+
1113
requester: Requester
1214

1315
invoice_id: str

lightspark/objects/ChannelSnapshot.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,70 @@
88

99
from .CurrencyAmount import CurrencyAmount
1010
from .CurrencyAmount import from_json as CurrencyAmount_from_json
11+
from .Entity import Entity
1112

1213

1314
@dataclass
14-
class ChannelSnapshot:
15+
class ChannelSnapshot(Entity):
1516
requester: Requester
1617

17-
channel_id: str
18+
id: str
19+
"""The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string."""
1820

19-
timestamp: datetime
21+
created_at: datetime
22+
"""The date and time when the entity was first created."""
23+
24+
updated_at: datetime
25+
"""The date and time when the entity was last updated."""
2026

2127
local_balance: Optional[CurrencyAmount]
2228

2329
local_unsettled_balance: Optional[CurrencyAmount]
2430

25-
local_channel_reserve: Optional[CurrencyAmount]
26-
2731
remote_balance: Optional[CurrencyAmount]
2832

2933
remote_unsettled_balance: Optional[CurrencyAmount]
3034

35+
channel_id: str
36+
37+
local_channel_reserve: Optional[CurrencyAmount]
38+
39+
timestamp: datetime
40+
"""The timestamp that was used to query the snapshot of the channel"""
41+
typename: str
42+
3143
def to_json(self) -> Mapping[str, Any]:
3244
return {
33-
"channel_snapshot_channel": {"id": self.channel_id},
34-
"channel_snapshot_timestamp": self.timestamp.isoformat(),
45+
"__typename": "ChannelSnapshot",
46+
"channel_snapshot_id": self.id,
47+
"channel_snapshot_created_at": self.created_at.isoformat(),
48+
"channel_snapshot_updated_at": self.updated_at.isoformat(),
3549
"channel_snapshot_local_balance": self.local_balance.to_json()
3650
if self.local_balance
3751
else None,
3852
"channel_snapshot_local_unsettled_balance": self.local_unsettled_balance.to_json()
3953
if self.local_unsettled_balance
4054
else None,
41-
"channel_snapshot_local_channel_reserve": self.local_channel_reserve.to_json()
42-
if self.local_channel_reserve
43-
else None,
4455
"channel_snapshot_remote_balance": self.remote_balance.to_json()
4556
if self.remote_balance
4657
else None,
4758
"channel_snapshot_remote_unsettled_balance": self.remote_unsettled_balance.to_json()
4859
if self.remote_unsettled_balance
4960
else None,
61+
"channel_snapshot_channel": {"id": self.channel_id},
62+
"channel_snapshot_local_channel_reserve": self.local_channel_reserve.to_json()
63+
if self.local_channel_reserve
64+
else None,
65+
"channel_snapshot_timestamp": self.timestamp.isoformat(),
5066
}
5167

5268

5369
FRAGMENT = """
5470
fragment ChannelSnapshotFragment on ChannelSnapshot {
5571
__typename
56-
channel_snapshot_channel: channel {
57-
id
58-
}
59-
channel_snapshot_timestamp: timestamp
72+
channel_snapshot_id: id
73+
channel_snapshot_created_at: created_at
74+
channel_snapshot_updated_at: updated_at
6075
channel_snapshot_local_balance: local_balance {
6176
__typename
6277
currency_amount_original_value: original_value
@@ -73,39 +88,45 @@ def to_json(self) -> Mapping[str, Any]:
7388
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
7489
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
7590
}
76-
channel_snapshot_local_channel_reserve: local_channel_reserve {
91+
channel_snapshot_remote_balance: remote_balance {
7792
__typename
7893
currency_amount_original_value: original_value
7994
currency_amount_original_unit: original_unit
8095
currency_amount_preferred_currency_unit: preferred_currency_unit
8196
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
8297
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
8398
}
84-
channel_snapshot_remote_balance: remote_balance {
99+
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
85100
__typename
86101
currency_amount_original_value: original_value
87102
currency_amount_original_unit: original_unit
88103
currency_amount_preferred_currency_unit: preferred_currency_unit
89104
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
90105
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
91106
}
92-
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
107+
channel_snapshot_channel: channel {
108+
id
109+
}
110+
channel_snapshot_local_channel_reserve: local_channel_reserve {
93111
__typename
94112
currency_amount_original_value: original_value
95113
currency_amount_original_unit: original_unit
96114
currency_amount_preferred_currency_unit: preferred_currency_unit
97115
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
98116
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
99117
}
118+
channel_snapshot_timestamp: timestamp
100119
}
101120
"""
102121

103122

104123
def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
105124
return ChannelSnapshot(
106125
requester=requester,
107-
channel_id=obj["channel_snapshot_channel"]["id"],
108-
timestamp=datetime.fromisoformat(obj["channel_snapshot_timestamp"]),
126+
typename="ChannelSnapshot",
127+
id=obj["channel_snapshot_id"],
128+
created_at=datetime.fromisoformat(obj["channel_snapshot_created_at"]),
129+
updated_at=datetime.fromisoformat(obj["channel_snapshot_updated_at"]),
109130
local_balance=CurrencyAmount_from_json(
110131
requester, obj["channel_snapshot_local_balance"]
111132
)
@@ -116,11 +137,6 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
116137
)
117138
if obj["channel_snapshot_local_unsettled_balance"]
118139
else None,
119-
local_channel_reserve=CurrencyAmount_from_json(
120-
requester, obj["channel_snapshot_local_channel_reserve"]
121-
)
122-
if obj["channel_snapshot_local_channel_reserve"]
123-
else None,
124140
remote_balance=CurrencyAmount_from_json(
125141
requester, obj["channel_snapshot_remote_balance"]
126142
)
@@ -131,4 +147,11 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
131147
)
132148
if obj["channel_snapshot_remote_unsettled_balance"]
133149
else None,
150+
channel_id=obj["channel_snapshot_channel"]["id"],
151+
local_channel_reserve=CurrencyAmount_from_json(
152+
requester, obj["channel_snapshot_local_channel_reserve"]
153+
)
154+
if obj["channel_snapshot_local_channel_reserve"]
155+
else None,
156+
timestamp=datetime.fromisoformat(obj["channel_snapshot_timestamp"]),
134157
)

lightspark/objects/Entity.py

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,56 @@ class Entity:
200200
id
201201
}
202202
}
203+
... on ChannelSnapshot {
204+
__typename
205+
channel_snapshot_id: id
206+
channel_snapshot_created_at: created_at
207+
channel_snapshot_updated_at: updated_at
208+
channel_snapshot_local_balance: local_balance {
209+
__typename
210+
currency_amount_original_value: original_value
211+
currency_amount_original_unit: original_unit
212+
currency_amount_preferred_currency_unit: preferred_currency_unit
213+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
214+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
215+
}
216+
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
217+
__typename
218+
currency_amount_original_value: original_value
219+
currency_amount_original_unit: original_unit
220+
currency_amount_preferred_currency_unit: preferred_currency_unit
221+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
222+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
223+
}
224+
channel_snapshot_remote_balance: remote_balance {
225+
__typename
226+
currency_amount_original_value: original_value
227+
currency_amount_original_unit: original_unit
228+
currency_amount_preferred_currency_unit: preferred_currency_unit
229+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
230+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
231+
}
232+
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
233+
__typename
234+
currency_amount_original_value: original_value
235+
currency_amount_original_unit: original_unit
236+
currency_amount_preferred_currency_unit: preferred_currency_unit
237+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
238+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
239+
}
240+
channel_snapshot_channel: channel {
241+
id
242+
}
243+
channel_snapshot_local_channel_reserve: local_channel_reserve {
244+
__typename
245+
currency_amount_original_value: original_value
246+
currency_amount_original_unit: original_unit
247+
currency_amount_preferred_currency_unit: preferred_currency_unit
248+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
249+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
250+
}
251+
channel_snapshot_timestamp: timestamp
252+
}
203253
... on Deposit {
204254
__typename
205255
deposit_id: id
@@ -288,6 +338,7 @@ class Entity:
288338
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
289339
}
290340
incoming_payment_transaction_hash: transaction_hash
341+
incoming_payment_is_uma: is_uma
291342
incoming_payment_destination: destination {
292343
id
293344
}
@@ -907,6 +958,7 @@ class Entity:
907958
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
908959
}
909960
outgoing_payment_transaction_hash: transaction_hash
961+
outgoing_payment_is_uma: is_uma
910962
outgoing_payment_origin: origin {
911963
id
912964
}
@@ -1264,51 +1316,7 @@ class Entity:
12641316
id
12651317
}
12661318
outgoing_payment_attempt_channel_snapshot: channel_snapshot {
1267-
__typename
1268-
channel_snapshot_channel: channel {
1269-
id
1270-
}
1271-
channel_snapshot_timestamp: timestamp
1272-
channel_snapshot_local_balance: local_balance {
1273-
__typename
1274-
currency_amount_original_value: original_value
1275-
currency_amount_original_unit: original_unit
1276-
currency_amount_preferred_currency_unit: preferred_currency_unit
1277-
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1278-
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1279-
}
1280-
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
1281-
__typename
1282-
currency_amount_original_value: original_value
1283-
currency_amount_original_unit: original_unit
1284-
currency_amount_preferred_currency_unit: preferred_currency_unit
1285-
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1286-
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1287-
}
1288-
channel_snapshot_local_channel_reserve: local_channel_reserve {
1289-
__typename
1290-
currency_amount_original_value: original_value
1291-
currency_amount_original_unit: original_unit
1292-
currency_amount_preferred_currency_unit: preferred_currency_unit
1293-
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1294-
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1295-
}
1296-
channel_snapshot_remote_balance: remote_balance {
1297-
__typename
1298-
currency_amount_original_value: original_value
1299-
currency_amount_original_unit: original_unit
1300-
currency_amount_preferred_currency_unit: preferred_currency_unit
1301-
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1302-
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1303-
}
1304-
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
1305-
__typename
1306-
currency_amount_original_value: original_value
1307-
currency_amount_original_unit: original_unit
1308-
currency_amount_preferred_currency_unit: preferred_currency_unit
1309-
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1310-
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1311-
}
1319+
id
13121320
}
13131321
}
13141322
... on RoutingTransaction {

lightspark/objects/IncomingPayment.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class IncomingPayment(LightningTransaction, Transaction, Entity):
5050
transaction_hash: Optional[str]
5151
"""The hash of this transaction, so it can be uniquely identified on the Lightning Network."""
5252

53+
is_uma: bool
54+
"""Whether this payment is an UMA payment or not. NOTE: this field is only set if the invoice that is being paid has been created using the recommended `create_uma_invoice` function."""
55+
5356
destination_id: str
5457
"""The recipient Lightspark node this payment was sent to."""
5558

@@ -127,6 +130,7 @@ def to_json(self) -> Mapping[str, Any]:
127130
else None,
128131
"incoming_payment_amount": self.amount.to_json(),
129132
"incoming_payment_transaction_hash": self.transaction_hash,
133+
"incoming_payment_is_uma": self.is_uma,
130134
"incoming_payment_destination": {"id": self.destination_id},
131135
"incoming_payment_payment_request": {"id": self.payment_request_id}
132136
if self.payment_request_id
@@ -156,6 +160,7 @@ def to_json(self) -> Mapping[str, Any]:
156160
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
157161
}
158162
incoming_payment_transaction_hash: transaction_hash
163+
incoming_payment_is_uma: is_uma
159164
incoming_payment_destination: destination {
160165
id
161166
}
@@ -191,6 +196,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> IncomingPayment:
191196
else None,
192197
amount=CurrencyAmount_from_json(requester, obj["incoming_payment_amount"]),
193198
transaction_hash=obj["incoming_payment_transaction_hash"],
199+
is_uma=obj["incoming_payment_is_uma"],
194200
destination_id=obj["incoming_payment_destination"]["id"],
195201
payment_request_id=obj["incoming_payment_payment_request"]["id"]
196202
if obj["incoming_payment_payment_request"]

lightspark/objects/LightningTransaction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def to_json(self) -> Mapping[str, Any]:
8585
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
8686
}
8787
incoming_payment_transaction_hash: transaction_hash
88+
incoming_payment_is_uma: is_uma
8889
incoming_payment_destination: destination {
8990
id
9091
}
@@ -120,6 +121,7 @@ def to_json(self) -> Mapping[str, Any]:
120121
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
121122
}
122123
outgoing_payment_transaction_hash: transaction_hash
124+
outgoing_payment_is_uma: is_uma
123125
outgoing_payment_origin: origin {
124126
id
125127
}
@@ -504,6 +506,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> LightningTransact
504506
else None,
505507
amount=CurrencyAmount_from_json(requester, obj["incoming_payment_amount"]),
506508
transaction_hash=obj["incoming_payment_transaction_hash"],
509+
is_uma=obj["incoming_payment_is_uma"],
507510
destination_id=obj["incoming_payment_destination"]["id"],
508511
payment_request_id=obj["incoming_payment_payment_request"]["id"]
509512
if obj["incoming_payment_payment_request"]
@@ -534,6 +537,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> LightningTransact
534537
else None,
535538
amount=CurrencyAmount_from_json(requester, obj["outgoing_payment_amount"]),
536539
transaction_hash=obj["outgoing_payment_transaction_hash"],
540+
is_uma=obj["outgoing_payment_is_uma"],
537541
origin_id=obj["outgoing_payment_origin"]["id"],
538542
destination_id=obj["outgoing_payment_destination"]["id"]
539543
if obj["outgoing_payment_destination"]

0 commit comments

Comments
 (0)