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