diff --git a/bitcoin/src/address.rs b/bitcoin/src/address.rs index e05fe9ea..81354dee 100644 --- a/bitcoin/src/address.rs +++ b/bitcoin/src/address.rs @@ -43,9 +43,8 @@ use crate::blockdata::constants::{ }; use crate::blockdata::script::witness_program::{self, WitnessProgram}; use crate::blockdata::script::witness_version::{self, WitnessVersion}; -use crate::blockdata::script::{self, Script, ScriptBuf}; +use crate::blockdata::script::{self, Script, ScriptBuf, ScriptHash}; use crate::crypto::key::{PubkeyHash, PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey}; -use crate::hash_types::ScriptHash; use crate::network::Network; use crate::prelude::*; use crate::taproot::TapNodeHash; diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs index 9fd12b27..64a57abc 100644 --- a/bitcoin/src/blockdata/script/borrowed.rs +++ b/bitcoin/src/blockdata/script/borrowed.rs @@ -14,9 +14,9 @@ use crate::blockdata::opcodes::{self}; use crate::blockdata::script::witness_version::WitnessVersion; use crate::blockdata::script::{ bytes_to_asm_fmt, Builder, Instruction, InstructionIndices, Instructions, ScriptBuf, + ScriptHash, WScriptHash, }; use crate::consensus::Encodable; -use crate::hash_types::{ScriptHash, WScriptHash}; use crate::key::{PublicKey, UntweakedPublicKey}; use crate::policy::DUST_RELAY_TX_FEE; use crate::prelude::*; diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index ee45ed45..2a341eef 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -55,13 +55,13 @@ use core::cmp::Ordering; use core::fmt; use core::ops::{Deref, DerefMut}; +use hashes::{hash160, sha256}; #[cfg(feature = "serde")] use serde; use crate::blockdata::opcodes::all::*; use crate::blockdata::opcodes::{self}; use crate::consensus::{encode, Decodable, Encodable}; -use crate::hash_types::{ScriptHash, WScriptHash}; use crate::prelude::*; use crate::{io, OutPoint}; @@ -81,6 +81,38 @@ pub use self::instruction::*; pub use self::owned::*; pub use self::push_bytes::*; +hashes::hash_newtype! { + /// A hash of Bitcoin Script bytecode. + pub struct ScriptHash(hash160::Hash); + /// SegWit version of a Bitcoin Script bytecode hash. + pub struct WScriptHash(sha256::Hash); +} +crate::hash_types::impl_asref_push_bytes!(ScriptHash, WScriptHash); + +impl From for ScriptHash { + fn from(script: ScriptBuf) -> ScriptHash { script.script_hash() } +} + +impl From<&ScriptBuf> for ScriptHash { + fn from(script: &ScriptBuf) -> ScriptHash { script.script_hash() } +} + +impl From<&Script> for ScriptHash { + fn from(script: &Script) -> ScriptHash { script.script_hash() } +} + +impl From for WScriptHash { + fn from(script: ScriptBuf) -> WScriptHash { script.wscript_hash() } +} + +impl From<&ScriptBuf> for WScriptHash { + fn from(script: &ScriptBuf) -> WScriptHash { script.wscript_hash() } +} + +impl From<&Script> for WScriptHash { + fn from(script: &Script) -> WScriptHash { script.wscript_hash() } +} + /// Encodes an integer in script(minimal CScriptNum) format. /// /// Writes bytes into the buffer and returns the number of bytes written. @@ -304,30 +336,6 @@ impl From for Vec { fn from(v: ScriptBuf) -> Self { v.0 } } -impl From for ScriptHash { - fn from(script: ScriptBuf) -> ScriptHash { script.script_hash() } -} - -impl From<&ScriptBuf> for ScriptHash { - fn from(script: &ScriptBuf) -> ScriptHash { script.script_hash() } -} - -impl From<&Script> for ScriptHash { - fn from(script: &Script) -> ScriptHash { script.script_hash() } -} - -impl From for WScriptHash { - fn from(script: ScriptBuf) -> WScriptHash { script.wscript_hash() } -} - -impl From<&ScriptBuf> for WScriptHash { - fn from(script: &ScriptBuf) -> WScriptHash { script.wscript_hash() } -} - -impl From<&Script> for WScriptHash { - fn from(script: &Script) -> WScriptHash { script.wscript_hash() } -} - impl AsRef