Skip to content

Commit 2ece61c

Browse files
committed
Add ReceiveAmount and extend PayAmount to handle assets
1 parent 8e447d0 commit 2ece61c

File tree

14 files changed

+1342
-378
lines changed

14 files changed

+1342
-378
lines changed

cli/src/commands.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) enum Command {
3636
/// The amount in satoshi to pay, in case of a direct Liquid address
3737
/// or amount-less BIP21
3838
#[arg(short, long)]
39-
amount_sat: Option<u64>,
39+
receiver_amount: Option<u64>,
4040

4141
/// Optional id of the asset, in case of a direct Liquid address
4242
/// or amount-less BIP21
@@ -77,11 +77,11 @@ pub(crate) enum Command {
7777
#[arg(short = 'm', long = "method")]
7878
payment_method: Option<PaymentMethod>,
7979

80-
/// Amount the payer will send, in satoshi units. If receiving a non Liquid Bitcoin
80+
/// Amount the payer will send, in satoshi. If receiving a non Liquid Bitcoin
8181
/// asset, this is the units of the asset to receive.
8282
/// If not specified, it will generate a BIP21 URI/Liquid address with no amount
8383
#[arg(short, long)]
84-
payer_amount_sat: Option<u64>,
84+
payer_amount: Option<u64>,
8585

8686
/// Optional id of the asset to receive when the 'payment_method' is "liquid"
8787
#[clap(long = "asset")]
@@ -280,21 +280,29 @@ pub(crate) async fn handle_command(
280280
Ok(match command {
281281
Command::ReceivePayment {
282282
payment_method,
283-
payer_amount_sat,
283+
payer_amount,
284284
asset_id,
285285
description,
286286
use_description_hash,
287287
} => {
288+
let amount = match asset_id {
289+
Some(asset_id) => Some(ReceiveAmount::Asset {
290+
asset_id,
291+
payer_amount,
292+
}),
293+
None => {
294+
payer_amount.map(|payer_amount_sat| ReceiveAmount::Bitcoin { payer_amount_sat })
295+
}
296+
};
288297
let prepare_response = sdk
289298
.prepare_receive_payment(&PrepareReceiveRequest {
290-
payer_amount_sat,
291-
asset_id,
292299
payment_method: payment_method.unwrap_or(PaymentMethod::Lightning),
300+
amount: amount.clone(),
293301
})
294302
.await?;
295303

296304
let fees = prepare_response.fees_sat;
297-
let confirmation_msg = match payer_amount_sat {
305+
let confirmation_msg = match amount {
298306
Some(_) => format!("Fees: {fees} sat. Are the fees acceptable? (y/N)"),
299307
None => {
300308
let min = prepare_response.min_payer_amount_sat;
@@ -348,14 +356,14 @@ pub(crate) async fn handle_command(
348356
invoice,
349357
offer,
350358
address,
351-
amount_sat,
359+
receiver_amount,
352360
asset_id,
353361
drain,
354362
delay,
355363
} => {
356364
let destination = match (invoice, offer, address) {
357365
(Some(invoice), None, None) => Ok(invoice),
358-
(None, Some(offer), None) => match amount_sat {
366+
(None, Some(offer), None) => match receiver_amount {
359367
Some(_) => Ok(offer),
360368
None => Err(anyhow!(
361369
"Must specify an amount for a BOLT12 offer."
@@ -371,17 +379,22 @@ pub(crate) async fn handle_command(
371379
"Must specify either a BOLT11 invoice, a BOLT12 offer or a direct/BIP21 address."
372380
))
373381
}?;
374-
let amount = match (amount_sat, drain.unwrap_or(false)) {
375-
(Some(amount_sat), _) => Some(PayAmount::Receiver { amount_sat }),
376-
(_, true) => Some(PayAmount::Drain),
377-
(_, _) => None,
382+
let amount = match (asset_id, receiver_amount, drain.unwrap_or(false)) {
383+
(Some(asset_id), Some(receiver_amount), _) => Some(PayAmount::Asset {
384+
asset_id,
385+
receiver_amount,
386+
}),
387+
(None, Some(receiver_amount_sat), _) => Some(PayAmount::Bitcoin {
388+
receiver_amount_sat,
389+
}),
390+
(_, _, true) => Some(PayAmount::Drain),
391+
_ => None,
378392
};
379393

380394
let prepare_response = sdk
381395
.prepare_send_payment(&PrepareSendRequest {
382396
destination,
383397
amount,
384-
asset_id,
385398
})
386399
.await?;
387400

@@ -418,8 +431,8 @@ pub(crate) async fn handle_command(
418431
} => {
419432
let amount = match drain.unwrap_or(false) {
420433
true => PayAmount::Drain,
421-
false => PayAmount::Receiver {
422-
amount_sat: receiver_amount_sat.ok_or(anyhow::anyhow!(
434+
false => PayAmount::Bitcoin {
435+
receiver_amount_sat: receiver_amount_sat.ok_or(anyhow::anyhow!(
423436
"Must specify `receiver_amount_sat` if not draining"
424437
))?,
425438
},

lib/bindings/langs/flutter/breez_sdk_liquid/include/breez_sdk_liquid.h

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,18 @@ typedef struct wire_cst_prepare_ln_url_pay_request {
355355
bool *validate_success_action_url;
356356
} wire_cst_prepare_ln_url_pay_request;
357357

358-
typedef struct wire_cst_PayAmount_Receiver {
359-
uint64_t amount_sat;
360-
} wire_cst_PayAmount_Receiver;
358+
typedef struct wire_cst_PayAmount_Bitcoin {
359+
uint64_t receiver_amount_sat;
360+
} wire_cst_PayAmount_Bitcoin;
361+
362+
typedef struct wire_cst_PayAmount_Asset {
363+
struct wire_cst_list_prim_u_8_strict *asset_id;
364+
uint64_t receiver_amount;
365+
} wire_cst_PayAmount_Asset;
361366

362367
typedef union PayAmountKind {
363-
struct wire_cst_PayAmount_Receiver Receiver;
368+
struct wire_cst_PayAmount_Bitcoin Bitcoin;
369+
struct wire_cst_PayAmount_Asset Asset;
364370
} PayAmountKind;
365371

366372
typedef struct wire_cst_pay_amount {
@@ -373,10 +379,28 @@ typedef struct wire_cst_prepare_pay_onchain_request {
373379
uint32_t *fee_rate_sat_per_vbyte;
374380
} wire_cst_prepare_pay_onchain_request;
375381

382+
typedef struct wire_cst_ReceiveAmount_Bitcoin {
383+
uint64_t payer_amount_sat;
384+
} wire_cst_ReceiveAmount_Bitcoin;
385+
386+
typedef struct wire_cst_ReceiveAmount_Asset {
387+
struct wire_cst_list_prim_u_8_strict *asset_id;
388+
uint64_t *payer_amount;
389+
} wire_cst_ReceiveAmount_Asset;
390+
391+
typedef union ReceiveAmountKind {
392+
struct wire_cst_ReceiveAmount_Bitcoin Bitcoin;
393+
struct wire_cst_ReceiveAmount_Asset Asset;
394+
} ReceiveAmountKind;
395+
396+
typedef struct wire_cst_receive_amount {
397+
int32_t tag;
398+
union ReceiveAmountKind kind;
399+
} wire_cst_receive_amount;
400+
376401
typedef struct wire_cst_prepare_receive_request {
377402
int32_t payment_method;
378-
uint64_t *payer_amount_sat;
379-
struct wire_cst_list_prim_u_8_strict *asset_id;
403+
struct wire_cst_receive_amount *amount;
380404
} wire_cst_prepare_receive_request;
381405

382406
typedef struct wire_cst_prepare_refund_request {
@@ -388,13 +412,11 @@ typedef struct wire_cst_prepare_refund_request {
388412
typedef struct wire_cst_prepare_send_request {
389413
struct wire_cst_list_prim_u_8_strict *destination;
390414
struct wire_cst_pay_amount *amount;
391-
struct wire_cst_list_prim_u_8_strict *asset_id;
392415
} wire_cst_prepare_send_request;
393416

394417
typedef struct wire_cst_prepare_receive_response {
395418
int32_t payment_method;
396-
uint64_t *payer_amount_sat;
397-
struct wire_cst_list_prim_u_8_strict *asset_id;
419+
struct wire_cst_receive_amount *amount;
398420
uint64_t fees_sat;
399421
uint64_t *min_payer_amount_sat;
400422
uint64_t *max_payer_amount_sat;
@@ -1339,6 +1361,8 @@ struct wire_cst_prepare_refund_request *frbgen_breez_liquid_cst_new_box_autoadd_
13391361

13401362
struct wire_cst_prepare_send_request *frbgen_breez_liquid_cst_new_box_autoadd_prepare_send_request(void);
13411363

1364+
struct wire_cst_receive_amount *frbgen_breez_liquid_cst_new_box_autoadd_receive_amount(void);
1365+
13421366
struct wire_cst_receive_payment_request *frbgen_breez_liquid_cst_new_box_autoadd_receive_payment_request(void);
13431367

13441368
struct wire_cst_refund_request *frbgen_breez_liquid_cst_new_box_autoadd_refund_request(void);
@@ -1435,6 +1459,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
14351459
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_receive_request);
14361460
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_refund_request);
14371461
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_prepare_send_request);
1462+
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_receive_amount);
14381463
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_receive_payment_request);
14391464
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_refund_request);
14401465
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_restore_request);

lib/bindings/src/breez_sdk_liquid.udl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ dictionary LnUrlPayRequest {
409409
dictionary PrepareSendRequest {
410410
string destination;
411411
PayAmount? amount = null;
412-
string? asset_id = null;
413412
};
414413

415414
[Enum]
@@ -438,17 +437,21 @@ enum PaymentMethod {
438437
"LiquidAddress",
439438
};
440439

440+
[Enum]
441+
interface ReceiveAmount {
442+
Bitcoin(u64 payer_amount_sat);
443+
Asset(string asset_id, u64? payer_amount);
444+
};
445+
441446
dictionary PrepareReceiveRequest {
442447
PaymentMethod payment_method;
443-
u64? payer_amount_sat = null;
444-
string? asset_id = null;
448+
ReceiveAmount? amount = null;
445449
};
446450

447451
dictionary PrepareReceiveResponse {
448452
PaymentMethod payment_method;
449453
u64 fees_sat;
450-
u64? payer_amount_sat;
451-
string? asset_id;
454+
ReceiveAmount? amount;
452455
u64? min_payer_amount_sat;
453456
u64? max_payer_amount_sat;
454457
f64? swapper_feerate;
@@ -482,7 +485,8 @@ dictionary OnchainPaymentLimitsResponse {
482485

483486
[Enum]
484487
interface PayAmount {
485-
Receiver(u64 amount_sat);
488+
Bitcoin(u64 receiver_amount_sat);
489+
Asset(string asset_id, u64 receiver_amount);
486490
Drain();
487491
};
488492

0 commit comments

Comments
 (0)