Skip to content

Commit

Permalink
Fix api::get_invoice func
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Jan 19, 2024
1 parent dbca006 commit 2be7b1e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
95 changes: 95 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ bech32 = { version = "0.9", default-features = false }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls", "socks"], optional = true }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

[dev-dependencies]
tokio = { version = "1", features = ["full"] }

[[example]]
name = "get-invoice"
required-features = ["api"]
11 changes: 11 additions & 0 deletions examples/get-invoice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2024 Yuki Kishimoto
// Distributed under the MIT software license

use lnurl_pay::{api, LightningAddress};

#[tokio::main]
async fn main() {
let addr = LightningAddress::parse("[email protected]").unwrap();
let invoice = api::get_invoice(addr, 1 * 1000, None, None).await.unwrap();
println!("{invoice}");
}
9 changes: 8 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ struct PayResponse {
// pub nostr_pubkey: Option<String>,
}

#[derive(Serialize, Deserialize)]
struct LnURLPayInvoice {
/// Encoded bolt 11 invoice
pr: String,
}

pub enum Lud06OrLud16 {
Lud06(LnUrl),
Lud16(LightningAddress),
Expand Down Expand Up @@ -119,5 +125,6 @@ where
None => format!("{}{}amount={}", pay_response.callback, symbol, msats),
};
let resp = client.get(&url).send().await?;
Ok(resp.error_for_status()?.json().await?)
let invoice: LnURLPayInvoice = resp.error_for_status()?.json().await?;
Ok(invoice.pr)
}

0 comments on commit 2be7b1e

Please sign in to comment.