Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external input parsing in sdk-common #1143

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libs/Cargo.lock

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

2 changes: 1 addition & 1 deletion libs/sdk-bindings/src/uniffi_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ pub fn parse_invoice(invoice: String) -> SdkResult<LNInvoice> {
}

pub fn parse_input(s: String) -> SdkResult<InputType> {
rt().block_on(async move { Ok(sdk_parse_input(&s).await?) })
rt().block_on(async move { Ok(sdk_parse_input(&s, None).await?) })
}

pub fn mnemonic_to_seed(phrase: String) -> SdkResult<Vec<u8>> {
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tonic = { workspace = true, features = [
url = "2.5.0"
elements = { version = "0.24.1", optional = true }
urlencoding = { version = "2.1.3" }
percent-encoding = "2.3.1"

[dev-dependencies]
bitcoin = { workspace = true, features = ["rand"] }
Expand Down
457 changes: 360 additions & 97 deletions libs/sdk-common/src/input_parser.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/sdk-common/src/liquid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
for (amount_sat, amount_btc) in get_bip21_rounding_test_vectors() {
let addr = format!("liquidnetwork:tlq1qqw5ur50rnvcx33vmljjtnez3hrtl6n7vs44tdj2c9fmnxrrgzgwnhw6jtpn8cljkmlr8tgfw9hemrr5y8u2nu024hhak3tpdk?amount={amount_btc}&assetid={asset_id}");

match parse(&addr).await? {
match parse(&addr, None).await? {
InputType::LiquidAddress {
address: addr_with_amount_parsed,
} => {
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-core/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub fn parse_invoice(invoice: String) -> Result<LNInvoice> {
}

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

/* Payment API's */
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,7 @@ pub(crate) mod tests {
assert_eq!(parsed.host_str(), Some("mock.moonpay"));
assert_eq!(parsed.path(), "/");

let wallet_address = parse(query_pairs.get("wa").unwrap()).await?;
let wallet_address = parse(query_pairs.get("wa").unwrap(), None).await?;
assert!(matches!(wallet_address, InputType::BitcoinAddress { .. }));

let max_amount = query_pairs.get("ma").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion tools/sdk-cli/Cargo.lock

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

8 changes: 4 additions & 4 deletions tools/sdk-cli/src/command_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(crate) async fn handle_command(
sdk()?.sync().await?;
Ok("Sync finished successfully".to_string())
}
Commands::Parse { input } => parse(&input)
Commands::Parse { input } => parse(&input, None)
.await
.map(|res| serde_json::to_string_pretty(&res))?
.map_err(|e| e.into()),
Expand Down Expand Up @@ -466,7 +466,7 @@ pub(crate) async fn handle_command(
label,
validate_success_url,
use_trampoline,
} => match parse(&lnurl).await? {
} => match parse(&lnurl, None).await? {
LnUrlPay { data: pd } => {
let prompt = format!(
"Amount to pay in millisatoshi (min {} msat, max {} msat: ",
Expand Down Expand Up @@ -494,7 +494,7 @@ pub(crate) async fn handle_command(
_ => Err(anyhow!("Invalid input")),
},
Commands::LnurlWithdraw { lnurl } => {
match parse(&lnurl).await? {
match parse(&lnurl, None).await? {
LnUrlWithdraw { data: wd } => {
info!("Endpoint description: {}", wd.default_description);

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

match parse(lnurl_endpoint).await? {
match parse(lnurl_endpoint, None).await? {
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
Loading