fix bug with hex_to_int; remove unused function

This commit is contained in:
ThomasV 2013-11-12 10:14:29 +01:00
parent 69639f901c
commit df76aac2db
2 changed files with 5 additions and 38 deletions

View File

@ -18,7 +18,7 @@
import threading, time, Queue, os, sys, shutil
from util import user_dir, appdata_dir, print_error, hex_to_int
from util import user_dir, appdata_dir, print_error
from bitcoin import *
@ -118,7 +118,7 @@ class Blockchain(threading.Thread):
try:
assert prev_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert hex_to_int(_hash) < target
assert int('0x'+_hash,16) < target
except Exception:
return False
@ -149,7 +149,7 @@ class Blockchain(threading.Thread):
_hash = self.hash_header(header)
assert previous_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert hex_to_int(_hash) < target
assert int('0x'+_hash,16) < target
previous_header = header
previous_hash = _hash
@ -157,36 +157,6 @@ class Blockchain(threading.Thread):
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
def verify_header(self, header):
# add header to the blockchain file
# if there is a reorg, push it in a stack
height = header.get('block_height')
prev_header = self.read_header(height -1)
if not prev_header:
# return False to request previous header
return False
prev_hash = self.hash_header(prev_header)
bits, target = self.get_target(height/2016)
_hash = self.hash_header(header)
try:
assert prev_hash == header.get('prev_block_hash')
assert bits == header.get('bits')
assert hex_to_int(_hash) < target
except Exception:
# this can be caused by a reorg.
print_error("verify header failed"+ repr(header))
verifier.undo_verifications()
# return False to request previous header.
return False
self.save_header(header)
print_error("verify header:", _hash, height)
return True
def header_to_string(self, res):
@ -200,6 +170,7 @@ class Blockchain(threading.Thread):
def header_from_string(self, s):
hex_to_int = lambda s: int('0x' + s[::-1].encode('hex'), 16)
h = {}
h['version'] = hex_to_int(s[0:4])
h['prev_block_hash'] = hash_encode(s[4:36])
@ -305,7 +276,7 @@ class Blockchain(threading.Thread):
c = c[2:]
i -= 1
c = hex_to_int(c[0:6])
c = int('0x'+c[0:6],16)
if c > 0x800000:
c /= 256
i += 1

View File

@ -5,10 +5,6 @@ from datetime import datetime
is_verbose = True
def hex_to_int(s):
return int('0x' + s[::-1].encode('hex'), 16)
class MyEncoder(json.JSONEncoder):
def default(self, obj):
from transaction import Transaction