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
cargo install mdbook
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>
## 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
let config = BreezServices::default_config(
let mut config = BreezServices::default_config(
EnvironmentType::Production,
"your API key".into(),
breez_sdk_core::NodeConfig::Greenlight {
config: GreenlightNodeConfig {
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:
```rust,no_run
```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;

View File

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

View File

@@ -6,7 +6,7 @@
<div slot="title">Rust</div>
<section>
```rust,no_run
```rust,ignore
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
@@ -145,7 +145,7 @@ catch (Exception)
}
```
</section>
</custom-tab>
</custom-tabs>
## Supported Specs
- [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>
<section>
```rust,no_run
```rust,ignore
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
let lnurl_withdraw_url = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
@@ -143,7 +143,7 @@ catch (Exception)
}
```
</section>
</custom-tab>
</custom-tabs>
## 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 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?;
```
## Sending Lightning Payments
```rust,no_run
```rust,ignore
let bolt11 = "...";
sdk.send_payment(bolt11.into(), Some(3000)).await?;
```
## Sending Spontaneous Lightning Payments
```rust,no_run
```rust,ignore
let node_id = "...";
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>
<section>
```rust,no_run
```rust,ignore
let current_fees = sdk.fetch_reverse_swap_fees().await?;
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:
```rust,no_run
```rust,ignore
info!("Minimum amount, in sats: {}", current_fees.min);
info!("Maximum amount, in sats: {}", current_fees.max);
```
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 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:
```rust,no_run
```rust,ignore
for rs in sdk.in_progress_reverse_swaps().await? {
info!("Reverse swap {} in progress, status is {}", rs.id, rs.status);
}