From: Jeffrey Czyz Date: Fri, 14 Jul 2023 20:59:33 +0000 (-0500) Subject: Qualify the BOLT 11 invoice description type X-Git-Tag: v0.0.116-rc1~3^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=7ad3f88ebadb39864c192e0961c2542422801e21;p=rust-lightning Qualify the BOLT 11 invoice description type A previous commit qualified the BOLT 11 invoice type, so any related types should be similarly qualified, if public. --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index f26903a74..d1b381130 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -260,7 +260,7 @@ pub struct Bolt11Invoice { /// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this /// practically impossible to use safely in languages like C. #[derive(Eq, PartialEq, Debug, Clone, Ord, PartialOrd)] -pub enum InvoiceDescription<'f> { +pub enum Bolt11InvoiceDescription<'f> { /// Reference to the directly supplied description in the invoice Direct(&'f Description), @@ -671,12 +671,12 @@ impl InvoiceBui } /// Set the description or description hash. This function is only available if no description (hash) was set. - pub fn invoice_description(self, description: InvoiceDescription) -> InvoiceBuilder { + pub fn invoice_description(self, description: Bolt11InvoiceDescription) -> InvoiceBuilder { match description { - InvoiceDescription::Direct(desc) => { + Bolt11InvoiceDescription::Direct(desc) => { self.description(desc.clone().into_inner()) } - InvoiceDescription::Hash(hash) => { + Bolt11InvoiceDescription::Hash(hash) => { self.description_hash(hash.0) } } @@ -1310,12 +1310,12 @@ impl Bolt11Invoice { /// Return the description or a hash of it for longer ones /// - /// This is not exported to bindings users because we don't yet export InvoiceDescription - pub fn description(&self) -> InvoiceDescription { + /// This is not exported to bindings users because we don't yet export Bolt11InvoiceDescription + pub fn description(&self) -> Bolt11InvoiceDescription { if let Some(direct) = self.signed_invoice.description() { - return InvoiceDescription::Direct(direct); + return Bolt11InvoiceDescription::Direct(direct); } else if let Some(hash) = self.signed_invoice.description_hash() { - return InvoiceDescription::Hash(hash); + return Bolt11InvoiceDescription::Hash(hash); } unreachable!("ensured by constructor"); } @@ -2142,7 +2142,7 @@ mod test { assert_eq!(invoice.private_routes(), vec![&PrivateRoute(route_1), &PrivateRoute(route_2)]); assert_eq!( invoice.description(), - InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap())) + Bolt11InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap())) ); assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap()); assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32])); diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 8d11d54e6..25a7cf77d 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -2,7 +2,7 @@ use crate::{Bolt11Invoice, CreationError, Currency, InvoiceBuilder, SignOrCreationError}; -use crate::{prelude::*, Description, InvoiceDescription, Sha256}; +use crate::{prelude::*, Description, Bolt11InvoiceDescription, Sha256}; use bech32::ToBase32; use bitcoin_hashes::Hash; use lightning::chain; @@ -71,7 +71,7 @@ where L::Target: Logger, { let description = Description::new(description).map_err(SignOrCreationError::CreationError)?; - let description = InvoiceDescription::Direct(&description,); + let description = Bolt11InvoiceDescription::Direct(&description,); _create_phantom_invoice::( amt_msat, payment_hash, description, invoice_expiry_delta_secs, phantom_route_hints, entropy_source, node_signer, logger, network, min_final_cltv_expiry_delta, duration_since_epoch, @@ -127,7 +127,7 @@ where L::Target: Logger, { _create_phantom_invoice::( - amt_msat, payment_hash, InvoiceDescription::Hash(&description_hash), + amt_msat, payment_hash, Bolt11InvoiceDescription::Hash(&description_hash), invoice_expiry_delta_secs, phantom_route_hints, entropy_source, node_signer, logger, network, min_final_cltv_expiry_delta, duration_since_epoch, ) @@ -136,7 +136,7 @@ where const MAX_CHANNEL_HINTS: usize = 3; fn _create_phantom_invoice( - amt_msat: Option, payment_hash: Option, description: InvoiceDescription, + amt_msat: Option, payment_hash: Option, description: Bolt11InvoiceDescription, invoice_expiry_delta_secs: u32, phantom_route_hints: Vec, entropy_source: ES, node_signer: NS, logger: L, network: Currency, min_final_cltv_expiry_delta: Option, duration_since_epoch: Duration, ) -> Result> @@ -157,10 +157,10 @@ where } let invoice = match description { - InvoiceDescription::Direct(description) => { + Bolt11InvoiceDescription::Direct(description) => { InvoiceBuilder::new(network).description(description.0.clone()) } - InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0), + Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0), }; // If we ever see performance here being too slow then we should probably take this ExpandedKey as a parameter instead. @@ -417,7 +417,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin { _create_invoice_from_channelmanager_and_duration_since_epoch( channelmanager, node_signer, logger, network, amt_msat, - InvoiceDescription::Hash(&description_hash), + Bolt11InvoiceDescription::Hash(&description_hash), duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta, ) } @@ -442,7 +442,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch( channelmanager: &ChannelManager, node_signer: NS, logger: L, - network: Currency, amt_msat: Option, description: InvoiceDescription, + network: Currency, amt_msat: Option, description: Bolt11InvoiceDescription, duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option, ) -> Result> where @@ -503,7 +503,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_ .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?; _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash( channelmanager, node_signer, logger, network, amt_msat, - InvoiceDescription::Direct( + Bolt11InvoiceDescription::Direct( &Description::new(description).map_err(SignOrCreationError::CreationError)?, ), duration_since_epoch, invoice_expiry_delta_secs, payment_hash, payment_secret, @@ -513,9 +513,9 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash( channelmanager: &ChannelManager, node_signer: NS, logger: L, - network: Currency, amt_msat: Option, description: InvoiceDescription, duration_since_epoch: Duration, - invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, payment_secret: PaymentSecret, - min_final_cltv_expiry_delta: Option, + network: Currency, amt_msat: Option, description: Bolt11InvoiceDescription, + duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, + payment_secret: PaymentSecret, min_final_cltv_expiry_delta: Option, ) -> Result> where M::Target: chain::Watch<::Signer>, @@ -537,10 +537,10 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has log_trace!(logger, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0)); let invoice = match description { - InvoiceDescription::Direct(description) => { + Bolt11InvoiceDescription::Direct(description) => { InvoiceBuilder::new(network).description(description.0.clone()) } - InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0), + Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0), }; let mut invoice = invoice @@ -794,7 +794,7 @@ fn prefer_current_channel(min_inbound_capacity_msat: Option, current_channe mod test { use core::cell::RefCell; use core::time::Duration; - use crate::{Currency, Description, InvoiceDescription, SignOrCreationError, CreationError}; + use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError}; use bitcoin_hashes::{Hash, sha256}; use bitcoin_hashes::sha256::Hash as Sha256; use lightning::sign::PhantomKeysManager; @@ -852,7 +852,7 @@ mod test { 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(), InvoiceDescription::Direct(&Description("test".to_string()))); + assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("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 @@ -948,7 +948,7 @@ mod test { ).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(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes())))); + assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes())))); } #[test] @@ -965,7 +965,7 @@ mod test { ).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(), InvoiceDescription::Direct(&Description("test".to_string()))); + assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string()))); assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap()); } @@ -1317,7 +1317,7 @@ mod test { }; assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64); - assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string()))); + assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("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()); @@ -1455,7 +1455,7 @@ mod test { assert_eq!(invoice.amount_pico_btc(), Some(200_000)); assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64); assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into())); - assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes())))); + assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes())))); } #[test]