9
9
10
10
//! Data structures and encoding for `invoice_request` messages.
11
11
//!
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
14
13
//! 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`.
17
15
//!
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
19
20
//!
20
21
//! ```ignore
21
22
//! extern crate bitcoin;
34
35
//! let pubkey = PublicKey::from(keys);
35
36
//! let mut buffer = Vec::new();
36
37
//!
37
- //! // "offer to be paid" flow
38
38
//! "lno1qcp4256ypq"
39
39
//! .parse::<Offer>()?
40
40
//! .request_invoice(vec![42; 64], pubkey)?
@@ -287,7 +287,7 @@ impl InvoiceRequest {
287
287
self . contents . amount_msats
288
288
}
289
289
290
- /// Features for paying the invoice.
290
+ /// Features pertaining to requesting an invoice.
291
291
pub fn features ( & self ) -> & InvoiceRequestFeatures {
292
292
& self . contents . features
293
293
}
@@ -471,7 +471,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
471
471
472
472
#[ cfg( test) ]
473
473
mod tests {
474
- use super :: InvoiceRequest ;
474
+ use super :: { InvoiceRequest , InvoiceRequestTlvStreamRef } ;
475
475
476
476
use bitcoin:: blockdata:: constants:: ChainHash ;
477
477
use bitcoin:: network:: constants:: Network ;
@@ -483,9 +483,10 @@ mod tests {
483
483
use core:: time:: Duration ;
484
484
use crate :: ln:: features:: InvoiceRequestFeatures ;
485
485
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 } ;
488
488
use crate :: offers:: parse:: { ParseError , SemanticError } ;
489
+ use crate :: offers:: payer:: PayerTlvStreamRef ;
489
490
use crate :: util:: ser:: { BigSize , Writeable } ;
490
491
use crate :: util:: string:: PrintableString ;
491
492
@@ -517,14 +518,13 @@ mod tests {
517
518
518
519
#[ test]
519
520
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 ( ) )
521
522
. 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 ( ) ;
525
527
526
- let ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, signature_tlv_stream) =
527
- invoice_request. as_tlv_stream ( ) ;
528
528
let mut buffer = Vec :: new ( ) ;
529
529
invoice_request. write ( & mut buffer) . unwrap ( ) ;
530
530
@@ -538,25 +538,34 @@ mod tests {
538
538
assert_eq ! ( invoice_request. payer_note( ) , None ) ;
539
539
assert ! ( invoice_request. signature( ) . is_some( ) ) ;
540
540
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
+ ) ;
560
569
561
570
if let Err ( e) = InvoiceRequest :: try_from ( buffer) {
562
571
panic ! ( "error parsing invoice request: {:?}" , e) ;
0 commit comments