@@ -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 )
0 commit comments