Add LNURL examples

This commit is contained in:
ok300
2023-04-29 20:55:57 +02:00
parent 746a9d3376
commit e0cf8477ee
4 changed files with 84 additions and 0 deletions

View File

@@ -1 +1,7 @@
# Using LNURL
Interacting with a LNURL endpoint consists of two steps:
1. Parse the LNURL string using `parse(lnurl_url).await`. This returns a `Result<InputType>`. The specific `InputType`
you receive will tell you what kind of endpoint this is, as well as give you the relevant endpoint parameters.
2. Call the corresponding service method. For example, for LNURL-pay, that is `BreezServices::lnurl_pay()`.

View File

@@ -1 +1,30 @@
# LNURL-Auth
## Usage
```rust,no_run
// 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}")
}
}
}
```
## Supported Specs
- [LUD-01](https://github.com/lnurl/luds/blob/luds/01.md) LNURL bech32 encoding
- [LUD-04](https://github.com/lnurl/luds/blob/luds/04.md) `auth` base spec
- [LUD-17](https://github.com/lnurl/luds/blob/luds/17.md) Support for keyauth prefix with non-bech32-encoded LNURL URLs

View File

@@ -1 +1,26 @@
# LNURL-Pay
## Usage
```rust,no_run
// 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?;
}
```
## Supported Specs
- [LUD-01](https://github.com/lnurl/luds/blob/luds/01.md) LNURL bech32 encoding
- [LUD-06](https://github.com/lnurl/luds/blob/luds/06.md) `payRequest` spec
- [LUD-16](https://github.com/lnurl/luds/blob/luds/16.md) LN Address
- [LUD-17](https://github.com/lnurl/luds/blob/luds/17.md) Support for lnurlp prefix with non-bech32-encoded LNURL URLs

View File

@@ -1 +1,25 @@
# LNURL-Withdraw
## Usage
```rust,no_run
// 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 {
// TODO Determine withdraw amount
let amount_msat = wd.min_withdrawable;
let description = "Test withdraw".to_string();
sdk.lnurl_withdraw(wd, amount_msat, Some(description)).await?;
}
```
## Supported Specs
- [LUD-01](https://github.com/lnurl/luds/blob/luds/01.md) LNURL bech32 encoding
- [LUD-03](https://github.com/lnurl/luds/blob/luds/03.md) `withdrawRequest` spec
- [LUD-17](https://github.com/lnurl/luds/blob/luds/17.md) Support for lnurlw prefix with non-bech32-encoded LNURL URLs