def btc_addr_to_hash_160(btc_addr):
""" Calculates the RIPEMD-160 hash from a given Bitcoin address
:param btc_addr: Bitcoin address.
:type btc_addr: str
:return: The corresponding RIPEMD-160 hash.
:rtype: hex str
"""
# Base 58 decode the Bitcoin address.
decoded_addr = b58decode(btc_addr)
# Covert the address from bytes to hex.
decoded_addr_hex = hexlify(decoded_addr)
# Obtain the RIPEMD-160 hash by removing the first and four last bytes of the decoded address, corresponding to
# the network version and the checksum of the address.
h160 = decoded_addr_hex[2:-8]
return h160
评论列表
文章目录