From e4284860022f019c0db40449373f2ecb21bcc06a Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 22 Dec 2022 17:55:19 +0100 Subject: [PATCH] Add `from_bytes(Vec)` 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. --- bitcoin/src/blockdata/script.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bitcoin/src/blockdata/script.rs b/bitcoin/src/blockdata/script.rs index dc3a0f91..fc5fb5e7 100644 --- a/bitcoin/src/blockdata/script.rs +++ b/bitcoin/src/blockdata/script.rs @@ -1163,7 +1163,16 @@ impl ScriptBuf { .into_script() } + /// 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 } /// Computes the P2SH output corresponding to this redeem script.