Rename SigHash -> Sighash
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 the `SigHash` type to `Sighash`.
This commit is contained in:
parent
52b711c084
commit
c3a167b96b
|
@ -39,7 +39,7 @@ use blockdata::script::Script;
|
|||
use blockdata::witness::Witness;
|
||||
use consensus::{encode, Decodable, Encodable};
|
||||
use consensus::encode::MAX_VEC_SIZE;
|
||||
use hash_types::{SigHash, Txid, Wtxid};
|
||||
use hash_types::{Sighash, Txid, Wtxid};
|
||||
use VarInt;
|
||||
|
||||
#[cfg(doc)]
|
||||
|
@ -432,15 +432,15 @@ impl Transaction {
|
|||
input_index: usize,
|
||||
script_pubkey: &Script,
|
||||
sighash_u32: u32
|
||||
) -> SigHash {
|
||||
) -> Sighash {
|
||||
if self.is_invalid_use_of_sighash_single(sighash_u32, input_index) {
|
||||
return SigHash::from_slice(&UINT256_ONE).expect("const-size array");
|
||||
return Sighash::from_slice(&UINT256_ONE).expect("const-size array");
|
||||
}
|
||||
|
||||
let mut engine = SigHash::engine();
|
||||
let mut engine = Sighash::engine();
|
||||
self.encode_signing_data_to(&mut engine, input_index, script_pubkey, sighash_u32)
|
||||
.expect("engines don't error");
|
||||
SigHash::from_engine(engine)
|
||||
Sighash::from_engine(engine)
|
||||
}
|
||||
|
||||
fn is_invalid_use_of_sighash_single(&self, sighash: u32, input_index: usize) -> bool {
|
||||
|
@ -1223,7 +1223,7 @@ mod tests {
|
|||
};
|
||||
let script = Script::new();
|
||||
let got = tx.signature_hash(1, &script, SIGHASH_SINGLE);
|
||||
let want = SigHash::from_slice(&UINT256_ONE).unwrap();
|
||||
let want = Sighash::from_slice(&UINT256_ONE).unwrap();
|
||||
|
||||
assert_eq!(got, want)
|
||||
}
|
||||
|
@ -1233,7 +1233,7 @@ mod tests {
|
|||
let script = Script::from(Vec::from_hex(script).unwrap());
|
||||
let mut raw_expected = Vec::from_hex(expected_result).unwrap();
|
||||
raw_expected.reverse();
|
||||
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
|
||||
let expected_result = Sighash::from_slice(&raw_expected[..]).unwrap();
|
||||
|
||||
let actual_result = if raw_expected[0] % 2 == 0 {
|
||||
// tx.signature_hash and cache.legacy_signature_hash are the same, this if helps to test
|
||||
|
|
|
@ -42,7 +42,7 @@ macro_rules! impl_hashencode {
|
|||
hash_newtype!(Txid, sha256d::Hash, 32, doc="A bitcoin transaction hash/transaction ID.");
|
||||
hash_newtype!(Wtxid, sha256d::Hash, 32, doc="A bitcoin witness transaction ID.");
|
||||
hash_newtype!(BlockHash, sha256d::Hash, 32, doc="A bitcoin block hash.");
|
||||
hash_newtype!(SigHash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
|
||||
hash_newtype!(Sighash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
|
||||
|
||||
hash_newtype!(PubkeyHash, hash160::Hash, 20, doc="A hash of a public key.");
|
||||
hash_newtype!(ScriptHash, hash160::Hash, 20, doc="A hash of Bitcoin Script bytecode.");
|
||||
|
@ -61,7 +61,7 @@ hash_newtype!(FilterHeader, sha256d::Hash, 32, doc="Filter header, as defined in
|
|||
impl_hashencode!(Txid);
|
||||
impl_hashencode!(Wtxid);
|
||||
impl_hashencode!(BlockHash);
|
||||
impl_hashencode!(SigHash);
|
||||
impl_hashencode!(Sighash);
|
||||
|
||||
impl_hashencode!(TxMerkleNode);
|
||||
impl_hashencode!(WitnessMerkleNode);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
//!
|
||||
|
||||
use hashes::Hash;
|
||||
use hash_types::SigHash;
|
||||
use hash_types::Sighash;
|
||||
use blockdata::script::Script;
|
||||
use blockdata::witness::Witness;
|
||||
use blockdata::transaction::{Transaction, TxIn, EcdsaSighashType};
|
||||
|
@ -38,11 +38,11 @@ pub struct SighashComponents {
|
|||
tx_version: i32,
|
||||
tx_locktime: u32,
|
||||
/// Hash of all the previous outputs
|
||||
pub hash_prevouts: SigHash,
|
||||
pub hash_prevouts: Sighash,
|
||||
/// Hash of all the input sequence nos
|
||||
pub hash_sequence: SigHash,
|
||||
pub hash_sequence: Sighash,
|
||||
/// Hash of all the outputs in this transaction
|
||||
pub hash_outputs: SigHash,
|
||||
pub hash_outputs: Sighash,
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
|
@ -53,27 +53,27 @@ impl SighashComponents {
|
|||
/// script_sig and witnesses.
|
||||
pub fn new(tx: &Transaction) -> SighashComponents {
|
||||
let hash_prevouts = {
|
||||
let mut enc = SigHash::engine();
|
||||
let mut enc = Sighash::engine();
|
||||
for txin in &tx.input {
|
||||
txin.previous_output.consensus_encode(&mut enc).expect("engines don't error");
|
||||
}
|
||||
SigHash::from_engine(enc)
|
||||
Sighash::from_engine(enc)
|
||||
};
|
||||
|
||||
let hash_sequence = {
|
||||
let mut enc = SigHash::engine();
|
||||
let mut enc = Sighash::engine();
|
||||
for txin in &tx.input {
|
||||
txin.sequence.consensus_encode(&mut enc).expect("engines don't error");
|
||||
}
|
||||
SigHash::from_engine(enc)
|
||||
Sighash::from_engine(enc)
|
||||
};
|
||||
|
||||
let hash_outputs = {
|
||||
let mut enc = SigHash::engine();
|
||||
let mut enc = Sighash::engine();
|
||||
for txout in &tx.output {
|
||||
txout.consensus_encode(&mut enc).expect("engines don't error");
|
||||
}
|
||||
SigHash::from_engine(enc)
|
||||
Sighash::from_engine(enc)
|
||||
};
|
||||
|
||||
SighashComponents {
|
||||
|
@ -87,8 +87,8 @@ impl SighashComponents {
|
|||
|
||||
/// Compute the BIP143 sighash for a `SIGHASH_ALL` signature for the given
|
||||
/// input.
|
||||
pub fn sighash_all(&self, txin: &TxIn, script_code: &Script, value: u64) -> SigHash {
|
||||
let mut enc = SigHash::engine();
|
||||
pub fn sighash_all(&self, txin: &TxIn, script_code: &Script, value: u64) -> Sighash {
|
||||
let mut enc = Sighash::engine();
|
||||
self.tx_version.consensus_encode(&mut enc).expect("engines don't error");
|
||||
self.hash_prevouts.consensus_encode(&mut enc).expect("engines don't error");
|
||||
self.hash_sequence.consensus_encode(&mut enc).expect("engines don't error");
|
||||
|
@ -102,7 +102,7 @@ impl SighashComponents {
|
|||
self.hash_outputs.consensus_encode(&mut enc).expect("engines don't error");
|
||||
self.tx_locktime.consensus_encode(&mut enc).expect("engines don't error");
|
||||
1u32.consensus_encode(&mut enc).expect("engines don't error"); // hashtype
|
||||
SigHash::from_engine(enc)
|
||||
Sighash::from_engine(enc)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,11 +146,11 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
|
|||
script_code: &Script,
|
||||
value: u64,
|
||||
sighash_type: EcdsaSighashType
|
||||
) -> SigHash {
|
||||
let mut enc = SigHash::engine();
|
||||
) -> Sighash {
|
||||
let mut enc = Sighash::engine();
|
||||
self.encode_signing_data_to(&mut enc, input_index, script_code, value, sighash_type)
|
||||
.expect("engines don't error");
|
||||
SigHash::from_engine(enc)
|
||||
Sighash::from_engine(enc)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
|
|||
#[allow(deprecated)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
use hash_types::SigHash;
|
||||
use hash_types::Sighash;
|
||||
use blockdata::script::Script;
|
||||
use blockdata::transaction::Transaction;
|
||||
use consensus::encode::deserialize;
|
||||
|
@ -208,8 +208,8 @@ mod tests {
|
|||
fn run_test_sighash_bip143(tx: &str, script: &str, input_index: usize, value: u64, hash_type: u32, expected_result: &str) {
|
||||
let tx: Transaction = deserialize(&Vec::<u8>::from_hex(tx).unwrap()[..]).unwrap();
|
||||
let script = Script::from(Vec::<u8>::from_hex(script).unwrap());
|
||||
let raw_expected = SigHash::from_hex(expected_result).unwrap();
|
||||
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
|
||||
let raw_expected = Sighash::from_hex(expected_result).unwrap();
|
||||
let expected_result = Sighash::from_slice(&raw_expected[..]).unwrap();
|
||||
let mut cache = SigHashCache::new(&tx);
|
||||
let sighash_type = EcdsaSighashType::from_u32_consensus(hash_type);
|
||||
let actual_result = cache.signature_hash(input_index, &script, value, sighash_type);
|
||||
|
@ -237,20 +237,20 @@ mod tests {
|
|||
tx_version: 1,
|
||||
tx_locktime: 17,
|
||||
hash_prevouts: hex_hash!(
|
||||
SigHash, "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
|
||||
Sighash, "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
|
||||
),
|
||||
hash_sequence: hex_hash!(
|
||||
SigHash, "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
|
||||
Sighash, "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
|
||||
),
|
||||
hash_outputs: hex_hash!(
|
||||
SigHash, "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
|
||||
Sighash, "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
comp.sighash_all(&tx.input[1], &witness_script, value),
|
||||
hex_hash!(SigHash, "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670")
|
||||
hex_hash!(Sighash, "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -273,20 +273,20 @@ mod tests {
|
|||
tx_version: 1,
|
||||
tx_locktime: 1170,
|
||||
hash_prevouts: hex_hash!(
|
||||
SigHash, "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
|
||||
Sighash, "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
|
||||
),
|
||||
hash_sequence: hex_hash!(
|
||||
SigHash, "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
|
||||
Sighash, "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
|
||||
),
|
||||
hash_outputs: hex_hash!(
|
||||
SigHash, "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
|
||||
Sighash, "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
comp.sighash_all(&tx.input[0], &witness_script, value),
|
||||
hex_hash!(SigHash, "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6")
|
||||
hex_hash!(Sighash, "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -316,20 +316,20 @@ mod tests {
|
|||
tx_version: 1,
|
||||
tx_locktime: 0,
|
||||
hash_prevouts: hex_hash!(
|
||||
SigHash, "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
|
||||
Sighash, "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
|
||||
),
|
||||
hash_sequence: hex_hash!(
|
||||
SigHash, "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
|
||||
Sighash, "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
|
||||
),
|
||||
hash_outputs: hex_hash!(
|
||||
SigHash, "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
|
||||
Sighash, "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
comp.sighash_all(&tx.input[0], &witness_script, value),
|
||||
hex_hash!(SigHash, "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c")
|
||||
hex_hash!(Sighash, "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c")
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
|
|
|
@ -31,7 +31,7 @@ use core::borrow::Borrow;
|
|||
use hashes::{sha256, sha256d, Hash};
|
||||
use io;
|
||||
use util::taproot::{TapLeafHash, TAPROOT_ANNEX_PREFIX, TapSighashHash};
|
||||
use SigHash;
|
||||
use Sighash;
|
||||
use {Script, Transaction, TxOut};
|
||||
|
||||
use super::taproot::LeafVersion;
|
||||
|
@ -593,9 +593,9 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
|
|||
if sighash != EcdsaSighashType::Single && sighash != EcdsaSighashType::None {
|
||||
self.segwit_cache().outputs.consensus_encode(&mut writer)?;
|
||||
} else if sighash == EcdsaSighashType::Single && input_index < self.tx.output.len() {
|
||||
let mut single_enc = SigHash::engine();
|
||||
let mut single_enc = Sighash::engine();
|
||||
self.tx.output[input_index].consensus_encode(&mut single_enc)?;
|
||||
SigHash::from_engine(single_enc).consensus_encode(&mut writer)?;
|
||||
Sighash::from_engine(single_enc).consensus_encode(&mut writer)?;
|
||||
} else {
|
||||
zero_hash.consensus_encode(&mut writer)?;
|
||||
}
|
||||
|
@ -612,8 +612,8 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
|
|||
script_code: &Script,
|
||||
value: u64,
|
||||
sighash_type: EcdsaSighashType,
|
||||
) -> Result<SigHash, Error> {
|
||||
let mut enc = SigHash::engine();
|
||||
) -> Result<Sighash, Error> {
|
||||
let mut enc = Sighash::engine();
|
||||
self.segwit_encode_signing_data_to(
|
||||
&mut enc,
|
||||
input_index,
|
||||
|
@ -621,7 +621,7 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
|
|||
value,
|
||||
sighash_type,
|
||||
)?;
|
||||
Ok(SigHash::from_engine(enc))
|
||||
Ok(Sighash::from_engine(enc))
|
||||
}
|
||||
|
||||
/// Encode the legacy signing data for any flag type into a given object implementing a
|
||||
|
@ -651,10 +651,10 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
|
|||
input_index: usize,
|
||||
script_pubkey: &Script,
|
||||
sighash_type: u32,
|
||||
) -> Result<SigHash, Error> {
|
||||
let mut enc = SigHash::engine();
|
||||
) -> Result<Sighash, Error> {
|
||||
let mut enc = Sighash::engine();
|
||||
self.legacy_encode_signing_data_to(&mut enc, input_index, script_pubkey, sighash_type)?;
|
||||
Ok(SigHash::from_engine(enc))
|
||||
Ok(Sighash::from_engine(enc))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue