From 29df410ea330c9a0feae8416c826d3711a3502bf Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sat, 29 Oct 2022 07:50:09 +1100 Subject: [PATCH] Document state after call to calculate_root_inline The function call `calculate_root_inline` calculates the merkle root using the input array as a scratch buffer, i.e., we trash the data during recursive calls to `merkle_root_r`. Add explicit documentation to the function so its super clear not to use the hashes again after calling this function. --- bitcoin/src/merkle_tree.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitcoin/src/merkle_tree.rs b/bitcoin/src/merkle_tree.rs index ddfa559b..a9cfb385 100644 --- a/bitcoin/src/merkle_tree.rs +++ b/bitcoin/src/merkle_tree.rs @@ -26,7 +26,9 @@ use crate::consensus::encode::Encodable; /// Calculates the merkle root of a list of *hashes*, inline (in place) in `hashes`. /// -/// In most cases, you'll want to use [`calculate_root`] instead. +/// In most cases, you'll want to use [`calculate_root`] instead. Please note, calling this function +/// trashes the data in `hashes` (i.e. the `hashes` is left in an undefined state at conclusion of +/// this method and should not be used again afterwards). /// /// # Returns /// - `None` if `hashes` is empty. The merkle root of an empty tree of hashes is undefined.