Skip to content

Commit

Permalink
Merkle tree fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuterin committed Feb 11, 2015
1 parent a26770e commit 189fc66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bitcoin/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def mk_merkle_proof(header, hashes, index):
newnodes = []
for i in range(0, len(nodes) - 1, 2):
newnodes.append(bin_sha256(bin_sha256(nodes[i] + nodes[i+1])))
if len(nodes) % 2:
newnodes.append(bin_sha256(bin_sha256(nodes[-1] + nodes[-1])))
if len(newnodes) % 2 and len(newnodes) > 2:
newnodes.append(newnodes[-1])
nodes = newnodes
layers.append(nodes)
# Sanity check, make sure merkle root is valid
Expand Down
5 changes: 3 additions & 2 deletions bitcoin/py3specials.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def changebase(string, frm, to, minlen=0):
return encode(decode(string, frm), to, minlen)

def bin_to_b58check(inp, magicbyte=0):
inp_fmtd = from_int_to_byte(magicbyte)+inp
inp_fmtd = from_int_to_byte(int(magicbyte))+inp

leadingzbytes = 0
for x in inp_fmtd:
Expand Down Expand Up @@ -84,7 +84,8 @@ def encode(val, base, minlen=0):

pad_size = minlen - len(result_bytes)

padding_element = b'\x00' if base == 256 else b'0'
padding_element = b'\x00' if base == 256 else b'1' \
if base == 58 else b'0'
if (pad_size > 0):
result_bytes = padding_element*pad_size + result_bytes

Expand Down

0 comments on commit 189fc66

Please sign in to comment.