From 889848d5edb6dc53aa2aac999e54f1a80b7c618f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 11 Aug 2023 21:56:21 -0500 Subject: [PATCH] Rename field of unsigned BOLT message contents Using `contents` for the field name is more consistent with the signed messages. --- lightning/src/offers/invoice.rs | 16 ++++++++-------- lightning/src/offers/invoice_request.rs | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 5442a072f..bb62e71c5 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -370,16 +370,16 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> { /// A semantically valid [`Bolt12Invoice`] that hasn't been signed. pub struct UnsignedBolt12Invoice { bytes: Vec, - 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 { - 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) { diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 1dea6503f..978ae77bf 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -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, - 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 { - 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) { -- 2.39.5