mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 05:44:20 +01:00
Extract rust snippets and reference them
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
||||
book
|
||||
.DS_Store
|
||||
.idea
|
||||
|
||||
# Sub-projects with code snippets
|
||||
snippets/rust/target
|
||||
3622
snippets/rust/Cargo.lock
generated
Normal file
3622
snippets/rust/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
snippets/rust/Cargo.toml
Normal file
11
snippets/rust/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "sdk_docs_snippets"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
bip39 = { version = "2", features = ["rand"] }
|
||||
breez-sdk-core = { git = "https://github.com/breez/breez-sdk", rev = "d6365dc90263f3ad3f65a113fdc016a0bf070d9d" }
|
||||
log = "0.4"
|
||||
tokio = "1.29"
|
||||
14
snippets/rust/src/buy_btc.rs
Normal file
14
snippets/rust/src/buy_btc.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn buy(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let res = sdk.buy_bitcoin(
|
||||
BuyBitcoinRequest {
|
||||
provider: BuyBitcoinProvider::Moonpay,
|
||||
opening_fee_params: None})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
17
snippets/rust/src/connecting_lsp.rs
Normal file
17
snippets/rust/src/connecting_lsp.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn get_lsp_info(sdk: Arc<BreezServices>) -> Result<LspInformation> {
|
||||
let lsp_id = sdk.lsp_id().await?;
|
||||
let lsp_info = sdk.lsp_info().await?;
|
||||
|
||||
Ok(lsp_info)
|
||||
}
|
||||
|
||||
async fn connect_lsp(sdk: Arc<BreezServices>, lsp_id: String) -> Result<()> {
|
||||
sdk.connect_lsp(lsp_id).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
40
snippets/rust/src/fiat_currencies.rs
Normal file
40
snippets/rust/src/fiat_currencies.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn list_supported_fiat_currencies(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let supported_fiat_currencies = sdk.list_fiat_currencies().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_current_rates(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let fiat_rates = sdk.fetch_fiat_rates().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_fiat_currencies_and_rates(sdk: Arc<BreezServices>) -> Result<Vec<(FiatCurrency, Rate)>> {
|
||||
let supported_fiat_currencies = sdk.list_fiat_currencies().await?;
|
||||
let fiat_rates = sdk.fetch_fiat_rates().await?;
|
||||
|
||||
let mut rates_map : HashMap<String, Rate> = HashMap::new();
|
||||
for rate in fiat_rates {
|
||||
rates_map.insert(rate.coin.to_string().to_lowercase(), rate);
|
||||
}
|
||||
|
||||
let mut sorted = supported_fiat_currencies.clone();
|
||||
sorted.sort_by_key(|f| f.info.name);
|
||||
|
||||
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() {
|
||||
result.push((currency, rate));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
47
snippets/rust/src/getting_started.rs
Normal file
47
snippets/rust/src/getting_started.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use anyhow::Result;
|
||||
use bip39::{Language, Mnemonic};
|
||||
use breez_sdk_core::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::AppEventListener;
|
||||
|
||||
async fn getting_started() -> Result<Arc<BreezServices>> {
|
||||
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
|
||||
let seed = mnemonic.to_seed("");
|
||||
let invite_code = Some("<invite code>".into());
|
||||
let api_key = "<api key>".into();
|
||||
|
||||
// Create the default config
|
||||
let mut config = BreezServices::default_config(
|
||||
EnvironmentType::Production,
|
||||
api_key,
|
||||
breez_sdk_core::NodeConfig::Greenlight {
|
||||
config: GreenlightNodeConfig {
|
||||
partner_credentials: None,
|
||||
invite_code
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
// Customize the config object according to your needs
|
||||
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?;
|
||||
|
||||
Ok(sdk)
|
||||
}
|
||||
|
||||
async fn getting_started_node_info(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
if let Some(node_state) = sdk.node_info()? {
|
||||
let balance_ln = node_state.channels_balance_msat;
|
||||
let balance_onchain = node_state.onchain_balance_msat;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
30
snippets/rust/src/list_payments.rs
Normal file
30
snippets/rust/src/list_payments.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn list_payments(sdk: Arc<BreezServices>) -> Result<Vec<Payment>> {
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::All,
|
||||
from_timestamp: None,
|
||||
to_timestamp: None,
|
||||
include_failures: None,
|
||||
}
|
||||
).await?;
|
||||
|
||||
Ok(payments)
|
||||
}
|
||||
|
||||
async fn list_payments_filtered(sdk: Arc<BreezServices>) -> Result<Vec<Payment>> {
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::Sent,
|
||||
from_timestamp: 1696880000,
|
||||
to_timestamp: None,
|
||||
include_failures: true,
|
||||
}
|
||||
).await?;
|
||||
|
||||
Ok(payments)
|
||||
}
|
||||
28
snippets/rust/src/lnurl_auth.rs
Normal file
28
snippets/rust/src/lnurl_auth.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
use breez_sdk_core::InputType::LnUrlAuth;
|
||||
use log::{error, info};
|
||||
|
||||
async fn auth(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// Endpoint can also be of the form:
|
||||
// keyauth://domain.com/auth?key=val
|
||||
let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
|
||||
|
||||
if let Ok(LnUrlAuth{data: ad}) = parse(lnurl_auth_url).await {
|
||||
match sdk.lnurl_auth(ad).await {
|
||||
Ok(LnUrlCallbackStatus::Ok) => {
|
||||
info!("Successfully authenticated")
|
||||
}
|
||||
Ok(LnUrlCallbackStatus::ErrorStatus { data }) => {
|
||||
error!("Failed to authenticate: {}", data.reason)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to connect: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
22
snippets/rust/src/lnurl_pay.rs
Normal file
22
snippets/rust/src/lnurl_pay.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
use breez_sdk_core::InputType::LnUrlPay;
|
||||
|
||||
async fn pay(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlp://domain.com/lnurl-pay?key=val
|
||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
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?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
19
snippets/rust/src/lnurl_withdraw.rs
Normal file
19
snippets/rust/src/lnurl_withdraw.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn withdraw(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
|
||||
|
||||
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(wd, amount_msat, Some(description)).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
32
snippets/rust/src/main.rs
Normal file
32
snippets/rust/src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
mod getting_started;
|
||||
mod receive_payment;
|
||||
mod send_payment;
|
||||
mod send_spontaneous_payment;
|
||||
mod list_payments;
|
||||
mod connecting_lsp;
|
||||
mod receive_onchain;
|
||||
mod send_onchain;
|
||||
mod lnurl_pay;
|
||||
mod lnurl_withdraw;
|
||||
mod lnurl_auth;
|
||||
mod fiat_currencies;
|
||||
mod buy_btc;
|
||||
mod static_channel_backup;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
use log::info;
|
||||
|
||||
struct AppEventListener {}
|
||||
impl EventListener for AppEventListener {
|
||||
fn on_event(&self, e: BreezEvent) {
|
||||
info!("Received Breez event: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
43
snippets/rust/src/receive_onchain.rs
Normal file
43
snippets/rust/src/receive_onchain.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn generate_receive_onchain_address(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let swap_info = sdk.receive_onchain(
|
||||
ReceiveOnchainRequest { opening_fee_params: None } )
|
||||
.await?;
|
||||
|
||||
// Send your funds to the below bitcoin address
|
||||
let address = swap_info.bitcoin_address;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_in_progress_swap(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let swap_info = sdk.in_progress_swap().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_refundables(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let refundables = sdk.list_refundables().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn execute_refund(sdk: Arc<BreezServices>, refund_tx_fee_rate: u32, refundable: SwapInfo) -> Result<()> {
|
||||
let destination_address = "...".into();
|
||||
let sat_per_vbyte = refund_tx_fee_rate;
|
||||
sdk.refund(refundable.bitcoin_address, destination_address, sat_per_vbyte).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_channel_opening_fees(sdk: Arc<BreezServices>, amount_msat: u64) -> Result<()> {
|
||||
let channel_fees = sdk.open_channel_fee(
|
||||
OpenChannelFeeRequest { amount_msat, expiry: None })
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
20
snippets/rust/src/receive_payment.rs
Normal file
20
snippets/rust/src/receive_payment.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn receive_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let res = sdk.receive_payment(
|
||||
ReceivePaymentRequest {
|
||||
amount_sats: 3000,
|
||||
description: "Invoice for 3000 sats".into(),
|
||||
cltv: None,
|
||||
expiry: None,
|
||||
opening_fee_params: None,
|
||||
preimage: None,
|
||||
use_description_hash: None
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
42
snippets/rust/src/send_onchain.rs
Normal file
42
snippets/rust/src/send_onchain.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
use log::info;
|
||||
|
||||
async fn get_current_fees(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let current_fees = sdk.fetch_reverse_swap_fees(
|
||||
ReverseSwapFeesRequest {
|
||||
send_amount_sat: Some(50000),
|
||||
})
|
||||
.await?;
|
||||
|
||||
info!("Total estimated fees for reverse swap: {:?}", current_fees.total_estimated_fees);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_current_fees(sdk: Arc<BreezServices>, current_fees: ReverseSwapPairInfo) -> Result<()> {
|
||||
info!("Minimum amount, in sats: {}", current_fees.min);
|
||||
info!("Maximum amount, in sats: {}", current_fees.max);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start_reverse_swap(sdk: Arc<BreezServices>, current_fees: ReverseSwapPairInfo, fee_rate: u64) -> Result<()> {
|
||||
let destination_address = String::from("bc1..");
|
||||
let amount_sat = current_fees.min;
|
||||
let satPerVbyte = fee_rate;
|
||||
|
||||
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash, satPerVbyte).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn check_reverse_swap_status(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
for rs in sdk.in_progress_reverse_swaps().await? {
|
||||
info!("Reverse swap {} in progress, status is {:?}", rs.id, rs.status);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
11
snippets/rust/src/send_payment.rs
Normal file
11
snippets/rust/src/send_payment.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn send_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let bolt11 = "...";
|
||||
sdk.send_payment(bolt11.into(), None).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
11
snippets/rust/src/send_spontaneous_payment.rs
Normal file
11
snippets/rust/src/send_spontaneous_payment.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn send_spontaneous_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
let node_id = "...";
|
||||
sdk.send_spontaneous_payment(node_id.into(), 3000).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
10
snippets/rust/src/static_channel_backup.rs
Normal file
10
snippets/rust/src/static_channel_backup.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn retrieve_backup_files() -> Result<()> {
|
||||
let backup_data = BreezServices::static_backup(StaticBackupRequest {
|
||||
working_dir: "<working directory>".into(),
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -12,11 +12,7 @@ Once the buy is completed, the provider will transfer the Bitcoin to the generat
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let res = sdk.buy_bitcoin(
|
||||
BuyBitcoinRequest {
|
||||
provider: BuyBitcoinProvider::Moonpay,
|
||||
opening_fee_params: None})
|
||||
.await?;
|
||||
{{#include ../../snippets/rust/src/buy_btc.rs:7:11}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let lsp_id = sdk.lsp_id().await?;
|
||||
let lsp_info = sdk.lsp_info().await?;
|
||||
{{#include ../../snippets/rust/src/connecting_lsp.rs:7:8}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -118,7 +117,7 @@ When you have selected an LSP you may then connect to it.
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
sdk.connect_lsp(lsp_id).await?;
|
||||
{{#include ../../snippets/rust/src/connecting_lsp.rs:14}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
In order to list the available fiat currencies:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
{{#include ../../snippets/rust/src/fiat_currencies.rs:8}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Android</div>
|
||||
<section>
|
||||
|
||||
@@ -80,6 +88,14 @@ catch (Exception)
|
||||
To get the current BTC rate for the currencies:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
{{#include ../../snippets/rust/src/fiat_currencies.rs:14}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Android</div>
|
||||
<section>
|
||||
|
||||
@@ -159,6 +175,14 @@ catch (Exception)
|
||||
At the example project you can see these methods combined:
|
||||
|
||||
<custom-tabs category="lang">
|
||||
<div slot="title">Rust</div>
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
{{#include ../../snippets/rust/src/fiat_currencies.rs:20:39}}
|
||||
```
|
||||
</section>
|
||||
|
||||
<div slot="title">Android</div>
|
||||
<section>
|
||||
|
||||
|
||||
@@ -38,33 +38,7 @@ Now your SDK is ready to be used.
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
|
||||
let seed = mnemonic.to_seed("");
|
||||
let invite_code = Some("<invite code>".into());
|
||||
let api_key = "<api key>".into()
|
||||
|
||||
// Create the default config
|
||||
let mut config = BreezServices::default_config(
|
||||
EnvironmentType::Production,
|
||||
api_key,
|
||||
breez_sdk_core::NodeConfig::Greenlight {
|
||||
config: GreenlightNodeConfig {
|
||||
partner_credentials: None,
|
||||
invite_code
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
// Customize the config object according to your needs
|
||||
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?;
|
||||
{{#include ../../snippets/rust/src/getting_started.rs:9:35}}
|
||||
```
|
||||
|
||||
</section>
|
||||
@@ -322,10 +296,7 @@ At any point we can fetch our balance from the Greenlight node:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
if let Some(node_state) = sdk.node_info()? {
|
||||
let balance_ln = node_state.channels_balance_msat;
|
||||
let balance_onchain = node_state.onchain_balance_msat;
|
||||
}
|
||||
{{#include ../../snippets/rust/src/getting_started.rs:41:44}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -7,14 +7,7 @@ To view your payment history you can list and filter all the sent and received p
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::All,
|
||||
from_timestamp: None,
|
||||
to_timestamp: None,
|
||||
include_failures: None,
|
||||
}
|
||||
).await?;
|
||||
{{#include ../../snippets/rust/src/list_payments.rs:7:14}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -112,14 +105,7 @@ You can optionally filter payments by timestamp and include failed payments.
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::Sent,
|
||||
from_timestamp: 1696880000,
|
||||
to_timestamp: None,
|
||||
include_failures: true,
|
||||
}
|
||||
).await?;
|
||||
{{#include ../../snippets/rust/src/list_payments.rs:20:27}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -6,23 +6,7 @@
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
// Endpoint can also be of the form:
|
||||
// keyauth://domain.com/auth?key=val
|
||||
let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
|
||||
|
||||
if let Ok(LnUrlAuth{data: ad}) = parse(lnurl_auth_url).await {
|
||||
match sdk.lnurl_auth(ad).await {
|
||||
Ok(LnUrlCallbackStatus::Ok) => {
|
||||
info!("Successfully authenticated")
|
||||
}
|
||||
Ok(LnUrlCallbackStatus::ErrorStatus { data }) => {
|
||||
error!("Failed to authenticate: {}", data.reason)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to connect: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
{{#include ../../snippets/rust/src/lnurl_auth.rs:9:25}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -7,18 +7,7 @@
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlp://domain.com/lnurl-pay?key=val
|
||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
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?;
|
||||
}
|
||||
{{#include ../../snippets/rust/src/lnurl_pay.rs:8:19}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -8,16 +8,7 @@
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
|
||||
|
||||
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(wd, amount_msat, Some(description)).await?;
|
||||
}
|
||||
{{#include ../../snippets/rust/src/lnurl_withdraw.rs:7:17}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -10,12 +10,7 @@ In order to receive funds you first have to be connected to an [LSP](connecting_
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let swap_info = sdk.receive_onchain(
|
||||
ReceiveOnchainRequest { opening_fee_params: None } )
|
||||
.await?;
|
||||
|
||||
// Send your funds to the below bitcoin address
|
||||
let address = swap_info.bitcoin_address;
|
||||
{{#include ../../snippets/rust/src/receive_onchain.rs:7:12}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -132,7 +127,7 @@ Once you've sent the funds to the above address, the SDK will monitor this addre
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let swap_info = sdk.in_progress_swap().await?
|
||||
{{#include ../../snippets/rust/src/receive_onchain.rs:18}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -233,7 +228,7 @@ In order to execute a refund, you need to supply an on-chain address to where th
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let refundables = sdk.list_refundables().await?
|
||||
{{#include ../../snippets/rust/src/receive_onchain.rs:24}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -329,9 +324,7 @@ Once you have a refundable swap in hand, use the following code to execute a ref
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let destination_address = "...".into()
|
||||
let sat_per_vbyte = <refund tx fee rate>
|
||||
sdk.refund(refundable.bitcoin_address, destination_address, sat_per_vbyte).await?
|
||||
{{#include ../../snippets/rust/src/receive_onchain.rs:30:32}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -460,10 +453,7 @@ To calculate the fees for a channel being opened by the LSP:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let amount_msat = <amount msat>;
|
||||
let channel_fees = sdk.open_channel_fee(
|
||||
OpenChannelFeeRequest { amount_msat, expiry: None })
|
||||
.await?;
|
||||
{{#include ../../snippets/rust/src/receive_onchain.rs:38:40}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -8,17 +8,7 @@ The Breez SDK automatically connects your node to the LSP peer and you can now r
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let res = sdk.receive_payment(
|
||||
ReceivePaymentRequest {
|
||||
amount_sats: 3000,
|
||||
description: "Invoice for 3000 sats".into(),
|
||||
cltv: None,
|
||||
expiry: None,
|
||||
opening_fee_params: None,
|
||||
preimage: None,
|
||||
use_description_hash: None
|
||||
})
|
||||
.await?;
|
||||
{{#include ../../snippets/rust/src/receive_payment.rs:7:17}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -9,13 +9,7 @@ First, fetch the current reverse swap fees:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let current_fees = sdk.fetch_reverse_swap_fees(
|
||||
ReverseSwapFeesRequest {
|
||||
send_amount_sat: Some(50000),
|
||||
})
|
||||
.await?;
|
||||
|
||||
info!("Total estimated fees for reverse swap: {}", current_fees.total_estimated_fees);
|
||||
{{#include ../../snippets/rust/src/send_onchain.rs:8:14}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -135,8 +129,7 @@ Fetching the fees also tells you what is the range of amounts you can send:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
info!("Minimum amount, in sats: {}", current_fees.min);
|
||||
info!("Maximum amount, in sats: {}", current_fees.max);
|
||||
{{#include ../../snippets/rust/src/send_onchain.rs:20:21}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -211,11 +204,7 @@ Once you checked the fees are acceptable, you can start the reverse swap:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let destination_address = String::from("bc1..");
|
||||
let amount_sat = current_fees.min;
|
||||
let satPerVbyte = <fee rate>;
|
||||
|
||||
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash, satPerVbyte).await?;
|
||||
{{#include ../../snippets/rust/src/send_onchain.rs:27:31}}
|
||||
```
|
||||
</section>
|
||||
|
||||
@@ -352,9 +341,7 @@ You can check its status with:
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
for rs in sdk.in_progress_reverse_swaps().await? {
|
||||
info!("Reverse swap {} in progress, status is {}", rs.id, rs.status);
|
||||
}
|
||||
{{#include ../../snippets/rust/src/send_onchain.rs:37:40}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ Once you have outbound liquidity you can start sending payments too.
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let bolt11 = "...";
|
||||
sdk.send_payment(bolt11.into(), None).await?;
|
||||
{{#include ../../snippets/rust/src/send_payment.rs:7:8}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ They can even be spontaneous payments to a node without a bolt11 invoice.
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let node_id = "...";
|
||||
sdk.send_spontaneous_payment(node_id.into(), 3000).await?;
|
||||
{{#include ../../snippets/rust/src/send_spontaneous_payment.rs:7:8}}
|
||||
```
|
||||
</section>
|
||||
|
||||
|
||||
@@ -12,9 +12,7 @@ In order to use the recoverchannel method, the user needs to provide the static
|
||||
<section>
|
||||
|
||||
```rust,ignore
|
||||
let backup_data = BreezServices::static_backup(StaticBackupRequest {
|
||||
working_dir: "<working directory>".into(),
|
||||
})?;
|
||||
{{#include ../../snippets/rust/src/static_channel_backup.rs:5:7}}
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user