Skip to content

Commit

Permalink
Node: Update RedeemNode::encode_to_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
uncomputable committed Dec 5, 2023
1 parent 8d03d20 commit 522d4a0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/node/redeem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ impl<J: Jet> RedeemNode<J> {
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<W: io::Write>(&self, w: &mut BitWriter<W>) -> io::Result<usize> {
let sharing_iter = self.post_order_iter::<MaxSharing<Redeem<J>>>();
let program_bits = encode::encode_program(self, w)?;
Expand All @@ -374,15 +376,11 @@ impl<J: Jet> RedeemNode<J> {
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<u8> {
let mut program_and_witness_bytes = Vec::<u8>::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))
}
}

Expand Down

0 comments on commit 522d4a0

Please sign in to comment.