20
20
//!
21
21
22
22
use hashes:: Hash ;
23
- use hash_types:: SigHash ;
23
+ use hash_types:: Sighash ;
24
24
use blockdata:: script:: Script ;
25
25
use blockdata:: witness:: Witness ;
26
26
use blockdata:: transaction:: { Transaction , TxIn , EcdsaSighashType } ;
@@ -38,11 +38,11 @@ pub struct SighashComponents {
38
38
tx_version : i32 ,
39
39
tx_locktime : u32 ,
40
40
/// Hash of all the previous outputs
41
- pub hash_prevouts : SigHash ,
41
+ pub hash_prevouts : Sighash ,
42
42
/// Hash of all the input sequence nos
43
- pub hash_sequence : SigHash ,
43
+ pub hash_sequence : Sighash ,
44
44
/// Hash of all the outputs in this transaction
45
- pub hash_outputs : SigHash ,
45
+ pub hash_outputs : Sighash ,
46
46
}
47
47
48
48
#[ allow( deprecated) ]
@@ -53,27 +53,27 @@ impl SighashComponents {
53
53
/// script_sig and witnesses.
54
54
pub fn new ( tx : & Transaction ) -> SighashComponents {
55
55
let hash_prevouts = {
56
- let mut enc = SigHash :: engine ( ) ;
56
+ let mut enc = Sighash :: engine ( ) ;
57
57
for txin in & tx. input {
58
58
txin. previous_output . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
59
59
}
60
- SigHash :: from_engine ( enc)
60
+ Sighash :: from_engine ( enc)
61
61
} ;
62
62
63
63
let hash_sequence = {
64
- let mut enc = SigHash :: engine ( ) ;
64
+ let mut enc = Sighash :: engine ( ) ;
65
65
for txin in & tx. input {
66
66
txin. sequence . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
67
67
}
68
- SigHash :: from_engine ( enc)
68
+ Sighash :: from_engine ( enc)
69
69
} ;
70
70
71
71
let hash_outputs = {
72
- let mut enc = SigHash :: engine ( ) ;
72
+ let mut enc = Sighash :: engine ( ) ;
73
73
for txout in & tx. output {
74
74
txout. consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
75
75
}
76
- SigHash :: from_engine ( enc)
76
+ Sighash :: from_engine ( enc)
77
77
} ;
78
78
79
79
SighashComponents {
@@ -87,8 +87,8 @@ impl SighashComponents {
87
87
88
88
/// Compute the BIP143 sighash for a `SIGHASH_ALL` signature for the given
89
89
/// 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 ( ) ;
92
92
self . tx_version . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
93
93
self . hash_prevouts . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
94
94
self . hash_sequence . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
@@ -102,7 +102,7 @@ impl SighashComponents {
102
102
self . hash_outputs . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
103
103
self . tx_locktime . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ;
104
104
1u32 . consensus_encode ( & mut enc) . expect ( "engines don't error" ) ; // hashtype
105
- SigHash :: from_engine ( enc)
105
+ Sighash :: from_engine ( enc)
106
106
}
107
107
}
108
108
@@ -146,11 +146,11 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
146
146
script_code : & Script ,
147
147
value : u64 ,
148
148
sighash_type : EcdsaSighashType
149
- ) -> SigHash {
150
- let mut enc = SigHash :: engine ( ) ;
149
+ ) -> Sighash {
150
+ let mut enc = Sighash :: engine ( ) ;
151
151
self . encode_signing_data_to ( & mut enc, input_index, script_code, value, sighash_type)
152
152
. expect ( "engines don't error" ) ;
153
- SigHash :: from_engine ( enc)
153
+ Sighash :: from_engine ( enc)
154
154
}
155
155
}
156
156
@@ -188,7 +188,7 @@ impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
188
188
#[ allow( deprecated) ]
189
189
mod tests {
190
190
use std:: str:: FromStr ;
191
- use hash_types:: SigHash ;
191
+ use hash_types:: Sighash ;
192
192
use blockdata:: script:: Script ;
193
193
use blockdata:: transaction:: Transaction ;
194
194
use consensus:: encode:: deserialize;
@@ -208,8 +208,8 @@ mod tests {
208
208
fn run_test_sighash_bip143 ( tx : & str , script : & str , input_index : usize , value : u64 , hash_type : u32 , expected_result : & str ) {
209
209
let tx: Transaction = deserialize ( & Vec :: < u8 > :: from_hex ( tx) . unwrap ( ) [ ..] ) . unwrap ( ) ;
210
210
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 ( ) ;
213
213
let mut cache = SigHashCache :: new ( & tx) ;
214
214
let sighash_type = EcdsaSighashType :: from_u32_consensus ( hash_type) ;
215
215
let actual_result = cache. signature_hash ( input_index, & script, value, sighash_type) ;
@@ -237,20 +237,20 @@ mod tests {
237
237
tx_version: 1 ,
238
238
tx_locktime: 17 ,
239
239
hash_prevouts: hex_hash!(
240
- SigHash , "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
240
+ Sighash , "96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37"
241
241
) ,
242
242
hash_sequence: hex_hash!(
243
- SigHash , "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
243
+ Sighash , "52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b"
244
244
) ,
245
245
hash_outputs: hex_hash!(
246
- SigHash , "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
246
+ Sighash , "863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5"
247
247
) ,
248
248
}
249
249
) ;
250
250
251
251
assert_eq ! (
252
252
comp. sighash_all( & tx. input[ 1 ] , & witness_script, value) ,
253
- hex_hash!( SigHash , "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670" )
253
+ hex_hash!( Sighash , "c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670" )
254
254
) ;
255
255
}
256
256
@@ -273,20 +273,20 @@ mod tests {
273
273
tx_version: 1 ,
274
274
tx_locktime: 1170 ,
275
275
hash_prevouts: hex_hash!(
276
- SigHash , "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
276
+ Sighash , "b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a"
277
277
) ,
278
278
hash_sequence: hex_hash!(
279
- SigHash , "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
279
+ Sighash , "18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198"
280
280
) ,
281
281
hash_outputs: hex_hash!(
282
- SigHash , "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
282
+ Sighash , "de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83"
283
283
) ,
284
284
}
285
285
) ;
286
286
287
287
assert_eq ! (
288
288
comp. sighash_all( & tx. input[ 0 ] , & witness_script, value) ,
289
- hex_hash!( SigHash , "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6" )
289
+ hex_hash!( Sighash , "64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6" )
290
290
) ;
291
291
}
292
292
@@ -316,20 +316,20 @@ mod tests {
316
316
tx_version: 1 ,
317
317
tx_locktime: 0 ,
318
318
hash_prevouts: hex_hash!(
319
- SigHash , "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
319
+ Sighash , "74afdc312af5183c4198a40ca3c1a275b485496dd3929bca388c4b5e31f7aaa0"
320
320
) ,
321
321
hash_sequence: hex_hash!(
322
- SigHash , "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
322
+ Sighash , "3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044"
323
323
) ,
324
324
hash_outputs: hex_hash!(
325
- SigHash , "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
325
+ Sighash , "bc4d309071414bed932f98832b27b4d76dad7e6c1346f487a8fdbb8eb90307cc"
326
326
) ,
327
327
}
328
328
) ;
329
329
330
330
assert_eq ! (
331
331
comp. sighash_all( & tx. input[ 0 ] , & witness_script, value) ,
332
- hex_hash!( SigHash , "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c" )
332
+ hex_hash!( Sighash , "185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c" )
333
333
) ;
334
334
}
335
335
#[ test]
0 commit comments