Skip to content

Commit f93242c

Browse files
committed
f - check against offer amount
1 parent 8007029 commit f93242c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
567567
human_readable_name: None,
568568
},
569569
});
570-
assert_eq!(invoice_request.amount_msats(), None);
570+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
571571
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
572572
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
573573

@@ -728,7 +728,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
728728
human_readable_name: None,
729729
},
730730
});
731-
assert_eq!(invoice_request.amount_msats(), None);
731+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
732732
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
733733
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id));
734734

@@ -1117,7 +1117,7 @@ fn creates_and_pays_for_offer_with_retry() {
11171117
human_readable_name: None,
11181118
},
11191119
});
1120-
assert_eq!(invoice_request.amount_msats(), None);
1120+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
11211121
assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
11221122
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id));
11231123
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
@@ -1412,7 +1412,7 @@ fn fails_authentication_when_handling_invoice_request() {
14121412
alice.onion_messenger.handle_onion_message(david_id, &onion_message);
14131413

14141414
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
1415-
assert_eq!(invoice_request.amount_msats(), None);
1415+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
14161416
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
14171417
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
14181418

@@ -1442,7 +1442,7 @@ fn fails_authentication_when_handling_invoice_request() {
14421442
alice.onion_messenger.handle_onion_message(bob_id, &onion_message);
14431443

14441444
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
1445-
assert_eq!(invoice_request.amount_msats(), None);
1445+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
14461446
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
14471447
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
14481448

@@ -1544,7 +1544,7 @@ fn fails_authentication_when_handling_invoice_for_offer() {
15441544
alice.onion_messenger.handle_onion_message(bob_id, &onion_message);
15451545

15461546
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
1547-
assert_eq!(invoice_request.amount_msats(), None);
1547+
assert_eq!(invoice_request.amount_msats(), Some(10_000_000));
15481548
assert_ne!(invoice_request.payer_signing_pubkey(), david_id);
15491549
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
15501550

lightning/src/offers/invoice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ macro_rules! invoice_builder_methods { (
342342
pub(crate) fn amount_msats(
343343
invoice_request: &InvoiceRequest
344344
) -> Result<u64, Bolt12SemanticError> {
345-
match invoice_request.amount_msats() {
345+
match invoice_request.contents.inner.amount_msats() {
346346
Some(amount_msats) => Ok(amount_msats),
347347
None => match invoice_request.contents.inner.offer.amount() {
348348
Some(Amount::Bitcoin { amount_msats }) => {

lightning/src/offers/invoice_request.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
8080
use crate::ln::msgs::DecodeError;
8181
use crate::offers::merkle::{SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream, self, SIGNATURE_TLV_RECORD_SIZE};
8282
use crate::offers::nonce::Nonce;
83-
use crate::offers::offer::{EXPERIMENTAL_OFFER_TYPES, ExperimentalOfferTlvStream, ExperimentalOfferTlvStreamRef, OFFER_TYPES, Offer, OfferContents, OfferId, OfferTlvStream, OfferTlvStreamRef};
83+
use crate::offers::offer::{Amount, EXPERIMENTAL_OFFER_TYPES, ExperimentalOfferTlvStream, ExperimentalOfferTlvStreamRef, OFFER_TYPES, Offer, OfferContents, OfferId, OfferTlvStream, OfferTlvStreamRef};
8484
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
8585
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
8686
use crate::offers::signer::{Metadata, MetadataMaterial};
@@ -975,7 +975,15 @@ impl InvoiceRequestContents {
975975
}
976976

977977
pub(super) fn amount_msats(&self) -> Option<u64> {
978-
self.inner.amount_msats
978+
self.inner
979+
.amount_msats()
980+
.or_else(|| match self.inner.offer.amount() {
981+
Some(Amount::Bitcoin { amount_msats }) => {
982+
Some(amount_msats.saturating_mul(self.quantity().unwrap_or(1)))
983+
},
984+
Some(Amount::Currency { .. }) => None,
985+
None => { debug_assert!(false); None},
986+
})
979987
}
980988

981989
pub(super) fn features(&self) -> &InvoiceRequestFeatures {
@@ -1016,6 +1024,10 @@ impl InvoiceRequestContentsWithoutPayerSigningPubkey {
10161024
self.chain.unwrap_or_else(|| self.offer.implied_chain())
10171025
}
10181026

1027+
pub(super) fn amount_msats(&self) -> Option<u64> {
1028+
self.amount_msats
1029+
}
1030+
10191031
pub(super) fn as_tlv_stream(&self) -> PartialInvoiceRequestTlvStreamRef {
10201032
let payer = PayerTlvStreamRef {
10211033
metadata: self.payer.0.as_bytes(),
@@ -1383,7 +1395,7 @@ mod tests {
13831395
assert_eq!(invoice_request.supported_quantity(), Quantity::One);
13841396
assert_eq!(invoice_request.issuer_signing_pubkey(), Some(recipient_pubkey()));
13851397
assert_eq!(invoice_request.chain(), ChainHash::using_genesis_block(Network::Bitcoin));
1386-
assert_eq!(invoice_request.amount_msats(), None);
1398+
assert_eq!(invoice_request.amount_msats(), Some(1000));
13871399
assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::empty());
13881400
assert_eq!(invoice_request.quantity(), None);
13891401
assert_eq!(invoice_request.payer_note(), None);

0 commit comments

Comments
 (0)