use crate::amount::Amount;
use lightning_invoice::Bolt11Invoice;
pub use lightning::onion_message::dns_resolution::HumanReadableName;
use core::future::Future;
use core::pin::Pin;
use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
pub enum HrnResolution {
DNSSEC {
proof: Option<Vec<u8>>,
result: String,
},
LNURLPay {
min_value: Amount,
max_value: Amount,
expected_description_hash: [u8; 32],
recipient_description: Option<String>,
callback: String,
},
}
pub type HrnResolutionFuture<'a> =
Pin<Box<dyn Future<Output = Result<HrnResolution, &'static str>> + Send + 'a>>;
pub type LNURLResolutionFuture<'a> =
Pin<Box<dyn Future<Output = Result<Bolt11Invoice, &'static str>> + Send + 'a>>;
#[cfg_attr(feature = "std", doc = "[`dns_resolver::DNSHrnResolver`]")]
#[cfg_attr(not(feature = "std"), doc = "`dns_resolver::DNSHrnResolver`")]
#[cfg_attr(feature = "http", doc = "[`http_resolver::HTTPHrnResolver`]")]
#[cfg_attr(not(feature = "http"), doc = "`http_resolver::HTTPHrnResolver`")]
#[cfg_attr(
feature = "std",
doc = "[`dns_resolver::DNSHrnResolver`]: crate::dns_resolver::DNSHrnResolver"
)]
#[cfg_attr(
feature = "http",
doc = "[`http_resolver::HTTPHrnResolver`]: crate::http_resolver::HTTPHrnResolver"
)]
pub trait HrnResolver {
fn resolve_hrn<'a>(&'a self, hrn: &'a HumanReadableName) -> HrnResolutionFuture<'a>;
fn resolve_lnurl<'a>(&'a self, url: &'a str) -> HrnResolutionFuture<'a>;
fn resolve_lnurl_to_invoice<'a>(
&'a self, callback_url: String, amount: Amount, expected_description_hash: [u8; 32],
) -> LNURLResolutionFuture<'a>;
}
#[derive(Clone, Copy)]
pub struct DummyHrnResolver;
impl HrnResolver for DummyHrnResolver {
fn resolve_hrn<'a>(&'a self, _hrn: &'a HumanReadableName) -> HrnResolutionFuture<'a> {
Box::pin(async { Err("Human Readable Name resolution not supported") })
}
fn resolve_lnurl<'a>(&'a self, _lnurl: &'a str) -> HrnResolutionFuture<'a> {
Box::pin(async { Err("LNURL resolution not supported") })
}
fn resolve_lnurl_to_invoice<'a>(
&'a self, _: String, _: Amount, _: [u8; 32],
) -> LNURLResolutionFuture<'a> {
Box::pin(async { Err("LNURL resolution not supported") })
}
}