Skip to content

Commit 9d44ad6

Browse files
committed
Add payment preimage to OutgoingPayment
1 parent 0d672f2 commit 9d44ad6

24 files changed

Lines changed: 206 additions & 3 deletions

lightspark/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from lightspark.objects.ChannelClosingTransaction import ChannelClosingTransaction
2222
from lightspark.objects.ChannelFees import ChannelFees
2323
from lightspark.objects.ChannelOpeningTransaction import ChannelOpeningTransaction
24+
from lightspark.objects.ChannelSnapshot import ChannelSnapshot
2425
from lightspark.objects.ChannelStatus import ChannelStatus
2526
from lightspark.objects.ChannelToTransactionsConnection import (
2627
ChannelToTransactionsConnection,

lightspark/objects/Account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ def get_transactions(
11361136
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
11371137
}
11381138
}
1139+
outgoing_payment_payment_preimage: payment_preimage
11391140
}
11401141
... on RoutingTransaction {
11411142
__typename
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
3+
from dataclasses import dataclass
4+
from typing import Any, Mapping, Optional
5+
6+
from lightspark.requests.requester import Requester
7+
8+
from .CurrencyAmount import CurrencyAmount
9+
from .CurrencyAmount import from_json as CurrencyAmount_from_json
10+
11+
12+
@dataclass
13+
class ChannelSnapshot:
14+
requester: Requester
15+
16+
local_balance: Optional[CurrencyAmount]
17+
18+
local_unsettled_balance: Optional[CurrencyAmount]
19+
20+
local_channel_reserve: Optional[CurrencyAmount]
21+
22+
23+
FRAGMENT = """
24+
fragment ChannelSnapshotFragment on ChannelSnapshot {
25+
__typename
26+
channel_snapshot_local_balance: local_balance {
27+
__typename
28+
currency_amount_original_value: original_value
29+
currency_amount_original_unit: original_unit
30+
currency_amount_preferred_currency_unit: preferred_currency_unit
31+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
32+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
33+
}
34+
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
35+
__typename
36+
currency_amount_original_value: original_value
37+
currency_amount_original_unit: original_unit
38+
currency_amount_preferred_currency_unit: preferred_currency_unit
39+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
40+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
41+
}
42+
channel_snapshot_local_channel_reserve: local_channel_reserve {
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]) -> ChannelSnapshot:
55+
return ChannelSnapshot(
56+
requester=requester,
57+
local_balance=CurrencyAmount_from_json(
58+
requester, obj["channel_snapshot_local_balance"]
59+
)
60+
if obj["channel_snapshot_local_balance"]
61+
else None,
62+
local_unsettled_balance=CurrencyAmount_from_json(
63+
requester, obj["channel_snapshot_local_unsettled_balance"]
64+
)
65+
if obj["channel_snapshot_local_unsettled_balance"]
66+
else None,
67+
local_channel_reserve=CurrencyAmount_from_json(
68+
requester, obj["channel_snapshot_local_channel_reserve"]
69+
)
70+
if obj["channel_snapshot_local_channel_reserve"]
71+
else None,
72+
)

lightspark/objects/Entity.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ class Entity:
10701070
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
10711071
}
10721072
}
1073+
outgoing_payment_payment_preimage: payment_preimage
10731074
}
10741075
... on OutgoingPaymentAttempt {
10751076
__typename
@@ -1099,6 +1100,33 @@ class Entity:
10991100
outgoing_payment_attempt_outgoing_payment: outgoing_payment {
11001101
id
11011102
}
1103+
outgoing_payment_attempt_channel_snapshot: channel_snapshot {
1104+
__typename
1105+
channel_snapshot_local_balance: local_balance {
1106+
__typename
1107+
currency_amount_original_value: original_value
1108+
currency_amount_original_unit: original_unit
1109+
currency_amount_preferred_currency_unit: preferred_currency_unit
1110+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1111+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1112+
}
1113+
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
1114+
__typename
1115+
currency_amount_original_value: original_value
1116+
currency_amount_original_unit: original_unit
1117+
currency_amount_preferred_currency_unit: preferred_currency_unit
1118+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1119+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1120+
}
1121+
channel_snapshot_local_channel_reserve: local_channel_reserve {
1122+
__typename
1123+
currency_amount_original_value: original_value
1124+
currency_amount_original_unit: original_unit
1125+
currency_amount_preferred_currency_unit: preferred_currency_unit
1126+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
1127+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
1128+
}
1129+
}
11021130
}
11031131
... on RoutingTransaction {
11041132
__typename

lightspark/objects/IdAndSignature.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
@dataclass
88
class IdAndSignature:
99
id: str
10+
"""The id of the message."""
1011

1112
signature: str
13+
"""The signature of the message."""
1214

1315

1416
def from_json(obj: Mapping[str, Any]) -> IdAndSignature:

lightspark/objects/LightningTransaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ class LightningTransaction(Transaction, Entity):
377377
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
378378
}
379379
}
380+
outgoing_payment_payment_preimage: payment_preimage
380381
}
381382
... on RoutingTransaction {
382383
__typename
@@ -490,6 +491,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> LightningTransact
490491
)
491492
if obj["outgoing_payment_uma_post_transaction_data"]
492493
else None,
494+
payment_preimage=obj["outgoing_payment_payment_preimage"],
493495
)
494496
if obj["__typename"] == "RoutingTransaction":
495497
# pylint: disable=import-outside-toplevel

lightspark/objects/OutgoingPayment.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class OutgoingPayment(LightningTransaction, Transaction, Entity):
7575

7676
uma_post_transaction_data: Optional[List[PostTransactionData]]
7777
"""The post transaction data which can be used in KYT payment registration."""
78+
79+
payment_preimage: Optional[str]
80+
"""The preimage of the payment."""
7881
typename: str
7982

8083
def get_attempts(
@@ -123,6 +126,33 @@ def get_attempts(
123126
outgoing_payment_attempt_outgoing_payment: outgoing_payment {
124127
id
125128
}
129+
outgoing_payment_attempt_channel_snapshot: channel_snapshot {
130+
__typename
131+
channel_snapshot_local_balance: local_balance {
132+
__typename
133+
currency_amount_original_value: original_value
134+
currency_amount_original_unit: original_unit
135+
currency_amount_preferred_currency_unit: preferred_currency_unit
136+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
137+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
138+
}
139+
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
140+
__typename
141+
currency_amount_original_value: original_value
142+
currency_amount_original_unit: original_unit
143+
currency_amount_preferred_currency_unit: preferred_currency_unit
144+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
145+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
146+
}
147+
channel_snapshot_local_channel_reserve: local_channel_reserve {
148+
__typename
149+
currency_amount_original_value: original_value
150+
currency_amount_original_unit: original_unit
151+
currency_amount_preferred_currency_unit: preferred_currency_unit
152+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
153+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
154+
}
155+
}
126156
}
127157
}
128158
}
@@ -423,6 +453,7 @@ def get_attempts(
423453
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
424454
}
425455
}
456+
outgoing_payment_payment_preimage: payment_preimage
426457
}
427458
"""
428459

@@ -467,4 +498,5 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> OutgoingPayment:
467498
)
468499
if obj["outgoing_payment_uma_post_transaction_data"]
469500
else None,
501+
payment_preimage=obj["outgoing_payment_payment_preimage"],
470502
)

lightspark/objects/OutgoingPaymentAttempt.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from lightspark.requests.requester import Requester
1010
from lightspark.utils.enums import parse_enum, parse_enum_optional
1111

12+
from .ChannelSnapshot import ChannelSnapshot
13+
from .ChannelSnapshot import from_json as ChannelSnapshot_from_json
1214
from .CurrencyAmount import CurrencyAmount
1315
from .CurrencyAmount import from_json as CurrencyAmount_from_json
1416
from .Entity import Entity
@@ -57,6 +59,9 @@ class OutgoingPaymentAttempt(Entity):
5759

5860
outgoing_payment_id: str
5961
"""The outgoing payment for this attempt."""
62+
63+
channel_snapshot: Optional[ChannelSnapshot]
64+
"""The channel snapshot at the time the outgoing payment attempt was made."""
6065
typename: str
6166

6267
def get_hops(
@@ -147,6 +152,33 @@ def get_hops(
147152
outgoing_payment_attempt_outgoing_payment: outgoing_payment {
148153
id
149154
}
155+
outgoing_payment_attempt_channel_snapshot: channel_snapshot {
156+
__typename
157+
channel_snapshot_local_balance: local_balance {
158+
__typename
159+
currency_amount_original_value: original_value
160+
currency_amount_original_unit: original_unit
161+
currency_amount_preferred_currency_unit: preferred_currency_unit
162+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
163+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
164+
}
165+
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
166+
__typename
167+
currency_amount_original_value: original_value
168+
currency_amount_original_unit: original_unit
169+
currency_amount_preferred_currency_unit: preferred_currency_unit
170+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
171+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
172+
}
173+
channel_snapshot_local_channel_reserve: local_channel_reserve {
174+
__typename
175+
currency_amount_original_value: original_value
176+
currency_amount_original_unit: original_unit
177+
currency_amount_preferred_currency_unit: preferred_currency_unit
178+
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
179+
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
180+
}
181+
}
150182
}
151183
"""
152184

@@ -175,4 +207,9 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> OutgoingPaymentAt
175207
if obj["outgoing_payment_attempt_fees"]
176208
else None,
177209
outgoing_payment_id=obj["outgoing_payment_attempt_outgoing_payment"]["id"],
210+
channel_snapshot=ChannelSnapshot_from_json(
211+
requester, obj["outgoing_payment_attempt_channel_snapshot"]
212+
)
213+
if obj["outgoing_payment_attempt_channel_snapshot"]
214+
else None,
178215
)

lightspark/objects/RegisterPaymentInput.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
@dataclass
1515
class RegisterPaymentInput:
1616
provider: ComplianceProvider
17+
"""The compliance provider that is going to screen the node. You need to be a customer of the selected provider and store the API key on the Lightspark account setting page."""
1718

1819
payment_id: str
20+
"""The Lightspark ID of the lightning payment you want to register. It can be the id of either an OutgoingPayment or an IncomingPayment."""
1921

2022
node_pubkey: str
23+
"""The public key of the counterparty lightning node, which would be the public key of the recipient node if it is to register an outgoing payment, or the public key of the sender node if it is to register an incoming payment."""
2124

2225
direction: PaymentDirection
26+
"""Indicates whether this payment is an OutgoingPayment or an IncomingPayment."""
2327

2428

2529
def from_json(obj: Mapping[str, Any]) -> RegisterPaymentInput:

lightspark/objects/ReleaseChannelPerCommitmentSecretInput.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
@dataclass
88
class ReleaseChannelPerCommitmentSecretInput:
99
channel_id: str
10+
"""The unique identifier of the channel."""
1011

1112
per_commitment_secret: str
13+
"""The per-commitment secret to be released."""
1214

1315
per_commitment_index: int
16+
"""The index associated with the per-commitment secret."""
1417

1518

1619
def from_json(obj: Mapping[str, Any]) -> ReleaseChannelPerCommitmentSecretInput:

0 commit comments

Comments
 (0)