@@ -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 , SemanticError } ;
63
+ use crate :: offers:: parse:: { Bech32Encode , ParseError , SemanticError } ;
63
64
use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
64
65
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
65
66
@@ -317,6 +318,12 @@ impl InvoiceRequestContents {
317
318
}
318
319
}
319
320
321
+ impl AsRef < [ u8 ] > for InvoiceRequest {
322
+ fn as_ref ( & self ) -> & [ u8 ] {
323
+ & self . bytes
324
+ }
325
+ }
326
+
320
327
impl Writeable for InvoiceRequest {
321
328
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
322
329
WithoutLength ( & self . bytes ) . write ( writer)
@@ -349,6 +356,10 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, 80..160, {
349
356
350
357
try_from_tlv_stream_bytes ! ( FullInvoiceRequestTlvStream , ParsedInvoiceRequest ) ;
351
358
359
+ impl Bech32Encode for InvoiceRequest {
360
+ const BECH32_HRP : & ' static str = "lnr" ;
361
+ }
362
+
352
363
struct ParsedInvoiceRequest ( Vec < u8 > , FullInvoiceRequestTlvStream ) ;
353
364
354
365
type FullInvoiceRequestTlvStream =
@@ -373,6 +384,14 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
373
384
InvoiceRequestTlvStreamRef < ' a > ,
374
385
) ;
375
386
387
+ impl FromStr for InvoiceRequest {
388
+ type Err = ParseError ;
389
+
390
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
391
+ InvoiceRequest :: from_bech32_str ( s)
392
+ }
393
+ }
394
+
376
395
impl TryFrom < ParsedInvoiceRequest > for InvoiceRequest {
377
396
type Error = ParseError ;
378
397
@@ -457,6 +476,12 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
457
476
}
458
477
}
459
478
479
+ impl core:: fmt:: Display for InvoiceRequest {
480
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
481
+ self . fmt_bech32_str ( f)
482
+ }
483
+ }
484
+
460
485
#[ cfg( test) ]
461
486
mod tests {
462
487
use super :: InvoiceRequest ;
0 commit comments