diff --git a/bitcoin/src/blockdata/script/owned.rs b/bitcoin/src/blockdata/script/owned.rs index a6d283729..43f645e40 100644 --- a/bitcoin/src/blockdata/script/owned.rs +++ b/bitcoin/src/blockdata/script/owned.rs @@ -64,6 +64,32 @@ impl ScriptBuf { /// Returns a mutable reference to unsized script. pub fn as_mut_script(&mut self) -> &mut Script { Script::from_bytes_mut(&mut self.0) } + /// Converts byte vector into script. + /// + /// This method doesn't (re)allocate. + pub fn from_bytes(bytes: Vec) -> Self { ScriptBuf(bytes) } + + /// Converts the script into a byte vector. + /// + /// This method doesn't (re)allocate. + pub fn into_bytes(self) -> Vec { self.0 } + + /// Converts this `ScriptBuf` into a [boxed](Box) [`Script`]. + /// + /// This method reallocates if the capacity is greater than length of the script but should not + /// when they are equal. If you know beforehand that you need to create a script of exact size + /// use [`reserve_exact`](Self::reserve_exact) before adding data to the script so that the + /// reallocation can be avoided. + #[must_use = "`self` will be dropped if the result is not used"] + #[inline] + pub fn into_boxed_script(self) -> Box