use std::str::FromStr;
use cdk_common::wallet::MeltQuote;
use tracing::instrument;
use crate::lightning_address::LightningAddress;
use crate::{Amount, Error, Wallet};
impl Wallet {
#[instrument(skip(self, amount_msat), fields(lightning_address = %lightning_address))]
pub async fn melt_lightning_address_quote(
&self,
lightning_address: &str,
amount_msat: impl Into<Amount>,
) -> Result<MeltQuote, Error> {
let amount = amount_msat.into();
let ln_address = LightningAddress::from_str(lightning_address).map_err(|e| {
tracing::error!(
"Failed to parse Lightning address '{}': {}",
lightning_address,
e
);
Error::LightningAddressParse(e.to_string())
})?;
tracing::debug!("Resolving Lightning address: {}", ln_address);
let invoice = ln_address
.request_invoice(&self.client, amount)
.await
.map_err(|e| {
tracing::error!(
"Failed to get invoice from Lightning address service: {}",
e
);
Error::LightningAddressRequest(e.to_string())
})?;
tracing::debug!(
"Received invoice from Lightning address service: {}",
invoice
);
self.melt_bolt11_quote(invoice.to_string(), None).await
}
}