Skip to content

Commit

Permalink
Merge pull request #4 from zyluo/add_leaf
Browse files Browse the repository at this point in the history
Refactor add_leaf
  • Loading branch information
EderSantana authored Sep 26, 2017
2 parents 192f7e9 + 8ffcddb commit 86d2518
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions merkletools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@ def reset_tree(self):
def add_leaf(self, values, do_hash=False):
self.is_ready = False
# check if single leaf
if isinstance(values, tuple) or isinstance(values, list):
for v in values:
if do_hash:
v = v.encode('utf-8')
v = self.hash_function(v).hexdigest()
v = bytearray.fromhex(v)
else:
v = bytearray.fromhex(v)
self.leaves.append(v)
else:
if not isinstance(values, tuple) and not isinstance(values, list):
values = [values]
for v in values:
if do_hash:
v = values.encode("utf-8")
v = v.encode('utf-8')
v = self.hash_function(v).hexdigest()
v = bytearray.fromhex(v)
else:
v = bytearray.fromhex(values)
v = bytearray.fromhex(v)
self.leaves.append(v)

def get_leaf(self, index):
Expand Down

0 comments on commit 86d2518

Please sign in to comment.