Merge pull request #3018 from jkczyz/2024-04-optional-description
[rust-lightning] / lightning / src / offers / invoice_request.rs
index 90d6d5bf3084f4fafabcb55935bc83250abb9033..1fbb00d6f0da2ff054532fcd8ad843596e9a2fa0 100644 (file)
@@ -902,14 +902,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()
                                .map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
@@ -1162,15 +1160,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<u64>,
-
-       /// Features pertaining to requesting an invoice.
-       pub features: InvoiceRequestFeatures,
-
        /// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
        pub quantity: Option<u64>,
 
@@ -1186,10 +1175,8 @@ impl Writeable for InvoiceRequestFields {
        fn write<W: Writer>(&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, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
+                       (4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
                });
                Ok(())
        }
@@ -1199,15 +1186,13 @@ impl Readable for InvoiceRequestFields {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                _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, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
+                       (4, 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(),
+                       quantity,
                        payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)),
                })
        }
@@ -1263,7 +1248,7 @@ mod tests {
                assert_eq!(unsigned_invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]);
                assert_eq!(unsigned_invoice_request.metadata(), None);
                assert_eq!(unsigned_invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
-               assert_eq!(unsigned_invoice_request.description(), PrintableString(""));
+               assert_eq!(unsigned_invoice_request.description(), Some(PrintableString("")));
                assert_eq!(unsigned_invoice_request.offer_features(), &OfferFeatures::empty());
                assert_eq!(unsigned_invoice_request.absolute_expiry(), None);
                assert_eq!(unsigned_invoice_request.paths(), &[]);
@@ -1295,7 +1280,7 @@ mod tests {
                assert_eq!(invoice_request.chains(), vec![ChainHash::using_genesis_block(Network::Bitcoin)]);
                assert_eq!(invoice_request.metadata(), None);
                assert_eq!(invoice_request.amount(), Some(&Amount::Bitcoin { amount_msats: 1000 }));
-               assert_eq!(invoice_request.description(), PrintableString(""));
+               assert_eq!(invoice_request.description(), Some(PrintableString("")));
                assert_eq!(invoice_request.offer_features(), &OfferFeatures::empty());
                assert_eq!(invoice_request.absolute_expiry(), None);
                assert_eq!(invoice_request.paths(), &[]);
@@ -1996,6 +1981,7 @@ mod tests {
                }
 
                let invoice_request = OfferBuilder::new(recipient_pubkey())
+                       .description("foo".to_string())
                        .amount(Amount::Currency { iso4217_code: *b"USD", amount: 1000 })
                        .build_unchecked()
                        .request_invoice(vec![1; 32], payer_pubkey()).unwrap()
@@ -2300,7 +2286,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()
@@ -2313,8 +2298,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))),
                                        }