refactor network constants
This commit is contained in:
@@ -25,6 +25,7 @@ import threading
|
||||
|
||||
from . import util
|
||||
from . import bitcoin
|
||||
from . import constants
|
||||
from .bitcoin import *
|
||||
|
||||
MAX_TARGET = 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
@@ -102,7 +103,7 @@ class Blockchain(util.PrintError):
|
||||
self.config = config
|
||||
self.catch_up = None # interface catching up
|
||||
self.checkpoint = checkpoint
|
||||
self.checkpoints = bitcoin.NetworkConstants.CHECKPOINTS
|
||||
self.checkpoints = constants.net.CHECKPOINTS
|
||||
self.parent_id = parent_id
|
||||
self.lock = threading.Lock()
|
||||
with self.lock:
|
||||
@@ -152,7 +153,7 @@ class Blockchain(util.PrintError):
|
||||
_hash = hash_header(header)
|
||||
if prev_hash != header.get('prev_block_hash'):
|
||||
raise BaseException("prev hash mismatch: %s vs %s" % (prev_hash, header.get('prev_block_hash')))
|
||||
if bitcoin.NetworkConstants.TESTNET:
|
||||
if constants.net.TESTNET:
|
||||
return
|
||||
bits = self.target_to_bits(target)
|
||||
if bits != header.get('bits'):
|
||||
@@ -262,7 +263,7 @@ class Blockchain(util.PrintError):
|
||||
if height == -1:
|
||||
return '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
elif height == 0:
|
||||
return bitcoin.NetworkConstants.GENESIS
|
||||
return constants.net.GENESIS
|
||||
elif height < len(self.checkpoints) * 2016:
|
||||
assert (height+1) % 2016 == 0, height
|
||||
index = height // 2016
|
||||
@@ -273,7 +274,7 @@ class Blockchain(util.PrintError):
|
||||
|
||||
def get_target(self, index):
|
||||
# compute target from chunk x, used in chunk x+1
|
||||
if bitcoin.NetworkConstants.TESTNET:
|
||||
if constants.net.TESTNET:
|
||||
return 0
|
||||
if index == -1:
|
||||
return MAX_TARGET
|
||||
@@ -317,7 +318,7 @@ class Blockchain(util.PrintError):
|
||||
#self.print_error("cannot connect at height", height)
|
||||
return False
|
||||
if height == 0:
|
||||
return hash_header(header) == bitcoin.NetworkConstants.GENESIS
|
||||
return hash_header(header) == constants.net.GENESIS
|
||||
try:
|
||||
prev_hash = self.get_hash(height - 1)
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user