Skip to content

Commit 30965e6

Browse files
f make as_tlv_stream consistent w Bolt12Invoice
1 parent dab261e commit 30965e6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lightning/src/offers/static_invoice.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_me
2323
use crate::offers::merkle::{
2424
self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash,
2525
};
26-
use crate::offers::offer::{Amount, Offer, OfferContents, OfferTlvStream, Quantity};
26+
use crate::offers::offer::{
27+
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity,
28+
};
2729
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
2830
use crate::util::ser::{
2931
HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer,
@@ -243,11 +245,15 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
243245

244246
impl UnsignedStaticInvoice {
245247
fn new(offer_bytes: &Vec<u8>, contents: InvoiceContents) -> Self {
248+
let (_, invoice_tlv_stream) = contents.as_tlv_stream();
249+
let offer_bytes = WithoutLength(offer_bytes);
250+
let unsigned_tlv_stream = (offer_bytes, invoice_tlv_stream);
251+
246252
let mut bytes = Vec::new();
247-
WithoutLength(offer_bytes).write(&mut bytes).unwrap();
248-
contents.as_invoice_fields_tlv_stream().write(&mut bytes).unwrap();
253+
unsigned_tlv_stream.write(&mut bytes).unwrap();
249254

250255
let tagged_hash = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &bytes);
256+
251257
Self { contents, tagged_hash, bytes }
252258
}
253259

@@ -336,7 +342,7 @@ impl InvoiceContents {
336342
}
337343
}
338344

339-
fn as_invoice_fields_tlv_stream(&self) -> InvoiceTlvStreamRef {
345+
fn as_tlv_stream(&self) -> PartialInvoiceTlvStreamRef {
340346
let features = {
341347
if self.features == Bolt12InvoiceFeatures::empty() {
342348
None
@@ -345,7 +351,7 @@ impl InvoiceContents {
345351
}
346352
};
347353

348-
InvoiceTlvStreamRef {
354+
let invoice = InvoiceTlvStreamRef {
349355
paths: Some(Iterable(self.payment_paths.iter().map(|(_, path)| path))),
350356
message_paths: Some(self.message_paths.as_ref()),
351357
blindedpay: Some(Iterable(self.payment_paths.iter().map(|(payinfo, _)| payinfo))),
@@ -356,7 +362,9 @@ impl InvoiceContents {
356362
node_id: Some(&self.signing_pubkey),
357363
amount: None,
358364
payment_hash: None,
359-
}
365+
};
366+
367+
(self.offer.as_tlv_stream(), invoice)
360368
}
361369

362370
fn chain(&self) -> ChainHash {
@@ -464,6 +472,8 @@ impl SeekReadable for FullInvoiceTlvStream {
464472

465473
type PartialInvoiceTlvStream = (OfferTlvStream, InvoiceTlvStream);
466474

475+
type PartialInvoiceTlvStreamRef<'a> = (OfferTlvStreamRef<'a>, InvoiceTlvStreamRef<'a>);
476+
467477
impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for StaticInvoice {
468478
type Error = Bolt12ParseError;
469479

0 commit comments

Comments
 (0)