@@ -167,19 +167,8 @@ async fn on_lsps_lsps2_buy(
167
167
. context ( "Failed to create Bolt8Transport" ) ?;
168
168
let client = JsonRpcClient :: new ( transport) ;
169
169
170
- // Convert from AmountOrAny to Msat.
171
- let payment_size_msat = if let Some ( payment_size) = req. payment_size_msat {
172
- match payment_size {
173
- AmountOrAny :: Amount ( amount) => Some ( Msat :: from_msat ( amount. msat ( ) ) ) ,
174
- AmountOrAny :: Any => None ,
175
- }
176
- } else {
177
- None
178
- } ;
179
-
180
170
let selected_params = req. opening_fee_params ;
181
-
182
- if let Some ( payment_size) = payment_size_msat {
171
+ if let Some ( payment_size) = req. payment_size_msat {
183
172
if payment_size < selected_params. min_payment_size_msat {
184
173
return Err ( anyhow ! (
185
174
"Requested payment size {}msat is below minimum {}msat required by LSP" ,
@@ -224,7 +213,7 @@ async fn on_lsps_lsps2_buy(
224
213
debug ! ( "Calling lsps2.buy for peer {}" , req. lsp_id) ;
225
214
let buy_req = Lsps2BuyRequest {
226
215
opening_fee_params : selected_params, // Pass the chosen params back
227
- payment_size_msat,
216
+ payment_size_msat : req . payment_size_msat ,
228
217
} ;
229
218
let buy_res: Lsps2BuyResponse = client
230
219
. call_typed ( buy_req)
@@ -270,16 +259,18 @@ async fn on_lsps_jitchannel(
270
259
#[ derive( Deserialize ) ]
271
260
struct Request {
272
261
lsp_id : String ,
273
- // Optional: for fixed-amount invoices
274
- payment_size_msat : Option < AmountOrAny > ,
275
262
// Optional: for discounts/API keys
276
263
token : Option < String > ,
264
+ // Pass-through of cln invoice rpc params
265
+ pub amount_msat : cln_rpc:: primitives:: AmountOrAny ,
266
+ pub description : String ,
267
+ pub label : String ,
277
268
}
278
269
279
270
let req: Request = serde_json:: from_value ( v) . context ( "Failed to parse request JSON" ) ?;
280
271
debug ! (
281
272
"Handling lsps-buy-jit-channel request for peer {} with payment_size {:?} and token {:?}" ,
282
- req. lsp_id, req. payment_size_msat , req. token
273
+ req. lsp_id, req. amount_msat , req. token
283
274
) ;
284
275
285
276
let dir = p. configuration ( ) . lightning_dir ;
@@ -322,13 +313,18 @@ async fn on_lsps_jitchannel(
322
313
323
314
info ! ( "Selected fee parameters: {:?}" , selected_params) ;
324
315
316
+ let payment_size_msat = match req. amount_msat {
317
+ AmountOrAny :: Amount ( amount) => Some ( Msat :: from_msat ( amount. msat ( ) ) ) ,
318
+ AmountOrAny :: Any => None ,
319
+ } ;
320
+
325
321
// 3. Request channel from LSP.
326
322
let buy_res: Lsps2BuyResponse = cln_client
327
323
. call_raw (
328
324
"lsps-lsps2-buy" ,
329
325
& ClnRpcLsps2BuyRequest {
330
326
lsp_id : req. lsp_id . clone ( ) ,
331
- payment_size_msat : req . payment_size_msat ,
327
+ payment_size_msat,
332
328
opening_fee_params : selected_params. clone ( ) ,
333
329
} ,
334
330
)
@@ -356,20 +352,14 @@ async fn on_lsps_jitchannel(
356
352
cltv_expiry_delta : u16:: try_from ( buy_res. lsp_cltv_expiry_delta ) ?,
357
353
} ;
358
354
359
- let amount_msat = if let Some ( payment_size) = req. payment_size_msat {
360
- payment_size
361
- } else {
362
- AmountOrAny :: Any
363
- } ;
364
-
365
355
let inv: cln_rpc:: model:: responses:: InvoiceResponse = cln_client
366
356
. call_raw (
367
357
"invoice" ,
368
358
& InvoiceRequest {
369
- amount_msat,
359
+ amount_msat : req . amount_msat ,
370
360
dev_routes : Some ( vec ! [ vec![ hint] ] ) ,
371
- description : String :: from ( "TODO" ) , // TODO: Pass down description from rpc call
372
- label : gen_label ( None ) , // TODO: Pass down label from rpc call
361
+ description : req . description ,
362
+ label : req . label ,
373
363
expiry : Some ( expiry as u64 ) ,
374
364
cltv : Some ( u32:: try_from ( 6 + 2 ) ?) , // TODO: FETCH REAL VALUE!
375
365
deschashonly : None ,
@@ -619,15 +609,6 @@ async fn ensure_lsp_connected(cln_client: &mut ClnRpc, lsp_id: &str) -> Result<(
619
609
Ok ( ( ) )
620
610
}
621
611
622
- /// Generates a unique label from an optional `String`. The given label is
623
- /// appended by a timestamp (now).
624
- fn gen_label ( label : Option < & str > ) -> String {
625
- let now = Utc :: now ( ) ;
626
- let millis = now. timestamp_millis ( ) ;
627
- let l = label. unwrap_or_else ( || "lsps2.buy" ) ;
628
- format ! ( "{}_{}" , l, millis)
629
- }
630
-
631
612
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
632
613
struct LspsBuyJitChannelResponse {
633
614
bolt11 : String ,
@@ -668,8 +649,7 @@ pub struct RoutehintHopDev {
668
649
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
669
650
struct ClnRpcLsps2BuyRequest {
670
651
lsp_id : String ,
671
- #[ serde( skip_serializing_if = "Option::is_none" ) ]
672
- payment_size_msat : Option < AmountOrAny > ,
652
+ payment_size_msat : Option < Msat > ,
673
653
opening_fee_params : OpeningFeeParams ,
674
654
}
675
655
0 commit comments