Stop accessing inner ScriptBuf field when encoding

In preparation for moving the `ScriptBuf` type to `primitives` stop
accessing the inner field when encoding/decoding, use `as_script`
and `from_bytes` instead.
This commit is contained in:
Tobin C. Harding 2024-08-21 11:20:40 +10:00
parent 8b82363d97
commit 900af453ff
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 4 additions and 3 deletions

View File

@ -616,14 +616,14 @@ impl<'de> serde::Deserialize<'de> for ScriptBuf {
impl Encodable for Script {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
crate::consensus::encode::consensus_encode_with_size(&self.0, w)
crate::consensus::encode::consensus_encode_with_size(self.as_bytes(), w)
}
}
impl Encodable for ScriptBuf {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
self.0.consensus_encode(w)
self.as_script().consensus_encode(w)
}
}
@ -632,7 +632,8 @@ impl Decodable for ScriptBuf {
fn consensus_decode_from_finite_reader<R: BufRead + ?Sized>(
r: &mut R,
) -> Result<Self, encode::Error> {
Ok(ScriptBuf(Decodable::consensus_decode_from_finite_reader(r)?))
let v: Vec<u8> = Decodable::consensus_decode_from_finite_reader(r)?;
Ok(ScriptBuf::from_bytes(v))
}
}