@@ -137,17 +137,18 @@ def create_invoice(
137
137
amount_msats : int ,
138
138
memo : Optional [str ] = None ,
139
139
invoice_type : Optional [InvoiceType ] = None ,
140
+ expiry_secs : Optional [int ] = None ,
140
141
) -> Invoice :
141
142
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 )
151
152
152
153
return Invoice_from_json (self ._requester , json ["create_invoice" ]["invoice" ])
153
154
@@ -156,6 +157,7 @@ def create_lnurl_invoice(
156
157
node_id : str ,
157
158
amount_msats : int ,
158
159
metadata : str ,
160
+ expiry_secs : Optional [int ] = None ,
159
161
) -> Invoice :
160
162
"""Generates a Lightning Invoice (follows the Bolt 11 specification) to request a payment
161
163
from another Lightning Node. This should only be used for generating invoices for LNURLs,
@@ -168,19 +170,21 @@ def create_lnurl_invoice(
168
170
metadata (str): The LNURL metadata payload field in the initial payreq response. This
169
171
will be hashed and present in the h-tag (SHA256 purpose of payment) of the resulting
170
172
Bolt 11 invoice.
173
+ expiry_secs (int, optional): The number of seconds after which the invoice will expire.
174
+ Defaults to 1 day.
171
175
172
176
Returns:
173
177
Invoice: An `Invoice` object representing the generated invoice.
174
178
"""
175
179
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 )
184
188
185
189
return Invoice_from_json (
186
190
self ._requester , json ["create_lnurl_invoice" ]["invoice" ]
@@ -244,6 +248,7 @@ def create_uma_invoice(
244
248
node_id : str ,
245
249
amount_msats : int ,
246
250
metadata : str ,
251
+ expiry_secs : Optional [int ] = None ,
247
252
) -> Invoice :
248
253
logger .info ("Creating an uma invoice for node %s." , node_id )
249
254
json = self ._requester .execute_graphql (
@@ -252,12 +257,11 @@ def create_uma_invoice(
252
257
"amount_msats" : amount_msats ,
253
258
"node_id" : node_id ,
254
259
"metadata_hash" : sha256 (metadata .encode ("utf-8" )).hexdigest (),
260
+ "expiry_secs" : expiry_secs if expiry_secs is not None else 600 ,
255
261
},
256
262
)
257
263
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" ])
261
265
262
266
def delete_api_token (self , api_token_id : str ) -> None :
263
267
logger .info ("Deleting API token %s." , api_token_id )
0 commit comments