@@ -55,10 +55,11 @@ use bitcoin::secp256k1::{Message, PublicKey, self};
55
55
use bitcoin:: secp256k1:: schnorr:: Signature ;
56
56
use core:: convert:: TryFrom ;
57
57
use io;
58
+ use core:: str:: FromStr ;
58
59
use ln:: features:: OfferFeatures ;
59
60
use offers:: merkle:: { SignatureTlvStream , SignatureTlvStreamRef , self } ;
60
61
use offers:: offer:: { Amount , Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef , SendInvoiceOfferContents } ;
61
- use offers:: parse:: { ParseError , SemanticError } ;
62
+ use offers:: parse:: { Bech32Encode , ParseError , SemanticError } ;
62
63
use offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
63
64
use util:: ser:: { Readable , WithoutLength , Writeable , Writer } ;
64
65
@@ -325,6 +326,12 @@ impl InvoiceRequestContents {
325
326
}
326
327
}
327
328
329
+ impl AsRef < [ u8 ] > for InvoiceRequest {
330
+ fn as_ref ( & self ) -> & [ u8 ] {
331
+ & self . bytes
332
+ }
333
+ }
334
+
328
335
impl Writeable for InvoiceRequest {
329
336
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
330
337
WithoutLength ( & self . bytes ) . write ( writer)
@@ -355,6 +362,12 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, {
355
362
( 89 , payer_note: String ) ,
356
363
} ) ;
357
364
365
+ impl Bech32Encode for InvoiceRequest {
366
+ type TlvStream = FullInvoiceRequestTlvStream ;
367
+
368
+ const BECH32_HRP : & ' static str = "lnr" ;
369
+ }
370
+
358
371
type ParsedInvoiceRequest = ( Vec < u8 > , FullInvoiceRequestTlvStream ) ;
359
372
360
373
type FullInvoiceRequestTlvStream =
@@ -368,6 +381,15 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
368
381
InvoiceRequestTlvStreamRef < ' a > ,
369
382
) ;
370
383
384
+ impl FromStr for InvoiceRequest {
385
+ type Err = ParseError ;
386
+
387
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
388
+ let ( tlv_stream, bytes) = InvoiceRequest :: from_bech32_str ( s) ?;
389
+ InvoiceRequest :: try_from ( ( bytes, tlv_stream) )
390
+ }
391
+ }
392
+
371
393
impl TryFrom < ParsedInvoiceRequest > for InvoiceRequest {
372
394
type Error = ParseError ;
373
395
@@ -451,3 +473,9 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
451
473
} )
452
474
}
453
475
}
476
+
477
+ impl core:: fmt:: Display for InvoiceRequest {
478
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
479
+ self . fmt_bech32_str ( f)
480
+ }
481
+ }
0 commit comments