replace hexlify to hex()
This commit is contained in:
parent
2432e59d2a
commit
d6559acd18
@ -22,7 +22,7 @@ def merkle_root(tx_hash_list, hex=True):
|
|||||||
if len(new_hash_list) > 1:
|
if len(new_hash_list) > 1:
|
||||||
tx_hash_list = new_hash_list
|
tx_hash_list = new_hash_list
|
||||||
else:
|
else:
|
||||||
return new_hash_list[0] if not hex else hexlify(new_hash_list[0]).decode()
|
return new_hash_list[0] if not hex else new_hash_list[0].hex()
|
||||||
|
|
||||||
|
|
||||||
def merkle_branches(tx_hash_list, hex=True):
|
def merkle_branches(tx_hash_list, hex=True):
|
||||||
@ -53,7 +53,7 @@ def merkle_branches(tx_hash_list, hex=True):
|
|||||||
else:
|
else:
|
||||||
if new_hash_list:
|
if new_hash_list:
|
||||||
branches.append(new_hash_list.pop(0))
|
branches.append(new_hash_list.pop(0))
|
||||||
return branches if not hex else [hexlify(h).decode() for h in branches]
|
return branches if not hex else [h.hex() for h in branches]
|
||||||
|
|
||||||
|
|
||||||
def merkleroot_from_branches(merkle_branches, coinbase_hash, hex=True):
|
def merkleroot_from_branches(merkle_branches, coinbase_hash, hex=True):
|
||||||
@ -65,12 +65,12 @@ def merkleroot_from_branches(merkle_branches, coinbase_hash, hex=True):
|
|||||||
:param hex: (optional) If set to True return result in HEX format, by default is True.
|
:param hex: (optional) If set to True return result in HEX format, by default is True.
|
||||||
:return: merkle root in bytes or HEX encoded string corresponding hex flag.
|
:return: merkle root in bytes or HEX encoded string corresponding hex flag.
|
||||||
"""
|
"""
|
||||||
merkle_root = coinbase_hash if not isinstance(coinbase_hash, str) else unhexlify(coinbase_hash)
|
merkle_root = coinbase_hash if not isinstance(coinbase_hash, str) else bytes.fromhex(coinbase_hash)
|
||||||
for h in merkle_branches:
|
for h in merkle_branches:
|
||||||
if type(h) == str:
|
if type(h) == str:
|
||||||
h = unhexlify(h)
|
h = bytes.fromhex(h)
|
||||||
merkle_root = double_sha256(merkle_root + h)
|
merkle_root = double_sha256(merkle_root + h)
|
||||||
return merkle_root if not hex else hexlify(merkle_root).decode()
|
return merkle_root if not hex else merkle_root.hex()
|
||||||
|
|
||||||
|
|
||||||
# Difficulty
|
# Difficulty
|
||||||
@ -84,7 +84,7 @@ def bits_to_target(bits):
|
|||||||
:return: integer.
|
:return: integer.
|
||||||
"""
|
"""
|
||||||
if type(bits) == str:
|
if type(bits) == str:
|
||||||
bits = unhexlify(bits)
|
bits = bytes.fromhex(bits)
|
||||||
if type(bits) == bytes:
|
if type(bits) == bytes:
|
||||||
return int.from_bytes(bits[1:], 'big') * (2 ** (8 * (bits[0] - 3)))
|
return int.from_bytes(bits[1:], 'big') * (2 ** (8 * (bits[0] - 3)))
|
||||||
else:
|
else:
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ setup(name='pybtc',
|
|||||||
author_email='admin@bitaps.com',
|
author_email='admin@bitaps.com',
|
||||||
license='GPL-3.0',
|
license='GPL-3.0',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[ 'secp256k1'],
|
install_requires=['secp256k1'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
package_data={
|
package_data={
|
||||||
'pybtc': ['bip39_word_list/*.txt', 'test/*.txt'],
|
'pybtc': ['bip39_word_list/*.txt', 'test/*.txt'],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user