@@ -117,6 +117,7 @@ use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents}
117
117
use crate :: offers:: signer;
118
118
use crate :: onion_message:: BlindedPath ;
119
119
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Iterable , SeekReadable , WithoutLength , Writeable , Writer } ;
120
+ use crate :: util:: string:: PrintableString ;
120
121
121
122
use crate :: prelude:: * ;
122
123
@@ -452,6 +453,12 @@ struct InvoiceFields {
452
453
}
453
454
454
455
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
+
455
462
/// Paths to the recipient originating from publicly reachable nodes, including information
456
463
/// needed for routing payments across them.
457
464
///
@@ -607,6 +614,15 @@ impl InvoiceContents {
607
614
}
608
615
}
609
616
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
+
610
626
fn fields ( & self ) -> & InvoiceFields {
611
627
match self {
612
628
InvoiceContents :: ForOffer { fields, .. } => fields,
@@ -939,6 +955,7 @@ mod tests {
939
955
use crate :: offers:: test_utils:: * ;
940
956
use crate :: onion_message:: { BlindedHop , BlindedPath } ;
941
957
use crate :: util:: ser:: { BigSize , Iterable , Writeable } ;
958
+ use crate :: util:: string:: PrintableString ;
942
959
943
960
trait ToBytes {
944
961
fn to_bytes ( & self ) -> Vec < u8 > ;
@@ -975,6 +992,7 @@ mod tests {
975
992
invoice. write ( & mut buffer) . unwrap ( ) ;
976
993
977
994
assert_eq ! ( invoice. bytes, buffer. as_slice( ) ) ;
995
+ assert_eq ! ( invoice. description( ) , PrintableString ( "foo" ) ) ;
978
996
assert_eq ! ( invoice. payment_paths( ) , payment_paths. as_slice( ) ) ;
979
997
assert_eq ! ( invoice. created_at( ) , now) ;
980
998
assert_eq ! ( invoice. relative_expiry( ) , DEFAULT_RELATIVE_EXPIRY ) ;
@@ -1057,6 +1075,7 @@ mod tests {
1057
1075
invoice. write ( & mut buffer) . unwrap ( ) ;
1058
1076
1059
1077
assert_eq ! ( invoice. bytes, buffer. as_slice( ) ) ;
1078
+ assert_eq ! ( invoice. description( ) , PrintableString ( "foo" ) ) ;
1060
1079
assert_eq ! ( invoice. payment_paths( ) , payment_paths. as_slice( ) ) ;
1061
1080
assert_eq ! ( invoice. created_at( ) , now) ;
1062
1081
assert_eq ! ( invoice. relative_expiry( ) , DEFAULT_RELATIVE_EXPIRY ) ;
0 commit comments