From 0699adeb9da4d84e6460fb8b06bdc34399446c88 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 23 Oct 2023 19:38:32 +0200 Subject: [PATCH] Integrate SDK Request / Response changes --- snippets/rust/Cargo.lock | 2 +- snippets/rust/Cargo.toml | 2 +- snippets/rust/src/fiat_currencies.rs | 2 +- snippets/rust/src/getting_started.rs | 7 +++---- snippets/rust/src/list_payments.rs | 12 ++++++++---- snippets/rust/src/lnurl_pay.rs | 7 +++++-- snippets/rust/src/lnurl_withdraw.rs | 7 ++++++- snippets/rust/src/receive_onchain.rs | 7 ++++++- snippets/rust/src/receive_payment.rs | 2 +- snippets/rust/src/send_onchain.rs | 15 ++++++++++----- snippets/rust/src/send_payment.rs | 8 ++++++-- snippets/rust/src/send_spontaneous_payment.rs | 8 ++++++-- 12 files changed, 54 insertions(+), 25 deletions(-) diff --git a/snippets/rust/Cargo.lock b/snippets/rust/Cargo.lock index d1117f8..7567bb2 100644 --- a/snippets/rust/Cargo.lock +++ b/snippets/rust/Cargo.lock @@ -468,7 +468,7 @@ dependencies = [ [[package]] name = "breez-sdk-core" version = "0.2.3" -source = "git+https://github.com/breez/breez-sdk?branch=main#576c1a892563f867c2b48fceb48f0a49d6efd61e" +source = "git+https://github.com/breez/breez-sdk?rev=3486c951e2422fe4ac3978795849f0b7649a9f1e#3486c951e2422fe4ac3978795849f0b7649a9f1e" dependencies = [ "aes", "anyhow", diff --git a/snippets/rust/Cargo.toml b/snippets/rust/Cargo.toml index fc70b9e..18f2cdb 100644 --- a/snippets/rust/Cargo.toml +++ b/snippets/rust/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" [dependencies] anyhow = "1" bip39 = { version = "2", features = ["rand"] } -breez-sdk-core = { git = "https://github.com/breez/breez-sdk", rev = "d6365dc90263f3ad3f65a113fdc016a0bf070d9d" } +breez-sdk-core = { git = "https://github.com/breez/breez-sdk", rev = "3486c951e2422fe4ac3978795849f0b7649a9f1e" } log = "0.4" tokio = "1.29" \ No newline at end of file diff --git a/snippets/rust/src/fiat_currencies.rs b/snippets/rust/src/fiat_currencies.rs index 4d836c4..1954c69 100644 --- a/snippets/rust/src/fiat_currencies.rs +++ b/snippets/rust/src/fiat_currencies.rs @@ -31,7 +31,7 @@ async fn get_fiat_currencies_and_rates(sdk: Arc) -> Result = Vec::new(); for currency in sorted { diff --git a/snippets/rust/src/getting_started.rs b/snippets/rust/src/getting_started.rs index ac69413..4ef2b53 100644 --- a/snippets/rust/src/getting_started.rs +++ b/snippets/rust/src/getting_started.rs @@ -41,10 +41,9 @@ async fn getting_started() -> Result> { async fn getting_started_node_info(sdk: Arc) -> Result<()> { // ANCHOR: fetch-balance - if let Some(node_state) = sdk.node_info()? { - let balance_ln = node_state.channels_balance_msat; - let balance_onchain = node_state.onchain_balance_msat; - } + let node_state = sdk.node_info()?; + let balance_ln = node_state.channels_balance_msat; + let balance_onchain = node_state.onchain_balance_msat; // ANCHOR_END: fetch-balance Ok(()) diff --git a/snippets/rust/src/list_payments.rs b/snippets/rust/src/list_payments.rs index 582f12d..88c81e6 100644 --- a/snippets/rust/src/list_payments.rs +++ b/snippets/rust/src/list_payments.rs @@ -6,11 +6,13 @@ use breez_sdk_core::*; async fn list_payments(sdk: Arc) -> Result> { // ANCHOR: list-payments let payments = sdk.list_payments( - ListPaymentRequest { + ListPaymentsRequest { filter: PaymentTypeFilter::All, from_timestamp: None, to_timestamp: None, include_failures: None, + offset: None, + limit: None } ).await?; // ANCHOR_END: list-payments @@ -21,11 +23,13 @@ async fn list_payments(sdk: Arc) -> Result> { async fn list_payments_filtered(sdk: Arc) -> Result> { // ANCHOR: list-payments-filtered let payments = sdk.list_payments( - ListPaymentRequest { + ListPaymentsRequest { filter: PaymentTypeFilter::Sent, - from_timestamp: 1696880000, + from_timestamp: Some(1696880000), to_timestamp: None, - include_failures: true, + include_failures: Some(true), + offset: None, + limit: None } ).await?; // ANCHOR_END: list-payments-filtered diff --git a/snippets/rust/src/lnurl_pay.rs b/snippets/rust/src/lnurl_pay.rs index 62e4d07..3846b51 100644 --- a/snippets/rust/src/lnurl_pay.rs +++ b/snippets/rust/src/lnurl_pay.rs @@ -12,11 +12,14 @@ async fn pay(sdk: Arc) -> Result<()> { let lnurl_pay_url = "lightning@address.com"; if let Ok(LnUrlPay{data: pd}) = parse(lnurl_pay_url).await { - // TODO Show payment details in UI, read user input let amount_msat = pd.min_sendable; let comment = "Test payment".to_string(); - sdk.lnurl_pay(amount_msat, Some(comment), pd).await?; + sdk.lnurl_pay(LnUrlPayRequest { + data: pd, + amount_msat, + comment: Some(comment) + }).await?; } // ANCHOR_END: lnurl-pay diff --git a/snippets/rust/src/lnurl_withdraw.rs b/snippets/rust/src/lnurl_withdraw.rs index 0cfeac3..a88bd3a 100644 --- a/snippets/rust/src/lnurl_withdraw.rs +++ b/snippets/rust/src/lnurl_withdraw.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use anyhow::Result; use breez_sdk_core::*; +use breez_sdk_core::InputType::LnUrlWithdraw; async fn withdraw(sdk: Arc) -> Result<()> { // ANCHOR: lnurl-withdraw @@ -13,7 +14,11 @@ async fn withdraw(sdk: Arc) -> Result<()> { let amount_msat = wd.min_withdrawable; let description = "Test withdraw".to_string(); - sdk.lnurl_withdraw(wd, amount_msat, Some(description)).await?; + sdk.lnurl_withdraw(LnUrlWithdrawRequest { + data: wd, + amount_msat, + description: Some(description) + }).await?; } // ANCHOR_END: lnurl-withdraw diff --git a/snippets/rust/src/receive_onchain.rs b/snippets/rust/src/receive_onchain.rs index 4567638..468049e 100644 --- a/snippets/rust/src/receive_onchain.rs +++ b/snippets/rust/src/receive_onchain.rs @@ -36,7 +36,12 @@ async fn execute_refund(sdk: Arc, refund_tx_fee_rate: u32, refund // ANCHOR: execute-refund let destination_address = "...".into(); let sat_per_vbyte = refund_tx_fee_rate; - sdk.refund(refundable.bitcoin_address, destination_address, sat_per_vbyte).await?; + + sdk.refund(RefundRequest { + to_address: destination_address, + sat_per_vbyte, + swap_address: refundable.bitcoin_address + }).await?; // ANCHOR_END: execute-refund Ok(()) diff --git a/snippets/rust/src/receive_payment.rs b/snippets/rust/src/receive_payment.rs index 12149a4..31a1643 100644 --- a/snippets/rust/src/receive_payment.rs +++ b/snippets/rust/src/receive_payment.rs @@ -7,7 +7,7 @@ async fn receive_payment(sdk: Arc) -> Result<()> { // ANCHOR: receive-payment let res = sdk.receive_payment( ReceivePaymentRequest { - amount_sats: 3000, + amount_msat: 3_000_000, description: "Invoice for 3000 sats".into(), cltv: None, expiry: None, diff --git a/snippets/rust/src/send_onchain.rs b/snippets/rust/src/send_onchain.rs index 2513c8a..0dcffb3 100644 --- a/snippets/rust/src/send_onchain.rs +++ b/snippets/rust/src/send_onchain.rs @@ -18,7 +18,7 @@ async fn get_current_fees(sdk: Arc) -> Result<()> { Ok(()) } -async fn list_current_fees(sdk: Arc, current_fees: ReverseSwapPairInfo) -> Result<()> { +async fn list_current_fees(current_fees: ReverseSwapPairInfo) -> Result<()> { // ANCHOR: get-current-reverse-swap-min-max info!("Minimum amount, in sats: {}", current_fees.min); info!("Maximum amount, in sats: {}", current_fees.max); @@ -27,14 +27,19 @@ async fn list_current_fees(sdk: Arc, current_fees: ReverseSwapPai Ok(()) } -async fn start_reverse_swap(sdk: Arc, current_fees: ReverseSwapPairInfo, fee_rate: u64) -> Result<()> { +async fn start_reverse_swap(sdk: Arc, current_fees: ReverseSwapPairInfo, fee_rate: u32) -> Result<()> { // ANCHOR: start-reverse-swap let destination_address = String::from("bc1.."); let amount_sat = current_fees.min; - let satPerVbyte = fee_rate; - // ANCHOR_END: start-reverse-swap + let sat_per_vbyte = fee_rate; - sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash, satPerVbyte).await?; + sdk.send_onchain(SendOnchainRequest { + pair_hash: current_fees.fees_hash, + amount_sat, + sat_per_vbyte, + onchain_recipient_address: destination_address + }).await?; + // ANCHOR_END: start-reverse-swap Ok(()) } diff --git a/snippets/rust/src/send_payment.rs b/snippets/rust/src/send_payment.rs index 89844b3..c681ebe 100644 --- a/snippets/rust/src/send_payment.rs +++ b/snippets/rust/src/send_payment.rs @@ -5,8 +5,12 @@ use breez_sdk_core::*; async fn send_payment(sdk: Arc) -> Result<()> { // ANCHOR: send-payment - let bolt11 = "..."; - sdk.send_payment(bolt11.into(), None).await?; + let bolt11 = "...".into(); + + sdk.send_payment(SendPaymentRequest { + bolt11, + amount_msat: None + }).await?; // ANCHOR_END: send-payment Ok(()) diff --git a/snippets/rust/src/send_spontaneous_payment.rs b/snippets/rust/src/send_spontaneous_payment.rs index 8c75e8f..13454b3 100644 --- a/snippets/rust/src/send_spontaneous_payment.rs +++ b/snippets/rust/src/send_spontaneous_payment.rs @@ -5,8 +5,12 @@ use breez_sdk_core::*; async fn send_spontaneous_payment(sdk: Arc) -> Result<()> { // ANCHOR: send-spontaneous-payment - let node_id = "..."; - sdk.send_spontaneous_payment(node_id.into(), 3000).await?; + let node_id = "...".into(); + + sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest { + amount_msat: 3_000_000, + node_id + }).await?; // ANCHOR_END: send-spontaneous-payment Ok(())