@@ -55,11 +55,12 @@ 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 ln:: msgs:: DecodeError ;
60
61
use offers:: merkle:: { SignatureTlvStream , SignatureTlvStreamRef , self } ;
61
62
use offers:: offer:: { Amount , Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef , SendInvoiceOfferContents } ;
62
- use offers:: parse:: { ParseError , SemanticError } ;
63
+ use offers:: parse:: { Bech32Encode , ParseError , SemanticError } ;
63
64
use offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
64
65
use util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
65
66
@@ -324,6 +325,12 @@ impl InvoiceRequestContents {
324
325
}
325
326
}
326
327
328
+ impl AsRef < [ u8 ] > for InvoiceRequest {
329
+ fn as_ref ( & self ) -> & [ u8 ] {
330
+ & self . bytes
331
+ }
332
+ }
333
+
327
334
impl Writeable for InvoiceRequest {
328
335
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
329
336
WithoutLength ( & self . bytes ) . write ( writer)
@@ -356,6 +363,10 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, 80..160, {
356
363
357
364
try_from_tlv_stream_bytes ! ( FullInvoiceRequestTlvStream , ParsedInvoiceRequest ) ;
358
365
366
+ impl Bech32Encode for InvoiceRequest {
367
+ const BECH32_HRP : & ' static str = "lnr" ;
368
+ }
369
+
359
370
struct ParsedInvoiceRequest ( Vec < u8 > , FullInvoiceRequestTlvStream ) ;
360
371
361
372
type FullInvoiceRequestTlvStream =
@@ -380,6 +391,14 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
380
391
InvoiceRequestTlvStreamRef < ' a > ,
381
392
) ;
382
393
394
+ impl FromStr for InvoiceRequest {
395
+ type Err = ParseError ;
396
+
397
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
398
+ InvoiceRequest :: from_bech32_str ( s)
399
+ }
400
+ }
401
+
383
402
impl TryFrom < ParsedInvoiceRequest > for InvoiceRequest {
384
403
type Error = ParseError ;
385
404
@@ -464,6 +483,12 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
464
483
}
465
484
}
466
485
486
+ impl core:: fmt:: Display for InvoiceRequest {
487
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
488
+ self . fmt_bech32_str ( f)
489
+ }
490
+ }
491
+
467
492
#[ cfg( test) ]
468
493
mod tests {
469
494
use super :: InvoiceRequest ;
0 commit comments