@@ -20,7 +20,7 @@ use crate::transaction::special_transaction::TransactionPayload;
2020/// - `Some([u8; 32])`: The computed Merkle root if at least one hash is provided.
2121/// - `None`: If the input vector is empty.
2222#[ inline]
23- pub fn merkle_root_from_hashes ( hashes : Vec < [ u8 ; 32 ] > ) -> Option < [ u8 ; 32 ] > {
23+ pub fn merkle_root_from_hashes ( hashes : Vec < sha256d :: Hash > ) -> Option < sha256d :: Hash > {
2424 let length = hashes. len ( ) ;
2525 let mut level = hashes;
2626 match length {
@@ -29,12 +29,12 @@ pub fn merkle_root_from_hashes(hashes: Vec<[u8; 32]>) -> Option<[u8; 32]> {
2929 while level. len ( ) != 1 {
3030 let len = level. len ( ) ;
3131 let mut higher_level =
32- Vec :: < [ u8 ; 32 ] > :: with_capacity ( ( 0.5 * len as f64 ) . ceil ( ) as usize ) ;
32+ Vec :: < sha256d :: Hash > :: with_capacity ( ( 0.5 * len as f64 ) . ceil ( ) as usize ) ;
3333 for pair in level. chunks ( 2 ) {
3434 let mut buffer = Vec :: with_capacity ( 64 ) ;
35- buffer. extend_from_slice ( & pair[ 0 ] ) ;
36- buffer. extend_from_slice ( pair. get ( 1 ) . unwrap_or ( & pair[ 0 ] ) ) ;
37- higher_level. push ( sha256d:: Hash :: hash ( & buffer) . to_byte_array ( ) ) ;
35+ buffer. extend_from_slice ( pair[ 0 ] . as_byte_array ( ) ) ;
36+ buffer. extend_from_slice ( pair. get ( 1 ) . unwrap_or ( & pair[ 0 ] ) . as_byte_array ( ) ) ;
37+ higher_level. push ( sha256d:: Hash :: hash ( & buffer) ) ;
3838 }
3939 level = higher_level;
4040 }
@@ -126,7 +126,7 @@ impl MasternodeList {
126126 ) -> Option < MerkleRootMasternodeList > {
127127 self . hashes_for_merkle_root ( block_height)
128128 . and_then ( merkle_root_from_hashes)
129- . map ( |hash| MerkleRootMasternodeList :: from_byte_array ( hash ) )
129+ . map ( MerkleRootMasternodeList :: from_raw_hash )
130130 }
131131
132132 /// Computes the Merkle root for the LLMQ (Long-Living Masternode Quorum) list.
@@ -140,7 +140,7 @@ impl MasternodeList {
140140 /// - `None`: If no quorum commitment hashes are available.
141141 pub fn calculate_llmq_merkle_root ( & self ) -> Option < MerkleRootQuorums > {
142142 merkle_root_from_hashes ( self . hashes_for_quorum_merkle_root ( ) )
143- . map ( |hash| MerkleRootQuorums :: from_byte_array ( hash ) )
143+ . map ( MerkleRootQuorums :: from_raw_hash )
144144 }
145145
146146 /// Retrieves the list of hashes required to compute the masternode list Merkle root.
@@ -154,9 +154,9 @@ impl MasternodeList {
154154 ///
155155 /// # Returns
156156 ///
157- /// - `Some(Vec<[u8; 32] >)`: A sorted list of masternode entry hashes.
157+ /// - `Some(Vec<sha256d::Hash >)`: A sorted list of masternode entry hashes.
158158 /// - `None`: If the block height is invalid (`u32::MAX`).
159- pub fn hashes_for_merkle_root ( & self , block_height : u32 ) -> Option < Vec < [ u8 ; 32 ] > > {
159+ pub fn hashes_for_merkle_root ( & self , block_height : u32 ) -> Option < Vec < sha256d :: Hash > > {
160160 ( block_height != u32:: MAX ) . then_some ( {
161161 let mut pro_tx_hashes = self . reversed_pro_reg_tx_hashes ( ) ;
162162 pro_tx_hashes. sort_by ( |& s1, & s2| s1. reverse ( ) . cmp ( & s2. reverse ( ) ) ) ;
@@ -180,11 +180,11 @@ impl MasternodeList {
180180 /// # Returns
181181 ///
182182 /// - `Vec<[u8; 32]>`: A sorted list of quorum commitment hashes.
183- pub fn hashes_for_quorum_merkle_root ( & self ) -> Vec < [ u8 ; 32 ] > {
183+ pub fn hashes_for_quorum_merkle_root ( & self ) -> Vec < sha256d :: Hash > {
184184 let mut llmq_commitment_hashes = self
185185 . quorums
186186 . values ( )
187- . flat_map ( |q_map| q_map. values ( ) . map ( |entry| entry. entry_hash . to_byte_array ( ) ) )
187+ . flat_map ( |q_map| q_map. values ( ) . map ( |entry| entry. entry_hash . to_raw_hash ( ) ) )
188188 . collect :: < Vec < _ > > ( ) ;
189189 llmq_commitment_hashes. sort ( ) ;
190190 llmq_commitment_hashes
0 commit comments