aboutsummaryrefslogtreecommitdiff
path: root/contrib/linearize/linearize-data.py
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-17 22:15:40 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-02-17 22:28:15 +0100
commit3f863cfff1ec902454d64f82b12eb09bdb1eee04 (patch)
treec93ffef9f0c460ed6a890a27600556db465849f2 /contrib/linearize/linearize-data.py
parent922c49a1389531d9fba30168257c466bd413f625 (diff)
downloadbitcoin-3f863cfff1ec902454d64f82b12eb09bdb1eee04.tar.xz
contrib: refactor: simplify block header string routine in linearize-data.py
The string representation of a block header hash is simply the hexlified byte-reversed double SHA256 hash of its serialization.
Diffstat (limited to 'contrib/linearize/linearize-data.py')
-rwxr-xr-xcontrib/linearize/linearize-data.py39
1 files changed, 2 insertions, 37 deletions
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index 441b5da764..ad222c7223 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -25,44 +25,9 @@ def hex_switchEndian(s):
pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]
return b''.join(pairList[::-1]).decode()
-def uint32(x):
- return x & 0xffffffff
-
-def bytereverse(x):
- return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
- (((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
-
-def bufreverse(in_buf):
- out_words = []
- for i in range(0, len(in_buf), 4):
- word = struct.unpack('@I', in_buf[i:i+4])[0]
- out_words.append(struct.pack('@I', bytereverse(word)))
- return b''.join(out_words)
-
-def wordreverse(in_buf):
- out_words = []
- for i in range(0, len(in_buf), 4):
- out_words.append(in_buf[i:i+4])
- out_words.reverse()
- return b''.join(out_words)
-
-def calc_hdr_hash(blk_hdr):
- hash1 = hashlib.sha256()
- hash1.update(blk_hdr)
- hash1_o = hash1.digest()
-
- hash2 = hashlib.sha256()
- hash2.update(hash1_o)
- hash2_o = hash2.digest()
-
- return hash2_o
-
def calc_hash_str(blk_hdr):
- hash = calc_hdr_hash(blk_hdr)
- hash = bufreverse(hash)
- hash = wordreverse(hash)
- hash_str = hash.hex()
- return hash_str
+ blk_hdr_hash = hashlib.sha256(hashlib.sha256(blk_hdr).digest()).digest()
+ return blk_hdr_hash[::-1].hex()
def get_blk_dt(blk_hdr):
members = struct.unpack("<I", blk_hdr[68:68+4])