diff --git a/snippets/rust/Cargo.lock b/snippets/rust/Cargo.lock index 7567bb2..77f66ec 100644 --- a/snippets/rust/Cargo.lock +++ b/snippets/rust/Cargo.lock @@ -428,15 +428,6 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -467,8 +458,8 @@ dependencies = [ [[package]] name = "breez-sdk-core" -version = "0.2.3" -source = "git+https://github.com/breez/breez-sdk?rev=3486c951e2422fe4ac3978795849f0b7649a9f1e#3486c951e2422fe4ac3978795849f0b7649a9f1e" +version = "0.2.9" +source = "git+https://github.com/breez/breez-sdk?tag=0.2.9#82fdc4f7d2de354fc299cc4fbf8691492d4bc642" dependencies = [ "aes", "anyhow", @@ -481,6 +472,7 @@ dependencies = [ "ecies", "env_logger 0.10.0", "flutter_rust_bridge", + "futures", "gl-client", "hex", "lazy_static", @@ -698,16 +690,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "ctr" version = "0.9.2" @@ -811,7 +793,7 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", "crypto-common", "subtle", ] @@ -835,18 +817,20 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "ecies" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99640b5549bc868ffda7e9bd98d4998d86ddb7f5fb302f25837be276ba4dfcb4" +checksum = "53f43496fc04523aa716c5dd76133cb6d7c81eb213375684d06a8b1683f8bc1e" dependencies = [ "aes-gcm", "getrandom", "hkdf", "libsecp256k1", "once_cell", - "rand", - "sha2 0.10.7", + "parking_lot", + "rand_core", + "sha2", "typenum", + "wasm-bindgen", ] [[package]] @@ -952,9 +936,9 @@ dependencies = [ [[package]] name = "flutter_rust_bridge" -version = "1.75.2" +version = "1.80.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934edaa5cab8c8df975c347e08014605775fb6969631b725cf2b962bd0988663" +checksum = "fd0305ebc9f097d9826530a55fc2acd63222e912c663f7adce3ab641ecc0f346" dependencies = [ "allo-isolate", "anyhow", @@ -1148,7 +1132,7 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "gl-client" version = "0.1.9" -source = "git+https://github.com/Blockstream/greenlight.git?rev=f91390734fc8a3044812f05ff8d0e102660189bb#f91390734fc8a3044812f05ff8d0e102660189bb" +source = "git+https://github.com/Blockstream/greenlight.git?rev=c7ff67eb062c021105f5601df3ac8699ecbeb51c#c7ff67eb062c021105f5601df3ac8699ecbeb51c" dependencies = [ "anyhow", "async-trait", @@ -1286,17 +1270,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" dependencies = [ - "hmac 0.12.1", -] - -[[package]] -name = "hmac" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" -dependencies = [ - "crypto-mac", - "digest 0.9.0", + "hmac", ] [[package]] @@ -1308,17 +1282,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "hmac-drbg" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" -dependencies = [ - "digest 0.9.0", - "generic-array", - "hmac 0.8.1", -] - [[package]] name = "home" version = "0.5.5" @@ -1564,14 +1527,11 @@ dependencies = [ "arrayref", "base64 0.13.1", "digest 0.9.0", - "hmac-drbg", "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", "rand", "serde", - "sha2 0.9.9", - "typenum", ] [[package]] @@ -2671,19 +2631,6 @@ dependencies = [ "syn 2.0.32", ] -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha2" version = "0.10.7" @@ -2704,7 +2651,7 @@ dependencies = [ "async-trait", "bytes", "hex", - "sha2 0.10.7", + "sha2", "tokio", ] @@ -2921,12 +2868,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62cc94d358b5a1e84a5cb9109f559aa3c4d634d2b1b4de3d0fa4adc7c78e2861" dependencies = [ "anyhow", - "hmac 0.12.1", + "hmac", "once_cell", "pbkdf2", "rand", "rustc-hash", - "sha2 0.10.7", + "sha2", "thiserror", "unicode-normalization", "wasm-bindgen", diff --git a/snippets/rust/Cargo.toml b/snippets/rust/Cargo.toml index 18f2cdb..a721f79 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 = "3486c951e2422fe4ac3978795849f0b7649a9f1e" } +breez-sdk-core = { git = "https://github.com/breez/breez-sdk", tag = "0.2.9" } log = "0.4" tokio = "1.29" \ No newline at end of file diff --git a/snippets/rust/src/buy_btc.rs b/snippets/rust/src/buy_btc.rs index e8365ca..bc0435e 100644 --- a/snippets/rust/src/buy_btc.rs +++ b/snippets/rust/src/buy_btc.rs @@ -5,10 +5,11 @@ use breez_sdk_core::*; async fn buy(sdk: Arc) -> Result<()> { // ANCHOR: buy-btc - let res = sdk.buy_bitcoin( - BuyBitcoinRequest { + let res = sdk + .buy_bitcoin(BuyBitcoinRequest { provider: BuyBitcoinProvider::Moonpay, - opening_fee_params: None}) + opening_fee_params: None, + }) .await?; // ANCHOR_END: buy-btc diff --git a/snippets/rust/src/connecting_lsp.rs b/snippets/rust/src/connecting_lsp.rs index ccb5ee5..ae5cc71 100644 --- a/snippets/rust/src/connecting_lsp.rs +++ b/snippets/rust/src/connecting_lsp.rs @@ -18,4 +18,4 @@ async fn connect_lsp(sdk: Arc, lsp_id: String) -> Result<()> { // ANCHOR_END: connect-lsp Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/fiat_currencies.rs b/snippets/rust/src/fiat_currencies.rs index 1954c69..d7151dc 100644 --- a/snippets/rust/src/fiat_currencies.rs +++ b/snippets/rust/src/fiat_currencies.rs @@ -20,12 +20,14 @@ async fn get_current_rates(sdk: Arc) -> Result<()> { Ok(()) } -async fn get_fiat_currencies_and_rates(sdk: Arc) -> Result> { +async fn get_fiat_currencies_and_rates( + sdk: Arc, +) -> Result> { // ANCHOR: get-fiat-currencies-and-rates let supported_fiat_currencies = sdk.list_fiat_currencies().await?; let fiat_rates = sdk.fetch_fiat_rates().await?; - let mut rates_map : HashMap = HashMap::new(); + let mut rates_map: HashMap = HashMap::new(); for rate in fiat_rates { rates_map.insert(rate.coin.to_string().to_lowercase(), rate); } @@ -33,7 +35,7 @@ async fn get_fiat_currencies_and_rates(sdk: Arc) -> Result = Vec::new(); + let mut result: Vec<(FiatCurrency, Rate)> = Vec::new(); for currency in sorted { let rate = rates_map.get(¤cy.id.to_lowercase()); if let Some(rate) = rate.cloned() { @@ -43,4 +45,4 @@ async fn get_fiat_currencies_and_rates(sdk: Arc) -> Result Result> { breez_sdk_core::NodeConfig::Greenlight { config: GreenlightNodeConfig { partner_credentials: None, - invite_code + invite_code, }, }, ); @@ -28,12 +28,7 @@ async fn getting_started() -> Result> { config.working_dir = "path to an existing directory".into(); // Connect to the Breez SDK make it ready for use - let sdk = BreezServices::connect( - config, - seed.to_vec(), - Box::new(AppEventListener {}), - ) - .await?; + let sdk = BreezServices::connect(config, seed.to_vec(), Box::new(AppEventListener {})).await?; // ANCHOR_END: init-sdk Ok(sdk) @@ -47,4 +42,4 @@ async fn getting_started_node_info(sdk: Arc) -> Result<()> { // ANCHOR_END: fetch-balance Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/list_payments.rs b/snippets/rust/src/list_payments.rs index 88c81e6..086ba85 100644 --- a/snippets/rust/src/list_payments.rs +++ b/snippets/rust/src/list_payments.rs @@ -5,16 +5,7 @@ use breez_sdk_core::*; async fn list_payments(sdk: Arc) -> Result> { // ANCHOR: list-payments - let payments = sdk.list_payments( - ListPaymentsRequest { - filter: PaymentTypeFilter::All, - from_timestamp: None, - to_timestamp: None, - include_failures: None, - offset: None, - limit: None - } - ).await?; + let payments = sdk.list_payments(ListPaymentsRequest::default()).await?; // ANCHOR_END: list-payments Ok(payments) @@ -22,17 +13,15 @@ async fn list_payments(sdk: Arc) -> Result> { async fn list_payments_filtered(sdk: Arc) -> Result> { // ANCHOR: list-payments-filtered - let payments = sdk.list_payments( - ListPaymentsRequest { - filter: PaymentTypeFilter::Sent, + let payments = sdk + .list_payments(ListPaymentsRequest { + filters: Some(vec![PaymentTypeFilter::Sent]), from_timestamp: Some(1696880000), - to_timestamp: None, include_failures: Some(true), - offset: None, - limit: None - } - ).await?; + ..Default::default() + }) + .await?; // ANCHOR_END: list-payments-filtered Ok(payments) -} \ No newline at end of file +} diff --git a/snippets/rust/src/lnurl_auth.rs b/snippets/rust/src/lnurl_auth.rs index 2f93fcb..a97baaf 100644 --- a/snippets/rust/src/lnurl_auth.rs +++ b/snippets/rust/src/lnurl_auth.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use anyhow::Result; -use breez_sdk_core::*; use breez_sdk_core::InputType::LnUrlAuth; +use breez_sdk_core::*; use log::{error, info}; async fn auth(sdk: Arc) -> Result<()> { @@ -11,7 +11,7 @@ async fn auth(sdk: Arc) -> Result<()> { // keyauth://domain.com/auth?key=val let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"; - if let Ok(LnUrlAuth{data: ad}) = parse(lnurl_auth_url).await { + if let Ok(LnUrlAuth { data: ad }) = parse(lnurl_auth_url).await { match sdk.lnurl_auth(ad).await { Ok(LnUrlCallbackStatus::Ok) => { info!("Successfully authenticated") diff --git a/snippets/rust/src/lnurl_pay.rs b/snippets/rust/src/lnurl_pay.rs index 3846b51..7f323cd 100644 --- a/snippets/rust/src/lnurl_pay.rs +++ b/snippets/rust/src/lnurl_pay.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use anyhow::Result; -use breez_sdk_core::*; use breez_sdk_core::InputType::LnUrlPay; +use breez_sdk_core::*; async fn pay(sdk: Arc) -> Result<()> { // ANCHOR: lnurl-pay @@ -11,15 +11,16 @@ async fn pay(sdk: Arc) -> Result<()> { // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf let lnurl_pay_url = "lightning@address.com"; - if let Ok(LnUrlPay{data: pd}) = parse(lnurl_pay_url).await { + if let Ok(LnUrlPay { data: pd }) = parse(lnurl_pay_url).await { let amount_msat = pd.min_sendable; let comment = "Test payment".to_string(); sdk.lnurl_pay(LnUrlPayRequest { data: pd, amount_msat, - comment: Some(comment) - }).await?; + 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 a88bd3a..4f10815 100644 --- a/snippets/rust/src/lnurl_withdraw.rs +++ b/snippets/rust/src/lnurl_withdraw.rs @@ -1,8 +1,8 @@ use std::sync::Arc; use anyhow::Result; -use breez_sdk_core::*; use breez_sdk_core::InputType::LnUrlWithdraw; +use breez_sdk_core::*; async fn withdraw(sdk: Arc) -> Result<()> { // ANCHOR: lnurl-withdraw @@ -10,15 +10,16 @@ async fn withdraw(sdk: Arc) -> Result<()> { // lnurlw://domain.com/lnurl-withdraw?key=val let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"; - if let Ok(LnUrlWithdraw{data: wd}) = parse(lnurl_withdraw_url).await { + if let Ok(LnUrlWithdraw { data: wd }) = parse(lnurl_withdraw_url).await { let amount_msat = wd.min_withdrawable; let description = "Test withdraw".to_string(); sdk.lnurl_withdraw(LnUrlWithdrawRequest { data: wd, amount_msat, - description: Some(description) - }).await?; + description: Some(description), + }) + .await?; } // ANCHOR_END: lnurl-withdraw diff --git a/snippets/rust/src/main.rs b/snippets/rust/src/main.rs index c86bf6c..9c0d04e 100644 --- a/snippets/rust/src/main.rs +++ b/snippets/rust/src/main.rs @@ -1,16 +1,16 @@ -mod getting_started; -mod receive_payment; -mod send_payment; -mod send_spontaneous_payment; -mod list_payments; +mod buy_btc; mod connecting_lsp; -mod receive_onchain; -mod send_onchain; +mod fiat_currencies; +mod getting_started; +mod list_payments; +mod lnurl_auth; mod lnurl_pay; mod lnurl_withdraw; -mod lnurl_auth; -mod fiat_currencies; -mod buy_btc; +mod receive_onchain; +mod receive_payment; +mod send_onchain; +mod send_payment; +mod send_spontaneous_payment; mod static_channel_backup; use anyhow::Result; diff --git a/snippets/rust/src/receive_onchain.rs b/snippets/rust/src/receive_onchain.rs index 468049e..e689019 100644 --- a/snippets/rust/src/receive_onchain.rs +++ b/snippets/rust/src/receive_onchain.rs @@ -5,8 +5,8 @@ use breez_sdk_core::*; async fn generate_receive_onchain_address(sdk: Arc) -> Result<()> { // ANCHOR: generate-receive-onchain-address - let swap_info = sdk.receive_onchain( - ReceiveOnchainRequest { opening_fee_params: None } ) + let swap_info = sdk + .receive_onchain(ReceiveOnchainRequest::default()) .await?; // Send your funds to the below bitcoin address @@ -32,7 +32,11 @@ async fn list_refundables(sdk: Arc) -> Result<()> { Ok(()) } -async fn execute_refund(sdk: Arc, refund_tx_fee_rate: u32, refundable: SwapInfo) -> Result<()> { +async fn execute_refund( + sdk: Arc, + refund_tx_fee_rate: u32, + refundable: SwapInfo, +) -> Result<()> { // ANCHOR: execute-refund let destination_address = "...".into(); let sat_per_vbyte = refund_tx_fee_rate; @@ -40,8 +44,9 @@ async fn execute_refund(sdk: Arc, refund_tx_fee_rate: u32, refund sdk.refund(RefundRequest { to_address: destination_address, sat_per_vbyte, - swap_address: refundable.bitcoin_address - }).await?; + swap_address: refundable.bitcoin_address, + }) + .await?; // ANCHOR_END: execute-refund Ok(()) @@ -49,10 +54,13 @@ async fn execute_refund(sdk: Arc, refund_tx_fee_rate: u32, refund async fn get_channel_opening_fees(sdk: Arc, amount_msat: u64) -> Result<()> { // ANCHOR: get-channel-opening-fees - let channel_fees = sdk.open_channel_fee( - OpenChannelFeeRequest { amount_msat, expiry: None }) + let channel_fees = sdk + .open_channel_fee(OpenChannelFeeRequest { + amount_msat, + expiry: None, + }) .await?; // ANCHOR_END: get-channel-opening-fees Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/receive_payment.rs b/snippets/rust/src/receive_payment.rs index 31a1643..bede251 100644 --- a/snippets/rust/src/receive_payment.rs +++ b/snippets/rust/src/receive_payment.rs @@ -5,18 +5,14 @@ use breez_sdk_core::*; async fn receive_payment(sdk: Arc) -> Result<()> { // ANCHOR: receive-payment - let res = sdk.receive_payment( - ReceivePaymentRequest { + let res = sdk + .receive_payment(ReceivePaymentRequest { amount_msat: 3_000_000, description: "Invoice for 3000 sats".into(), - cltv: None, - expiry: None, - opening_fee_params: None, - preimage: None, - use_description_hash: None + ..Default::default() }) .await?; // ANCHOR_END: receive-payment Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/send_onchain.rs b/snippets/rust/src/send_onchain.rs index 0dcffb3..4b450d0 100644 --- a/snippets/rust/src/send_onchain.rs +++ b/snippets/rust/src/send_onchain.rs @@ -6,13 +6,16 @@ use log::info; async fn get_current_fees(sdk: Arc) -> Result<()> { // ANCHOR: estimate-current-reverse-swap-total-fees - let current_fees = sdk.fetch_reverse_swap_fees( - ReverseSwapFeesRequest { + let current_fees = sdk + .fetch_reverse_swap_fees(ReverseSwapFeesRequest { send_amount_sat: Some(50_000), }) .await?; - info!("Total estimated fees for reverse swap: {:?}", current_fees.total_estimated_fees); + info!( + "Total estimated fees for reverse swap: {:?}", + current_fees.total_estimated_fees + ); // ANCHOR_END: estimate-current-reverse-swap-total-fees Ok(()) @@ -27,7 +30,11 @@ async fn list_current_fees(current_fees: ReverseSwapPairInfo) -> Result<()> { Ok(()) } -async fn start_reverse_swap(sdk: Arc, current_fees: ReverseSwapPairInfo, fee_rate: u32) -> 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; @@ -37,8 +44,9 @@ async fn start_reverse_swap(sdk: Arc, current_fees: ReverseSwapPa pair_hash: current_fees.fees_hash, amount_sat, sat_per_vbyte, - onchain_recipient_address: destination_address - }).await?; + onchain_recipient_address: destination_address, + }) + .await?; // ANCHOR_END: start-reverse-swap Ok(()) @@ -47,9 +55,12 @@ async fn start_reverse_swap(sdk: Arc, current_fees: ReverseSwapPa async fn check_reverse_swap_status(sdk: Arc) -> Result<()> { // ANCHOR: check-reverse-swaps-status for rs in sdk.in_progress_reverse_swaps().await? { - info!("Reverse swap {} in progress, status is {:?}", rs.id, rs.status); + info!( + "Reverse swap {} in progress, status is {:?}", + rs.id, rs.status + ); } // ANCHOR_END: check-reverse-swaps-status Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/send_payment.rs b/snippets/rust/src/send_payment.rs index 051dac7..633fe5d 100644 --- a/snippets/rust/src/send_payment.rs +++ b/snippets/rust/src/send_payment.rs @@ -16,4 +16,4 @@ async fn send_payment(sdk: Arc) -> Result<()> { // ANCHOR_END: send-payment Ok(()) -} \ No newline at end of file +} diff --git a/snippets/rust/src/send_spontaneous_payment.rs b/snippets/rust/src/send_spontaneous_payment.rs index 13454b3..001bd44 100644 --- a/snippets/rust/src/send_spontaneous_payment.rs +++ b/snippets/rust/src/send_spontaneous_payment.rs @@ -9,9 +9,10 @@ async fn send_spontaneous_payment(sdk: Arc) -> Result<()> { sdk.send_spontaneous_payment(SendSpontaneousPaymentRequest { amount_msat: 3_000_000, - node_id - }).await?; + node_id, + }) + .await?; // ANCHOR_END: send-spontaneous-payment Ok(()) -} \ No newline at end of file +}