From: Jeffrey Czyz Date: Fri, 26 Apr 2024 17:03:07 +0000 (-0500) Subject: Remove InvoiceRequestFields::amount_msats X-Git-Tag: v0.0.123-rc1~1^2~9^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=7b864425ea884f816b3801cd1b4fdb99d95a4e36;p=rust-lightning Remove InvoiceRequestFields::amount_msats Event::PaymentClaimable and Event::PaymentClaimed already contain the paid amount, so there's no need to included the requested amount in InvoiceRequestFields. --- diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index 75a2e290f..5a6285373 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -412,7 +412,6 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { offer_id: offer.id(), invoice_request: InvoiceRequestFields { payer_id: invoice_request.payer_id(), - amount_msats: None, features: InvoiceRequestFeatures::empty(), quantity: None, payer_note_truncated: None, @@ -565,7 +564,6 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { offer_id: offer.id(), invoice_request: InvoiceRequestFields { payer_id: invoice_request.payer_id(), - amount_msats: None, features: InvoiceRequestFeatures::empty(), quantity: None, payer_note_truncated: None, @@ -687,7 +685,6 @@ fn pays_for_offer_without_blinded_paths() { offer_id: offer.id(), invoice_request: InvoiceRequestFields { payer_id: invoice_request.payer_id(), - amount_msats: None, features: InvoiceRequestFeatures::empty(), quantity: None, payer_note_truncated: None, diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 9157613fc..e1256b71a 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -877,13 +877,12 @@ impl VerifiedInvoiceRequest { let InvoiceRequestContents { payer_id, inner: InvoiceRequestContentsWithoutPayerId { - payer: _, offer: _, chain: _, amount_msats, features, quantity, payer_note + payer: _, offer: _, chain: _, amount_msats: _, features, quantity, payer_note }, } = &self.inner.contents; InvoiceRequestFields { payer_id: *payer_id, - amount_msats: *amount_msats, features: features.clone(), quantity: *quantity, payer_note_truncated: payer_note.clone() @@ -1126,12 +1125,6 @@ pub struct InvoiceRequestFields { /// A possibly transient pubkey used to sign the invoice request. pub payer_id: PublicKey, - /// The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which - /// must be greater than or equal to [`Offer::amount`], converted if necessary. - /// - /// [`chain`]: InvoiceRequest::chain - pub amount_msats: Option, - /// Features pertaining to requesting an invoice. pub features: InvoiceRequestFeatures, @@ -1150,10 +1143,9 @@ impl Writeable for InvoiceRequestFields { fn write(&self, writer: &mut W) -> Result<(), io::Error> { write_tlv_fields!(writer, { (0, self.payer_id, required), - (2, self.amount_msats.map(|v| HighZeroBytesDroppedBigSize(v)), option), - (4, WithoutLength(&self.features), required), - (6, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option), - (8, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option), + (2, WithoutLength(&self.features), required), + (4, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option), + (6, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option), }); Ok(()) } @@ -1163,15 +1155,14 @@ impl Readable for InvoiceRequestFields { fn read(reader: &mut R) -> Result { _init_and_read_len_prefixed_tlv_fields!(reader, { (0, payer_id, required), - (2, amount_msats, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), - (4, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))), - (6, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), - (8, payer_note_truncated, (option, encoding: (String, WithoutLength))), + (2, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))), + (4, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), + (6, payer_note_truncated, (option, encoding: (String, WithoutLength))), }); let features = features.unwrap_or(InvoiceRequestFeatures::empty()); Ok(InvoiceRequestFields { - payer_id: payer_id.0.unwrap(), amount_msats, features, quantity, + payer_id: payer_id.0.unwrap(), features, quantity, payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)), }) } @@ -2264,7 +2255,6 @@ mod tests { let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .chain(Network::Testnet).unwrap() - .amount_msats(1001).unwrap() .quantity(1).unwrap() .payer_note("0".repeat(PAYER_NOTE_LIMIT * 2)) .build().unwrap() @@ -2277,7 +2267,6 @@ mod tests { fields, InvoiceRequestFields { payer_id: payer_pubkey(), - amount_msats: Some(1001), features: InvoiceRequestFeatures::empty(), quantity: Some(1), payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),