From e0bc50953a21fc13aabb6b6b31e554a1c1557a8d Mon Sep 17 00:00:00 2001 From: Jiri Jakes Date: Thu, 29 Dec 2022 15:22:16 +0100 Subject: [PATCH] Make `Witness::tapscript()` return `Script` instead of raw bytes --- bitcoin/src/blockdata/witness.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index 7c54ee7d..cc99e242 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -15,7 +15,7 @@ use crate::consensus::{Decodable, Encodable, WriteExt}; use crate::sighash::EcdsaSighashType; use crate::io::{self, Read, Write}; use crate::prelude::*; -use crate::VarInt; +use crate::{Script, VarInt}; use crate::taproot::TAPROOT_ANNEX_PREFIX; /// The Witness is the data used to unlock bitcoin since the [segwit upgrade]. @@ -317,7 +317,7 @@ impl Witness { /// the first byte of the last element being equal to 0x50. See /// [Script::is_v1_p2tr](crate::blockdata::script::Script::is_v1_p2tr) to /// check whether this is actually a Taproot witness. - pub fn tapscript(&self) -> Option<&[u8]> { + pub fn tapscript(&self) -> Option<&Script> { let len = self.len(); self .last() @@ -338,6 +338,7 @@ impl Witness { .and_then(|script_pos_from_last| { self.nth(len - script_pos_from_last) }) + .map(Script::from_bytes) } } @@ -641,8 +642,8 @@ mod test { }; // With or without annex, the tapscript should be returned. - assert_eq!(witness.tapscript(), Some(&tapscript[..])); - assert_eq!(witness_annex.tapscript(), Some(&tapscript[..])); + assert_eq!(witness.tapscript(), Some(Script::from_bytes(&tapscript[..]))); + assert_eq!(witness_annex.tapscript(), Some(Script::from_bytes(&tapscript[..]))); } #[test]