@@ -15,15 +15,20 @@ use bitcoin::secp256k1::schnorr::Signature;
15
15
use core:: convert:: TryFrom ;
16
16
use core:: str:: FromStr ;
17
17
use ln:: features:: OfferFeatures ;
18
- use offers:: { Offer , PayerTlvStream } ;
18
+ use offers:: PayerTlvStream ;
19
19
use offers:: merkle:: SignatureTlvStream ;
20
- use offers:: offer:: { OfferTlvStream , ParsedOffer } ;
20
+ use offers:: offer:: { OfferContents , OfferTlvStream } ;
21
21
use offers:: parse:: { Bech32Encode , ParseError , SemanticError } ;
22
22
23
23
///
24
24
pub struct InvoiceRequest {
25
25
bytes : Vec < u8 > ,
26
- offer : Offer ,
26
+ contents : InvoiceRequestContents ,
27
+ }
28
+
29
+ ///
30
+ pub ( crate ) struct InvoiceRequestContents {
31
+ offer : OfferContents ,
27
32
chain : Option < BlockHash > ,
28
33
amount_msat : Option < u64 > ,
29
34
features : Option < OfferFeatures > ,
@@ -63,24 +68,23 @@ impl FromStr for InvoiceRequest {
63
68
64
69
fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
65
70
let ( tlv_stream, bytes) = InvoiceRequest :: from_bech32_str ( s) ?;
66
- Ok ( InvoiceRequest :: try_from ( ( tlv_stream, bytes) ) ?)
71
+ let contents = InvoiceRequestContents :: try_from ( tlv_stream) ?;
72
+ Ok ( InvoiceRequest { bytes, contents } )
67
73
}
68
74
}
69
75
70
- type ParsedInvoiceRequest = ( FullInvoiceRequestTlvStream , Vec < u8 > ) ;
71
-
72
- impl TryFrom < ParsedInvoiceRequest > for InvoiceRequest {
76
+ impl TryFrom < FullInvoiceRequestTlvStream > for InvoiceRequestContents {
73
77
type Error = SemanticError ;
74
78
75
- fn try_from ( invoice_request : ParsedInvoiceRequest ) -> Result < Self , Self :: Error > {
76
- let ( (
77
- PayerTlvStream { payer_info } ,
78
- offer_tlv_stream,
79
- InvoiceRequestTlvStream { chain, amount, features, quantity, payer_id, payer_note } ,
80
- SignatureTlvStream { signature } ,
81
- ) , bytes ) = invoice_request ;
79
+ fn try_from ( tlv_stream : FullInvoiceRequestTlvStream ) -> Result < Self , Self :: Error > {
80
+ let (
81
+ PayerTlvStream { payer_info } ,
82
+ offer_tlv_stream,
83
+ InvoiceRequestTlvStream { chain, amount, features, quantity, payer_id, payer_note } ,
84
+ SignatureTlvStream { signature } ,
85
+ ) = tlv_stream ;
82
86
83
- let offer = Offer :: try_from ( ParsedOffer ( offer_tlv_stream, vec ! [ ] ) ) ?;
87
+ let offer = OfferContents :: try_from ( offer_tlv_stream) ?;
84
88
85
89
let chain = match chain {
86
90
None => None ,
@@ -97,8 +101,8 @@ impl TryFrom<ParsedInvoiceRequest> for InvoiceRequest {
97
101
98
102
let payer_info = payer_info. map ( Into :: into) ;
99
103
100
- Ok ( InvoiceRequest {
101
- bytes , offer, chain, amount_msat, features, quantity, payer_id, payer_note, payer_info,
104
+ Ok ( InvoiceRequestContents {
105
+ offer, chain, amount_msat, features, quantity, payer_id, payer_note, payer_info,
102
106
signature,
103
107
} )
104
108
}
0 commit comments