aboutsummaryrefslogtreecommitdiff
path: root/contrib/linearize
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-17 22:38:10 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-17 22:38:10 +0100
commit254a63e097def1bf7e157c72ea9e4fff1eeb7a28 (patch)
tree5ff18dd90fbac73d72de04dea8739802b4371872 /contrib/linearize
parent3f863cfff1ec902454d64f82b12eb09bdb1eee04 (diff)
downloadbitcoin-254a63e097def1bf7e157c72ea9e4fff1eeb7a28.tar.xz
contrib: refactor: replace `hex_switchEndian` in linearize scripts
Switching the endianness of a hex string `str` can simply be achieved by `bytes.fromhex(str)[::-1].hex()`, i.e. we can use that and remove those helper methods.
Diffstat (limited to 'contrib/linearize')
-rwxr-xr-xcontrib/linearize/linearize-data.py7
-rwxr-xr-xcontrib/linearize/linearize-hashes.py7
2 files changed, 2 insertions, 12 deletions
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index ad222c7223..7510204bb1 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -20,11 +20,6 @@ from collections import namedtuple
settings = {}
-def hex_switchEndian(s):
- """ Switches the endianness of a hex string (in pairs of hex chars) """
- pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]
- return b''.join(pairList[::-1]).decode()
-
def calc_hash_str(blk_hdr):
blk_hdr_hash = hashlib.sha256(hashlib.sha256(blk_hdr).digest()).digest()
return blk_hdr_hash[::-1].hex()
@@ -43,7 +38,7 @@ def get_block_hashes(settings):
for line in f:
line = line.rstrip()
if settings['rev_hash_bytes'] == 'true':
- line = hex_switchEndian(line)
+ line = bytes.fromhex(line)[::-1].hex()
blkindex.append(line)
print("Read " + str(len(blkindex)) + " hashes")
diff --git a/contrib/linearize/linearize-hashes.py b/contrib/linearize/linearize-hashes.py
index fed6e665b8..0a316eb818 100755
--- a/contrib/linearize/linearize-hashes.py
+++ b/contrib/linearize/linearize-hashes.py
@@ -17,11 +17,6 @@ import os.path
settings = {}
-def hex_switchEndian(s):
- """ Switches the endianness of a hex string (in pairs of hex chars) """
- pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]
- return b''.join(pairList[::-1]).decode()
-
class BitcoinRPC:
def __init__(self, host, port, username, password):
authpair = "%s:%s" % (username, password)
@@ -85,7 +80,7 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
sys.exit(1)
assert(resp_obj['id'] == x) # assume replies are in-sequence
if settings['rev_hash_bytes'] == 'true':
- resp_obj['result'] = hex_switchEndian(resp_obj['result'])
+ resp_obj['result'] = bytes.fromhex(resp_obj['result'])[::-1].hex()
print(resp_obj['result'])
height += num_blocks