@@ -73,6 +73,7 @@ pub use lightning::ln::PaymentSecret;
73
73
pub use lightning:: routing:: router:: { RouteHint , RouteHintHop } ;
74
74
#[ doc( no_inline) ]
75
75
pub use lightning:: routing:: gossip:: RoutingFees ;
76
+ use lightning:: util:: string:: UntrustedString ;
76
77
77
78
mod de;
78
79
mod ser;
@@ -269,6 +270,15 @@ pub enum Bolt11InvoiceDescription<'f> {
269
270
Hash ( & ' f Sha256 ) ,
270
271
}
271
272
273
+ impl < ' f > Display for Bolt11InvoiceDescription < ' f > {
274
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
275
+ match self {
276
+ Bolt11InvoiceDescription :: Direct ( desc) => write ! ( f, "{}" , desc. 0 ) ,
277
+ Bolt11InvoiceDescription :: Hash ( hash) => write ! ( f, "{}" , hash. 0 ) ,
278
+ }
279
+ }
280
+ }
281
+
272
282
/// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
273
283
/// invalid.
274
284
///
@@ -470,8 +480,8 @@ impl Sha256 {
470
480
///
471
481
/// # Invariants
472
482
/// The description can be at most 639 __bytes__ long
473
- #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
474
- pub struct Description ( String ) ;
483
+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd , Default ) ]
484
+ pub struct Description ( UntrustedString ) ;
475
485
476
486
/// Payee public key
477
487
#[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
@@ -520,7 +530,7 @@ impl Ord for Bolt11InvoiceSignature {
520
530
/// The encoded route has to be <1024 5bit characters long (<=639 bytes or <=12 hops)
521
531
///
522
532
#[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
523
- pub struct PrivateRoute ( RouteHint ) ;
533
+ pub struct PrivateRoute ( pub RouteHint ) ;
524
534
525
535
/// Tag constants as specified in BOLT11
526
536
#[ allow( missing_docs) ]
@@ -675,7 +685,7 @@ impl<H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBui
675
685
pub fn invoice_description ( self , description : Bolt11InvoiceDescription ) -> InvoiceBuilder < tb:: True , H , T , C , S , M > {
676
686
match description {
677
687
Bolt11InvoiceDescription :: Direct ( desc) => {
678
- self . description ( desc. clone ( ) . into_inner ( ) )
688
+ self . description ( desc. clone ( ) . into_inner ( ) . 0 )
679
689
}
680
690
Bolt11InvoiceDescription :: Hash ( hash) => {
681
691
self . description_hash ( hash. 0 )
@@ -1136,6 +1146,12 @@ impl PositiveTimestamp {
1136
1146
}
1137
1147
}
1138
1148
1149
+ impl From < PositiveTimestamp > for Duration {
1150
+ fn from ( val : PositiveTimestamp ) -> Self {
1151
+ val. 0
1152
+ }
1153
+ }
1154
+
1139
1155
#[ cfg( feature = "std" ) ]
1140
1156
impl From < PositiveTimestamp > for SystemTime {
1141
1157
fn from ( val : PositiveTimestamp ) -> Self {
@@ -1502,27 +1518,19 @@ impl Description {
1502
1518
if description. len ( ) > 639 {
1503
1519
Err ( CreationError :: DescriptionTooLong )
1504
1520
} else {
1505
- Ok ( Description ( description) )
1521
+ Ok ( Description ( UntrustedString ( description) ) )
1506
1522
}
1507
1523
}
1508
1524
1509
- /// Returns the underlying description [`String `]
1510
- pub fn into_inner ( self ) -> String {
1525
+ /// Returns the underlying description [`UntrustedString `]
1526
+ pub fn into_inner ( self ) -> UntrustedString {
1511
1527
self . 0
1512
1528
}
1513
1529
}
1514
1530
1515
- impl From < Description > for String {
1516
- fn from ( val : Description ) -> Self {
1517
- val. into_inner ( )
1518
- }
1519
- }
1520
-
1521
- impl Deref for Description {
1522
- type Target = str ;
1523
-
1524
- fn deref ( & self ) -> & str {
1525
- & self . 0
1531
+ impl Display for Description {
1532
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1533
+ write ! ( f, "{}" , self . 0 )
1526
1534
}
1527
1535
}
1528
1536
0 commit comments