From b84f25584e4868d91292611c974ff80d293f9af2 Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Tue, 29 Mar 2022 08:59:14 +1100 Subject: [PATCH] Rename SigHashCache -> SighashCache Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash' is a well known word in the Bitcoin ecosystem it should appear in identifiers as `Sighash`. Rename `SigHashCache` to `SighashCache`. --- src/blockdata/transaction.rs | 4 ++-- src/util/bip143.rs | 8 ++++---- src/util/sighash.rs | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 41b355e1..4e763e9c 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -905,7 +905,7 @@ mod tests { use hash_types::*; use super::EcdsaSighashType; - use util::sighash::SigHashCache; + use util::sighash::SighashCache; #[test] fn test_outpoint() { @@ -1240,7 +1240,7 @@ mod tests { // both the codepaths without repeating the test code tx.signature_hash(input_index, &script, hash_type as u32) } else { - let cache = SigHashCache::new(&tx); + let cache = SighashCache::new(&tx); cache.legacy_signature_hash(input_index, &script, hash_type as u32).unwrap() }; diff --git a/src/util/bip143.rs b/src/util/bip143.rs index 1acc9b27..1791507c 100644 --- a/src/util/bip143.rs +++ b/src/util/bip143.rs @@ -33,7 +33,7 @@ use util::sighash; /// Parts of a sighash which are common across inputs or signatures, and which are /// sufficient (in conjunction with a private key) to sign the transaction #[derive(Clone, PartialEq, Eq, Debug)] -#[deprecated(since = "0.24.0", note = "please use [sighash::SigHashCache] instead")] +#[deprecated(since = "0.24.0", note = "please use [sighash::SighashCache] instead")] pub struct SighashComponents { tx_version: i32, tx_locktime: u32, @@ -107,9 +107,9 @@ impl SighashComponents { } /// A replacement for SigHashComponents which supports all sighash modes -#[deprecated(since = "0.28.0", note = "please use [sighash::SigHashCache] instead")] +#[deprecated(since = "0.28.0", note = "please use [sighash::SighashCache] instead")] pub struct SigHashCache> { - cache: sighash::SigHashCache, + cache: sighash::SighashCache, } #[allow(deprecated)] @@ -119,7 +119,7 @@ impl> SigHashCache { /// For the generated sighashes to be valid, no fields in the transaction may change except for /// script_sig and witnesses. pub fn new(tx: R) -> Self { - Self { cache: sighash::SigHashCache::new(tx) } + Self { cache: sighash::SighashCache::new(tx) } } /// Encode the BIP143 signing data for any flag type into a given object implementing a diff --git a/src/util/sighash.rs b/src/util/sighash.rs index 6babb5a0..60ad756a 100644 --- a/src/util/sighash.rs +++ b/src/util/sighash.rs @@ -38,10 +38,10 @@ use super::taproot::LeafVersion; /// Efficiently calculates signature hash message for legacy, segwit and taproot inputs. #[derive(Debug)] -pub struct SigHashCache> { +pub struct SighashCache> { /// Access to transaction required for various introspection, moreover type /// `T: Deref` allows to accept borrow and mutable borrow, the - /// latter in particular is necessary for [`SigHashCache::witness_mut`] + /// latter in particular is necessary for [`SighashCache::witness_mut`] tx: T, /// Common cache for taproot and segwit inputs. It's an option because it's not needed for legacy inputs @@ -332,13 +332,13 @@ impl SchnorrSighashType { } } -impl> SigHashCache { +impl> SighashCache { /// Compute the sighash components from an unsigned transaction and auxiliary /// in a lazy manner when required. /// For the generated sighashes to be valid, no fields in the transaction may change except for /// script_sig and witnesses. pub fn new(tx: R) -> Self { - SigHashCache { + SighashCache { tx, common_cache: None, taproot_cache: None, @@ -520,7 +520,7 @@ impl> SigHashCache { /// Compute the BIP341 sighash for a script spend /// /// Assumes the default `OP_CODESEPARATOR` position of `0xFFFFFFFF`. Custom values can be - /// provided through the more fine-grained API of [`SigHashCache::taproot_encode_signing_data_to`]. + /// provided through the more fine-grained API of [`SighashCache::taproot_encode_signing_data_to`]. pub fn taproot_script_spend_signature_hash, T: Borrow>( &mut self, input_index: usize, @@ -729,20 +729,20 @@ impl> SigHashCache { } } -impl> SigHashCache { - /// When the SigHashCache is initialized with a mutable reference to a transaction instead of a +impl> SighashCache { + /// When the SighashCache is initialized with a mutable reference to a transaction instead of a /// regular reference, this method is available to allow modification to the witnesses. /// /// This allows in-line signing such as /// ``` /// use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType}; - /// use bitcoin::util::sighash::SigHashCache; + /// use bitcoin::util::sighash::SighashCache; /// use bitcoin::Script; /// /// let mut tx_to_sign = Transaction { version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() }; /// let input_count = tx_to_sign.input.len(); /// - /// let mut sig_hasher = SigHashCache::new(&mut tx_to_sign); + /// let mut sig_hasher = SighashCache::new(&mut tx_to_sign); /// for inp in 0..input_count { /// let prevout_script = Script::new(); /// let _sighash = sig_hasher.segwit_signature_hash(inp, &prevout_script, 42, EcdsaSighashType::All); @@ -793,7 +793,7 @@ mod tests { use consensus::deserialize; use hashes::hex::FromHex; use hashes::{Hash, HashEngine}; - use util::sighash::{Annex, Error, Prevouts, ScriptPath, SigHashCache}; + use util::sighash::{Annex, Error, Prevouts, ScriptPath, SighashCache}; use std::str::FromStr; use hashes::hex::ToHex; use util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash}; @@ -939,7 +939,7 @@ mod tests { input: vec![TxIn::default()], output: vec![], }; - let mut c = SigHashCache::new(&dumb_tx); + let mut c = SighashCache::new(&dumb_tx); // 1.29 fixes let empty_vec = vec![]; @@ -1039,7 +1039,7 @@ mod tests { Prevouts::All(&prevouts) }; - let mut sig_hash_cache = SigHashCache::new(&tx); + let mut sig_hash_cache = SighashCache::new(&tx); let hash = sig_hash_cache .taproot_signature_hash(input_index, &prevouts, annex, leaf_hash, sighash_type) @@ -1065,7 +1065,7 @@ mod tests { } // Test intermediary - let mut cache = SigHashCache::new(&raw_unsigned_tx); + let mut cache = SighashCache::new(&raw_unsigned_tx); let expected_amt_hash = key_path["intermediary"]["hashAmounts"].as_str().unwrap(); let expected_outputs_hash = key_path["intermediary"]["hashOutputs"].as_str().unwrap(); let expected_prevouts_hash = key_path["intermediary"]["hashPrevouts"].as_str().unwrap();