Merge rust-bitcoin/rust-bitcoin#1499: Add `from_bytes(Vec<u8>)` to `ScriptBuf`

e428486002 Add `from_bytes(Vec<u8>)` to `ScriptBuf` (Martin Habovstiak)

Pull request description:

  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.

ACKs for top commit:
  tcharding:
    ACK e428486002
  sanket1729:
    ACK e428486002

Tree-SHA512: 257b9c2cae24fd5006b6ec0e4db4a8baac177e67308758fb6167ef90e79ce75d5553433557d0e887a3e18a8fc63036f5a2acd061528a4467f76f25b6f4852400
This commit is contained in:
sanket1729 2022-12-22 22:35:35 -08:00
commit 46eda5fc33
No known key found for this signature in database
GPG Key ID: 648FFB183E0870A2
1 changed files with 9 additions and 0 deletions

View File

@ -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<u8>) -> Self {
ScriptBuf(bytes)
}
/// Converts the script into a byte vector.
///
/// This method doesn't (re)allocate.
pub fn into_bytes(self) -> Vec<u8> { self.0 }
/// Computes the P2SH output corresponding to this redeem script.