Skip to content

Commit b72ef1a

Browse files
committed
f - refactor payer into submodule
1 parent d81b900 commit b72ef1a

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

lightning/src/offers/invoice_request.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use core::convert::TryFrom;
1616
use core::str::FromStr;
1717
use io;
1818
use ln::features::OfferFeatures;
19-
use offers::{PayerTlvStream, self};
2019
use offers::merkle::{SignatureTlvStream, self};
2120
use offers::offer::{Amount, OfferContents, OfferTlvStream, self};
2221
use offers::parse::{Bech32Encode, ParseError, SemanticError};
22+
use offers::payer::{PayerContents, PayerTlvStream, self};
2323
use util::ser::{Writeable, Writer};
2424

2525
///
@@ -30,14 +30,14 @@ pub struct InvoiceRequest {
3030

3131
///
3232
pub(crate) struct InvoiceRequestContents {
33+
payer: PayerContents,
3334
offer: OfferContents,
3435
chain: Option<BlockHash>,
3536
amount_msats: Option<u64>,
3637
features: Option<OfferFeatures>,
3738
quantity: Option<u64>,
3839
payer_id: PublicKey,
3940
payer_note: Option<String>,
40-
payer_info: Option<Vec<u8>>,
4141
signature: Option<Signature>,
4242
}
4343

@@ -49,8 +49,8 @@ impl AsRef<[u8]> for InvoiceRequest {
4949

5050
impl InvoiceRequestContents {
5151
pub(super) fn as_tlv_stream(&self) -> ReferencedFullInvoiceRequestTlvStream {
52-
let payer = offers::reference::PayerTlvStream {
53-
payer_info: self.payer_info.as_ref().map(Into::into),
52+
let payer = payer::reference::PayerTlvStream {
53+
payer_info: self.payer.0.as_ref().map(Into::into),
5454
};
5555

5656
let offer = self.offer.as_tlv_stream();
@@ -97,7 +97,7 @@ type FullInvoiceRequestTlvStream =
9797
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream);
9898

9999
type ReferencedFullInvoiceRequestTlvStream<'a> = (
100-
offers::reference::PayerTlvStream<'a>,
100+
payer::reference::PayerTlvStream<'a>,
101101
offer::reference::OfferTlvStream<'a>,
102102
reference::InvoiceRequestTlvStream<'a>,
103103
merkle::reference::SignatureTlvStream<'a>,
@@ -130,6 +130,7 @@ impl TryFrom<FullInvoiceRequestTlvStream> for InvoiceRequestContents {
130130
SignatureTlvStream { signature },
131131
) = tlv_stream;
132132

133+
let payer = PayerContents(payer_info.map(Into::into));
133134
let offer = OfferContents::try_from(offer_tlv_stream)?;
134135

135136
let chain = match chain {
@@ -171,11 +172,8 @@ impl TryFrom<FullInvoiceRequestTlvStream> for InvoiceRequestContents {
171172

172173
let payer_note = payer_note.map(Into::into);
173174

174-
let payer_info = payer_info.map(Into::into);
175-
176175
Ok(InvoiceRequestContents {
177-
offer, chain, amount_msats, features, quantity, payer_id, payer_note, payer_info,
178-
signature,
176+
payer, offer, chain, amount_msats, features, quantity, payer_id, payer_note, signature,
179177
})
180178
}
181179
}

lightning/src/offers/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ mod invoice_request;
1414
mod merkle;
1515
mod offer;
1616
mod parse;
17+
mod payer;
1718

1819
pub use self::offer::{Amount, BlindedPath, CurrencyCode, Offer, OfferBuilder};
19-
20-
tlv_stream!(struct PayerTlvStream {
21-
(0, payer_info: Vec<u8>),
22-
});

lightning/src/offers/payer.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Data structures and encoding for `invoice_request_payer_info` records.
11+
12+
/// An unpredictable sequence of bytes typically containing information needed to derive
13+
/// [`InvoiceRequestContents::payer_id`].
14+
///
15+
/// [`InvoiceRequestContents::payer_id`]: invoice_request::InvoiceRequestContents::payer_id
16+
pub(crate) struct PayerContents(pub Option<Vec<u8>>);
17+
18+
tlv_stream!(struct PayerTlvStream {
19+
(0, payer_info: Vec<u8>),
20+
});
21+

0 commit comments

Comments
 (0)