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`.
This commit is contained in:
parent
e37652578b
commit
b84f25584e
|
@ -905,7 +905,7 @@ mod tests {
|
||||||
|
|
||||||
use hash_types::*;
|
use hash_types::*;
|
||||||
use super::EcdsaSighashType;
|
use super::EcdsaSighashType;
|
||||||
use util::sighash::SigHashCache;
|
use util::sighash::SighashCache;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_outpoint() {
|
fn test_outpoint() {
|
||||||
|
@ -1240,7 +1240,7 @@ mod tests {
|
||||||
// both the codepaths without repeating the test code
|
// both the codepaths without repeating the test code
|
||||||
tx.signature_hash(input_index, &script, hash_type as u32)
|
tx.signature_hash(input_index, &script, hash_type as u32)
|
||||||
} else {
|
} else {
|
||||||
let cache = SigHashCache::new(&tx);
|
let cache = SighashCache::new(&tx);
|
||||||
cache.legacy_signature_hash(input_index, &script, hash_type as u32).unwrap()
|
cache.legacy_signature_hash(input_index, &script, hash_type as u32).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ use util::sighash;
|
||||||
/// Parts of a sighash which are common across inputs or signatures, and which are
|
/// 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
|
/// sufficient (in conjunction with a private key) to sign the transaction
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[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 {
|
pub struct SighashComponents {
|
||||||
tx_version: i32,
|
tx_version: i32,
|
||||||
tx_locktime: u32,
|
tx_locktime: u32,
|
||||||
|
@ -107,9 +107,9 @@ impl SighashComponents {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A replacement for SigHashComponents which supports all sighash modes
|
/// 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<R: Deref<Target = Transaction>> {
|
pub struct SigHashCache<R: Deref<Target = Transaction>> {
|
||||||
cache: sighash::SigHashCache<R>,
|
cache: sighash::SighashCache<R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
|
@ -119,7 +119,7 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
|
||||||
/// For the generated sighashes to be valid, no fields in the transaction may change except for
|
/// For the generated sighashes to be valid, no fields in the transaction may change except for
|
||||||
/// script_sig and witnesses.
|
/// script_sig and witnesses.
|
||||||
pub fn new(tx: R) -> Self {
|
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
|
/// Encode the BIP143 signing data for any flag type into a given object implementing a
|
||||||
|
|
|
@ -38,10 +38,10 @@ use super::taproot::LeafVersion;
|
||||||
|
|
||||||
/// Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
|
/// Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SigHashCache<T: Deref<Target=Transaction>> {
|
pub struct SighashCache<T: Deref<Target=Transaction>> {
|
||||||
/// Access to transaction required for various introspection, moreover type
|
/// Access to transaction required for various introspection, moreover type
|
||||||
/// `T: Deref<Target=Transaction>` allows to accept borrow and mutable borrow, the
|
/// `T: Deref<Target=Transaction>` 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,
|
tx: T,
|
||||||
|
|
||||||
/// Common cache for taproot and segwit inputs. It's an option because it's not needed for legacy inputs
|
/// 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<R: Deref<Target=Transaction>> SigHashCache<R> {
|
impl<R: Deref<Target=Transaction>> SighashCache<R> {
|
||||||
/// Compute the sighash components from an unsigned transaction and auxiliary
|
/// Compute the sighash components from an unsigned transaction and auxiliary
|
||||||
/// in a lazy manner when required.
|
/// in a lazy manner when required.
|
||||||
/// For the generated sighashes to be valid, no fields in the transaction may change except for
|
/// For the generated sighashes to be valid, no fields in the transaction may change except for
|
||||||
/// script_sig and witnesses.
|
/// script_sig and witnesses.
|
||||||
pub fn new(tx: R) -> Self {
|
pub fn new(tx: R) -> Self {
|
||||||
SigHashCache {
|
SighashCache {
|
||||||
tx,
|
tx,
|
||||||
common_cache: None,
|
common_cache: None,
|
||||||
taproot_cache: None,
|
taproot_cache: None,
|
||||||
|
@ -520,7 +520,7 @@ impl<R: Deref<Target=Transaction>> SigHashCache<R> {
|
||||||
/// Compute the BIP341 sighash for a script spend
|
/// Compute the BIP341 sighash for a script spend
|
||||||
///
|
///
|
||||||
/// Assumes the default `OP_CODESEPARATOR` position of `0xFFFFFFFF`. Custom values can be
|
/// 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<S: Into<TapLeafHash>, T: Borrow<TxOut>>(
|
pub fn taproot_script_spend_signature_hash<S: Into<TapLeafHash>, T: Borrow<TxOut>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
input_index: usize,
|
input_index: usize,
|
||||||
|
@ -729,20 +729,20 @@ impl<R: Deref<Target=Transaction>> SigHashCache<R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: DerefMut<Target=Transaction>> SigHashCache<R> {
|
impl<R: DerefMut<Target=Transaction>> SighashCache<R> {
|
||||||
/// When the SigHashCache is initialized with a mutable reference to a transaction instead of a
|
/// 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.
|
/// regular reference, this method is available to allow modification to the witnesses.
|
||||||
///
|
///
|
||||||
/// This allows in-line signing such as
|
/// This allows in-line signing such as
|
||||||
/// ```
|
/// ```
|
||||||
/// use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
|
/// use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
|
||||||
/// use bitcoin::util::sighash::SigHashCache;
|
/// use bitcoin::util::sighash::SighashCache;
|
||||||
/// use bitcoin::Script;
|
/// use bitcoin::Script;
|
||||||
///
|
///
|
||||||
/// let mut tx_to_sign = Transaction { version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
|
/// 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 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 {
|
/// for inp in 0..input_count {
|
||||||
/// let prevout_script = Script::new();
|
/// let prevout_script = Script::new();
|
||||||
/// let _sighash = sig_hasher.segwit_signature_hash(inp, &prevout_script, 42, EcdsaSighashType::All);
|
/// let _sighash = sig_hasher.segwit_signature_hash(inp, &prevout_script, 42, EcdsaSighashType::All);
|
||||||
|
@ -793,7 +793,7 @@ mod tests {
|
||||||
use consensus::deserialize;
|
use consensus::deserialize;
|
||||||
use hashes::hex::FromHex;
|
use hashes::hex::FromHex;
|
||||||
use hashes::{Hash, HashEngine};
|
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 std::str::FromStr;
|
||||||
use hashes::hex::ToHex;
|
use hashes::hex::ToHex;
|
||||||
use util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash};
|
use util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash};
|
||||||
|
@ -939,7 +939,7 @@ mod tests {
|
||||||
input: vec![TxIn::default()],
|
input: vec![TxIn::default()],
|
||||||
output: vec![],
|
output: vec![],
|
||||||
};
|
};
|
||||||
let mut c = SigHashCache::new(&dumb_tx);
|
let mut c = SighashCache::new(&dumb_tx);
|
||||||
|
|
||||||
// 1.29 fixes
|
// 1.29 fixes
|
||||||
let empty_vec = vec![];
|
let empty_vec = vec![];
|
||||||
|
@ -1039,7 +1039,7 @@ mod tests {
|
||||||
Prevouts::All(&prevouts)
|
Prevouts::All(&prevouts)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut sig_hash_cache = SigHashCache::new(&tx);
|
let mut sig_hash_cache = SighashCache::new(&tx);
|
||||||
|
|
||||||
let hash = sig_hash_cache
|
let hash = sig_hash_cache
|
||||||
.taproot_signature_hash(input_index, &prevouts, annex, leaf_hash, sighash_type)
|
.taproot_signature_hash(input_index, &prevouts, annex, leaf_hash, sighash_type)
|
||||||
|
@ -1065,7 +1065,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test intermediary
|
// 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_amt_hash = key_path["intermediary"]["hashAmounts"].as_str().unwrap();
|
||||||
let expected_outputs_hash = key_path["intermediary"]["hashOutputs"].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();
|
let expected_prevouts_hash = key_path["intermediary"]["hashPrevouts"].as_str().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue