Skip to content

Commit dcd6237

Browse files
Lightspark Engjklein24
Lightspark Eng
authored andcommitted
Project import generated by Copybara.
GitOrigin-RevId: 377b0ab32b4de60755ef95439c0c0a1df060cabf
1 parent cdca495 commit dcd6237

8 files changed

+43
-23
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
# v1.4.3
4+
5+
- Fix a few UMA bugs/ommisions:
6+
- Add expiry_secs to invoice calls
7+
- Parse create_uma_invoice correctly
8+
- Add fees to the invoice amount
9+
310
# v1.4.2
411

512
- Fix a packaging problem with UMA.

lightspark/lightspark_client.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ def create_invoice(
137137
amount_msats: int,
138138
memo: Optional[str] = None,
139139
invoice_type: Optional[InvoiceType] = None,
140+
expiry_secs: Optional[int] = None,
140141
) -> Invoice:
141142
logger.info("Creating an invoice for node %s.", node_id)
142-
json = self._requester.execute_graphql(
143-
CREATE_INVOICE_MUTATION,
144-
{
145-
"amount_msats": amount_msats,
146-
"node_id": node_id,
147-
"memo": memo,
148-
"invoice_type": invoice_type,
149-
},
150-
)
143+
variables = {
144+
"amount_msats": amount_msats,
145+
"node_id": node_id,
146+
"memo": memo,
147+
"invoice_type": invoice_type,
148+
}
149+
if expiry_secs is not None:
150+
variables["expiry_secs"] = expiry_secs
151+
json = self._requester.execute_graphql(CREATE_INVOICE_MUTATION, variables)
151152

152153
return Invoice_from_json(self._requester, json["create_invoice"]["invoice"])
153154

@@ -156,6 +157,7 @@ def create_lnurl_invoice(
156157
node_id: str,
157158
amount_msats: int,
158159
metadata: str,
160+
expiry_secs: Optional[int] = None,
159161
) -> Invoice:
160162
"""Generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
161163
from another Lightning Node. This should only be used for generating invoices for LNURLs,
@@ -168,19 +170,21 @@ def create_lnurl_invoice(
168170
metadata (str): The LNURL metadata payload field in the initial payreq response. This
169171
will be hashed and present in the h-tag (SHA256 purpose of payment) of the resulting
170172
Bolt 11 invoice.
173+
expiry_secs (int, optional): The number of seconds after which the invoice will expire.
174+
Defaults to 1 day.
171175
172176
Returns:
173177
Invoice: An `Invoice` object representing the generated invoice.
174178
"""
175179
logger.info("Creating an lnurl invoice for node %s.", node_id)
176-
json = self._requester.execute_graphql(
177-
CREATE_LNURL_INVOICE_MUTATION,
178-
{
179-
"amount_msats": amount_msats,
180-
"node_id": node_id,
181-
"metadata_hash": sha256(metadata.encode("utf-8")).hexdigest(),
182-
},
183-
)
180+
variables = {
181+
"amount_msats": amount_msats,
182+
"node_id": node_id,
183+
"metadata_hash": sha256(metadata.encode("utf-8")).hexdigest(),
184+
}
185+
if expiry_secs is not None:
186+
variables["expiry_secs"] = expiry_secs
187+
json = self._requester.execute_graphql(CREATE_LNURL_INVOICE_MUTATION, variables)
184188

185189
return Invoice_from_json(
186190
self._requester, json["create_lnurl_invoice"]["invoice"]
@@ -244,6 +248,7 @@ def create_uma_invoice(
244248
node_id: str,
245249
amount_msats: int,
246250
metadata: str,
251+
expiry_secs: Optional[int] = None,
247252
) -> Invoice:
248253
logger.info("Creating an uma invoice for node %s.", node_id)
249254
json = self._requester.execute_graphql(
@@ -252,12 +257,11 @@ def create_uma_invoice(
252257
"amount_msats": amount_msats,
253258
"node_id": node_id,
254259
"metadata_hash": sha256(metadata.encode("utf-8")).hexdigest(),
260+
"expiry_secs": expiry_secs if expiry_secs is not None else 600,
255261
},
256262
)
257263

258-
return Invoice_from_json(
259-
self._requester, json["create_lnurl_invoice"]["invoice"]
260-
)
264+
return Invoice_from_json(self._requester, json["create_uma_invoice"]["invoice"])
261265

262266
def delete_api_token(self, api_token_id: str) -> None:
263267
logger.info("Deleting API token %s.", api_token_id)

lightspark/scripts/create_invoice.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
$amount_msats: Long!
99
$memo: String
1010
$invoice_type: InvoiceType
11+
$expiry_secs: Int
1112
) {{
1213
create_invoice(input: {{
1314
node_id: $node_id
1415
amount_msats: $amount_msats
1516
memo: $memo
1617
invoice_type: $invoice_type
18+
expiry_secs: $expiry_secs
1719
}}) {{
1820
invoice {{
1921
...InvoiceFragment

lightspark/scripts/create_lnurl_invoice.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
$node_id: ID!
88
$amount_msats: Long!
99
$metadata_hash: String!
10+
$expiry_secs: Int
1011
) {{
1112
create_lnurl_invoice(input: {{
1213
node_id: $node_id
1314
amount_msats: $amount_msats
1415
metadata_hash: $metadata_hash
16+
expiry_secs: $expiry_secs
1517
}}) {{
1618
invoice {{
1719
...InvoiceFragment

lightspark/scripts/create_uma_invoice.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
$node_id: ID!
88
$amount_msats: Long!
99
$metadata_hash: String!
10+
$expiry_secs: Int
1011
) {{
1112
create_uma_invoice(input: {{
1213
node_id: $node_id
1314
amount_msats: $amount_msats
1415
metadata_hash: $metadata_hash
16+
expiry_secs: $expiry_secs
1517
}}) {{
1618
invoice {{
1719
...InvoiceFragment

lightspark/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.4.2"
1+
__version__ = "1.4.3"

uma/uma.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def create_pay_req_response(
304304
utxo_callback: the URL that the receiving VASP will call to send UTXOs of the channel that the receiver used to receive the payment once it completes.
305305
"""
306306

307-
amount_msats = request.amount * msats_per_currency_unit
307+
amount_msats = request.amount * msats_per_currency_unit + receiver_fees_msats
308308
metadata += "{" + request.payer_data.to_json() + "}"
309309
encoded_invoice = invoice_creator.create_uma_invoice(
310310
amount_msats=amount_msats,

uma/uma_invoice_creator.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def create_uma_invoice(
3333
metadata: str,
3434
) -> str:
3535
invoice = self.lightspark_client.create_uma_invoice(
36-
self.node_id, amount_msats=amount_msats, metadata=metadata
36+
self.node_id,
37+
amount_msats=amount_msats,
38+
metadata=metadata,
39+
expiry_secs=self.expiry_secs,
3740
)
3841
return invoice.data.encoded_payment_request

0 commit comments

Comments
 (0)