diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py --- a/contrib/linearize/linearize-data.py +++ b/contrib/linearize/linearize-data.py @@ -17,7 +17,7 @@ import datetime import time from collections import namedtuple -from binascii import hexlify, unhexlify +from binascii import unhexlify settings = {} @@ -69,7 +69,7 @@ hash = calc_hdr_hash(blk_hdr) hash = bufreverse(hash) hash = wordreverse(hash) - hash_str = hexlify(hash).decode('utf-8') + hash_str = hash.hex() return hash_str @@ -230,7 +230,7 @@ inMagic = inhdr[:4] if (inMagic != self.settings['netmagic']): - print("Invalid magic: " + hexlify(inMagic).decode('utf-8')) + print("Invalid magic: " + inMagic.hex()) return inLenLE = inhdr[4:] su = struct.unpack(" 0: diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -28,7 +28,7 @@ import time from test_framework.siphash import siphash256 -from test_framework.util import bytes_to_hex_str, hex_str_to_bytes +from test_framework.util import hex_str_to_bytes MIN_VERSION_SUPPORTED = 60001 # past bip-31 for ping/pong @@ -198,7 +198,7 @@ def ToHex(obj): - return bytes_to_hex_str(obj.serialize()) + return obj.serialize().hex() # Objects that map to bitcoind objects, which can be serialized/deserialized @@ -334,7 +334,7 @@ def __repr__(self): return "CTxIn(prevout={} scriptSig={} nSequence={})".format( - repr(self.prevout), bytes_to_hex_str(self.scriptSig), self.nSequence) + repr(self.prevout), self.scriptSig.hex(), self.nSequence) class CTxOut: @@ -356,8 +356,7 @@ def __repr__(self): return "CTxOut(nValue={}.{:08d} scriptPubKey={})".format( - self.nValue // COIN, self.nValue % COIN, - bytes_to_hex_str(self.scriptPubKey)) + self.nValue // COIN, self.nValue % COIN, self.scriptPubKey.hex()) class CTransaction: diff --git a/test/functional/test_framework/netutil.py b/test/functional/test_framework/netutil.py --- a/test/functional/test_framework/netutil.py +++ b/test/functional/test_framework/netutil.py @@ -8,7 +8,7 @@ """ import array -from binascii import unhexlify, hexlify +from binascii import unhexlify import fcntl import os import socket @@ -149,7 +149,7 @@ addr = sub[0] + ([0] * nullbytes) + sub[1] else: raise ValueError('Could not parse address {}'.format(addr)) - return hexlify(bytearray(addr)).decode('ascii') + return bytearray(addr).hex() def test_ipv6_local(): diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -8,7 +8,6 @@ """ from .bignum import bn2vch -from binascii import hexlify import hashlib import struct @@ -558,7 +557,7 @@ def __repr__(self): def _repr(o): if isinstance(o, bytes): - return "x('{}')".format(hexlify(o).decode('ascii')) + return "x('{}')".format(o.hex()) else: return repr(o) diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -5,7 +5,7 @@ """Helpful routines for regression testing.""" from base64 import b64encode -from binascii import hexlify, unhexlify +from binascii import unhexlify from decimal import Decimal, ROUND_DOWN import hashlib import inspect @@ -215,8 +215,8 @@ return len(bytearray.fromhex(hex_string)) -def bytes_to_hex_str(byte_str): - return hexlify(byte_str).decode('ascii') +def b_2_x(byte_str): + return byte_str.hex() def hash256(byte_str):