Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Witness Serialization #1071

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/blockdata/witness.rs
Expand Up @@ -11,9 +11,6 @@ use crate::prelude::*;
use secp256k1::ecdsa;
use crate::VarInt;

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

/// The Witness is the data used to unlock bitcoins since the [segwit upgrade](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki)
///
/// Can be logically seen as an array of byte-arrays `Vec<Vec<u8>>` and indeed you can convert from
Expand Down Expand Up @@ -282,8 +279,15 @@ impl serde::Serialize for Witness {
where
S: serde::Serializer,
{
let vec: Vec<_> = self.to_vec();
serde::Serialize::serialize(&vec, serializer)
use serde::ser::SerializeSeq;

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