Add `from_bytes(Vec<u8>)` to `ScriptBuf`

This is useful when one already has bytes allocated in a vec that can be
reused.

The change also documents that the mirror method `into_bytes()` doesn't
allocate.
This commit is contained in:
Martin Habovstiak 2022-12-22 17:55:19 +01:00
parent 7fee6239e1
commit e428486002
1 changed files with 9 additions and 0 deletions

View File

@ -1163,7 +1163,16 @@ impl ScriptBuf {
.into_script() .into_script()
} }
/// Converts byte vector into script.
///
/// This method doesn't (re)allocate.
pub fn from_bytes(bytes: Vec<u8>) -> Self {
ScriptBuf(bytes)
}
/// Converts the script into a byte vector. /// Converts the script into a byte vector.
///
/// This method doesn't (re)allocate.
pub fn into_bytes(self) -> Vec<u8> { self.0 } pub fn into_bytes(self) -> Vec<u8> { self.0 }
/// Computes the P2SH output corresponding to this redeem script. /// Computes the P2SH output corresponding to this redeem script.