Merge rust-bitcoin/rust-bitcoin#1285: Implement From for hash types
96dfcdf3b7
Implement From for hash types (Noah) Pull request description: Reopening #1280 on the right branch + implemented `From` for references of types that were done in #1280. ACKs for top commit: Kixunil: ACK96dfcdf3b7
apoelstra: ACK96dfcdf3b7
Tree-SHA512: ad762032390f060b87cdd24033a5fc13a4c5297c55d7091ed89c5ca240be2f57998c0be084f40f9b04833920756b93a3ca4576a2ef944872354d1b3607734228
This commit is contained in:
commit
ccf9c3a172
|
@ -425,6 +425,30 @@ impl std::error::Error for Bip34Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BlockHeader> for BlockHash {
|
||||||
|
fn from(header: BlockHeader) -> BlockHash {
|
||||||
|
header.block_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&BlockHeader> for BlockHash {
|
||||||
|
fn from(header: &BlockHeader) -> BlockHash {
|
||||||
|
header.block_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Block> for BlockHash {
|
||||||
|
fn from(block: Block) -> BlockHash {
|
||||||
|
block.block_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Block> for BlockHash {
|
||||||
|
fn from(block: &Block) -> BlockHash {
|
||||||
|
block.block_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::hashes::hex::FromHex;
|
use crate::hashes::hex::FromHex;
|
||||||
|
|
|
@ -760,6 +760,30 @@ impl From<Vec<u8>> for Script {
|
||||||
fn from(v: Vec<u8>) -> Script { Script(v.into_boxed_slice()) }
|
fn from(v: Vec<u8>) -> Script { Script(v.into_boxed_slice()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Script> for ScriptHash {
|
||||||
|
fn from(script: Script) -> ScriptHash {
|
||||||
|
script.script_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Script> for ScriptHash {
|
||||||
|
fn from(script: &Script) -> ScriptHash {
|
||||||
|
script.script_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Script> for WScriptHash {
|
||||||
|
fn from(script: Script) -> WScriptHash {
|
||||||
|
script.wscript_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Script> for WScriptHash {
|
||||||
|
fn from(script: &Script) -> WScriptHash {
|
||||||
|
script.wscript_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A "parsed opcode" which allows iterating over a [`Script`] in a more sensible way.
|
/// A "parsed opcode" which allows iterating over a [`Script`] in a more sensible way.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum Instruction<'a> {
|
pub enum Instruction<'a> {
|
||||||
|
|
|
@ -990,6 +990,30 @@ impl Decodable for Transaction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Transaction> for Txid {
|
||||||
|
fn from(tx: Transaction) -> Txid {
|
||||||
|
tx.txid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Transaction> for Txid {
|
||||||
|
fn from(tx: &Transaction) -> Txid {
|
||||||
|
tx.txid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Transaction> for Wtxid {
|
||||||
|
fn from(tx: Transaction) -> Wtxid {
|
||||||
|
tx.wtxid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Transaction> for Wtxid {
|
||||||
|
fn from(tx: &Transaction) -> Wtxid {
|
||||||
|
tx.wtxid()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[deprecated(since = "0.30.0", note = "use crate::NonStandardSighashType instead")]
|
#[deprecated(since = "0.30.0", note = "use crate::NonStandardSighashType instead")]
|
||||||
pub use crate::util::sighash::NonStandardSighashType;
|
pub use crate::util::sighash::NonStandardSighashType;
|
||||||
#[deprecated(since = "0.30.0", note = "use crate::EcdsaSighashType instead")]
|
#[deprecated(since = "0.30.0", note = "use crate::EcdsaSighashType instead")]
|
||||||
|
|
|
@ -831,6 +831,18 @@ impl FromStr for ExtendedPubKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ExtendedPubKey> for XpubIdentifier {
|
||||||
|
fn from(key: ExtendedPubKey) -> XpubIdentifier {
|
||||||
|
key.identifier()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&ExtendedPubKey> for XpubIdentifier {
|
||||||
|
fn from(key: &ExtendedPubKey) -> XpubIdentifier {
|
||||||
|
key.identifier()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -107,6 +107,18 @@ impl TapLeafHash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ScriptLeaf> for TapLeafHash {
|
||||||
|
fn from(leaf: ScriptLeaf) -> TapLeafHash {
|
||||||
|
leaf.leaf_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&ScriptLeaf> for TapLeafHash {
|
||||||
|
fn from(leaf: &ScriptLeaf) -> TapLeafHash {
|
||||||
|
leaf.leaf_hash()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TapBranchHash {
|
impl TapBranchHash {
|
||||||
/// Computes branch hash given two hashes of the nodes underneath it.
|
/// Computes branch hash given two hashes of the nodes underneath it.
|
||||||
pub fn from_node_hashes(a: sha256::Hash, b: sha256::Hash) -> TapBranchHash {
|
pub fn from_node_hashes(a: sha256::Hash, b: sha256::Hash) -> TapBranchHash {
|
||||||
|
@ -311,6 +323,18 @@ impl TaprootSpendInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<TaprootSpendInfo> for TapTweakHash {
|
||||||
|
fn from(spend_info: TaprootSpendInfo) -> TapTweakHash {
|
||||||
|
spend_info.tap_tweak()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&TaprootSpendInfo> for TapTweakHash {
|
||||||
|
fn from(spend_info: &TaprootSpendInfo) -> TapTweakHash {
|
||||||
|
spend_info.tap_tweak()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Builder for building taproot iteratively. Users can specify tap leaf or omitted/hidden branches
|
/// Builder for building taproot iteratively. Users can specify tap leaf or omitted/hidden branches
|
||||||
/// in a depth-first search (DFS) walk order to construct this tree.
|
/// in a depth-first search (DFS) walk order to construct this tree.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue