Skip to content

Commit

Permalink
Optimize Witness Serialization
Browse files Browse the repository at this point in the history
fix #942
  • Loading branch information
DanGould committed Jun 28, 2022
1 parent b645b6b commit 0912593
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/blockdata/witness.rs
Expand Up @@ -13,6 +13,8 @@ use crate::VarInt;

#[cfg(feature = "serde")]
use serde;
use serde::ser::SerializeSeq;


/// The Witness is the data used to unlock bitcoins since the [segwit upgrade](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki)
///
Expand Down Expand Up @@ -282,8 +284,13 @@ impl serde::Serialize for Witness {
where
S: serde::Serializer,
{
let vec: Vec<_> = self.to_vec();
serde::Serialize::serialize(&vec, serializer)
let mut seq = serializer.serialize_seq(Some(self.witness_elements))?;

for elem in self.iter() {
seq.serialize_element(&elem)?;
}

seq.end()
}
}
#[cfg(feature = "serde")]
Expand Down

0 comments on commit 0912593

Please sign in to comment.