@@ -666,17 +666,10 @@ impl UnsignedBolt12Invoice {
666
666
& self . tagged_hash
667
667
}
668
668
669
- /// Computes the offer ID if this invoice corresponds to an offer .
669
+ /// Computes the [`OfferId`] if this invoice corresponds to an [`Offer`] .
670
670
fn compute_offer_id ( & self ) -> Option < OfferId > {
671
671
match & self . contents {
672
- InvoiceContents :: ForOffer { .. } => {
673
- // Extract offer TLV records from the invoice bytes
674
- let offer_tlv_stream = TlvStream :: new ( & self . bytes ) . range ( OFFER_TYPES ) ;
675
- let experimental_offer_tlv_stream = TlvStream :: new ( & self . experimental_bytes ) . range ( EXPERIMENTAL_OFFER_TYPES ) ;
676
- let combined_tlv_stream = offer_tlv_stream. chain ( experimental_offer_tlv_stream) ;
677
- let tagged_hash = TaggedHash :: from_tlv_stream ( "LDK Offer ID" , combined_tlv_stream) ;
678
- Some ( OfferId ( tagged_hash. to_bytes ( ) ) )
679
- } ,
672
+ InvoiceContents :: ForOffer { .. } => Some ( OfferId :: from_invoice_bytes ( & self . bytes ) ) ,
680
673
InvoiceContents :: ForRefund { .. } => None ,
681
674
}
682
675
}
@@ -987,7 +980,7 @@ impl Bolt12Invoice {
987
980
self . tagged_hash . as_digest ( ) . as_ref ( ) . clone ( )
988
981
}
989
982
990
- /// Returns the offer ID if this invoice corresponds to an offer .
983
+ /// Returns the [`OfferId`] if this invoice corresponds to an [`Offer`] .
991
984
pub fn offer_id ( & self ) -> Option < OfferId > {
992
985
self . offer_id
993
986
}
@@ -1647,11 +1640,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
1647
1640
let pubkey = contents. fields ( ) . signing_pubkey ;
1648
1641
merkle:: verify_signature ( & signature, & tagged_hash, pubkey) ?;
1649
1642
1650
- let offer_tlv_stream = TlvStream :: new ( & bytes) . range ( OFFER_TYPES ) ;
1651
- let experimental_offer_tlv_stream = TlvStream :: new ( & bytes) . range ( EXPERIMENTAL_OFFER_TYPES ) ;
1652
- let combined_tlv_stream = offer_tlv_stream. chain ( experimental_offer_tlv_stream) ;
1653
- let offer_tagged_hash = TaggedHash :: from_tlv_stream ( "LDK Offer ID" , combined_tlv_stream) ;
1654
- let offer_id = OfferId :: from_tagged_hash ( & offer_tagged_hash) ;
1643
+ let offer_id = OfferId :: from_invoice_bytes ( & bytes) ;
1655
1644
Ok ( Bolt12Invoice { bytes, contents, signature, tagged_hash, offer_id : Some ( offer_id) } )
1656
1645
}
1657
1646
}
@@ -3595,23 +3584,19 @@ mod tests {
3595
3584
let secp_ctx = Secp256k1 :: new ( ) ;
3596
3585
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
3597
3586
3598
- // Create an offer
3599
3587
let offer = OfferBuilder :: new ( recipient_pubkey ( ) )
3600
3588
. amount_msats ( 1000 )
3601
3589
. build ( )
3602
3590
. unwrap ( ) ;
3603
3591
3604
- // Get the offer ID
3605
3592
let offer_id = offer. id ( ) ;
3606
3593
3607
- // Create an invoice request from the offer
3608
3594
let invoice_request = offer
3609
3595
. request_invoice ( & expanded_key, nonce, & secp_ctx, payment_id)
3610
3596
. unwrap ( )
3611
3597
. build_and_sign ( )
3612
3598
. unwrap ( ) ;
3613
3599
3614
- // Create an invoice from the invoice request
3615
3600
let invoice = invoice_request
3616
3601
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , now ( ) )
3617
3602
. unwrap ( )
@@ -3620,19 +3605,16 @@ mod tests {
3620
3605
. sign ( recipient_sign)
3621
3606
. unwrap ( ) ;
3622
3607
3623
- // Verify that the invoice's offer_id matches the offer's id
3624
3608
assert_eq ! ( invoice. offer_id( ) , Some ( offer_id) ) ;
3625
3609
}
3626
3610
3627
3611
#[ test]
3628
3612
fn refund_invoice_has_no_offer_id ( ) {
3629
- // Create a refund
3630
3613
let refund = RefundBuilder :: new ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) , 1000 )
3631
3614
. unwrap ( )
3632
3615
. build ( )
3633
3616
. unwrap ( ) ;
3634
3617
3635
- // Create an invoice from the refund
3636
3618
let invoice = refund
3637
3619
. respond_with_no_std ( payment_paths ( ) , payment_hash ( ) , recipient_pubkey ( ) , now ( ) )
3638
3620
. unwrap ( )
@@ -3641,7 +3623,6 @@ mod tests {
3641
3623
. sign ( recipient_sign)
3642
3624
. unwrap ( ) ;
3643
3625
3644
- // Verify that the refund invoice has no offer_id
3645
3626
assert_eq ! ( invoice. offer_id( ) , None ) ;
3646
3627
}
3647
3628
}
0 commit comments