Skip to content

Commit 0ac13e8

Browse files
Revert "Disallow (de)serializing BlindedPaths."
This reverts commit e2701ad. We're making the struct private so no reason to diverge from using the ser traits
1 parent e2701ad commit 0ac13e8

File tree

1 file changed

+50
-46
lines changed
  • lightning/src/blinded_path

1 file changed

+50
-46
lines changed

lightning/src/blinded_path/mod.rs

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -119,52 +119,6 @@ pub struct BlindedHop {
119119
}
120120

121121
impl BlindedPath {
122-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
123-
match &self.introduction_node {
124-
IntroductionNode::NodeId(pubkey) => pubkey.write(w)?,
125-
IntroductionNode::DirectedShortChannelId(direction, scid) => {
126-
match direction {
127-
Direction::NodeOne => 0u8.write(w)?,
128-
Direction::NodeTwo => 1u8.write(w)?,
129-
}
130-
scid.write(w)?;
131-
},
132-
}
133-
134-
self.blinding_point.write(w)?;
135-
(self.blinded_hops.len() as u8).write(w)?;
136-
for hop in &self.blinded_hops {
137-
hop.write(w)?;
138-
}
139-
Ok(())
140-
}
141-
142-
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
143-
let mut first_byte: u8 = Readable::read(r)?;
144-
let introduction_node = match first_byte {
145-
0 => IntroductionNode::DirectedShortChannelId(Direction::NodeOne, Readable::read(r)?),
146-
1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?),
147-
2|3 => {
148-
use io::Read;
149-
let mut pubkey_read = core::slice::from_mut(&mut first_byte).chain(r.by_ref());
150-
IntroductionNode::NodeId(Readable::read(&mut pubkey_read)?)
151-
},
152-
_ => return Err(DecodeError::InvalidValue),
153-
};
154-
let blinding_point = Readable::read(r)?;
155-
let num_hops: u8 = Readable::read(r)?;
156-
if num_hops == 0 { return Err(DecodeError::InvalidValue) }
157-
let mut blinded_hops: Vec<BlindedHop> = Vec::with_capacity(num_hops.into());
158-
for _ in 0..num_hops {
159-
blinded_hops.push(Readable::read(r)?);
160-
}
161-
Ok(Self {
162-
introduction_node,
163-
blinding_point,
164-
blinded_hops,
165-
})
166-
}
167-
168122
/// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
169123
/// it is found in the network graph).
170124
pub fn public_introduction_node_id<'a>(
@@ -216,6 +170,56 @@ impl BlindedPath {
216170
}
217171
}
218172

173+
impl Writeable for BlindedPath {
174+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
175+
match &self.introduction_node {
176+
IntroductionNode::NodeId(pubkey) => pubkey.write(w)?,
177+
IntroductionNode::DirectedShortChannelId(direction, scid) => {
178+
match direction {
179+
Direction::NodeOne => 0u8.write(w)?,
180+
Direction::NodeTwo => 1u8.write(w)?,
181+
}
182+
scid.write(w)?;
183+
},
184+
}
185+
186+
self.blinding_point.write(w)?;
187+
(self.blinded_hops.len() as u8).write(w)?;
188+
for hop in &self.blinded_hops {
189+
hop.write(w)?;
190+
}
191+
Ok(())
192+
}
193+
}
194+
195+
impl Readable for BlindedPath {
196+
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
197+
let mut first_byte: u8 = Readable::read(r)?;
198+
let introduction_node = match first_byte {
199+
0 => IntroductionNode::DirectedShortChannelId(Direction::NodeOne, Readable::read(r)?),
200+
1 => IntroductionNode::DirectedShortChannelId(Direction::NodeTwo, Readable::read(r)?),
201+
2|3 => {
202+
use io::Read;
203+
let mut pubkey_read = core::slice::from_mut(&mut first_byte).chain(r.by_ref());
204+
IntroductionNode::NodeId(Readable::read(&mut pubkey_read)?)
205+
},
206+
_ => return Err(DecodeError::InvalidValue),
207+
};
208+
let blinding_point = Readable::read(r)?;
209+
let num_hops: u8 = Readable::read(r)?;
210+
if num_hops == 0 { return Err(DecodeError::InvalidValue) }
211+
let mut blinded_hops: Vec<BlindedHop> = Vec::with_capacity(num_hops.into());
212+
for _ in 0..num_hops {
213+
blinded_hops.push(Readable::read(r)?);
214+
}
215+
Ok(BlindedPath {
216+
introduction_node,
217+
blinding_point,
218+
blinded_hops,
219+
})
220+
}
221+
}
222+
219223
impl_writeable!(BlindedHop, {
220224
blinded_node_id,
221225
encrypted_payload

0 commit comments

Comments
 (0)