Skip to content
This repository was archived by the owner on Dec 27, 2021. It is now read-only.

Commit 8d94d27

Browse files
committed
Merkle root calculation python notes
1 parent ce9afbc commit 8d94d27

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/merkle.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def merkle(items):
2+
print(items)
3+
out = []
4+
while items:
5+
pair = []
6+
for _ in range(2):
7+
pair.append(items.pop(0) if items else pair[0])
8+
# "hashing"
9+
out.append(pair[0] + pair[1])
10+
if len(out) == 1:
11+
return out
12+
else:
13+
return merkle(out)
14+
15+
16+
items = [1, 2, 3, 4, 5, 5, 6, 2, 6, 2, 1, 2]
17+
print(merkle(items))

0 commit comments

Comments
 (0)