mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
Use snippet anchor instead of line range
This commit is contained in:
@@ -4,11 +4,13 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn buy(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: buy-btc
|
||||
let res = sdk.buy_bitcoin(
|
||||
BuyBitcoinRequest {
|
||||
provider: BuyBitcoinProvider::Moonpay,
|
||||
opening_fee_params: None})
|
||||
.await?;
|
||||
// ANCHOR_END: buy-btc
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,14 +4,18 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn get_lsp_info(sdk: Arc<BreezServices>) -> Result<LspInformation> {
|
||||
// ANCHOR: get-lsp-info
|
||||
let lsp_id = sdk.lsp_id().await?;
|
||||
let lsp_info = sdk.lsp_info().await?;
|
||||
// ANCHOR_END: get-lsp-info
|
||||
|
||||
Ok(lsp_info)
|
||||
}
|
||||
|
||||
async fn connect_lsp(sdk: Arc<BreezServices>, lsp_id: String) -> Result<()> {
|
||||
// ANCHOR: connect-lsp
|
||||
sdk.connect_lsp(lsp_id).await?;
|
||||
// ANCHOR_END: connect-lsp
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,18 +5,23 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn list_supported_fiat_currencies(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: list-fiat-currencies
|
||||
let supported_fiat_currencies = sdk.list_fiat_currencies().await?;
|
||||
// ANCHOR_END: list-fiat-currencies
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_current_rates(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: fetch-fiat-rates
|
||||
let fiat_rates = sdk.fetch_fiat_rates().await?;
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_fiat_currencies_and_rates(sdk: Arc<BreezServices>) -> Result<Vec<(FiatCurrency, Rate)>> {
|
||||
// ANCHOR: get-fiat-currencies-and-rates
|
||||
let supported_fiat_currencies = sdk.list_fiat_currencies().await?;
|
||||
let fiat_rates = sdk.fetch_fiat_rates().await?;
|
||||
|
||||
@@ -37,4 +42,5 @@ async fn get_fiat_currencies_and_rates(sdk: Arc<BreezServices>) -> Result<Vec<(F
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use std::sync::Arc;
|
||||
use crate::AppEventListener;
|
||||
|
||||
async fn getting_started() -> Result<Arc<BreezServices>> {
|
||||
// ANCHOR: init-sdk
|
||||
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
|
||||
let seed = mnemonic.to_seed("");
|
||||
let invite_code = Some("<invite code>".into());
|
||||
@@ -33,15 +34,18 @@ async fn getting_started() -> Result<Arc<BreezServices>> {
|
||||
Box::new(AppEventListener {}),
|
||||
)
|
||||
.await?;
|
||||
// ANCHOR_END: init-sdk
|
||||
|
||||
Ok(sdk)
|
||||
}
|
||||
|
||||
async fn getting_started_node_info(sdk: Arc<BreezServices>) -> 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;
|
||||
}
|
||||
// ANCHOR_END: fetch-balance
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -4,6 +4,7 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn list_payments(sdk: Arc<BreezServices>) -> Result<Vec<Payment>> {
|
||||
// ANCHOR: list-payments
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::All,
|
||||
@@ -12,11 +13,13 @@ async fn list_payments(sdk: Arc<BreezServices>) -> Result<Vec<Payment>> {
|
||||
include_failures: None,
|
||||
}
|
||||
).await?;
|
||||
// ANCHOR_END: list-payments
|
||||
|
||||
Ok(payments)
|
||||
}
|
||||
|
||||
async fn list_payments_filtered(sdk: Arc<BreezServices>) -> Result<Vec<Payment>> {
|
||||
// ANCHOR: list-payments-filtered
|
||||
let payments = sdk.list_payments(
|
||||
ListPaymentRequest {
|
||||
filter: PaymentTypeFilter::Sent,
|
||||
@@ -25,6 +28,7 @@ async fn list_payments_filtered(sdk: Arc<BreezServices>) -> Result<Vec<Payment>>
|
||||
include_failures: true,
|
||||
}
|
||||
).await?;
|
||||
// ANCHOR_END: list-payments-filtered
|
||||
|
||||
Ok(payments)
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use breez_sdk_core::InputType::LnUrlAuth;
|
||||
use log::{error, info};
|
||||
|
||||
async fn auth(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: lnurl-auth
|
||||
// Endpoint can also be of the form:
|
||||
// keyauth://domain.com/auth?key=val
|
||||
let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
|
||||
@@ -23,6 +24,7 @@ async fn auth(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ANCHOR_END: lnurl-auth
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use breez_sdk_core::*;
|
||||
use breez_sdk_core::InputType::LnUrlPay;
|
||||
|
||||
async fn pay(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: lnurl-pay
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlp://domain.com/lnurl-pay?key=val
|
||||
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
|
||||
@@ -17,6 +18,7 @@ async fn pay(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
|
||||
sdk.lnurl_pay(amount_msat, Some(comment), pd).await?;
|
||||
}
|
||||
// ANCHOR_END: lnurl-pay
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn withdraw(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: lnurl-withdraw
|
||||
// Endpoint can also be of the form:
|
||||
// lnurlw://domain.com/lnurl-withdraw?key=val
|
||||
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
|
||||
@@ -14,6 +15,7 @@ async fn withdraw(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
|
||||
sdk.lnurl_withdraw(wd, amount_msat, Some(description)).await?;
|
||||
}
|
||||
// ANCHOR_END: lnurl-withdraw
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,40 +4,50 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn generate_receive_onchain_address(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: generate-receive-onchain-address
|
||||
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;
|
||||
// ANCHOR_END: generate-receive-onchain-address
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_in_progress_swap(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: in-progress-swap
|
||||
let swap_info = sdk.in_progress_swap().await?;
|
||||
// ANCHOR_END: in-progress-swap
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_refundables(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: list-refundables
|
||||
let refundables = sdk.list_refundables().await?;
|
||||
// ANCHOR_END: list-refundables
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn execute_refund(sdk: Arc<BreezServices>, refund_tx_fee_rate: u32, refundable: SwapInfo) -> Result<()> {
|
||||
// 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?;
|
||||
// ANCHOR_END: execute-refund
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_channel_opening_fees(sdk: Arc<BreezServices>, amount_msat: u64) -> Result<()> {
|
||||
// ANCHOR: get-channel-opening-fees
|
||||
let channel_fees = sdk.open_channel_fee(
|
||||
OpenChannelFeeRequest { amount_msat, expiry: None })
|
||||
.await?;
|
||||
// ANCHOR_END: get-channel-opening-fees
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -4,6 +4,7 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn receive_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: receive-payment
|
||||
let res = sdk.receive_payment(
|
||||
ReceivePaymentRequest {
|
||||
amount_sats: 3000,
|
||||
@@ -15,6 +16,7 @@ async fn receive_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
use_description_hash: None
|
||||
})
|
||||
.await?;
|
||||
// ANCHOR_END: receive-payment
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -5,28 +5,34 @@ use breez_sdk_core::*;
|
||||
use log::info;
|
||||
|
||||
async fn get_current_fees(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: estimate-current-reverse-swap-total-fees
|
||||
let current_fees = sdk.fetch_reverse_swap_fees(
|
||||
ReverseSwapFeesRequest {
|
||||
send_amount_sat: Some(50000),
|
||||
send_amount_sat: Some(50_000),
|
||||
})
|
||||
.await?;
|
||||
|
||||
info!("Total estimated fees for reverse swap: {:?}", current_fees.total_estimated_fees);
|
||||
// ANCHOR_END: estimate-current-reverse-swap-total-fees
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_current_fees(sdk: Arc<BreezServices>, 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);
|
||||
// ANCHOR_END: get-current-reverse-swap-min-max
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn start_reverse_swap(sdk: Arc<BreezServices>, current_fees: ReverseSwapPairInfo, fee_rate: u64) -> 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
|
||||
|
||||
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash, satPerVbyte).await?;
|
||||
|
||||
@@ -34,9 +40,11 @@ async fn start_reverse_swap(sdk: Arc<BreezServices>, current_fees: ReverseSwapPa
|
||||
}
|
||||
|
||||
async fn check_reverse_swap_status(sdk: Arc<BreezServices>) -> 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);
|
||||
}
|
||||
// ANCHOR_END: check-reverse-swaps-status
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -4,8 +4,10 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn send_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: send-payment
|
||||
let bolt11 = "...";
|
||||
sdk.send_payment(bolt11.into(), None).await?;
|
||||
// ANCHOR_END: send-payment
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -4,8 +4,10 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn send_spontaneous_payment(sdk: Arc<BreezServices>) -> Result<()> {
|
||||
// ANCHOR: send-spontaneous-payment
|
||||
let node_id = "...";
|
||||
sdk.send_spontaneous_payment(node_id.into(), 3000).await?;
|
||||
// ANCHOR_END: send-spontaneous-payment
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -2,9 +2,11 @@ use anyhow::Result;
|
||||
use breez_sdk_core::*;
|
||||
|
||||
async fn retrieve_backup_files() -> Result<()> {
|
||||
// ANCHOR: static-channel-backup
|
||||
let backup_data = BreezServices::static_backup(StaticBackupRequest {
|
||||
working_dir: "<working directory>".into(),
|
||||
})?;
|
||||
// ANCHOR_END: static-channel-backup
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user