File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use bitcoin:: hash_types:: TxMerkleNode ;
4
4
use bitcoin:: hashes:: sha256d:: Hash as Sha256d ;
5
- use bitcoin:: hashes:: Hash ;
5
+ use bitcoin:: hashes:: { Hash , HashEngine } ;
6
6
use bitcoin:: Txid ;
7
7
use types:: GetMerkleRes ;
8
8
@@ -22,20 +22,20 @@ pub fn validate_merkle_proof(
22
22
let mut index = merkle_res. pos ;
23
23
let mut cur = txid. to_raw_hash ( ) ;
24
24
for bytes in & merkle_res. merkle {
25
- let mut reversed = [ 0u8 ; 32 ] ;
26
- reversed. copy_from_slice ( bytes) ;
25
+ let mut reversed = bytes. to_owned ( ) ;
27
26
reversed. reverse ( ) ;
28
- // unwrap() safety: `reversed` has len 32 so `from_slice` can never fail.
29
- let next_hash = Sha256d :: from_slice ( & reversed) . unwrap ( ) ;
27
+ let next_hash = Sha256d :: from_byte_array ( reversed) ;
30
28
31
29
let ( left, right) = if index % 2 == 0 {
32
30
( cur, next_hash)
33
31
} else {
34
32
( next_hash, cur)
35
33
} ;
36
34
37
- let data = [ & left[ ..] , & right[ ..] ] . concat ( ) ;
38
- cur = Sha256d :: hash ( & data) ;
35
+ let mut engine = Sha256d :: engine ( ) ;
36
+ engine. input ( left. as_ref ( ) ) ;
37
+ engine. input ( right. as_ref ( ) ) ;
38
+ cur = Sha256d :: from_engine ( engine) ;
39
39
index /= 2 ;
40
40
}
41
41
You can’t perform that action at this time.
0 commit comments