Skip to content

Commit 7ad3f88

Browse files
committed
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.
1 parent a28c90a commit 7ad3f88

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

lightning-invoice/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub struct Bolt11Invoice {
260260
/// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
261261
/// practically impossible to use safely in languages like C.
262262
#[derive(Eq, PartialEq, Debug, Clone, Ord, PartialOrd)]
263-
pub enum InvoiceDescription<'f> {
263+
pub enum Bolt11InvoiceDescription<'f> {
264264
/// Reference to the directly supplied description in the invoice
265265
Direct(&'f Description),
266266

@@ -671,12 +671,12 @@ impl<H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBui
671671
}
672672

673673
/// Set the description or description hash. This function is only available if no description (hash) was set.
674-
pub fn invoice_description(self, description: InvoiceDescription) -> InvoiceBuilder<tb::True, H, T, C, S, M> {
674+
pub fn invoice_description(self, description: Bolt11InvoiceDescription) -> InvoiceBuilder<tb::True, H, T, C, S, M> {
675675
match description {
676-
InvoiceDescription::Direct(desc) => {
676+
Bolt11InvoiceDescription::Direct(desc) => {
677677
self.description(desc.clone().into_inner())
678678
}
679-
InvoiceDescription::Hash(hash) => {
679+
Bolt11InvoiceDescription::Hash(hash) => {
680680
self.description_hash(hash.0)
681681
}
682682
}
@@ -1310,12 +1310,12 @@ impl Bolt11Invoice {
13101310

13111311
/// Return the description or a hash of it for longer ones
13121312
///
1313-
/// This is not exported to bindings users because we don't yet export InvoiceDescription
1314-
pub fn description(&self) -> InvoiceDescription {
1313+
/// This is not exported to bindings users because we don't yet export Bolt11InvoiceDescription
1314+
pub fn description(&self) -> Bolt11InvoiceDescription {
13151315
if let Some(direct) = self.signed_invoice.description() {
1316-
return InvoiceDescription::Direct(direct);
1316+
return Bolt11InvoiceDescription::Direct(direct);
13171317
} else if let Some(hash) = self.signed_invoice.description_hash() {
1318-
return InvoiceDescription::Hash(hash);
1318+
return Bolt11InvoiceDescription::Hash(hash);
13191319
}
13201320
unreachable!("ensured by constructor");
13211321
}
@@ -2142,7 +2142,7 @@ mod test {
21422142
assert_eq!(invoice.private_routes(), vec![&PrivateRoute(route_1), &PrivateRoute(route_2)]);
21432143
assert_eq!(
21442144
invoice.description(),
2145-
InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap()))
2145+
Bolt11InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap()))
21462146
);
21472147
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap());
21482148
assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32]));

lightning-invoice/src/utils.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{Bolt11Invoice, CreationError, Currency, InvoiceBuilder, SignOrCreationError};
44

5-
use crate::{prelude::*, Description, InvoiceDescription, Sha256};
5+
use crate::{prelude::*, Description, Bolt11InvoiceDescription, Sha256};
66
use bech32::ToBase32;
77
use bitcoin_hashes::Hash;
88
use lightning::chain;
@@ -71,7 +71,7 @@ where
7171
L::Target: Logger,
7272
{
7373
let description = Description::new(description).map_err(SignOrCreationError::CreationError)?;
74-
let description = InvoiceDescription::Direct(&description,);
74+
let description = Bolt11InvoiceDescription::Direct(&description,);
7575
_create_phantom_invoice::<ES, NS, L>(
7676
amt_msat, payment_hash, description, invoice_expiry_delta_secs, phantom_route_hints,
7777
entropy_source, node_signer, logger, network, min_final_cltv_expiry_delta, duration_since_epoch,
@@ -127,7 +127,7 @@ where
127127
L::Target: Logger,
128128
{
129129
_create_phantom_invoice::<ES, NS, L>(
130-
amt_msat, payment_hash, InvoiceDescription::Hash(&description_hash),
130+
amt_msat, payment_hash, Bolt11InvoiceDescription::Hash(&description_hash),
131131
invoice_expiry_delta_secs, phantom_route_hints, entropy_source, node_signer, logger, network,
132132
min_final_cltv_expiry_delta, duration_since_epoch,
133133
)
@@ -136,7 +136,7 @@ where
136136
const MAX_CHANNEL_HINTS: usize = 3;
137137

138138
fn _create_phantom_invoice<ES: Deref, NS: Deref, L: Deref>(
139-
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: InvoiceDescription,
139+
amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: Bolt11InvoiceDescription,
140140
invoice_expiry_delta_secs: u32, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
141141
node_signer: NS, logger: L, network: Currency, min_final_cltv_expiry_delta: Option<u16>, duration_since_epoch: Duration,
142142
) -> Result<Bolt11Invoice, SignOrCreationError<()>>
@@ -157,10 +157,10 @@ where
157157
}
158158

159159
let invoice = match description {
160-
InvoiceDescription::Direct(description) => {
160+
Bolt11InvoiceDescription::Direct(description) => {
161161
InvoiceBuilder::new(network).description(description.0.clone())
162162
}
163-
InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
163+
Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
164164
};
165165

166166
// 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
417417
{
418418
_create_invoice_from_channelmanager_and_duration_since_epoch(
419419
channelmanager, node_signer, logger, network, amt_msat,
420-
InvoiceDescription::Hash(&description_hash),
420+
Bolt11InvoiceDescription::Hash(&description_hash),
421421
duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
422422
)
423423
}
@@ -442,7 +442,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
442442
{
443443
_create_invoice_from_channelmanager_and_duration_since_epoch(
444444
channelmanager, node_signer, logger, network, amt_msat,
445-
InvoiceDescription::Direct(
445+
Bolt11InvoiceDescription::Direct(
446446
&Description::new(description).map_err(SignOrCreationError::CreationError)?,
447447
),
448448
duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
@@ -451,7 +451,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
451451

452452
fn _create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
453453
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
454-
network: Currency, amt_msat: Option<u64>, description: InvoiceDescription,
454+
network: Currency, amt_msat: Option<u64>, description: Bolt11InvoiceDescription,
455455
duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
456456
) -> Result<Bolt11Invoice, SignOrCreationError<()>>
457457
where
@@ -503,7 +503,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
503503
.map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
504504
_create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
505505
channelmanager, node_signer, logger, network, amt_msat,
506-
InvoiceDescription::Direct(
506+
Bolt11InvoiceDescription::Direct(
507507
&Description::new(description).map_err(SignOrCreationError::CreationError)?,
508508
),
509509
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_
513513

514514
fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
515515
channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
516-
network: Currency, amt_msat: Option<u64>, description: InvoiceDescription, duration_since_epoch: Duration,
517-
invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, payment_secret: PaymentSecret,
518-
min_final_cltv_expiry_delta: Option<u16>,
516+
network: Currency, amt_msat: Option<u64>, description: Bolt11InvoiceDescription,
517+
duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, payment_hash: PaymentHash,
518+
payment_secret: PaymentSecret, min_final_cltv_expiry_delta: Option<u16>,
519519
) -> Result<Bolt11Invoice, SignOrCreationError<()>>
520520
where
521521
M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
@@ -537,10 +537,10 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
537537
log_trace!(logger, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0));
538538

539539
let invoice = match description {
540-
InvoiceDescription::Direct(description) => {
540+
Bolt11InvoiceDescription::Direct(description) => {
541541
InvoiceBuilder::new(network).description(description.0.clone())
542542
}
543-
InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
543+
Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
544544
};
545545

546546
let mut invoice = invoice
@@ -794,7 +794,7 @@ fn prefer_current_channel(min_inbound_capacity_msat: Option<u64>, current_channe
794794
mod test {
795795
use core::cell::RefCell;
796796
use core::time::Duration;
797-
use crate::{Currency, Description, InvoiceDescription, SignOrCreationError, CreationError};
797+
use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError};
798798
use bitcoin_hashes::{Hash, sha256};
799799
use bitcoin_hashes::sha256::Hash as Sha256;
800800
use lightning::sign::PhantomKeysManager;
@@ -852,7 +852,7 @@ mod test {
852852
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
853853
// If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
854854
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
855-
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
855+
assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
856856
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
857857

858858
// Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
@@ -948,7 +948,7 @@ mod test {
948948
).unwrap();
949949
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
950950
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
951-
assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
951+
assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
952952
}
953953

954954
#[test]
@@ -965,7 +965,7 @@ mod test {
965965
).unwrap();
966966
assert_eq!(invoice.amount_pico_btc(), Some(100_000));
967967
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
968-
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
968+
assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
969969
assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
970970
}
971971

@@ -1317,7 +1317,7 @@ mod test {
13171317
};
13181318

13191319
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
1320-
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
1320+
assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
13211321
assert_eq!(invoice.route_hints().len(), 2);
13221322
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
13231323
assert!(!invoice.features().unwrap().supports_basic_mpp());
@@ -1455,7 +1455,7 @@ mod test {
14551455
assert_eq!(invoice.amount_pico_btc(), Some(200_000));
14561456
assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
14571457
assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
1458-
assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
1458+
assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
14591459
}
14601460

14611461
#[test]

0 commit comments

Comments
 (0)