Skip to content

Commit c1a7ad4

Browse files
committed
use as_chunks and fix clippy error
1 parent 0f95f37 commit c1a7ad4

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

stacks-common/src/types/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl BurnchainHeaderHash {
488488
}
489489

490490
pub fn to_bitcoin_hash(&self) -> Sha256dHash {
491-
let mut buf = self.0.clone();
491+
let mut buf = self.0;
492492
buf.reverse();
493493
Sha256dHash(buf)
494494
}

stackslib/src/chainstate/burn/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,19 @@ impl SortitionHash {
157157
}
158158

159159
/// Convert a SortitionHash into a (little-endian) uint256
160-
#[allow(clippy::indexing_slicing)]
161160
pub fn to_uint256(&self) -> Uint256 {
162-
let mut tmp = [0u64; 4];
163-
for i in 0..4 {
164-
let b: &[u8; 8] = &self.0[8 * i..8 * (i + 1)].try_into().unwrap();
165-
tmp[i] = u64::from_le_bytes(*b);
166-
}
167-
Uint256(tmp)
161+
let (u64_chunks, []) = self.0.as_chunks::<8>() else {
162+
panic!("SortitionHash was not evenly divisible by 8")
163+
};
164+
165+
let tmp: Vec<u64> = u64_chunks
166+
.iter()
167+
.map(|chunk| u64::from_le_bytes(*chunk))
168+
.collect();
169+
Uint256(
170+
tmp.try_into()
171+
.expect("SortitionHash should have 4 chunks of 8 bytes"),
172+
)
168173
}
169174
}
170175

stackslib/src/chainstate/stacks/index/trie.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,6 @@ impl Trie {
853853
storage: &mut TrieStorageConnection<T>,
854854
children_root_hash: &TrieHash,
855855
) -> Result<TrieHash, Error> {
856-
let hashes = Trie::get_trie_root_ancestor_hashes_bytes(storage, children_root_hash)?;
857856
let hashes = Trie::get_trie_root_ancestor_hashes_bytes(storage, children_root_hash)?;
858857
match hashes.as_slice() {
859858
[single_hash] => Ok(*single_hash),

0 commit comments

Comments
 (0)