util: kill bh2u
no longer useful, and the name is so confusing...
This commit is contained in:
@@ -28,7 +28,7 @@ from typing import List, Tuple, TYPE_CHECKING, Optional, Union, Sequence
|
||||
import enum
|
||||
from enum import IntEnum, Enum
|
||||
|
||||
from .util import bfh, bh2u, BitcoinException, assert_bytes, to_bytes, inv_dict, is_hex_str
|
||||
from .util import bfh, BitcoinException, assert_bytes, to_bytes, inv_dict, is_hex_str
|
||||
from . import version
|
||||
from . import segwit_addr
|
||||
from . import constants
|
||||
@@ -198,7 +198,7 @@ class opcodes(IntEnum):
|
||||
|
||||
|
||||
def rev_hex(s: str) -> str:
|
||||
return bh2u(bfh(s)[::-1])
|
||||
return bfh(s)[::-1].hex()
|
||||
|
||||
|
||||
def int_to_hex(i: int, length: int=1) -> str:
|
||||
@@ -238,7 +238,7 @@ def script_num_to_hex(i: int) -> str:
|
||||
elif neg:
|
||||
result[-1] |= 0x80
|
||||
|
||||
return bh2u(result)
|
||||
return result.hex()
|
||||
|
||||
|
||||
def var_int(i: int) -> str:
|
||||
@@ -288,11 +288,11 @@ def push_script(data: str) -> str:
|
||||
if data_len == 0 or data_len == 1 and data[0] == 0:
|
||||
return opcodes.OP_0.hex()
|
||||
elif data_len == 1 and data[0] <= 16:
|
||||
return bh2u(bytes([opcodes.OP_1 - 1 + data[0]]))
|
||||
return bytes([opcodes.OP_1 - 1 + data[0]]).hex()
|
||||
elif data_len == 1 and data[0] == 0x81:
|
||||
return opcodes.OP_1NEGATE.hex()
|
||||
|
||||
return _op_push(data_len) + bh2u(data)
|
||||
return _op_push(data_len) + data.hex()
|
||||
|
||||
|
||||
def make_op_return(x:bytes) -> bytes:
|
||||
@@ -310,7 +310,7 @@ def construct_witness(items: Sequence[Union[str, int, bytes]]) -> str:
|
||||
if type(item) is int:
|
||||
item = script_num_to_hex(item)
|
||||
elif isinstance(item, (bytes, bytearray)):
|
||||
item = bh2u(item)
|
||||
item = item.hex()
|
||||
else:
|
||||
assert is_hex_str(item)
|
||||
witness += witness_push(item)
|
||||
@@ -366,7 +366,7 @@ def dust_threshold(network: 'Network' = None) -> int:
|
||||
|
||||
|
||||
def hash_encode(x: bytes) -> str:
|
||||
return bh2u(x[::-1])
|
||||
return x[::-1].hex()
|
||||
|
||||
|
||||
def hash_decode(x: str) -> bytes:
|
||||
@@ -464,7 +464,7 @@ def address_to_script(addr: str, *, net=None) -> str:
|
||||
return construct_script([witver, bytes(witprog)])
|
||||
addrtype, hash_160_ = b58_address_to_hash160(addr)
|
||||
if addrtype == net.ADDRTYPE_P2PKH:
|
||||
script = pubkeyhash_to_p2pkh_script(bh2u(hash_160_))
|
||||
script = pubkeyhash_to_p2pkh_script(hash_160_.hex())
|
||||
elif addrtype == net.ADDRTYPE_P2SH:
|
||||
script = construct_script([opcodes.OP_HASH160, hash_160_, opcodes.OP_EQUAL])
|
||||
else:
|
||||
@@ -519,7 +519,7 @@ def address_to_scripthash(addr: str, *, net=None) -> str:
|
||||
|
||||
def script_to_scripthash(script: str) -> str:
|
||||
h = sha256(bfh(script))[0:32]
|
||||
return bh2u(bytes(reversed(h)))
|
||||
return h[::-1].hex()
|
||||
|
||||
def public_key_to_p2pk_script(pubkey: str) -> str:
|
||||
return construct_script([pubkey, opcodes.OP_CHECKSIG])
|
||||
@@ -613,7 +613,7 @@ def DecodeBase58Check(psz: Union[bytes, str]) -> bytes:
|
||||
csum_found = vchRet[-4:]
|
||||
csum_calculated = sha256d(payload)[0:4]
|
||||
if csum_calculated != csum_found:
|
||||
raise InvalidChecksum(f'calculated {bh2u(csum_calculated)}, found {bh2u(csum_found)}')
|
||||
raise InvalidChecksum(f'calculated {csum_calculated.hex()}, found {csum_found.hex()}')
|
||||
else:
|
||||
return payload
|
||||
|
||||
|
||||
Reference in New Issue
Block a user