99
1010//! Data structures and encoding for `invoice_request` messages. 
1111//! 
12- //! An [`InvoiceRequest`] can be either built from a parsed [`Offer`] as an "offer to be paid" or 
13- //! built directly as an "offer for money" (e.g., refund, ATM withdrawal). In the former case, it is 
12+ //! An [`InvoiceRequest`] can be built from a parsed [`Offer`] as an "offer to be paid". It is 
1413//! typically constructed by a customer and sent to the merchant who had published the corresponding 
15- //! offer. In the latter case, an offer doesn't exist as a precursor to the request. Rather the 
16- //! merchant would typically construct the invoice request and present it to the customer. 
14+ //! offer. The recipient of the request responds with an `Invoice`. 
1715//! 
18- //! The recipient of the request responds with an `Invoice`. 
16+ //! For an "offer for money" (e.g., refund, ATM withdrawal), where an offer doesn't exist as a 
17+ //! precursor, see [`Refund`]. 
18+ //! 
19+ //! [`Refund`]: crate::offers::refund::Refund 
1920//! 
2021//! ```ignore 
2122//! extern crate bitcoin; 
3435//! let pubkey = PublicKey::from(keys); 
3536//! let mut buffer = Vec::new(); 
3637//! 
37- //! // "offer to be paid" flow 
3838//! "lno1qcp4256ypq" 
3939//!     .parse::<Offer>()? 
4040//!     .request_invoice(vec![42; 64], pubkey)? 
@@ -287,7 +287,7 @@ impl InvoiceRequest {
287287		self . contents . amount_msats 
288288	} 
289289
290- 	/// Features for paying the  invoice. 
290+ 	/// Features pertaining to requesting an  invoice. 
291291pub  fn  features ( & self )  -> & InvoiceRequestFeatures  { 
292292		& self . contents . features 
293293	} 
@@ -471,7 +471,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
471471
472472#[ cfg( test) ]  
473473mod  tests { 
474- 	use  super :: InvoiceRequest ; 
474+ 	use  super :: { InvoiceRequest ,   InvoiceRequestTlvStreamRef } ; 
475475
476476	use  bitcoin:: blockdata:: constants:: ChainHash ; 
477477	use  bitcoin:: network:: constants:: Network ; 
@@ -483,9 +483,10 @@ mod tests {
483483	use  core:: time:: Duration ; 
484484	use  crate :: ln:: features:: InvoiceRequestFeatures ; 
485485	use  crate :: ln:: msgs:: { DecodeError ,  MAX_VALUE_MSAT } ; 
486- 	use  crate :: offers:: merkle:: SignError ; 
487- 	use  crate :: offers:: offer:: { Amount ,  OfferBuilder ,  Quantity } ; 
486+ 	use  crate :: offers:: merkle:: { SignError ,   SignatureTlvStreamRef } ; 
487+ 	use  crate :: offers:: offer:: { Amount ,  OfferBuilder ,  OfferTlvStreamRef ,   Quantity } ; 
488488	use  crate :: offers:: parse:: { ParseError ,  SemanticError } ; 
489+ 	use  crate :: offers:: payer:: PayerTlvStreamRef ; 
489490	use  crate :: util:: ser:: { BigSize ,  Writeable } ; 
490491	use  crate :: util:: string:: PrintableString ; 
491492
@@ -517,14 +518,13 @@ mod tests {
517518
518519	#[ test]  
519520	fn  builds_invoice_request_with_defaults ( )  { 
520- 		let  offer  = OfferBuilder :: new ( "foo" . into ( ) ,  recipient_pubkey ( ) ) 
521+ 		let  invoice_request  = OfferBuilder :: new ( "foo" . into ( ) ,  recipient_pubkey ( ) ) 
521522			. amount_msats ( 1000 ) 
522- 			. build ( ) . unwrap ( ) ; 
523- 		let  invoice_request = offer. request_invoice ( vec ! [ 1 ;  32 ] ,  payer_pubkey ( ) ) . unwrap ( ) 
524- 			. build ( ) . unwrap ( ) . sign ( payer_sign) . unwrap ( ) ; 
523+ 			. build ( ) . unwrap ( ) 
524+ 			. request_invoice ( vec ! [ 1 ;  32 ] ,  payer_pubkey ( ) ) . unwrap ( ) 
525+ 			. build ( ) . unwrap ( ) 
526+ 			. sign ( payer_sign) . unwrap ( ) ; 
525527
526- 		let  ( payer_tlv_stream,  offer_tlv_stream,  invoice_request_tlv_stream,  signature_tlv_stream)  =
527- 			invoice_request. as_tlv_stream ( ) ; 
528528		let  mut  buffer = Vec :: new ( ) ; 
529529		invoice_request. write ( & mut  buffer) . unwrap ( ) ; 
530530
@@ -538,25 +538,34 @@ mod tests {
538538		assert_eq ! ( invoice_request. payer_note( ) ,  None ) ; 
539539		assert ! ( invoice_request. signature( ) . is_some( ) ) ; 
540540
541- 		assert_eq ! ( payer_tlv_stream. metadata,  Some ( & vec![ 1 ;  32 ] ) ) ; 
542- 		assert_eq ! ( offer_tlv_stream. chains,  None ) ; 
543- 		assert_eq ! ( offer_tlv_stream. metadata,  None ) ; 
544- 		assert_eq ! ( offer_tlv_stream. currency,  None ) ; 
545- 		assert_eq ! ( offer_tlv_stream. amount,  Some ( 1000 ) ) ; 
546- 		assert_eq ! ( offer_tlv_stream. description,  Some ( & String :: from( "foo" ) ) ) ; 
547- 		assert_eq ! ( offer_tlv_stream. features,  None ) ; 
548- 		assert_eq ! ( offer_tlv_stream. absolute_expiry,  None ) ; 
549- 		assert_eq ! ( offer_tlv_stream. paths,  None ) ; 
550- 		assert_eq ! ( offer_tlv_stream. issuer,  None ) ; 
551- 		assert_eq ! ( offer_tlv_stream. quantity_max,  None ) ; 
552- 		assert_eq ! ( offer_tlv_stream. node_id,  Some ( & recipient_pubkey( ) ) ) ; 
553- 		assert_eq ! ( invoice_request_tlv_stream. chain,  None ) ; 
554- 		assert_eq ! ( invoice_request_tlv_stream. amount,  None ) ; 
555- 		assert_eq ! ( invoice_request_tlv_stream. features,  None ) ; 
556- 		assert_eq ! ( invoice_request_tlv_stream. quantity,  None ) ; 
557- 		assert_eq ! ( invoice_request_tlv_stream. payer_id,  Some ( & payer_pubkey( ) ) ) ; 
558- 		assert_eq ! ( invoice_request_tlv_stream. payer_note,  None ) ; 
559- 		assert ! ( signature_tlv_stream. signature. is_some( ) ) ; 
541+ 		assert_eq ! ( 
542+ 			invoice_request. as_tlv_stream( ) , 
543+ 			( 
544+ 				PayerTlvStreamRef  {  metadata:  Some ( & vec![ 1 ;  32 ] )  } , 
545+ 				OfferTlvStreamRef  { 
546+ 					chains:  None , 
547+ 					metadata:  None , 
548+ 					currency:  None , 
549+ 					amount:  Some ( 1000 ) , 
550+ 					description:  Some ( & String :: from( "foo" ) ) , 
551+ 					features:  None , 
552+ 					absolute_expiry:  None , 
553+ 					paths:  None , 
554+ 					issuer:  None , 
555+ 					quantity_max:  None , 
556+ 					node_id:  Some ( & recipient_pubkey( ) ) , 
557+ 				} , 
558+ 				InvoiceRequestTlvStreamRef  { 
559+ 					chain:  None , 
560+ 					amount:  None , 
561+ 					features:  None , 
562+ 					quantity:  None , 
563+ 					payer_id:  Some ( & payer_pubkey( ) ) , 
564+ 					payer_note:  None , 
565+ 				} , 
566+ 				SignatureTlvStreamRef  {  signature:  invoice_request. signature( ) . as_ref( )  } , 
567+ 			) , 
568+ 		) ; 
560569
561570		if  let  Err ( e)  = InvoiceRequest :: try_from ( buffer)  { 
562571			panic ! ( "error parsing invoice request: {:?}" ,  e) ; 
0 commit comments