Skip to content

Commit

Permalink
feat readme: progress and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 10, 2019
1 parent f26b6f0 commit b839cce
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,59 @@

[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/edouardparis/rust-lnurl/blob/master/LICENSE)

[lnurl specs](https://github.com/btcontract/lnurl-rfc/blob/master/spec.md)

## Documentation

_Readings about **lnurl**_


* [The spec](https://github.com/btcontract/lnurl-rfc/blob/master/spec.md) – **lnurl** spec, by [Anton Kumaigorodski](https://twitter.com/akumaigorodski).
* [An introduction to lnurl](https://telegra.ph/lnurl-a-protocol-for-seamless-interaction-between-services-and-Lightning-wallets-08-19) – An article introducing the various types of **lnurl**'s, by [fiatjaf](https://twitter.com/fiatjaf).

## Progress

- [x] lnurl-withdraw
- [ ] lnurl-auth
- [ ] lnurl-pay
- [ ] lnurl-channel

## Usage

You will certainly need some crates like:
```toml
bech32 = "0.7.1"
lightning-invoice = "0.2.0"
serde = { version = "1.0.93", features =["derive"]}
serde_json = "1.0.39"
```

Create a bech32 QRCode:
```rust
use bech32::ToBase32;
use image::Luma;
use qrcode::QrCode;

pub fn create_lnurl_qrcode(url: &str, path: &str) {
let encoded = bech32::encode("lnurl", url.as_bytes().to_base32()).unwrap();
let code = QrCode::new(encoded.to_string()).unwrap();
let image = code.render::<Luma<u8>>().build();
image.save(path).unwrap();
}
```

Use serde_json to encode your LNRUL object in the HTTP response body
of your server.

```rust
if let Err(_) = invoice.parse::<lightning_invoice::SignedRawInvoice>() {
let res = serde_json::to_string(
&lnurl::Response::Error{reason: "your invoice is wrong".to_string()}
).unwrap();
return Ok(Response::builder()
.status(StatusCode::BAD_REQUEST)
.header(header::CONTENT_TYPE, "application/json")
.body(Body::from(res)).unwrap())
}
```

See [lnurl-examples](https://github.com/edouardparis/lnurl-examples)

0 comments on commit b839cce

Please sign in to comment.