@@ -54,12 +54,13 @@ use bitcoin::network::constants::Network;
54
54
use bitcoin:: secp256k1:: { Message , PublicKey , self } ;
55
55
use bitcoin:: secp256k1:: schnorr:: Signature ;
56
56
use core:: convert:: TryFrom ;
57
+ use core:: str:: FromStr ;
57
58
use crate :: io;
58
59
use crate :: ln:: features:: OfferFeatures ;
59
60
use crate :: ln:: msgs:: DecodeError ;
60
61
use crate :: offers:: merkle:: { SignatureTlvStream , SignatureTlvStreamRef , self } ;
61
62
use crate :: offers:: offer:: { Amount , Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef , SendInvoiceOfferContents } ;
62
- use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
63
+ use crate :: offers:: parse:: { Bech32Encode , ParseError , ParsedMessage , SemanticError } ;
63
64
use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
64
65
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
65
66
@@ -323,6 +324,12 @@ impl InvoiceRequestContents {
323
324
}
324
325
}
325
326
327
+ impl AsRef < [ u8 ] > for InvoiceRequest {
328
+ fn as_ref ( & self ) -> & [ u8 ] {
329
+ & self . bytes
330
+ }
331
+ }
332
+
326
333
impl Writeable for InvoiceRequest {
327
334
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
328
335
WithoutLength ( & self . bytes ) . write ( writer)
@@ -353,6 +360,10 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, 80..160, {
353
360
( 89 , payer_note: ( String , WithoutLength ) ) ,
354
361
} ) ;
355
362
363
+ impl Bech32Encode for InvoiceRequest {
364
+ const BECH32_HRP : & ' static str = "lnr" ;
365
+ }
366
+
356
367
type FullInvoiceRequestTlvStream =
357
368
( PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream , SignatureTlvStream ) ;
358
369
@@ -375,6 +386,14 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
375
386
InvoiceRequestTlvStreamRef < ' a > ,
376
387
) ;
377
388
389
+ impl FromStr for InvoiceRequest {
390
+ type Err = ParseError ;
391
+
392
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
393
+ InvoiceRequest :: from_bech32_str ( s)
394
+ }
395
+ }
396
+
378
397
impl TryFrom < ParsedMessage < FullInvoiceRequestTlvStream > > for InvoiceRequest {
379
398
type Error = ParseError ;
380
399
@@ -460,6 +479,12 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
460
479
}
461
480
}
462
481
482
+ impl core:: fmt:: Display for InvoiceRequest {
483
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
484
+ self . fmt_bech32_str ( f)
485
+ }
486
+ }
487
+
463
488
#[ cfg( test) ]
464
489
mod tests {
465
490
use super :: InvoiceRequest ;
0 commit comments