Skip to content

Commit a7600dc

Browse files
authored
Merge pull request #2206 from jkczyz/2023-04-invoice-description
Expose description from Invoice's offer/refund
2 parents b8ed4d2 + 42a772d commit a7600dc

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lightning/src/offers/invoice.rs

+19
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents}
117117
use crate::offers::signer;
118118
use crate::onion_message::BlindedPath;
119119
use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer};
120+
use crate::util::string::PrintableString;
120121

121122
use crate::prelude::*;
122123

@@ -452,6 +453,12 @@ struct InvoiceFields {
452453
}
453454

454455
impl Invoice {
456+
/// A complete description of the purpose of the originating offer or refund. Intended to be
457+
/// displayed to the user but with the caveat that it has not been verified in any way.
458+
pub fn description(&self) -> PrintableString {
459+
self.contents.description()
460+
}
461+
455462
/// Paths to the recipient originating from publicly reachable nodes, including information
456463
/// needed for routing payments across them.
457464
///
@@ -607,6 +614,15 @@ impl InvoiceContents {
607614
}
608615
}
609616

617+
fn description(&self) -> PrintableString {
618+
match self {
619+
InvoiceContents::ForOffer { invoice_request, .. } => {
620+
invoice_request.inner.offer.description()
621+
},
622+
InvoiceContents::ForRefund { refund, .. } => refund.description(),
623+
}
624+
}
625+
610626
fn fields(&self) -> &InvoiceFields {
611627
match self {
612628
InvoiceContents::ForOffer { fields, .. } => fields,
@@ -939,6 +955,7 @@ mod tests {
939955
use crate::offers::test_utils::*;
940956
use crate::onion_message::{BlindedHop, BlindedPath};
941957
use crate::util::ser::{BigSize, Iterable, Writeable};
958+
use crate::util::string::PrintableString;
942959

943960
trait ToBytes {
944961
fn to_bytes(&self) -> Vec<u8>;
@@ -975,6 +992,7 @@ mod tests {
975992
invoice.write(&mut buffer).unwrap();
976993

977994
assert_eq!(invoice.bytes, buffer.as_slice());
995+
assert_eq!(invoice.description(), PrintableString("foo"));
978996
assert_eq!(invoice.payment_paths(), payment_paths.as_slice());
979997
assert_eq!(invoice.created_at(), now);
980998
assert_eq!(invoice.relative_expiry(), DEFAULT_RELATIVE_EXPIRY);
@@ -1057,6 +1075,7 @@ mod tests {
10571075
invoice.write(&mut buffer).unwrap();
10581076

10591077
assert_eq!(invoice.bytes, buffer.as_slice());
1078+
assert_eq!(invoice.description(), PrintableString("foo"));
10601079
assert_eq!(invoice.payment_paths(), payment_paths.as_slice());
10611080
assert_eq!(invoice.created_at(), now);
10621081
assert_eq!(invoice.relative_expiry(), DEFAULT_RELATIVE_EXPIRY);

lightning/src/offers/offer.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl Offer {
384384
/// A complete description of the purpose of the payment. Intended to be displayed to the user
385385
/// but with the caveat that it has not been verified in any way.
386386
pub fn description(&self) -> PrintableString {
387-
PrintableString(&self.contents.description)
387+
self.contents.description()
388388
}
389389

390390
/// Features pertaining to the offer.
@@ -536,6 +536,10 @@ impl OfferContents {
536536
self.metadata.as_ref().and_then(|metadata| metadata.as_bytes())
537537
}
538538

539+
pub fn description(&self) -> PrintableString {
540+
PrintableString(&self.description)
541+
}
542+
539543
#[cfg(feature = "std")]
540544
pub(super) fn is_expired(&self) -> bool {
541545
match self.absolute_expiry {

lightning/src/offers/refund.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl Refund {
310310
/// A complete description of the purpose of the refund. Intended to be displayed to the user
311311
/// but with the caveat that it has not been verified in any way.
312312
pub fn description(&self) -> PrintableString {
313-
PrintableString(&self.contents.description)
313+
self.contents.description()
314314
}
315315

316316
/// Duration since the Unix epoch when an invoice should no longer be sent.
@@ -489,6 +489,10 @@ impl AsRef<[u8]> for Refund {
489489
}
490490

491491
impl RefundContents {
492+
pub fn description(&self) -> PrintableString {
493+
PrintableString(&self.description)
494+
}
495+
492496
#[cfg(feature = "std")]
493497
pub(super) fn is_expired(&self) -> bool {
494498
match self.absolute_expiry {

0 commit comments

Comments
 (0)