aboutsummaryrefslogtreecommitdiff
path: root/contrib/linearize/linearize-data.py
diff options
context:
space:
mode:
authorDoug <joroark@vt.edu>2016-12-20 19:25:24 -0800
committerDouglas Roark <doug@bloq.com>2017-01-05 00:46:29 -0800
commitd5aa19813c32eff02d4b65ac9a4131f3eed04825 (patch)
treea7c97ce84513d941ab73733cb3b3afd3a9da1bb0 /contrib/linearize/linearize-data.py
parent7dac1e5e9e887f5f6ff146e812a05bd3bf281eae (diff)
downloadbitcoin-d5aa19813c32eff02d4b65ac9a4131f3eed04825.tar.xz
Allow linearization scripts to support hash byte reversal
Currently, the linearization scripts require input hashes to be in one endian form. Add support for byte reversal.
Diffstat (limited to 'contrib/linearize/linearize-data.py')
-rwxr-xr-xcontrib/linearize/linearize-data.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index d0417748fc..adea35dbd5 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -23,6 +23,12 @@ from collections import namedtuple
settings = {}
+##### Switch endian-ness #####
+def hex_switchEndian(s):
+ """ Switches the endianness of a hex string (in pairs of hex chars) """
+ pairList = [s[i]+s[i+1] for i in range(0,len(s),2)]
+ return ''.join(pairList[::-1])
+
def uint32(x):
return x & 0xffffffffL
@@ -69,17 +75,21 @@ def get_blk_dt(blk_hdr):
dt_ym = datetime.datetime(dt.year, dt.month, 1)
return (dt_ym, nTime)
+# When getting the list of block hashes, undo any byte reversals.
def get_block_hashes(settings):
blkindex = []
f = open(settings['hashlist'], "r")
for line in f:
line = line.rstrip()
+ if settings['rev_hash_bytes'] == 'true':
+ line = hex_switchEndian(line)
blkindex.append(line)
print("Read " + str(len(blkindex)) + " hashes")
return blkindex
+# The block map shouldn't give or receive byte-reversed hashes.
def mkblockmap(blkindex):
blkmap = {}
for height,hash in enumerate(blkindex):
@@ -265,6 +275,12 @@ if __name__ == '__main__':
settings[m.group(1)] = m.group(2)
f.close()
+ # Force hash byte format setting to be lowercase to make comparisons easier.
+ # Also place upfront in case any settings need to know about it.
+ if 'rev_hash_bytes' not in settings:
+ settings['rev_hash_bytes'] = 'false'
+ settings['rev_hash_bytes'] = settings['rev_hash_bytes'].lower()
+
if 'netmagic' not in settings:
settings['netmagic'] = 'f9beb4d9'
if 'genesis' not in settings:
@@ -295,9 +311,8 @@ if __name__ == '__main__':
blkindex = get_block_hashes(settings)
blkmap = mkblockmap(blkindex)
+ # Block hash map won't be byte-reversed. Neither should the genesis hash.
if not settings['genesis'] in blkmap:
print("Genesis block not found in hashlist")
else:
BlockDataCopier(settings, blkindex, blkmap).run()
-
-