Skip to content

Commit

Permalink
update: merkle_proof function with try
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Oct 16, 2022
1 parent 4327025 commit a08ac9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions merkly/mtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def merkle_root(leafs: list):
["159b0d5005a27c97537ff0e6d1d0d619be408a5e3f2570816b02dc5a18b74f47"]
>>> merkle_root(["a", "b"])
["63a9f18b64ca5a98ad9dba59259edb0710892614501480a9bed568d98450c151"]
["414e3a845393ef6d68973ddbf5bd85ff524443cf0e06a361624f3d51b879ec1c"]
```
"""
from merkly.utils.math import is_power_2
Expand Down Expand Up @@ -156,7 +156,13 @@ def merkle_proof(
)
return proof

index = leafs.index(leaf)
try:
index = leafs.index(leaf)
except ValueError as err:
raise ValueError(
f'leaf: {leaf} does not exist in the tree: {leafs}'
) from err

left, right = half(leafs)

if index < len(leafs) / 2:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "merkly"
version = "0.5.1"
version = "0.5.2"
description = "🌳 The simple and easy implementation of Merkle Tree"
authors = ["Lucas Oliveira <[email protected]>"]
repository = "https://github.com/olivmath/merkly.git"
Expand Down

0 comments on commit a08ac9f

Please sign in to comment.