improve hash_to_hex_str performance

This commit is contained in:
Jack Robison 2020-12-08 14:42:28 -05:00
parent b8c16d8ac5
commit 8da73ad3dd
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -67,17 +67,17 @@ def hash160(x):
return ripemd160(sha256(x)) return ripemd160(sha256(x))
def hash_to_hex_str(x): def hash_to_hex_str(x: bytes) -> str:
"""Convert a big-endian binary hash to displayed hex string. """Convert a big-endian binary hash to displayed hex string.
Display form of a binary hash is reversed and converted to hex. Display form of a binary hash is reversed and converted to hex.
""" """
return bytes(reversed(x)).hex() return x[::-1].hex()
def hex_str_to_hash(x): def hex_str_to_hash(x: str) -> bytes:
"""Convert a displayed hex string to a binary hash.""" """Convert a displayed hex string to a binary hash."""
return bytes(reversed(hex_to_bytes(x))) return hex_to_bytes(x)[::-1]
class Base58Error(Exception): class Base58Error(Exception):