diff --git a/src/node/redeem.rs b/src/node/redeem.rs index f97085c6..5bb933a9 100644 --- a/src/node/redeem.rs +++ b/src/node/redeem.rs @@ -364,7 +364,9 @@ impl RedeemNode { Ok(program) } - /// Encode a Simplicity program to bits, including the witness data. + /// Encode the program to bits. + /// + /// Includes witness data. Returns the number of written bits. pub fn encode(&self, w: &mut BitWriter) -> io::Result { let sharing_iter = self.post_order_iter::>>(); let program_bits = encode::encode_program(self, w)?; @@ -374,15 +376,11 @@ impl RedeemNode { Ok(program_bits + witness_bits) } - /// Encode a Simplicity program to a vector of bytes, including the witness data. + /// Encode the program to a byte vector. + /// + /// Includes witness data. pub fn encode_to_vec(&self) -> Vec { - let mut program_and_witness_bytes = Vec::::new(); - let mut writer = BitWriter::new(&mut program_and_witness_bytes); - self.encode(&mut writer) - .expect("write to vector never fails"); - debug_assert!(!program_and_witness_bytes.is_empty()); - - program_and_witness_bytes + BitWriter::vec(|w| self.encode(w)) } }