Rename field of unsigned BOLT message contents
authorJeffrey Czyz <jkczyz@gmail.com>
Sat, 12 Aug 2023 02:56:21 +0000 (21:56 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 22 Aug 2023 00:14:27 +0000 (19:14 -0500)
Using `contents` for the field name is more consistent with the signed
messages.

lightning/src/offers/invoice.rs
lightning/src/offers/invoice_request.rs

index 5442a072f37872ddb934b6a4103cd9e80f3f73be..bb62e71c5aab67a26e3e2ebf66b83b3c63c65e8b 100644 (file)
@@ -370,16 +370,16 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
 /// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
 pub struct UnsignedBolt12Invoice {
        bytes: Vec<u8>,
-       invoice: InvoiceContents,
+       contents: InvoiceContents,
        tagged_hash: TaggedHash,
 }
 
 impl UnsignedBolt12Invoice {
-       fn new(invreq_bytes: &[u8], invoice: InvoiceContents) -> Self {
+       fn new(invreq_bytes: &[u8], contents: InvoiceContents) -> Self {
                // Use the invoice_request bytes instead of the invoice_request TLV stream as the latter may
                // have contained unknown TLV records, which are not stored in `InvoiceRequestContents` or
                // `RefundContents`.
-               let (_, _, _, invoice_tlv_stream) = invoice.as_tlv_stream();
+               let (_, _, _, invoice_tlv_stream) = contents.as_tlv_stream();
                let invoice_request_bytes = WithoutSignatures(invreq_bytes);
                let unsigned_tlv_stream = (invoice_request_bytes, invoice_tlv_stream);
 
@@ -388,12 +388,12 @@ impl UnsignedBolt12Invoice {
 
                let tagged_hash = TaggedHash::new(SIGNATURE_TAG, &bytes);
 
-               Self { bytes, invoice, tagged_hash }
+               Self { bytes, contents, tagged_hash }
        }
 
        /// The public key corresponding to the key needed to sign the invoice.
        pub fn signing_pubkey(&self) -> PublicKey {
-               self.invoice.fields().signing_pubkey
+               self.contents.fields().signing_pubkey
        }
 
        /// Signs the invoice using the given function.
@@ -403,7 +403,7 @@ impl UnsignedBolt12Invoice {
        where
                F: FnOnce(&Self) -> Result<Signature, E>
        {
-               let pubkey = self.invoice.fields().signing_pubkey;
+               let pubkey = self.contents.fields().signing_pubkey;
                let signature = merkle::sign_message(sign, &self, pubkey)?;
 
                // Append the signature TLV record to the bytes.
@@ -414,7 +414,7 @@ impl UnsignedBolt12Invoice {
 
                Ok(Bolt12Invoice {
                        bytes: self.bytes,
-                       contents: self.invoice,
+                       contents: self.contents,
                        signature,
                })
        }
@@ -1802,7 +1802,7 @@ mod tests {
                        .sign(payer_sign).unwrap()
                        .respond_with_no_std(payment_paths(), payment_hash(), now()).unwrap()
                        .build().unwrap()
-                       .invoice
+                       .contents
                        .write(&mut buffer).unwrap();
 
                match Bolt12Invoice::try_from(buffer) {
index 1dea6503f58fd23913874d0aa33c234cc3d50bce..978ae77bfb7ae1e3e862780369b13eb857259a93 100644 (file)
@@ -346,16 +346,16 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
 /// A semantically valid [`InvoiceRequest`] that hasn't been signed.
 pub struct UnsignedInvoiceRequest {
        bytes: Vec<u8>,
-       invoice_request: InvoiceRequestContents,
+       contents: InvoiceRequestContents,
        tagged_hash: TaggedHash,
 }
 
 impl UnsignedInvoiceRequest {
-       fn new(offer: &Offer, invoice_request: InvoiceRequestContents) -> Self {
+       fn new(offer: &Offer, contents: InvoiceRequestContents) -> Self {
                // Use the offer bytes instead of the offer TLV stream as the offer may have contained
                // unknown TLV records, which are not stored in `OfferContents`.
                let (payer_tlv_stream, _offer_tlv_stream, invoice_request_tlv_stream) =
-                       invoice_request.as_tlv_stream();
+                       contents.as_tlv_stream();
                let offer_bytes = WithoutLength(&offer.bytes);
                let unsigned_tlv_stream = (payer_tlv_stream, offer_bytes, invoice_request_tlv_stream);
 
@@ -364,7 +364,7 @@ impl UnsignedInvoiceRequest {
 
                let tagged_hash = TaggedHash::new(SIGNATURE_TAG, &bytes);
 
-               Self { bytes, invoice_request, tagged_hash }
+               Self { bytes, contents, tagged_hash }
        }
 
        /// Signs the invoice request using the given function.
@@ -374,7 +374,7 @@ impl UnsignedInvoiceRequest {
        where
                F: FnOnce(&Self) -> Result<Signature, E>
        {
-               let pubkey = self.invoice_request.payer_id;
+               let pubkey = self.contents.payer_id;
                let signature = merkle::sign_message(sign, &self, pubkey)?;
 
                // Append the signature TLV record to the bytes.
@@ -385,7 +385,7 @@ impl UnsignedInvoiceRequest {
 
                Ok(InvoiceRequest {
                        bytes: self.bytes,
-                       contents: self.invoice_request,
+                       contents: self.contents,
                        signature,
                })
        }
@@ -1681,7 +1681,7 @@ mod tests {
                        .build().unwrap();
                let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
                        .build().unwrap();
-               let mut tlv_stream = unsigned_invoice_request.invoice_request.as_tlv_stream();
+               let mut tlv_stream = unsigned_invoice_request.contents.as_tlv_stream();
                tlv_stream.0.metadata = None;
 
                let mut buffer = Vec::new();
@@ -1702,7 +1702,7 @@ mod tests {
                        .build().unwrap();
                let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
                        .build().unwrap();
-               let mut tlv_stream = unsigned_invoice_request.invoice_request.as_tlv_stream();
+               let mut tlv_stream = unsigned_invoice_request.contents.as_tlv_stream();
                tlv_stream.2.payer_id = None;
 
                let mut buffer = Vec::new();
@@ -1721,7 +1721,7 @@ mod tests {
                        .build().unwrap();
                let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap()
                        .build().unwrap();
-               let mut tlv_stream = unsigned_invoice_request.invoice_request.as_tlv_stream();
+               let mut tlv_stream = unsigned_invoice_request.contents.as_tlv_stream();
                tlv_stream.1.node_id = None;
 
                let mut buffer = Vec::new();
@@ -1743,7 +1743,7 @@ mod tests {
                        .build().unwrap()
                        .request_invoice(vec![1; 32], payer_pubkey()).unwrap()
                        .build().unwrap()
-                       .invoice_request
+                       .contents
                        .write(&mut buffer).unwrap();
 
                match InvoiceRequest::try_from(buffer) {