zcash / librustzcash

Rust-language assets for Zcash
Other
324 stars 242 forks source link

Add `zcash_primitives::legacy::Script::serialized_size` #1424

Closed daira closed 1 week ago

daira commented 2 weeks ago

zcash_primitives::transaction::fees::transparent::OutputView::serialized_size currently writes a script to a temporary buffer in order to get its length. This could be made slightly more efficient by adding a (possibly crate-private) Script::serialized_size method, since all we need is to know what size the leading CompactSize will be, and then we can add that to the already-encoded inner Vec's length.

_Based on a comment originally posted by @str4d in https://github.com/zcash/librustzcash/pull/1257#discussion_r1638072994_