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

Integrate sdk-common #308

Merged
merged 30 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b3980b3
Rename Network to LiquidSdkNetwork to avoid naming conflicts with sdk…
ok300 Jun 12, 2024
e69d41d
Integrate sdk-common: re-use parse_invoice
ok300 Jun 12, 2024
42749e6
Fix UDL bindings tests
ok300 Jun 12, 2024
8c6fca9
Add input parser support
ok300 Jun 12, 2024
e107ebf
CLI: Add input parser support
ok300 Jun 12, 2024
d679f4b
Integrate lnurl-pay
ok300 Jun 13, 2024
3f42fab
Cargo format, re-generate FRB and RN bindings
ok300 Jun 13, 2024
928b8f7
Duplicate LnUrlPayError, update FRB/UniFFI bindings
ok300 Jun 13, 2024
23d6fe8
Move duplicate LnUrlPayError to FRB bindings.rs
ok300 Jun 13, 2024
84768e4
Add support for lnurl-withdraw
ok300 Jun 14, 2024
eab4eb5
Merge branch 'main' into ok300-integrate-sdk-common
ok300 Jun 14, 2024
5ebd1d0
Lnurl-withdraw: convert units, incorporate fees
ok300 Jun 14, 2024
f38c435
Bump sdk-common, rename InputType::LnUrlError
ok300 Jun 17, 2024
dd75736
Merge branch 'main' into ok300-integrate-sdk-common
ok300 Jun 17, 2024
02088a9
Bump sdk-common, remove Wrapped prefix from LnUrlPaySuccessData, LnUr…
ok300 Jun 17, 2024
ad34469
Merge branch 'main' into ok300-integrate-sdk-common
ok300 Jun 18, 2024
7d8bcea
LNURL-withdraw: add missing UDL mappings
ok300 Jun 18, 2024
cdbfd0e
Add support for LNURL-auth
ok300 Jun 18, 2024
cc7a206
Move LNURL structs into models.rs
ok300 Jun 19, 2024
11581d6
Rename LiquidSdkNetwork to LiquidNetwork
ok300 Jun 19, 2024
3f419b5
Fix binding tests
ok300 Jun 19, 2024
eb0d340
Merge branch 'main' into ok300-integrate-sdk-common
ok300 Jun 19, 2024
19ec1b4
Fix tests
ok300 Jun 19, 2024
48fd14b
Merge branch 'main' into ok300-integrate-sdk-common
ok300 Jun 19, 2024
db821d9
Move FRB mirroring structs to bindings.rs
ok300 Jun 19, 2024
d237d23
Remove TODO
ok300 Jun 19, 2024
4575757
Bump sdk-common, remove sdk-common dependency on rusqlite
ok300 Jun 20, 2024
ffc5472
Propagate LiquidNetwork rename into flutter example app
ok300 Jun 20, 2024
865ec21
CI: install protobuf before running clippy
ok300 Jun 20, 2024
c403703
CI: add rust cache, protobuf for remaining rust steps
ok300 Jun 20, 2024
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
381 changes: 344 additions & 37 deletions cli/Cargo.lock

Large diffs are not rendered by default.

87 changes: 86 additions & 1 deletion cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::time::Duration;
use anyhow::Result;
use breez_liquid_sdk::model::*;
use breez_liquid_sdk::sdk::LiquidSdk;
use breez_liquid_sdk::*;
use clap::{arg, Parser};
use qrcode_rs::render::unicode;
use qrcode_rs::{EcLevel, QrCode};
Expand Down Expand Up @@ -54,6 +55,24 @@ pub(crate) enum Command {
},
/// Shuts down all background threads of this SDK instance
Disconnect,
/// Parse a generic string to get its type and relevant metadata
Parse {
/// Generic input (URL, LNURL, BIP-21 BTC Address, LN invoice, etc)
input: String,
},
/// Pay using LNURL
LnurlPay {
/// LN Address or LNURL-pay endpoint
lnurl: String,
},
LnurlWithdraw {
/// LNURL-withdraw endpoint
lnurl: String,
},
LnurlAuth {
/// LNURL-auth endpoint
lnurl: String,
},
}

#[derive(Helper, Completer, Hinter, Validator)]
Expand Down Expand Up @@ -97,7 +116,7 @@ macro_rules! wait_confirmation {
}

pub(crate) async fn handle_command(
_rl: &mut Editor<CliHelper, DefaultHistory>,
rl: &mut Editor<CliHelper, DefaultHistory>,
sdk: &Arc<LiquidSdk>,
command: Command,
) -> Result<String> {
Expand Down Expand Up @@ -177,6 +196,72 @@ pub(crate) async fn handle_command(
sdk.disconnect().await?;
command_result!("Liquid SDK instance disconnected")
}
Command::Parse { input } => {
let res = LiquidSdk::parse(&input).await?;
command_result!(res)
}
Command::LnurlPay { lnurl } => {
let input = LiquidSdk::parse(&lnurl).await?;
let res = match input {
InputType::LnUrlPay { data: pd } => {
let prompt = format!(
"Amount to pay in millisatoshi (min {} msat, max {} msat): ",
pd.min_sendable, pd.max_sendable
);

let amount_msat = rl.readline(&prompt)?;
let pay_res = sdk
.lnurl_pay(LnUrlPayRequest {
data: pd,
amount_msat: amount_msat.parse::<u64>()?,
comment: None,
payment_label: None,
})
.await?;
Ok(pay_res)
}
_ => Err(anyhow::anyhow!("Invalid input")),
}?;

command_result!(res)
}
Command::LnurlWithdraw { lnurl } => {
let input = LiquidSdk::parse(&lnurl).await?;
let res = match input {
InputType::LnUrlWithdraw { data: pd } => {
let prompt = format!(
"Amount to withdraw in millisatoshi (min {} msat, max {} msat): ",
pd.min_withdrawable, pd.max_withdrawable
);

let amount_msat = rl.readline(&prompt)?;
let withdraw_res = sdk
.lnurl_withdraw(LnUrlWithdrawRequest {
data: pd,
amount_msat: amount_msat.parse()?,
description: Some("LNURL-withdraw".to_string()),
})
.await?;
Ok(withdraw_res)
}
_ => Err(anyhow::anyhow!("Invalid input")),
}?;

command_result!(res)
}
Command::LnurlAuth { lnurl } => {
let lnurl_endpoint = lnurl.trim();

let res = match 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())
}
_ => Err(anyhow::anyhow!("Unexpected result type")),
}?;

command_result!(res)
}
})
}

Expand Down
12 changes: 6 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ pub(crate) struct Args {
pub(crate) log_file: Option<String>,

#[clap(short, long, value_parser = parse_network_arg)]
pub(crate) network: Option<Network>,
pub(crate) network: Option<LiquidSdkNetwork>,
}

fn parse_network_arg(s: &str) -> Result<Network, String> {
Network::try_from(s).map_err(|e| e.to_string())
fn parse_network_arg(s: &str) -> Result<LiquidSdkNetwork, String> {
LiquidSdkNetwork::try_from(s).map_err(|e| e.to_string())
}

fn show_results(result: Result<String>) -> Result<()> {
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn main() -> Result<()> {
}

let mnemonic = persistence.get_or_create_mnemonic()?;
let network = args.network.unwrap_or(Network::Testnet);
let network = args.network.unwrap_or(LiquidSdkNetwork::Testnet);
let mut config = LiquidSdk::default_config(network);
config.working_dir = data_dir_str;
let sdk = LiquidSdk::connect(ConnectRequest {
Expand All @@ -86,8 +86,8 @@ async fn main() -> Result<()> {
.await?;

let cli_prompt = match network {
Network::Mainnet => "breez-liquid-cli [mainnet]> ",
Network::Testnet => "breez-liquid-cli [testnet]> ",
LiquidSdkNetwork::Mainnet => "breez-liquid-cli [mainnet]> ",
LiquidSdkNetwork::Testnet => "breez-liquid-cli [testnet]> ",
};

loop {
Expand Down
Loading
Loading