Skip to content

Commit 32ccbf4

Browse files
committed
rabbit
1 parent 2385f5f commit 32ccbf4

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

crates/lni/cln/api.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,15 @@ pub fn lookup_invoice(
427427
limit: Option<i64>,
428428
) -> Result<Transaction, ApiError> {
429429
match lookup_invoices(url, rune, payment_hash, from, limit) {
430-
Ok(transactions) => Ok(transactions.first().unwrap().clone()),
430+
Ok(transactions) => {
431+
if let Some(tx) = transactions.first() {
432+
Ok(tx.clone())
433+
} else {
434+
Err(ApiError::Api {
435+
reason: "No matching invoice found".to_string(),
436+
})
437+
}
438+
}
431439
Err(e) => Err(e),
432440
}
433441
}

crates/lni/phoenixd/api.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ pub async fn pay_invoice(
119119
.send()
120120
.unwrap();
121121
println!("Status: {}", response.status());
122+
let response_text = response.text().unwrap();
122123
let pay_invoice_resp: PhoenixPayInvoiceResp =
123-
serde_json::from_str(&response.text().unwrap()).unwrap();
124+
serde_json::from_str(&response_text).map_err(|e| ApiError::Json {
125+
reason: format!("Failed to parse pay_invoice response: {}", e),
126+
})?;
127+
124128
Ok(PayInvoiceResponse {
125129
payment_hash: pay_invoice_resp.payment_hash,
126130
preimage: pay_invoice_resp.preimage,

crates/lni/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use lightning_invoice::Bolt11Invoice;
22
use std::error::Error;
33
use std::str::FromStr;
4-
use regex::Regex;
54

65
pub fn calculate_fee_msats(
76
bolt11: &str,
87
fee_percentage: f64,
98
amount_msats: Option<u64>,
109
) -> Result<u64, Box<dyn Error>> {
1110
// Decode the BOLT11 invoice
12-
let invoice = Bolt11Invoice::from_str(bolt11).unwrap();
11+
let invoice = Bolt11Invoice::from_str(bolt11)
12+
.map_err(|e| format!("Failed to parse BOLT11 invoice: {}", e))?;
1313

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

0 commit comments

Comments
 (0)