@@ -33,10 +33,16 @@ pub(crate) enum Command {
33
33
#[ arg( long) ]
34
34
address : Option < String > ,
35
35
36
- /// The amount in satoshi to pay, in case of a direct Liquid address
37
- /// or amount-less BIP21
36
+ /// The amount to pay, in case of a direct Liquid address or amount-less BIP21.
37
+ /// If an asset id is provided, it is the base unit of that asset depending on its
38
+ /// precision, otherwise in satoshi.
38
39
#[ arg( short, long) ]
39
- amount_sat : Option < u64 > ,
40
+ receiver_amount : Option < u64 > ,
41
+
42
+ /// Optional id of the asset, in case of a direct Liquid address
43
+ /// or amount-less BIP21
44
+ #[ clap( long = "asset" ) ]
45
+ asset_id : Option < String > ,
40
46
41
47
/// Whether or not this is a drain operation. If true, all available funds will be used.
42
48
#[ arg( short, long) ]
@@ -72,10 +78,15 @@ pub(crate) enum Command {
72
78
#[ arg( short = 'm' , long = "method" ) ]
73
79
payment_method : Option < PaymentMethod > ,
74
80
75
- /// Amount the payer will send, in satoshi
76
- /// If not specified, it will generate a BIP21 URI/Liquid address with no amount
81
+ /// The amount the payer should send. If an asset id is provided, it is the base
82
+ /// unit of that asset depending on its precision, otherwise in satoshi.
83
+ /// If not specified, it will generate a BIP21 URI/address with no amount.
77
84
#[ arg( short, long) ]
78
- payer_amount_sat : Option < u64 > ,
85
+ payer_amount : Option < u64 > ,
86
+
87
+ /// Optional id of the asset to receive when the 'payment_method' is "liquid"
88
+ #[ clap( long = "asset" ) ]
89
+ asset_id : Option < String > ,
79
90
80
91
/// Optional description for the invoice
81
92
#[ clap( short = 'd' , long = "description" ) ]
@@ -118,6 +129,10 @@ pub(crate) enum Command {
118
129
#[ clap( short = 'o' , long = "offset" ) ]
119
130
offset : Option < u32 > ,
120
131
132
+ /// Optional id of the asset for Liquid payment method
133
+ #[ clap( long = "asset" ) ]
134
+ asset_id : Option < String > ,
135
+
121
136
/// Optional Liquid BIP21 URI/address for Liquid payment method
122
137
#[ clap( short = 'd' , long = "destination" ) ]
123
138
destination : Option < String > ,
@@ -270,19 +285,29 @@ pub(crate) async fn handle_command(
270
285
Ok ( match command {
271
286
Command :: ReceivePayment {
272
287
payment_method,
273
- payer_amount_sat,
288
+ payer_amount,
289
+ asset_id,
274
290
description,
275
291
use_description_hash,
276
292
} => {
293
+ let amount = match asset_id {
294
+ Some ( asset_id) => Some ( ReceiveAmount :: Asset {
295
+ asset_id,
296
+ payer_amount,
297
+ } ) ,
298
+ None => {
299
+ payer_amount. map ( |payer_amount_sat| ReceiveAmount :: Bitcoin { payer_amount_sat } )
300
+ }
301
+ } ;
277
302
let prepare_response = sdk
278
303
. prepare_receive_payment ( & PrepareReceiveRequest {
279
- payer_amount_sat,
280
304
payment_method : payment_method. unwrap_or ( PaymentMethod :: Lightning ) ,
305
+ amount : amount. clone ( ) ,
281
306
} )
282
307
. await ?;
283
308
284
309
let fees = prepare_response. fees_sat ;
285
- let confirmation_msg = match payer_amount_sat {
310
+ let confirmation_msg = match amount {
286
311
Some ( _) => format ! ( "Fees: {fees} sat. Are the fees acceptable? (y/N)" ) ,
287
312
None => {
288
313
let min = prepare_response. min_payer_amount_sat ;
@@ -336,13 +361,14 @@ pub(crate) async fn handle_command(
336
361
invoice,
337
362
offer,
338
363
address,
339
- amount_sat,
364
+ receiver_amount,
365
+ asset_id,
340
366
drain,
341
367
delay,
342
368
} => {
343
369
let destination = match ( invoice, offer, address) {
344
370
( Some ( invoice) , None , None ) => Ok ( invoice) ,
345
- ( None , Some ( offer) , None ) => match amount_sat {
371
+ ( None , Some ( offer) , None ) => match receiver_amount {
346
372
Some ( _) => Ok ( offer) ,
347
373
None => Err ( anyhow ! (
348
374
"Must specify an amount for a BOLT12 offer."
@@ -358,10 +384,16 @@ pub(crate) async fn handle_command(
358
384
"Must specify either a BOLT11 invoice, a BOLT12 offer or a direct/BIP21 address."
359
385
) )
360
386
} ?;
361
- let amount = match ( amount_sat, drain. unwrap_or ( false ) ) {
362
- ( Some ( amount_sat) , _) => Some ( PayAmount :: Receiver { amount_sat } ) ,
363
- ( _, true ) => Some ( PayAmount :: Drain ) ,
364
- ( _, _) => None ,
387
+ let amount = match ( asset_id, receiver_amount, drain. unwrap_or ( false ) ) {
388
+ ( Some ( asset_id) , Some ( receiver_amount) , _) => Some ( PayAmount :: Asset {
389
+ asset_id,
390
+ receiver_amount,
391
+ } ) ,
392
+ ( None , Some ( receiver_amount_sat) , _) => Some ( PayAmount :: Bitcoin {
393
+ receiver_amount_sat,
394
+ } ) ,
395
+ ( _, _, true ) => Some ( PayAmount :: Drain ) ,
396
+ _ => None ,
365
397
} ;
366
398
367
399
let prepare_response = sdk
@@ -404,8 +436,8 @@ pub(crate) async fn handle_command(
404
436
} => {
405
437
let amount = match drain. unwrap_or ( false ) {
406
438
true => PayAmount :: Drain ,
407
- false => PayAmount :: Receiver {
408
- amount_sat : receiver_amount_sat. ok_or ( anyhow:: anyhow!(
439
+ false => PayAmount :: Bitcoin {
440
+ receiver_amount_sat : receiver_amount_sat. ok_or ( anyhow:: anyhow!(
409
441
"Must specify `receiver_amount_sat` if not draining"
410
442
) ) ?,
411
443
} ,
@@ -492,13 +524,21 @@ pub(crate) async fn handle_command(
492
524
to_timestamp,
493
525
limit,
494
526
offset,
527
+ asset_id,
495
528
destination,
496
529
address,
497
530
sort_ascending,
498
531
} => {
499
- let details = match ( destination, address) {
500
- ( Some ( destination) , None ) => Some ( ListPaymentDetails :: Liquid { destination } ) ,
501
- ( None , Some ( address) ) => Some ( ListPaymentDetails :: Bitcoin { address } ) ,
532
+ let details = match ( asset_id. clone ( ) , destination. clone ( ) , address) {
533
+ ( None , Some ( _) , None ) | ( Some ( _) , None , None ) | ( Some ( _) , Some ( _) , None ) => {
534
+ Some ( ListPaymentDetails :: Liquid {
535
+ asset_id,
536
+ destination,
537
+ } )
538
+ }
539
+ ( None , None , Some ( address) ) => Some ( ListPaymentDetails :: Bitcoin {
540
+ address : Some ( address) ,
541
+ } ) ,
502
542
_ => None ,
503
543
} ;
504
544
0 commit comments