lnbits_rust

Crates.iolnbits_rust
lib.rslnbits_rust
version0.2.1
sourcesrc
created_at2023-01-08 11:47:18.788765
updated_at2023-02-11 11:14:17.444701
descriptionA Rust library for the LNbits API
homepage
repositoryhttps://github.com/0xtlt/lnbits_rust
max_upload_size
id753635
size20,734
Thomas (0xtlt)

documentation

https://docs.rs/lnbits_rust

README

lnbits_rust

crates.io Documentation MIT/Apache-2 licensed CI Issues

An ergonomic, LNBits API Client for Rust.

Example

[dependencies]
tokio = { version = "1.0", features = ["full"] }
lnbits_rust = "0.1"

And then the code:

use lnbits_rust::{api::invoice::CreateInvoiceParams, LNBitsClient};

#[tokio::main]
async fn main() {
    let client = LNBitsClient::new(
        "wallet id",
        "admin_key",
        "invoice_read_key",
        "http://lnbits_url",
        None,
    )
    .unwrap();

    // OR with tor

    let client = LNBitsClient::new(
        "wallet id",
        "admin_key",
        "invoice_read_key",
        "http://lnbits_url.onion",
        Some("socks5h://127.0.0.1:9050"),
    )
    .unwrap();

    let wallet_details = client.get_wallet_details().await.unwrap();

    println!("wallet_details: {:?}", wallet_details);

    let invoice = client
        .create_invoice(&CreateInvoiceParams {
            amount: 1,
            unit: "sat".to_string(),
            memo: None,
            expiry: Some(10000),
            webhook: None,
            internal: None,
        })
        .await
        .unwrap();

    println!("invoice: {:?}", i);

    println!(
        "decoded invoice: {:?}",
        client.decode_invoice(&i.payment_request).await.unwrap()
    );

    while !client.is_invoice_paid(&i.payment_hash).await.unwrap() {
        println!("Waiting for payment");
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    }

    println!("Payment received");
}

Key features

  • Create invoices
  • Decode invoices
  • Pay invoices
  • Get wallet details
  • Tor support

License

Licensed under MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Commit count: 17

cargo fmt