Skip to content

Commit

Permalink
Merge pull request #597 from breez/external-input-parsing
Browse files Browse the repository at this point in the history
External input parsing
  • Loading branch information
danielgranhao authored Dec 12, 2024
2 parents 1bf5be4 + 3705175 commit 8540cfe
Show file tree
Hide file tree
Showing 24 changed files with 980 additions and 202 deletions.
21 changes: 11 additions & 10 deletions cli/Cargo.lock

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

10 changes: 5 additions & 5 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub(crate) async fn handle_command(
let mut result = command_result!(&response);
result.push('\n');

match parse(&response.destination).await? {
match parse(&response.destination, None).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 @@ -574,14 +574,14 @@ pub(crate) async fn handle_command(
command_result!("Liquid SDK instance disconnected")
}
Command::Parse { input } => {
let res = LiquidSdk::parse(&input).await?;
let res = sdk.parse(&input).await?;
command_result!(res)
}
Command::LnurlPay {
lnurl,
validate_success_url,
} => {
let input = LiquidSdk::parse(&lnurl).await?;
let input = sdk.parse(&lnurl).await?;
let res = match input {
InputType::LnUrlPay { data: pd } => {
let prompt = format!(
Expand Down Expand Up @@ -618,7 +618,7 @@ pub(crate) async fn handle_command(
command_result!(res)
}
Command::LnurlWithdraw { lnurl } => {
let input = LiquidSdk::parse(&lnurl).await?;
let input = sdk.parse(&lnurl).await?;
let res = match input {
InputType::LnUrlWithdraw { data: pd } => {
let prompt = format!(
Expand All @@ -644,7 +644,7 @@ pub(crate) async fn handle_command(
Command::LnurlAuth { lnurl } => {
let lnurl_endpoint = lnurl.trim();

let res = match parse(lnurl_endpoint).await? {
let res = match parse(lnurl_endpoint, None).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
25 changes: 13 additions & 12 deletions 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 @@ -489,6 +489,11 @@ typedef struct wire_cst_sdk_event {
union SdkEventKind kind;
} wire_cst_sdk_event;

typedef struct wire_cst_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser {
uintptr_t *ptr;
int32_t len;
} wire_cst_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser;

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 @@ -500,6 +505,7 @@ typedef struct wire_cst_config {
uint32_t zero_conf_min_fee_rate_msat;
uint64_t *zero_conf_max_amount_sat;
struct wire_cst_list_prim_u_8_strict *breez_api_key;
struct wire_cst_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser *external_input_parsers;
} wire_cst_config;

typedef struct wire_cst_connect_request {
Expand Down Expand Up @@ -1091,6 +1097,10 @@ void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_withdraw(
uintptr_t that,
struct wire_cst_ln_url_withdraw_request *req);

void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_parse(int64_t port_,
uintptr_t that,
struct wire_cst_list_prim_u_8_strict *input);

void frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pay_onchain(int64_t port_,
uintptr_t that,
struct wire_cst_pay_onchain_request *req);
Expand Down Expand Up @@ -1166,15 +1176,16 @@ void frbgen_breez_liquid_wire__crate__bindings__connect(int64_t port_,
WireSyncRust2DartDco frbgen_breez_liquid_wire__crate__bindings__default_config(int32_t network,
struct wire_cst_list_prim_u_8_strict *breez_api_key);

void frbgen_breez_liquid_wire__crate__bindings__parse(int64_t port_,
struct wire_cst_list_prim_u_8_strict *input);

WireSyncRust2DartDco frbgen_breez_liquid_wire__crate__bindings__parse_invoice(struct wire_cst_list_prim_u_8_strict *input);

void frbgen_breez_liquid_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk(const void *ptr);

void frbgen_breez_liquid_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk(const void *ptr);

void frbgen_breez_liquid_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser(const void *ptr);

void frbgen_breez_liquid_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser(const void *ptr);

struct wire_cst_aes_success_action_data *frbgen_breez_liquid_cst_new_box_autoadd_aes_success_action_data(void);

struct wire_cst_aes_success_action_data_decrypted *frbgen_breez_liquid_cst_new_box_autoadd_aes_success_action_data_decrypted(void);
Expand Down Expand Up @@ -1275,6 +1286,8 @@ uint64_t *frbgen_breez_liquid_cst_new_box_autoadd_u_64(uint64_t value);

struct wire_cst_url_success_action_data *frbgen_breez_liquid_cst_new_box_autoadd_url_success_action_data(void);

struct wire_cst_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser *frbgen_breez_liquid_cst_new_list_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser(int32_t len);

struct wire_cst_list_String *frbgen_breez_liquid_cst_new_list_String(int32_t len);

struct wire_cst_list_fiat_currency *frbgen_breez_liquid_cst_new_list_fiat_currency(int32_t len);
Expand Down Expand Up @@ -1350,6 +1363,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_u_32);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_box_autoadd_u_64);
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_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_String);
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 All @@ -1363,7 +1377,9 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_route_hint);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_cst_new_list_route_hint_hop);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerBindingLiquidSdk);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerExternalInputParser);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_add_event_listener);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_backup);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_buy_bitcoin);
Expand All @@ -1381,6 +1397,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_auth);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_pay);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_lnurl_withdraw);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_parse);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_pay_onchain);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_buy_bitcoin);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__BindingLiquidSdk_prepare_lnurl_pay);
Expand All @@ -1402,7 +1419,6 @@ static int64_t dummy_method_to_enforce_bundling(void) {
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__breez_log_stream);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__connect);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__default_config);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__parse);
dummy_var ^= ((int64_t) (void*) frbgen_breez_liquid_wire__crate__bindings__parse_invoice);
dummy_var ^= ((int64_t) (void*) store_dart_post_cobject);
return dummy_var;
Expand Down
13 changes: 10 additions & 3 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ dictionary Config {
string? breez_api_key;
string? cache_dir;
u64? zero_conf_max_amount_sat;
sequence<ExternalInputParser>? external_input_parsers = null;
};

enum LiquidNetwork {
Expand Down Expand Up @@ -629,6 +630,12 @@ dictionary LogEntry {
string level;
};

dictionary ExternalInputParser {
string provider_id;
string input_regex;
string parser_url;
};

namespace breez_sdk_liquid {
[Throws=SdkError]
BindingLiquidSdk connect(ConnectRequest req);
Expand All @@ -642,9 +649,6 @@ namespace breez_sdk_liquid {
[Throws=SdkError]
Config default_config(LiquidNetwork network, string? breez_api_key);

[Throws=PaymentError]
InputType parse(string input);

[Throws=PaymentError]
LNInvoice parse_invoice(string input);
};
Expand Down Expand Up @@ -690,6 +694,9 @@ interface BindingLiquidSdk {
[Throws=SdkError]
CheckMessageResponse check_message(CheckMessageRequest req);

[Throws=PaymentError]
InputType parse(string input);

[Throws=PaymentError]
PrepareSendResponse prepare_send_payment(PrepareSendRequest req);

Expand Down
7 changes: 4 additions & 3 deletions lib/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ pub fn default_config(
LiquidSdk::default_config(network, breez_api_key)
}

pub fn parse(input: String) -> Result<InputType, PaymentError> {
rt().block_on(async { LiquidSdk::parse(&input).await })
}
pub fn parse_invoice(input: String) -> Result<LNInvoice, PaymentError> {
LiquidSdk::parse_invoice(&input)
}
Expand Down Expand Up @@ -103,6 +100,10 @@ impl BindingLiquidSdk {
self.sdk.check_message(&req)
}

pub fn parse(&self, input: String) -> Result<InputType, PaymentError> {
rt().block_on(async { self.sdk.parse(&input).await })
}

pub fn prepare_send_payment(
&self,
req: PrepareSendRequest,
Expand Down
8 changes: 4 additions & 4 deletions lib/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ boltz-client = { git = "https://github.com/SatoshiPortal/boltz-rust", branch = "
chrono = "0.4"
env_logger = "0.11"
flutter_rust_bridge = { version = "=2.4.0", features = [
"chrono",
"chrono",
], optional = true }
# We need at least lightning v0.0.125 for the Bolt12 structs. The lightning version from sdk-common is too old (v0.0.118, matching vls-core).
lightning = "0.0.125"
Expand All @@ -32,7 +32,7 @@ lwk_wollet = { git = "https://github.com/dangeross/lwk", branch = "savage-full-s
#lwk_wollet = "0.7.0"
rusqlite = { version = "0.31", features = ["backup", "bundled"] }
rusqlite_migration = "1.0"
sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "5955216ec4ed003972b4473a77207dfb744da882", features = ["liquid"]}
sdk-common = { git = "https://github.com/breez/breez-sdk", rev = "e537feb8ed134bc3c7af5196e10a0a189dd36ac7", features = ["liquid"] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.116"
strum = "0.25"
Expand All @@ -44,8 +44,8 @@ tokio = { version = "1", features = ["rt", "macros"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }
url = "2.5.0"
futures-util = { version = "0.3.28", default-features = false, features = [
"sink",
"std",
"sink",
"std",
] }
async-trait = "0.1.80"
hex = "0.4"
Expand Down
Loading

0 comments on commit 8540cfe

Please sign in to comment.