1
0

removed trailing whitespace and fixed indentation in history widget

This commit is contained in:
Tafelpoot
2014-10-21 19:05:51 +02:00
parent 49c0a3a08f
commit d9c5250a6f
35 changed files with 230 additions and 267 deletions

View File

@@ -36,7 +36,7 @@ class Blockchain(threading.Thread):
self.set_local_height()
self.queue = Queue.Queue()
def height(self):
return self.local_height
@@ -68,7 +68,7 @@ class Blockchain(threading.Thread):
i, header = result
if not header: continue
height = header.get('block_height')
if height <= self.local_height:
@@ -83,10 +83,10 @@ class Blockchain(threading.Thread):
chain = self.get_chain( i, header )
# skip that server if the result is not consistent
if not chain:
if not chain:
print_error('e')
continue
# verify the chain
if self.verify_chain( chain ):
print_error("height:", height, i.server)
@@ -101,13 +101,13 @@ class Blockchain(threading.Thread):
self.network.new_blockchain_height(height, i)
def verify_chain(self, chain):
first_header = chain[0]
prev_header = self.read_header(first_header.get('block_height') -1)
for header in chain:
height = header.get('block_height')
@@ -133,7 +133,7 @@ class Blockchain(threading.Thread):
height = index*2016
num = len(data)/80
if index == 0:
if index == 0:
previous_hash = ("0"*64)
else:
prev_header = self.read_header(index*2016-1)
@@ -152,12 +152,12 @@ class Blockchain(threading.Thread):
assert int('0x'+_hash,16) < target
previous_header = header
previous_hash = _hash
previous_hash = _hash
self.save_chunk(index, data)
print_error("validated chunk %d"%height)
def header_to_string(self, res):
s = int_to_hex(res.get('version'),4) \
@@ -190,7 +190,7 @@ class Blockchain(threading.Thread):
filename = self.path()
if os.path.exists(filename):
return
try:
import urllib, socket
socket.setdefaulttimeout(30)
@@ -238,7 +238,7 @@ class Blockchain(threading.Thread):
f.close()
if len(h) == 80:
h = self.header_from_string(h)
return h
return h
def get_target(self, index, chain=None):
@@ -254,13 +254,13 @@ class Blockchain(threading.Thread):
for h in chain:
if h.get('block_height') == index*2016-1:
last = h
nActualTimespan = last.get('timestamp') - first.get('timestamp')
nTargetTimespan = 14*24*60*60
nActualTimespan = max(nActualTimespan, nTargetTimespan/4)
nActualTimespan = min(nActualTimespan, nTargetTimespan*4)
bits = last.get('bits')
bits = last.get('bits')
# convert to bignum
MM = 256*256*256
a = bits%MM
@@ -270,7 +270,7 @@ class Blockchain(threading.Thread):
# new target
new_target = min( max_target, (target * nActualTimespan)/nTargetTimespan )
# convert it to bits
c = ("%064X"%new_target)[2:]
i = 31
@@ -279,7 +279,7 @@ class Blockchain(threading.Thread):
i -= 1
c = int('0x'+c[0:6],16)
if c >= 0x800000:
if c >= 0x800000:
c /= 256
i += 1
@@ -357,4 +357,3 @@ class Blockchain(threading.Thread):
return False
return True