diff --git a/chronik/bitcoinsuite-core/src/script/script.rs b/chronik/bitcoinsuite-core/src/script/script.rs index 7a811de24..b2cdf01d2 100644 --- a/chronik/bitcoinsuite-core/src/script/script.rs +++ b/chronik/bitcoinsuite-core/src/script/script.rs @@ -1,249 +1,258 @@ // Copyright (c) 2023 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. use bytes::Bytes; use crate::{ + error::DataError, hash::{Hashed, ShaRmd160}, script::{opcode::*, PubKey, ScriptMut, ScriptOpIter, UncompressedPubKey}, ser::{BitcoinSer, BitcoinSerializer}, }; /// A Bitcoin script. /// /// This is immutable, and uses [`Bytes`] to store the bytecode, making it cheap /// to copy. #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Script(Bytes); impl Script { /// Create a new script from the given bytecode. pub fn new(bytecode: Bytes) -> Self { Script(bytecode) } /// Pay-to-public-key-hash: /// `OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG` /// ``` /// # use bitcoinsuite_core::{script::Script, hash::ShaRmd160}; /// # use hex_literal::hex; /// let hash = ShaRmd160(hex!("00112233445566778899aabbccddeeff00112233")); /// let script = Script::p2pkh(&hash); /// assert_eq!( /// script.hex(), /// "76a91400112233445566778899aabbccddeeff0011223388ac", /// ); /// ``` pub fn p2pkh(hash: &ShaRmd160) -> Script { let mut script = ScriptMut::with_capacity(2 + 1 + ShaRmd160::SIZE + 2); script.put_opcodes([OP_DUP, OP_HASH160]); script.put_bytecode(&[ShaRmd160::SIZE as u8]); script.put_bytecode(hash.as_le_bytes()); script.put_opcodes([OP_EQUALVERIFY, OP_CHECKSIG]); script.freeze() } /// Pay-to-script-hash: `OP_HASH160