From 522d4a0115713c2c6bf8384ea241b2efa322c3ec Mon Sep 17 00:00:00 2001 From: Christian Lewe Date: Tue, 5 Dec 2023 13:51:01 +0100 Subject: [PATCH] Node: Update RedeemNode::encode_to_vec --- src/node/redeem.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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)) } }