Skip to content

Commit

Permalink
Implement external input parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Dec 11, 2024
1 parent 1bf5be4 commit 6d13f25
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 147 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 @@ -1091,6 +1091,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,9 +1170,6 @@ 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);
Expand Down Expand Up @@ -1381,6 +1382,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 +1404,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
14 changes: 11 additions & 3 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,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 +648,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 +693,11 @@ interface BindingLiquidSdk {
[Throws=SdkError]
CheckMessageResponse check_message(CheckMessageRequest req);

void set_external_input_parsers(sequence<ExternalInputParser> external_input_parsers);

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

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

Expand Down
15 changes: 12 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,18 @@ impl BindingLiquidSdk {
self.sdk.check_message(&req)
}

pub fn set_external_input_parsers(&self, external_input_parsers: Vec<ExternalInputParser>) {
rt().block_on(async {
self.sdk
.set_external_input_parsers(external_input_parsers)
.await
});
}

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 = "98e7994e40ebfec4b0b76632b4beeacd0ff73a34", 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
8 changes: 4 additions & 4 deletions lib/core/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ pub fn default_config(
LiquidSdk::default_config(network, breez_api_key)
}

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

#[frb(sync)]
pub fn parse_invoice(input: String) -> Result<LNInvoice, PaymentError> {
LiquidSdk::parse_invoice(&input)
Expand Down Expand Up @@ -97,6 +93,10 @@ impl BindingLiquidSdk {
self.sdk.check_message(&req)
}

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

pub async fn add_event_listener(
&self,
listener: StreamSink<SdkEvent>,
Expand Down
Loading

0 comments on commit 6d13f25

Please sign in to comment.