pub use lightning::routing::router::{RouteHint, RouteHintHop};
#[doc(no_inline)]
pub use lightning::routing::gossip::RoutingFees;
+use lightning::util::string::UntrustedString;
mod de;
mod ser;
/// # Invariants
/// The description can be at most 639 __bytes__ long
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd, Default)]
-pub struct Description(String);
+pub struct Description(UntrustedString);
/// Payee public key
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub fn invoice_description(self, description: Bolt11InvoiceDescription) -> InvoiceBuilder<tb::True, H, T, C, S, M> {
match description {
Bolt11InvoiceDescription::Direct(desc) => {
- self.description(desc.clone().into_inner())
+ self.description(desc.clone().into_inner().0)
}
Bolt11InvoiceDescription::Hash(hash) => {
self.description_hash(hash.0)
if description.len() > 639 {
Err(CreationError::DescriptionTooLong)
} else {
- Ok(Description(description))
+ Ok(Description(UntrustedString(description)))
}
}
- /// Returns the underlying description [`String`]
- pub fn into_inner(self) -> String {
+ /// Returns the underlying description [`UntrustedString`]
+ pub fn into_inner(self) -> UntrustedString {
self.0
}
}
-impl From<Description> for String {
- fn from(val: Description) -> Self {
- val.into_inner()
- }
-}
-
-impl Deref for Description {
- type Target = str;
-
- fn deref(&self) -> &str {
- &self.0
- }
-}
-
impl Display for Description {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
impl ToBase32 for Description {
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
- self.as_bytes().write_base32(writer)
+ self.0.0.as_bytes().write_base32(writer)
}
}
impl Base32Len for Description {
fn base32_len(&self) -> usize {
- self.0.as_bytes().base32_len()
+ self.0.0.as_bytes().base32_len()
}
}
let invoice = match description {
Bolt11InvoiceDescription::Direct(description) => {
- InvoiceBuilder::new(network).description(description.0.clone())
+ InvoiceBuilder::new(network).description(description.0.0.clone())
}
Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
};
let invoice = match description {
Bolt11InvoiceDescription::Direct(description) => {
- InvoiceBuilder::new(network).description(description.0.clone())
+ InvoiceBuilder::new(network).description(description.0.0.clone())
}
Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
};
use lightning::util::config::UserConfig;
use crate::utils::{create_invoice_from_channelmanager_and_duration_since_epoch, rotate_through_iterators};
use std::collections::HashSet;
+ use lightning::util::string::UntrustedString;
#[test]
fn test_prefer_current_channel() {
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
- assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
+ assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description(UntrustedString("test".to_string()))));
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
// Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
).unwrap();
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
- assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
+ assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description(UntrustedString("test".to_string()))));
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
}
};
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
- assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
+ assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description(UntrustedString("test".to_string()))));
assert_eq!(invoice.route_hints().len(), 2);
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
assert!(!invoice.features().unwrap().supports_basic_mpp());
use crate::util::ser::{Writeable, Writer, Readable};
/// Struct to `Display` fields in a safe way using `PrintableString`
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
pub struct UntrustedString(pub String);
impl Writeable for UntrustedString {