@@ -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
@@ -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)
@@ -355,6 +362,10 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, 80..160, {
355
362
356
363
try_from_tlv_stream_bytes ! ( FullInvoiceRequestTlvStream , ParsedInvoiceRequest ) ;
357
364
365
+ impl Bech32Encode for InvoiceRequest {
366
+ const BECH32_HRP : & ' static str = "lnr" ;
367
+ }
368
+
358
369
struct ParsedInvoiceRequest ( Vec < u8 > , FullInvoiceRequestTlvStream ) ;
359
370
360
371
type FullInvoiceRequestTlvStream =
@@ -379,6 +390,14 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
379
390
InvoiceRequestTlvStreamRef < ' a > ,
380
391
) ;
381
392
393
+ impl FromStr for InvoiceRequest {
394
+ type Err = ParseError ;
395
+
396
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
397
+ InvoiceRequest :: from_bech32_str ( s)
398
+ }
399
+ }
400
+
382
401
impl TryFrom < ParsedInvoiceRequest > for InvoiceRequest {
383
402
type Error = ParseError ;
384
403
@@ -462,6 +481,12 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
462
481
}
463
482
}
464
483
484
+ impl core:: fmt:: Display for InvoiceRequest {
485
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
486
+ self . fmt_bech32_str ( f)
487
+ }
488
+ }
489
+
465
490
#[ cfg( test) ]
466
491
mod tests {
467
492
use super :: InvoiceRequest ;
0 commit comments