diff --git a/src/lightning.rs b/src/lightning.rs index 0ec4a60b..cf4b3a28 100644 --- a/src/lightning.rs +++ b/src/lightning.rs @@ -75,7 +75,9 @@ pub struct Account { /// Pay Invoice request #[derive(Debug, Serialize, Deserialize)] pub struct PayInvoiceRequest { - pub payment_request: String, + pub payment_request: Option, + pub recipient: Option, + pub amount: Option, } /// Lightning transaction @@ -225,7 +227,28 @@ pub async fn pay_invoice(payment_request: &str, token: &str) -> Result Result { + let endpoint = LNDHUB_ENDPOINT.read().await; + let url = format!("{endpoint}/payinvoice"); + let req = PayInvoiceRequest { + payment_request: None, + recipient: Some(ln_address.to_string()), + amount: Some(amount), }; let response = post_json_auth(&url, &Some(req), Some(token)).await?; let response: PayInvoiceResponse = serde_json::from_str(&response)?; diff --git a/src/web.rs b/src/web.rs index 5a763613..408992ad 100644 --- a/src/web.rs +++ b/src/web.rs @@ -683,6 +683,20 @@ pub mod lightning { }) } + #[wasm_bindgen] + pub fn pay_ln_address(ln_address: String, amount: u32, token: String) -> Promise { + set_panic_hook(); + + future_to_promise(async move { + match crate::lightning::pay_ln_address(&ln_address, amount, &token).await { + Ok(result) => Ok(JsValue::from_string( + serde_json::to_string(&result).unwrap(), + )), + Err(err) => Err(JsValue::from_string(err.to_string())), + } + }) + } + #[wasm_bindgen] pub fn check_payment(payment_hash: String) -> Promise { set_panic_hook();