mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
Update rust examples
This commit is contained in:
@@ -7,10 +7,13 @@ This section of the Breez SDK documentation provides an example on purchasing Bi
|
|||||||
<div slot="title">Rust</div>
|
<div slot="title">Rust</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
```rust
|
```rust,ignore
|
||||||
// TODO add docs
|
let res = sdk.buy_bitcoin(
|
||||||
|
BuyBitcoinRequest {
|
||||||
|
provider: BuyBitcoinProvider::Moonpay,
|
||||||
|
opening_fee_params: None})
|
||||||
|
.await?;
|
||||||
```
|
```
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div slot="title">Swift</div>
|
<div slot="title">Swift</div>
|
||||||
@@ -23,7 +26,6 @@ do {
|
|||||||
} catch {
|
} catch {
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -59,7 +61,6 @@ try {
|
|||||||
} catch {
|
} catch {
|
||||||
// Handle error
|
// Handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -93,4 +94,5 @@ buyBitcoinResponse, err := sdkService.BuyBitcoin(breez_sdk.BuyBitcoinRequest{
|
|||||||
```cs
|
```cs
|
||||||
// TODO add docs
|
// TODO add docs
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
</custom-tabs>
|
||||||
@@ -3,6 +3,15 @@
|
|||||||
Based on the API key provided to the Breez SDK, a default LSP is selected for your node to provide liquidity to it. To get the information about the selected LSP you can do the following:
|
Based on the API key provided to the Breez SDK, a default LSP is selected for your node to provide liquidity to it. To get the information about the selected LSP you can do the following:
|
||||||
|
|
||||||
<custom-tabs category="lang">
|
<custom-tabs category="lang">
|
||||||
|
<div slot="title">Rust</div>
|
||||||
|
<section>
|
||||||
|
|
||||||
|
```rust,ignore
|
||||||
|
let lsp_id = sdk.lsp_id().await?;
|
||||||
|
let lsp_info = sdk.lsp_info().await?;
|
||||||
|
```
|
||||||
|
</section>
|
||||||
|
|
||||||
<div slot="title">Swift</div>
|
<div slot="title">Swift</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
@@ -107,6 +116,14 @@ catch (Exception)
|
|||||||
When you have selected an LSP you may then connect to it.
|
When you have selected an LSP you may then connect to it.
|
||||||
|
|
||||||
<custom-tabs category="lang">
|
<custom-tabs category="lang">
|
||||||
|
<div slot="title">Rust</div>
|
||||||
|
<section>
|
||||||
|
|
||||||
|
```rust,ignore
|
||||||
|
sdk.connect_lsp(lsp_id).await?;
|
||||||
|
```
|
||||||
|
</section>
|
||||||
|
|
||||||
<div slot="title">Swift</div>
|
<div slot="title">Swift</div>
|
||||||
<section>
|
<section>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,17 @@ Breez SDK automatically connects your node to the LSP peer and you can now recei
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
let invoice = sdk.receive_payment(3000, "Invoice for 3000 sats".into()).await?;
|
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?;
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -122,7 +132,7 @@ catch (Exception)
|
|||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
let bolt11 = "...";
|
let bolt11 = "...";
|
||||||
sdk.send_payment(bolt11.into(), Some(3000)).await?;
|
sdk.send_payment(bolt11.into(), None).await?;
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ In order to receive funds you first have to be connected to an [LSP](connecting_
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
// Optional user-selected dynamic fees (see Connecting to LSP section for details)
|
let swap_info = sdk.receive_onchain(
|
||||||
let opening_fee_params = None;
|
ReceiveOnchainRequest { opening_fee_params: None } )
|
||||||
|
.await?;
|
||||||
let swap_info = sdk.receive_onchain( ReceiveOnchainRequest { opening_fee_params } ).await?;
|
|
||||||
|
|
||||||
// Send your funds to the below bitcoin address
|
// Send your funds to the below bitcoin address
|
||||||
let address = swap_info.bitcoin_address;
|
let address = swap_info.bitcoin_address;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ First, fetch the current reverse swap fees:
|
|||||||
let current_fees = sdk.fetch_reverse_swap_fees().await?;
|
let current_fees = sdk.fetch_reverse_swap_fees().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);
|
||||||
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -203,8 +202,9 @@ Once you checked the fees are acceptable, you can start the reverse swap:
|
|||||||
```rust,ignore
|
```rust,ignore
|
||||||
let destination_address = String::from("bc1..");
|
let destination_address = String::from("bc1..");
|
||||||
let amount_sat = current_fees.min;
|
let amount_sat = current_fees.min;
|
||||||
|
let satPerVbyte = <fee rate>;
|
||||||
|
|
||||||
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash).await?;
|
sdk.send_onchain(amount_sat, destination_address, current_fees.fees_hash, satPerVbyte).await?;
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user