]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Prefer `Writeable.encode()` over `VecWriter` use
authorMatt Corallo <git@bluematt.me>
Sat, 4 Nov 2023 16:20:24 +0000 (16:20 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 4 Nov 2023 16:20:24 +0000 (16:20 +0000)
It does the same thing and its much simpler.

lightning/src/blinded_path/utils.rs

index c62b4e6c2612cb52ee57321b747947d2100bd214..33a2cde8c8f6666702b860a0b856bdf1d3c46ff2 100644 (file)
@@ -20,7 +20,7 @@ use crate::ln::msgs::DecodeError;
 use crate::ln::onion_utils;
 use crate::onion_message::Destination;
 use crate::util::chacha20poly1305rfc::ChaChaPolyWriteAdapter;
-use crate::util::ser::{Readable, VecWriter, Writeable};
+use crate::util::ser::{Readable, Writeable};
 
 use crate::io;
 use crate::prelude::*;
@@ -129,10 +129,8 @@ where
 
 /// Encrypt TLV payload to be used as a [`crate::blinded_path::BlindedHop::encrypted_payload`].
 fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_rho: [u8; 32]) -> Vec<u8> {
-       let mut writer = VecWriter(Vec::new());
        let write_adapter = ChaChaPolyWriteAdapter::new(encrypted_tlvs_rho, &payload);
-       write_adapter.write(&mut writer).expect("In-memory writes cannot fail");
-       writer.0
+       write_adapter.encode()
 }
 
 /// Blinded path encrypted payloads may be padded to ensure they are equal length.