Skip to content

Commit 87c8211

Browse files
committed
f - Don't wrap OfferTlvStream
1 parent 531a111 commit 87c8211

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

lightning/src/offers/mod.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,31 @@ use std::time::SystemTime;
3030
///
3131
#[derive(Debug)]
3232
pub struct Offer {
33-
tlv_stream: OfferTlvStream,
33+
description: String,
34+
features: Option<OfferFeatures>,
35+
absolute_expiry: Option<Duration>,
36+
issuer: Option<String>,
37+
destination: Destination,
38+
quantity_min: Option<u64>,
39+
quantity_max: Option<u64>,
40+
signature: Option<Signature>,
41+
// TODO: Add more fields
3442
}
3543

3644
impl Offer {
3745
///
3846
pub fn description(&self) -> &String {
39-
&self.tlv_stream.description.as_ref().unwrap().0
47+
&self.description
4048
}
4149

4250
///
4351
pub fn features(&self) -> Option<&OfferFeatures> {
44-
self.tlv_stream.features.as_ref()
52+
self.features.as_ref()
4553
}
4654

4755
///
4856
pub fn absolute_expiry(&self) -> Option<Duration> {
49-
self.tlv_stream.absolute_expiry.as_ref()
50-
.map(|seconds_from_epoch| Duration::from_secs(seconds_from_epoch.0))
57+
self.absolute_expiry
5158
}
5259

5360
///
@@ -64,33 +71,24 @@ impl Offer {
6471

6572
///
6673
pub fn issuer(&self) -> Option<&String> {
67-
self.tlv_stream.issuer.as_ref().map(|issuer| &issuer.0)
74+
self.issuer.as_ref()
6875
}
6976

7077
///
71-
pub fn destination(&self) -> Destination {
72-
if let Some(ref node_id) = self.tlv_stream.node_id {
73-
Destination::NodeId(node_id)
74-
} else if let Some(ref paths) = self.tlv_stream.paths {
75-
Destination::Paths(&paths.0)
76-
} else {
77-
unreachable!()
78-
}
78+
pub fn destination(&self) -> &Destination {
79+
&self.destination
7980
}
8081

8182
///
8283
pub fn quantity_min(&self) -> u64 {
83-
match self.tlv_stream.quantity_min {
84-
Some(HighZeroBytesDroppedVarInt(quantity_min)) => quantity_min,
85-
None => 1,
86-
}
84+
self.quantity_min.unwrap_or(1)
8785
}
8886

8987
///
9088
pub fn quantity_max(&self) -> u64 {
91-
match self.tlv_stream.quantity_max {
92-
Some(HighZeroBytesDroppedVarInt(quantity_max)) => quantity_max,
93-
None => match self.tlv_stream.quantity_min {
89+
match self.quantity_max {
90+
Some(quantity_max) => quantity_max,
91+
None => match self.quantity_min {
9492
Some(_) => u64::max_value(),
9593
None => 1,
9694
},
@@ -99,16 +97,17 @@ impl Offer {
9997

10098
///
10199
pub fn signature(&self) -> Option<&Signature> {
102-
self.tlv_stream.signature.as_ref()
100+
self.signature.as_ref()
103101
}
104102
}
105103

106104
///
107-
pub enum Destination<'a> {
105+
#[derive(Debug)]
106+
pub enum Destination {
108107
///
109-
NodeId(&'a XOnlyPublicKey),
108+
NodeId(XOnlyPublicKey),
110109
///
111-
Paths(&'a Vec<BlindedPath>),
110+
Paths(Vec<BlindedPath>),
112111
}
113112

114113
/// An `offer` TLV stream without any semantic checks, apart from any checks performed when parsing

0 commit comments

Comments
 (0)