Skip to content

Commit fdd0cf5

Browse files
committed
simplify ChannelReestablish read
1 parent c5a43f3 commit fdd0cf5

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/ln/msgs.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,16 +1744,12 @@ impl<R: ::std::io::Read> Readable<R> for ChannelReestablish{
17441744
next_local_commitment_number: Readable::read(r)?,
17451745
next_remote_commitment_number: Readable::read(r)?,
17461746
data_loss_protect: {
1747-
let mut buf = [0; 32+33];
1748-
match r.read_exact(&mut buf) {
1749-
Ok(()) => Some(DataLossProtect {
1750-
your_last_per_commitment_secret: {
1751-
let mut a: [u8; 32] = Default::default();
1752-
a.copy_from_slice(&buf[..32]);
1753-
a
1754-
},
1755-
my_current_per_commitment_point: secp_pubkey!(&Secp256k1::without_caps(), &buf[32..]),
1756-
}),
1747+
match <[u8; 32] as Readable<R>>::read(r) {
1748+
Ok(your_last_per_commitment_secret) =>
1749+
Some(DataLossProtect {
1750+
your_last_per_commitment_secret,
1751+
my_current_per_commitment_point: Readable::read(r)?,
1752+
}),
17571753
Err(DecodeError::ShortRead) => None,
17581754
Err(e) => return Err(e)
17591755
}
@@ -1893,11 +1889,7 @@ impl<R: ::std::io::Read> Readable<R> for OnionPacket {
18931889
r.read_exact(&mut buf)?;
18941890
PublicKey::from_slice(&Secp256k1::without_caps(), &buf)
18951891
},
1896-
hop_data: {
1897-
let mut buf = [0u8;20*65];
1898-
r.read_exact(&mut buf)?;
1899-
buf
1900-
},
1892+
hop_data: Readable::read(r)?,
19011893
hmac: Readable::read(r)?,
19021894
})
19031895
}

0 commit comments

Comments
 (0)