Merge pull request #34 from breez/ok300-improve-rust-snippets

Improve rust snippets
This commit is contained in:
ok300
2023-08-04 16:29:24 +02:00
committed by GitHub
8 changed files with 21 additions and 18 deletions

View File

@@ -14,5 +14,5 @@ To locally serve the docs run:
```bash ```bash
cargo install mdbook cargo install mdbook
mdbook build mdbook build
mdbook serve mdbook serve --open
``` ```

View File

@@ -1 +0,0 @@
# Introduction

View File

@@ -20,15 +20,19 @@ Breez SDK is available in several platforms. Follow the [Installing](install.md)
<section> <section>
## Connecting ## Connecting
```rust,no_run ```rust,ignore
let mnemonic = Mnemonic::generate_in(Language::English, 12)?;
let seed = mnemonic.to_seed("");
let invite_code = Some("...".into());
// Create the default config // Create the default config
let config = BreezServices::default_config( let mut config = BreezServices::default_config(
EnvironmentType::Production, EnvironmentType::Production,
"your API key".into(), "your API key".into(),
breez_sdk_core::NodeConfig::Greenlight { breez_sdk_core::NodeConfig::Greenlight {
config: GreenlightNodeConfig { config: GreenlightNodeConfig {
partner_credentials: None, partner_credentials: None,
invite_code: None, invite_code
}, },
}, },
); );
@@ -47,7 +51,7 @@ let sdk = BreezServices::connect(
At any point we can fetch our balance from the Greenlight node: At any point we can fetch our balance from the Greenlight node:
```rust,no_run ```rust,ignore
if let Some(node_state) = sdk.node_info()? { if let Some(node_state) = sdk.node_info()? {
let balance_ln = node_state.channels_balance_msat; let balance_ln = node_state.channels_balance_msat;
let balance_onchain = node_state.onchain_balance_msat; let balance_onchain = node_state.onchain_balance_msat;

View File

@@ -5,7 +5,7 @@
<div slot="title">Rust</div> <div slot="title">Rust</div>
<section> <section>
```rust,no_run ```rust,ignore
// Endpoint can also be of the form: // Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val // keyauth://domain.com/auth?key=val
let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"; let lnurl_auth_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";

View File

@@ -6,7 +6,7 @@
<div slot="title">Rust</div> <div slot="title">Rust</div>
<section> <section>
```rust,no_run ```rust,ignore
// Endpoint can also be of the form: // Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val // lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
@@ -145,7 +145,7 @@ catch (Exception)
} }
``` ```
</section> </section>
</custom-tab> </custom-tabs>
## Supported Specs ## Supported Specs
- [LUD-01](https://github.com/lnurl/luds/blob/luds/01.md) LNURL bech32 encoding - [LUD-01](https://github.com/lnurl/luds/blob/luds/01.md) LNURL bech32 encoding

View File

@@ -7,7 +7,7 @@
<div slot="title">Rust</div> <div slot="title">Rust</div>
<section> <section>
```rust,no_run ```rust,ignore
// Endpoint can also be of the form: // Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val // lnurlw://domain.com/lnurl-withdraw?key=val
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"; let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
@@ -143,7 +143,7 @@ catch (Exception)
} }
``` ```
</section> </section>
</custom-tab> </custom-tabs>
## Supported Specs ## Supported Specs

View File

@@ -8,18 +8,18 @@
Breez SDK doesn't require you to open a channel and set up your inbound liquidity. Breez SDK doesn't require you to open a channel and set up your inbound liquidity.
Breez SDK automatically connects your node to the LSP peer and you can now receive payments: Breez SDK automatically connects your node to the LSP peer and you can now receive payments:
```rust,no_run ```rust,ignore
let invoice = sdk.receive_payment(3000, "Invoice for 3000 sats".into()).await?; let invoice = sdk.receive_payment(3000, "Invoice for 3000 sats".into()).await?;
``` ```
## Sending Lightning Payments ## Sending Lightning Payments
```rust,no_run ```rust,ignore
let bolt11 = "..."; let bolt11 = "...";
sdk.send_payment(bolt11.into(), Some(3000)).await?; sdk.send_payment(bolt11.into(), Some(3000)).await?;
``` ```
## Sending Spontaneous Lightning Payments ## Sending Spontaneous Lightning Payments
```rust,no_run ```rust,ignore
let node_id = "..."; let node_id = "...";
sdk.send_payment(node_id.into(), Some(3000)).await?; sdk.send_payment(node_id.into(), Some(3000)).await?;
``` ```

View File

@@ -8,7 +8,7 @@ First, fetch the current reverse swap fees:
<div slot="title">Rust</div> <div slot="title">Rust</div>
<section> <section>
```rust,no_run ```rust,ignore
let current_fees = sdk.fetch_reverse_swap_fees().await?; let current_fees = sdk.fetch_reverse_swap_fees().await?;
info!("Percentage fee for the reverse swap service: {}", current_fees.fees_percentage); info!("Percentage fee for the reverse swap service: {}", current_fees.fees_percentage);
@@ -22,14 +22,14 @@ of the total costs.
Fetching the fees also tells you what is the range of amounts you can send: Fetching the fees also tells you what is the range of amounts you can send:
```rust,no_run ```rust,ignore
info!("Minimum amount, in sats: {}", current_fees.min); info!("Minimum amount, in sats: {}", current_fees.min);
info!("Maximum amount, in sats: {}", current_fees.max); info!("Maximum amount, in sats: {}", current_fees.max);
``` ```
Once you checked the fees are acceptable, you can start the reverse swap: Once you checked the fees are acceptable, you can start the reverse swap:
```rust,no_run ```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;
@@ -42,7 +42,7 @@ is either settled or cancelled. This will happen automatically at the end of the
You can check its status with: You can check its status with:
```rust,no_run ```rust,ignore
for rs in sdk.in_progress_reverse_swaps().await? { 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);
} }