@@ -117,6 +117,7 @@ use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents}
117117use crate :: offers:: signer;
118118use crate :: onion_message:: BlindedPath ;
119119use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Iterable , SeekReadable , WithoutLength , Writeable , Writer } ;
120+ use crate :: util:: string:: PrintableString ;
120121
121122use crate :: prelude:: * ;
122123
@@ -452,6 +453,12 @@ struct InvoiceFields {
452453}
453454
454455impl 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 ) ;
0 commit comments