Skip to content

Commit 9c42391

Browse files
committed
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`.
1 parent 1dfce22 commit 9c42391

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

src/blockdata/transaction.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use blockdata::script::Script;
3939
use blockdata::witness::Witness;
4040
use consensus::{encode, Decodable, Encodable};
4141
use consensus::encode::MAX_VEC_SIZE;
42-
use hash_types::{SigHash, Txid, Wtxid};
42+
use hash_types::{Sighash, Txid, Wtxid};
4343
use VarInt;
4444

4545
#[cfg(doc)]
@@ -432,15 +432,15 @@ impl Transaction {
432432
input_index: usize,
433433
script_pubkey: &Script,
434434
sighash_u32: u32
435-
) -> SigHash {
435+
) -> Sighash {
436436
if self.is_invalid_use_of_sighash_single(sighash_u32, input_index) {
437-
return SigHash::from_slice(&UINT256_ONE).expect("const-size array");
437+
return Sighash::from_slice(&UINT256_ONE).expect("const-size array");
438438
}
439439

440-
let mut engine = SigHash::engine();
440+
let mut engine = Sighash::engine();
441441
self.encode_signing_data_to(&mut engine, input_index, script_pubkey, sighash_u32)
442442
.expect("engines don't error");
443-
SigHash::from_engine(engine)
443+
Sighash::from_engine(engine)
444444
}
445445

446446
fn is_invalid_use_of_sighash_single(&self, sighash: u32, input_index: usize) -> bool {
@@ -1223,7 +1223,7 @@ mod tests {
12231223
};
12241224
let script = Script::new();
12251225
let got = tx.signature_hash(1, &script, SIGHASH_SINGLE);
1226-
let want = SigHash::from_slice(&UINT256_ONE).unwrap();
1226+
let want = Sighash::from_slice(&UINT256_ONE).unwrap();
12271227

12281228
assert_eq!(got, want)
12291229
}
@@ -1233,7 +1233,7 @@ mod tests {
12331233
let script = Script::from(Vec::from_hex(script).unwrap());
12341234
let mut raw_expected = Vec::from_hex(expected_result).unwrap();
12351235
raw_expected.reverse();
1236-
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
1236+
let expected_result = Sighash::from_slice(&raw_expected[..]).unwrap();
12371237

12381238
let actual_result = if raw_expected[0] % 2 == 0 {
12391239
// tx.signature_hash and cache.legacy_signature_hash are the same, this if helps to test

src/hash_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ macro_rules! impl_hashencode {
4242
hash_newtype!(Txid, sha256d::Hash, 32, doc="A bitcoin transaction hash/transaction ID.");
4343
hash_newtype!(Wtxid, sha256d::Hash, 32, doc="A bitcoin witness transaction ID.");
4444
hash_newtype!(BlockHash, sha256d::Hash, 32, doc="A bitcoin block hash.");
45-
hash_newtype!(SigHash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
45+
hash_newtype!(Sighash, sha256d::Hash, 32, doc="Hash of the transaction according to the signature algorithm");
4646

4747
hash_newtype!(PubkeyHash, hash160::Hash, 20, doc="A hash of a public key.");
4848
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
6161
impl_hashencode!(Txid);
6262
impl_hashencode!(Wtxid);
6363
impl_hashencode!(BlockHash);
64-
impl_hashencode!(SigHash);
64+
impl_hashencode!(Sighash);
6565

6666
impl_hashencode!(TxMerkleNode);
6767
impl_hashencode!(WitnessMerkleNode);

src/util/bip143.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//!
2121
2222
use hashes::Hash;
23-
use hash_types::SigHash;
23+
use hash_types::Sighash;
2424
use blockdata::script::Script;
2525
use blockdata::witness::Witness;
2626
use blockdata::transaction::{Transaction, TxIn, EcdsaSighashType};
@@ -38,11 +38,11 @@ pub struct SighashComponents {
3838
tx_version: i32,
3939
tx_locktime: u32,
4040
/// Hash of all the previous outputs
41-
pub hash_prevouts: SigHash,
41+
pub hash_prevouts: Sighash,
4242
/// Hash of all the input sequence nos
43-
pub hash_sequence: SigHash,
43+
pub hash_sequence: Sighash,
4444
/// Hash of all the outputs in this transaction
45-
pub hash_outputs: SigHash,
45+
pub hash_outputs: Sighash,
4646
}
4747

4848
#[allow(deprecated)]
@@ -53,27 +53,27 @@ impl SighashComponents {
5353
/// script_sig and witnesses.
5454
pub fn new(tx: &Transaction) -> SighashComponents {
5555
let hash_prevouts = {
56-
let mut enc = SigHash::engine();
56+
let mut enc = Sighash::engine();
5757
for txin in &tx.input {
5858
txin.previous_output.consensus_encode(&mut enc).expect("engines don't error");
5959
}
60-
SigHash::from_engine(enc)
60+
Sighash::from_engine(enc)
6161
};
6262

6363
let hash_sequence = {
64-
let mut enc = SigHash::engine();
64+
let mut enc = Sighash::engine();
6565
for txin in &tx.input {
6666
txin.sequence.consensus_encode(&mut enc).expect("engines don't error");
6767
}
68-
SigHash::from_engine(enc)
68+
Sighash::from_engine(enc)
6969
};
7070

7171
let hash_outputs = {
72-
let mut enc = SigHash::engine();
72+
let mut enc = Sighash::engine();
7373
for txout in &tx.output {
7474
txout.consensus_encode(&mut enc).expect("engines don't error");
7575
}
76-
SigHash::from_engine(enc)
76+
Sighash::from_engine(enc)
7777
};
7878

7979
SighashComponents {
@@ -87,8 +87,8 @@ impl SighashComponents {
8787

8888
/// Compute the BIP143 sighash for a `SIGHASH_ALL` signature for the given
8989
/// input.
90-
pub fn sighash_all(&self, txin: &TxIn, script_code: &Script, value: u64) -> SigHash {
91-
let mut enc = SigHash::engine();
90+
pub fn sighash_all(&self, txin: &TxIn, script_code: &Script, value: u64) -> Sighash {
91+
let mut enc = Sighash::engine();
9292
self.tx_version.consensus_encode(&mut enc).expect("engines don't error");
9393
self.hash_prevouts.consensus_encode(&mut enc).expect("engines don't error");
9494
self.hash_sequence.consensus_encode(&mut enc).expect("engines don't error");
@@ -102,7 +102,7 @@ impl SighashComponents {
102102
self.hash_outputs.consensus_encode(&mut enc).expect("engines don't error");
103103
self.tx_locktime.consensus_encode(&mut enc).expect("engines don't error");
104104
1u32.consensus_encode(&mut enc).expect("engines don't error"); // hashtype
105-
SigHash::from_engine(enc)
105+
Sighash::from_engine(enc)
106106
}
107107
}
108108

@@ -146,11 +146,11 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
146146
script_code: &Script,
147147
value: u64,
148148
sighash_type: EcdsaSighashType
149-
) -> SigHash {
150-
let mut enc = SigHash::engine();
149+
) -> Sighash {
150+
let mut enc = Sighash::engine();
151151
self.encode_signing_data_to(&mut enc, input_index, script_code, value, sighash_type)
152152
.expect("engines don't error");
153-
SigHash::from_engine(enc)
153+
Sighash::from_engine(enc)
154154
}
155155
}
156156

@@ -188,7 +188,7 @@ impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
188188
#[allow(deprecated)]
189189
mod tests {
190190
use std::str::FromStr;
191-
use hash_types::SigHash;
191+
use hash_types::Sighash;
192192
use blockdata::script::Script;
193193
use blockdata::transaction::Transaction;
194194
use consensus::encode::deserialize;
@@ -208,8 +208,8 @@ mod tests {
208208
fn run_test_sighash_bip143(tx: &str, script: &str, input_index: usize, value: u64, hash_type: u32, expected_result: &str) {
209209
let tx: Transaction = deserialize(&Vec::<u8>::from_hex(tx).unwrap()[..]).unwrap();
210210
let script = Script::from(Vec::<u8>::from_hex(script).unwrap());
211-
let raw_expected = SigHash::from_hex(expected_result).unwrap();
212-
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
211+
let raw_expected = Sighash::from_hex(expected_result).unwrap();
212+
let expected_result = Sighash::from_slice(&raw_expected[..]).unwrap();
213213
let mut cache = SigHashCache::new(&tx);
214214
let sighash_type = EcdsaSighashType::from_u32_consensus(hash_type);
215215
let actual_result = cache.signature_hash(input_index, &script, value, sighash_type);
@@ -237,20 +237,20 @@ mod tests {
237237
tx_version: 1,
238238
tx_locktime: 17,
239239
hash_prevouts: hex_hash!(
240-
SigHash, "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
240+
Sighash, "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
241241
),
242242
hash_sequence: hex_hash!(
243-
SigHash, "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
243+
Sighash, "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
244244
),
245245
hash_outputs: hex_hash!(
246-
SigHash, "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
246+
Sighash, "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
247247
),
248248
}
249249
);
250250

251251
assert_eq!(
252252
comp.sighash_all(&tx.input[1], &witness_script, value),
253-
hex_hash!(SigHash, "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670")
253+
hex_hash!(Sighash, "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670")
254254
);
255255
}
256256

@@ -273,20 +273,20 @@ mod tests {
273273
tx_version: 1,
274274
tx_locktime: 1170,
275275
hash_prevouts: hex_hash!(
276-
SigHash, "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
276+
Sighash, "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
277277
),
278278
hash_sequence: hex_hash!(
279-
SigHash, "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
279+
Sighash, "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
280280
),
281281
hash_outputs: hex_hash!(
282-
SigHash, "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
282+
Sighash, "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
283283
),
284284
}
285285
);
286286

287287
assert_eq!(
288288
comp.sighash_all(&tx.input[0], &witness_script, value),
289-
hex_hash!(SigHash, "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6")
289+
hex_hash!(Sighash, "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6")
290290
);
291291
}
292292

@@ -316,20 +316,20 @@ mod tests {
316316
tx_version: 1,
317317
tx_locktime: 0,
318318
hash_prevouts: hex_hash!(
319-
SigHash, "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
319+
Sighash, "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
320320
),
321321
hash_sequence: hex_hash!(
322-
SigHash, "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
322+
Sighash, "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
323323
),
324324
hash_outputs: hex_hash!(
325-
SigHash, "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
325+
Sighash, "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
326326
),
327327
}
328328
);
329329

330330
assert_eq!(
331331
comp.sighash_all(&tx.input[0], &witness_script, value),
332-
hex_hash!(SigHash, "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c")
332+
hex_hash!(Sighash, "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c")
333333
);
334334
}
335335
#[test]

src/util/sighash.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use core::borrow::Borrow;
3131
use hashes::{sha256, sha256d, Hash};
3232
use io;
3333
use util::taproot::{TapLeafHash, TAPROOT_ANNEX_PREFIX, TapSighashHash};
34-
use SigHash;
34+
use Sighash;
3535
use {Script, Transaction, TxOut};
3636

3737
use super::taproot::LeafVersion;
@@ -593,9 +593,9 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
593593
if sighash != EcdsaSighashType::Single && sighash != EcdsaSighashType::None {
594594
self.segwit_cache().outputs.consensus_encode(&mut writer)?;
595595
} else if sighash == EcdsaSighashType::Single && input_index < self.tx.output.len() {
596-
let mut single_enc = SigHash::engine();
596+
let mut single_enc = Sighash::engine();
597597
self.tx.output[input_index].consensus_encode(&mut single_enc)?;
598-
SigHash::from_engine(single_enc).consensus_encode(&mut writer)?;
598+
Sighash::from_engine(single_enc).consensus_encode(&mut writer)?;
599599
} else {
600600
zero_hash.consensus_encode(&mut writer)?;
601601
}
@@ -612,16 +612,16 @@ impl<R: Deref<Target=Transaction>> SighashCache<R> {
612612
script_code: &Script,
613613
value: u64,
614614
sighash_type: EcdsaSighashType,
615-
) -> Result<SigHash, Error> {
616-
let mut enc = SigHash::engine();
615+
) -> Result<Sighash, Error> {
616+
let mut enc = Sighash::engine();
617617
self.segwit_encode_signing_data_to(
618618
&mut enc,
619619
input_index,
620620
script_code,
621621
value,
622622
sighash_type,
623623
)?;
624-
Ok(SigHash::from_engine(enc))
624+
Ok(Sighash::from_engine(enc))
625625
}
626626

627627
/// 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> {
651651
input_index: usize,
652652
script_pubkey: &Script,
653653
sighash_type: u32,
654-
) -> Result<SigHash, Error> {
655-
let mut enc = SigHash::engine();
654+
) -> Result<Sighash, Error> {
655+
let mut enc = Sighash::engine();
656656
self.legacy_encode_signing_data_to(&mut enc, input_index, script_pubkey, sighash_type)?;
657-
Ok(SigHash::from_engine(enc))
657+
Ok(Sighash::from_engine(enc))
658658
}
659659

660660
#[inline]

0 commit comments

Comments
 (0)