diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 31a9cd5230e..990cabceb60 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -149,19 +149,24 @@ where where T: scale::Encode, { + fn inner(encoded: &mut [u8]) -> ::Hash { + let len_encoded = encoded.len(); + let mut result = ::Hash::clear(); + let len_result = result.as_ref().len(); + if len_encoded <= len_result { + result.as_mut()[..len_encoded].copy_from_slice(encoded); + } else { + let mut hash_output = ::Type::default(); + ::hash(encoded, &mut hash_output); + let copy_len = core::cmp::min(hash_output.len(), len_result); + result.as_mut()[0..copy_len].copy_from_slice(&hash_output[0..copy_len]); + } + result + } + let mut split = self.scoped_buffer.split(); let encoded = split.take_encoded(topic_value); - let len_encoded = encoded.len(); - let mut result = ::Hash::clear(); - let len_result = result.as_ref().len(); - if len_encoded <= len_result { - result.as_mut()[..len_encoded].copy_from_slice(encoded); - } else { - let mut hash_output = ::Type::default(); - ::hash(encoded, &mut hash_output); - let copy_len = core::cmp::min(hash_output.len(), len_result); - result.as_mut()[0..copy_len].copy_from_slice(&hash_output[0..copy_len]); - } + let result = inner::(encoded); self.scoped_buffer.append_encoded(&result); }