shuijian-xu / bitcoin

0 stars 0 forks source link

How to create Merkle Tree Structure? #238

Open shuijian-xu opened 4 years ago

shuijian-xu commented 4 years ago

Because Merkle trees are built from the leaves upward, the only thing a light client needs is the number of leaves that exist to know the structure.

shuijian-xu commented 4 years ago

import math total = 16 max_depth = math.ceil(math.log(total, 2))
merkle_tree = []

for depth in range(max_depth + 1):
num_items = math.ceil(total / 2*(max_depth - depth)) level_hashes = [None] num_items
merkle_tree.append(level_hashes)

for level in merkle_tree: print(level)