diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index cdf4496d..a796c60b 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -600,7 +600,7 @@ impl_vec!(u64); #[cfg(feature = "std")] impl_vec!((u32, Address)); #[cfg(feature = "std")] impl_vec!(AddrV2Message); -fn consensus_encode_with_size(data: &[u8], mut s: S) -> Result { +pub(crate) fn consensus_encode_with_size(data: &[u8], mut s: S) -> Result { let vi_len = VarInt(data.len() as u64).consensus_encode(&mut s)?; s.emit_slice(&data)?; Ok(vi_len + data.len()) diff --git a/src/util/sighash.rs b/src/util/sighash.rs index d049e37d..5557fa0a 100644 --- a/src/util/sighash.rs +++ b/src/util/sighash.rs @@ -20,7 +20,7 @@ //! pub use blockdata::transaction::SigHashType as LegacySigHashType; -use consensus::Encodable; +use consensus::{encode, Encodable}; use core::fmt; use core::ops::{Deref, DerefMut}; use hashes::{sha256, sha256d, Hash}; @@ -344,7 +344,7 @@ impl> SigHashCache { // includes the mandatory 0x50 prefix. if let Some(annex) = annex { let mut enc = sha256::Hash::engine(); - annex.as_bytes().to_vec().consensus_encode(&mut enc)?; + annex.consensus_encode(&mut enc)?; let hash = sha256::Hash::from_engine(enc); hash.consensus_encode(&mut writer)?; } @@ -626,6 +626,12 @@ impl<'a> Annex<'a> { } } +impl<'a> Encodable for Annex<'a> { + fn consensus_encode(&self, writer: W) -> Result { + encode::consensus_encode_with_size(&self.0, writer) + } +} + #[cfg(test)] mod tests { use consensus::deserialize;