electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 7deec48705d155115e04b7891c9aabc6ff687e52
parent d70087a0f57acb57b454d1a0807206c75f794fdc
Author: ThomasV <thomasv@gitorious>
Date:   Wed, 16 Oct 2013 14:42:52 +0200

pass chain to get_target (fixes issue #316)

Diffstat:
Mlib/blockchain.py | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/blockchain.py b/lib/blockchain.py @@ -113,7 +113,7 @@ class Blockchain(threading.Thread): height = header.get('block_height') prev_hash = self.hash_header(prev_header) - bits, target = self.get_target(height/2016) + bits, target = self.get_target(height/2016, chain) _hash = self.hash_header(header) try: assert prev_hash == header.get('prev_block_hash') @@ -271,14 +271,18 @@ class Blockchain(threading.Thread): return h - def get_target(self, index): + def get_target(self, index, chain=[]): max_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000 if index == 0: return 0x1d00ffff, max_target first = self.read_header((index-1)*2016) last = self.read_header(index*2016-1) - + if last is None: + 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)