1
0

updates for python3

This commit is contained in:
ThomasV
2017-03-15 12:13:20 +01:00
parent 65aeb0bd3c
commit ab15ff3a00
27 changed files with 50 additions and 51 deletions

View File

@@ -39,7 +39,7 @@ def serialize_header(res):
return s
def deserialize_header(s, height):
hex_to_int = lambda s: int('0x' + s[::-1].encode('hex'), 16)
hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16)
h = {}
h['version'] = hex_to_int(s[0:4])
h['prev_block_hash'] = hash_encode(s[4:36])
@@ -55,7 +55,7 @@ def hash_header(header):
return '0' * 64
if header.get('prev_block_hash') is None:
header['prev_block_hash'] = '00'*32
return hash_encode(Hash(serialize_header(header).decode('hex')))
return hash_encode(Hash(bfh(serialize_header(header))))
blockchains = {}
@@ -107,7 +107,7 @@ class Blockchain(util.PrintError):
return blockchains[self.parent_id]
def get_max_child(self):
children = filter(lambda y: y.parent_id==self.checkpoint, blockchains.values())
children = list(filter(lambda y: y.parent_id==self.checkpoint, blockchains.values()))
return max([x.checkpoint for x in children]) if children else None
def get_checkpoint(self):
@@ -141,7 +141,7 @@ class Blockchain(util.PrintError):
def update_size(self):
p = self.path()
self._size = os.path.getsize(p)/80 if os.path.exists(p) else 0
self._size = os.path.getsize(p)//80 if os.path.exists(p) else 0
def verify_header(self, header, prev_header, bits, target):
prev_hash = hash_header(prev_header)
@@ -230,7 +230,7 @@ class Blockchain(util.PrintError):
def save_header(self, header):
delta = header.get('block_height') - self.checkpoint
data = serialize_header(header).decode('hex')
data = bfh(serialize_header(header))
assert delta == self.size()
assert len(data) == 80
self.write(data, delta*80)
@@ -309,7 +309,7 @@ class Blockchain(util.PrintError):
prev_hash = hash_header(previous_header)
if prev_hash != header.get('prev_block_hash'):
return False
bits, target = self.get_target(height / 2016)
bits, target = self.get_target(height // 2016)
try:
self.verify_header(header, previous_header, bits, target)
except: