Merge pull request #1391 from terencechain/patch-85

Fix merkle_tree implementation
This commit is contained in:
Danny Ryan 2019-09-16 08:53:07 -06:00 committed by GitHub
commit 97b3ffcac3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -62,7 +62,7 @@ Note that the generalized index has the convenient property that the two childre
def merkle_tree(leaves: Sequence[Hash]) -> Sequence[Hash]: def merkle_tree(leaves: Sequence[Hash]) -> Sequence[Hash]:
padded_length = get_next_power_of_two(len(leaves)) padded_length = get_next_power_of_two(len(leaves))
o = [Hash()] * padded_length + list(leaves) + [Hash()] * (padded_length - len(leaves)) o = [Hash()] * padded_length + list(leaves) + [Hash()] * (padded_length - len(leaves))
for i in range(len(leaves) - 1, 0, -1): for i in range(padded_length - 1, 0, -1):
o[i] = hash(o[i * 2] + o[i * 2 + 1]) o[i] = hash(o[i * 2] + o[i * 2 + 1])
return o return o
``` ```