Skip to content

Commit

Permalink
Configure asset metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Jan 14, 2025
1 parent 01d77f8 commit e6a24e3
Show file tree
Hide file tree
Showing 25 changed files with 1,838 additions and 301 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 41 additions & 29 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,33 @@ pub(crate) enum Command {
/// Send a payment directly or via a swap
SendPayment {
/// Invoice which has to be paid (BOLT11)
#[arg(long)]
#[arg(short, long)]
invoice: Option<String>,

/// BOLT12 offer. If specified, amount_sat must also be set.
#[arg(long)]
#[arg(short, long)]
offer: Option<String>,

/// Either BIP21 URI or Liquid address we intend to pay to
#[arg(long)]
#[arg(short, long)]
address: Option<String>,

/// The amount to pay, in case of a direct Liquid address or amount-less BIP21.
/// If an asset id is provided, it is the base unit of that asset depending on its
/// precision, otherwise in satoshi.
#[arg(short, long)]
receiver_amount: Option<u64>,
/// The amount to pay, in satoshi. The amount is optional if it is already provided in the
/// invoice or BIP21 URI.
#[arg(long)]
amount_sat: Option<u64>,

/// Optional id of the asset, in case of a direct Liquid address
/// or amount-less BIP21
#[clap(long = "asset")]
asset_id: Option<String>,

/// The amount to pay, in case of a Liquid payment. The amount is optional if it is already
/// provided in the BIP21 URI.
/// The asset id must also be provided.
#[arg(long)]
amount: Option<f64>,

/// Whether or not this is a drain operation. If true, all available funds will be used.
#[arg(short, long)]
drain: Option<bool>,
Expand Down Expand Up @@ -78,23 +83,28 @@ pub(crate) enum Command {
#[arg(short = 'm', long = "method")]
payment_method: Option<PaymentMethod>,

/// The amount the payer should send. If an asset id is provided, it is the base
/// unit of that asset depending on its precision, otherwise in satoshi.
/// If not specified, it will generate a BIP21 URI/address with no amount.
#[arg(short, long)]
payer_amount: Option<u64>,

/// Optional id of the asset to receive when the 'payment_method' is "liquid"
#[clap(long = "asset")]
asset_id: Option<String>,

/// Optional description for the invoice
#[clap(short = 'd', long = "description")]
description: Option<String>,

/// Optional if true uses the hash of the description
#[clap(name = "use_description_hash", short = 's', long = "desc_hash")]
use_description_hash: Option<bool>,

/// The amount the payer should send, in satoshi. If not specified, it will generate a
/// BIP21 URI/address with no amount.
#[arg(long)]
amount_sat: Option<u64>,

/// Optional id of the asset to receive when the 'payment_method' is "liquid"
#[clap(long = "asset")]
asset_id: Option<String>,

/// The amount the payer should send, in asset units. If not specified, it will
/// generate a BIP21 URI/address with no amount.
/// The asset id must also be provided.
#[arg(long)]
amount: Option<f64>,
},
/// Generates an URL to buy bitcoin from a 3rd party provider
BuyBitcoin {
Expand Down Expand Up @@ -281,18 +291,19 @@ pub(crate) async fn handle_command(
Ok(match command {
Command::ReceivePayment {
payment_method,
payer_amount,
amount_sat,
amount,
asset_id,
description,
use_description_hash,
} => {
let amount = match asset_id {
Some(asset_id) => Some(ReceiveAmount::Asset {
asset_id,
payer_amount,
payer_amount: amount,
}),
None => {
payer_amount.map(|payer_amount_sat| ReceiveAmount::Bitcoin { payer_amount_sat })
amount_sat.map(|payer_amount_sat| ReceiveAmount::Bitcoin { payer_amount_sat })
}
};
let prepare_response = sdk
Expand Down Expand Up @@ -329,7 +340,7 @@ pub(crate) async fn handle_command(
let mut result = command_result!(&response);
result.push('\n');

match parse(&response.destination, None).await? {
match sdk.parse(&response.destination).await? {
InputType::Bolt11 { invoice } => result.push_str(&build_qr_text(&invoice.bolt11)),
InputType::LiquidAddress { address } => {
result.push_str(&build_qr_text(&address.to_uri().map_err(|e| {
Expand Down Expand Up @@ -357,14 +368,15 @@ pub(crate) async fn handle_command(
invoice,
offer,
address,
receiver_amount,
amount,
amount_sat,
asset_id,
drain,
delay,
} => {
let destination = match (invoice, offer, address) {
(Some(invoice), None, None) => Ok(invoice),
(None, Some(offer), None) => match receiver_amount {
(None, Some(offer), None) => match amount_sat {
Some(_) => Ok(offer),
None => Err(anyhow!(
"Must specify an amount for a BOLT12 offer."
Expand All @@ -380,15 +392,15 @@ pub(crate) async fn handle_command(
"Must specify either a BOLT11 invoice, a BOLT12 offer or a direct/BIP21 address."
))
}?;
let amount = match (asset_id, receiver_amount, drain.unwrap_or(false)) {
(Some(asset_id), Some(receiver_amount), _) => Some(PayAmount::Asset {
let amount = match (asset_id, amount, amount_sat, drain.unwrap_or(false)) {
(Some(asset_id), Some(receiver_amount), _, _) => Some(PayAmount::Asset {
asset_id,
receiver_amount,
}),
(None, Some(receiver_amount_sat), _) => Some(PayAmount::Bitcoin {
(None, None, Some(receiver_amount_sat), _) => Some(PayAmount::Bitcoin {
receiver_amount_sat,
}),
(_, _, true) => Some(PayAmount::Drain),
(_, _, _, true) => Some(PayAmount::Drain),
_ => None,
};

Expand Down Expand Up @@ -711,7 +723,7 @@ pub(crate) async fn handle_command(
Command::LnurlAuth { lnurl } => {
let lnurl_endpoint = lnurl.trim();

let res = match parse(lnurl_endpoint, None).await? {
let res = match sdk.parse(lnurl_endpoint).await? {
InputType::LnUrlAuth { data: ad } => {
let auth_res = sdk.lnurl_auth(ad).await?;
serde_json::to_string_pretty(&auth_res).map_err(|e| e.into())
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ typedef struct wire_cst_liquid_address_data {
struct wire_cst_list_prim_u_8_strict *address;
int32_t network;
struct wire_cst_list_prim_u_8_strict *asset_id;
double *amount;
uint64_t *amount_sat;
struct wire_cst_list_prim_u_8_strict *label;
struct wire_cst_list_prim_u_8_strict *message;
Expand Down Expand Up @@ -361,7 +362,7 @@ typedef struct wire_cst_PayAmount_Bitcoin {

typedef struct wire_cst_PayAmount_Asset {
struct wire_cst_list_prim_u_8_strict *asset_id;
uint64_t receiver_amount;
double receiver_amount;
} wire_cst_PayAmount_Asset;

typedef union PayAmountKind {
Expand All @@ -385,7 +386,7 @@ typedef struct wire_cst_ReceiveAmount_Bitcoin {

typedef struct wire_cst_ReceiveAmount_Asset {
struct wire_cst_list_prim_u_8_strict *asset_id;
uint64_t *payer_amount;
double *payer_amount;
} wire_cst_ReceiveAmount_Asset;

typedef union ReceiveAmountKind {
Expand Down Expand Up @@ -526,10 +527,17 @@ typedef struct wire_cst_PaymentDetails_Lightning {
uint64_t *refund_tx_amount_sat;
} wire_cst_PaymentDetails_Lightning;

typedef struct wire_cst_asset_info {
struct wire_cst_list_prim_u_8_strict *name;
struct wire_cst_list_prim_u_8_strict *ticker;
double amount;
} wire_cst_asset_info;

typedef struct wire_cst_PaymentDetails_Liquid {
struct wire_cst_list_prim_u_8_strict *destination;
struct wire_cst_list_prim_u_8_strict *description;
struct wire_cst_list_prim_u_8_strict *asset_id;
struct wire_cst_asset_info *asset_info;
} wire_cst_PaymentDetails_Liquid;

typedef struct wire_cst_PaymentDetails_Bitcoin {
Expand Down Expand Up @@ -619,6 +627,18 @@ typedef struct wire_cst_list_external_input_parser {
int32_t len;
} wire_cst_list_external_input_parser;

typedef struct wire_cst_asset_metadata {
struct wire_cst_list_prim_u_8_strict *asset_id;
struct wire_cst_list_prim_u_8_strict *name;
struct wire_cst_list_prim_u_8_strict *ticker;
uint32_t precision;
} wire_cst_asset_metadata;

typedef struct wire_cst_list_asset_metadata {
struct wire_cst_asset_metadata *ptr;
int32_t len;
} wire_cst_list_asset_metadata;

typedef struct wire_cst_config {
struct wire_cst_list_prim_u_8_strict *liquid_electrum_url;
struct wire_cst_list_prim_u_8_strict *bitcoin_electrum_url;
Expand All @@ -634,6 +654,7 @@ typedef struct wire_cst_config {
struct wire_cst_list_external_input_parser *external_input_parsers;
bool use_default_external_input_parsers;
uint32_t *onchain_fee_rate_leeway_sat_per_vbyte;
struct wire_cst_list_asset_metadata *asset_metadata;
} wire_cst_config;

typedef struct wire_cst_connect_request {
Expand Down Expand Up @@ -676,7 +697,10 @@ typedef struct wire_cst_symbol {

typedef struct wire_cst_asset_balance {
struct wire_cst_list_prim_u_8_strict *asset_id;
uint64_t balance;
uint64_t balance_sat;
struct wire_cst_list_prim_u_8_strict *name;
struct wire_cst_list_prim_u_8_strict *ticker;
double *balance;
} wire_cst_asset_balance;

typedef struct wire_cst_list_asset_balance {
Expand Down Expand Up @@ -1040,6 +1064,10 @@ typedef struct wire_cst_PaymentError_AmountMissing {
struct wire_cst_list_prim_u_8_strict *err;
} wire_cst_PaymentError_AmountMissing;

typedef struct wire_cst_PaymentError_AssetError {
struct wire_cst_list_prim_u_8_strict *err;
} wire_cst_PaymentError_AssetError;

typedef struct wire_cst_PaymentError_InvalidNetwork {
struct wire_cst_list_prim_u_8_strict *err;
} wire_cst_PaymentError_InvalidNetwork;
Expand Down Expand Up @@ -1079,6 +1107,7 @@ typedef struct wire_cst_PaymentError_SignerError {

typedef union PaymentErrorKind {
struct wire_cst_PaymentError_AmountMissing AmountMissing;
struct wire_cst_PaymentError_AssetError AssetError;
struct wire_cst_PaymentError_InvalidNetwork InvalidNetwork;
struct wire_cst_PaymentError_Generic Generic;
struct wire_cst_PaymentError_InvalidDescription InvalidDescription;
Expand Down Expand Up @@ -1303,6 +1332,8 @@ struct wire_cst_aes_success_action_data_result *frbgen_breez_liquid_cst_new_box_

struct wire_cst_amount *frbgen_breez_liquid_cst_new_box_autoadd_amount(void);

struct wire_cst_asset_info *frbgen_breez_liquid_cst_new_box_autoadd_asset_info(void);

struct wire_cst_backup_request *frbgen_breez_liquid_cst_new_box_autoadd_backup_request(void);

struct wire_cst_binding_event_listener *frbgen_breez_liquid_cst_new_box_autoadd_binding_event_listener(void);
Expand Down Expand Up @@ -1405,6 +1436,8 @@ struct wire_cst_list_String *frbgen_breez_liquid_cst_new_list_String(int32_t len

struct wire_cst_list_asset_balance *frbgen_breez_liquid_cst_new_list_asset_balance(int32_t len);

struct wire_cst_list_asset_metadata *frbgen_breez_liquid_cst_new_list_asset_metadata(int32_t len);

struct wire_cst_list_external_input_parser *frbgen_breez_liquid_cst_new_list_external_input_parser(int32_t len);

struct wire_cst_list_fiat_currency *frbgen_breez_liquid_cst_new_list_fiat_currency(int32_t len);
Expand Down Expand Up @@ -1437,6 +1470,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_aes_success_action_data_decrypted);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_aes_success_action_data_result);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_amount);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_asset_info);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_backup_request);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_binding_event_listener);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_bitcoin_address_data);
Expand Down Expand Up @@ -1488,6 +1522,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_url_success_action_data);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_String);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_asset_balance);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_asset_metadata);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_external_input_parser);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_fiat_currency);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_ln_offer_blinded_path);
Expand Down
27 changes: 23 additions & 4 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dictionary LiquidAddressData {
string address;
Network network;
string? asset_id;
f64? amount;
u64? amount_sat;
string? label;
string? message;
Expand Down Expand Up @@ -306,6 +307,7 @@ enum PaymentError {
"PaymentInProgress",
"AmountOutOfRange",
"AmountMissing",
"AssetError",
"Generic",
"InvalidOrExpiredFees",
"InsufficientFunds",
Expand Down Expand Up @@ -339,6 +341,7 @@ dictionary Config {
boolean use_default_external_input_parsers = true;
sequence<ExternalInputParser>? external_input_parsers = null;
u32? onchain_fee_rate_leeway_sat_per_vbyte = null;
sequence<AssetMetadata>? asset_metadata = null;
};

enum LiquidNetwork {
Expand All @@ -357,7 +360,10 @@ dictionary ConnectWithSignerRequest {

dictionary AssetBalance {
string asset_id;
u64 balance;
u64 balance_sat;
string? name;
string? ticker;
f64? balance;
};

dictionary BlockchainInfo {
Expand Down Expand Up @@ -450,7 +456,7 @@ enum PaymentMethod {
[Enum]
interface ReceiveAmount {
Bitcoin(u64 payer_amount_sat);
Asset(string asset_id, u64? payer_amount);
Asset(string asset_id, f64? payer_amount);
};

dictionary PrepareReceiveRequest {
Expand Down Expand Up @@ -496,7 +502,7 @@ dictionary OnchainPaymentLimitsResponse {
[Enum]
interface PayAmount {
Bitcoin(u64 receiver_amount_sat);
Asset(string asset_id, u64 receiver_amount);
Asset(string asset_id, f64 receiver_amount);
Drain();
};

Expand Down Expand Up @@ -590,10 +596,16 @@ dictionary LnUrlInfo {
string? lnurl_withdraw_endpoint;
};

dictionary AssetInfo {
string name;
string ticker;
f64 amount;
};

[Enum]
interface PaymentDetails {
Lightning(string swap_id, string description, u32 liquid_expiration_blockheight, string? preimage, string? invoice, string? bolt12_offer, string? payment_hash, string? destination_pubkey, LnUrlInfo? lnurl_info, string? refund_tx_id, u64? refund_tx_amount_sat);
Liquid(string asset_id, string destination, string description);
Liquid(string asset_id, string destination, string description, AssetInfo? asset_info);
Bitcoin(string swap_id, string description, u32? bitcoin_expiration_blockheight, u32? liquid_expiration_blockheight, string? refund_tx_id, u64? refund_tx_amount_sat);
};

Expand Down Expand Up @@ -693,6 +705,13 @@ dictionary ExternalInputParser {
string parser_url;
};

dictionary AssetMetadata {
string asset_id;
string name;
string ticker;
u32 precision;
};

namespace breez_sdk_liquid {
[Throws=SdkError]
BindingLiquidSdk connect(ConnectRequest req);
Expand Down
Loading

0 comments on commit e6a24e3

Please sign in to comment.