mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-28 13:22:43 +02:00
[tests] Fix pep8 style violations in address.py
This commit is contained in:
@@ -35,7 +35,7 @@ def byte_to_base58(b, version):
|
|||||||
str = chr(version).encode('latin-1').hex() + str
|
str = chr(version).encode('latin-1').hex() + str
|
||||||
checksum = hash256(hex_str_to_bytes(str)).hex()
|
checksum = hash256(hex_str_to_bytes(str)).hex()
|
||||||
str += checksum[:8]
|
str += checksum[:8]
|
||||||
value = int('0x'+str,0)
|
value = int('0x' + str, 0)
|
||||||
while value > 0:
|
while value > 0:
|
||||||
result = chars[value % 58] + result
|
result = chars[value % 58] + result
|
||||||
value //= 58
|
value //= 58
|
||||||
@@ -75,30 +75,30 @@ def base58_to_byte(s):
|
|||||||
return res[1:-4], int(res[0])
|
return res[1:-4], int(res[0])
|
||||||
|
|
||||||
|
|
||||||
def keyhash_to_p2pkh(hash, main = False):
|
def keyhash_to_p2pkh(hash, main=False):
|
||||||
assert len(hash) == 20
|
assert len(hash) == 20
|
||||||
version = 0 if main else 111
|
version = 0 if main else 111
|
||||||
return byte_to_base58(hash, version)
|
return byte_to_base58(hash, version)
|
||||||
|
|
||||||
def scripthash_to_p2sh(hash, main = False):
|
def scripthash_to_p2sh(hash, main=False):
|
||||||
assert len(hash) == 20
|
assert len(hash) == 20
|
||||||
version = 5 if main else 196
|
version = 5 if main else 196
|
||||||
return byte_to_base58(hash, version)
|
return byte_to_base58(hash, version)
|
||||||
|
|
||||||
def key_to_p2pkh(key, main = False):
|
def key_to_p2pkh(key, main=False):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
return keyhash_to_p2pkh(hash160(key), main)
|
return keyhash_to_p2pkh(hash160(key), main)
|
||||||
|
|
||||||
def script_to_p2sh(script, main = False):
|
def script_to_p2sh(script, main=False):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
return scripthash_to_p2sh(hash160(script), main)
|
return scripthash_to_p2sh(hash160(script), main)
|
||||||
|
|
||||||
def key_to_p2sh_p2wpkh(key, main = False):
|
def key_to_p2sh_p2wpkh(key, main=False):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
p2shscript = CScript([OP_0, hash160(key)])
|
p2shscript = CScript([OP_0, hash160(key)])
|
||||||
return script_to_p2sh(p2shscript, main)
|
return script_to_p2sh(p2shscript, main)
|
||||||
|
|
||||||
def program_to_witness(version, program, main = False):
|
def program_to_witness(version, program, main=False):
|
||||||
if (type(program) is str):
|
if (type(program) is str):
|
||||||
program = hex_str_to_bytes(program)
|
program = hex_str_to_bytes(program)
|
||||||
assert 0 <= version <= 16
|
assert 0 <= version <= 16
|
||||||
@@ -106,29 +106,29 @@ def program_to_witness(version, program, main = False):
|
|||||||
assert version > 0 or len(program) in [20, 32]
|
assert version > 0 or len(program) in [20, 32]
|
||||||
return encode_segwit_address("bc" if main else "bcrt", version, program)
|
return encode_segwit_address("bc" if main else "bcrt", version, program)
|
||||||
|
|
||||||
def script_to_p2wsh(script, main = False):
|
def script_to_p2wsh(script, main=False):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
return program_to_witness(0, sha256(script), main)
|
return program_to_witness(0, sha256(script), main)
|
||||||
|
|
||||||
def key_to_p2wpkh(key, main = False):
|
def key_to_p2wpkh(key, main=False):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
return program_to_witness(0, hash160(key), main)
|
return program_to_witness(0, hash160(key), main)
|
||||||
|
|
||||||
def script_to_p2sh_p2wsh(script, main = False):
|
def script_to_p2sh_p2wsh(script, main=False):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
p2shscript = CScript([OP_0, sha256(script)])
|
p2shscript = CScript([OP_0, sha256(script)])
|
||||||
return script_to_p2sh(p2shscript, main)
|
return script_to_p2sh(p2shscript, main)
|
||||||
|
|
||||||
def check_key(key):
|
def check_key(key):
|
||||||
if (type(key) is str):
|
if (type(key) is str):
|
||||||
key = hex_str_to_bytes(key) # Assuming this is hex string
|
key = hex_str_to_bytes(key) # Assuming this is hex string
|
||||||
if (type(key) is bytes and (len(key) == 33 or len(key) == 65)):
|
if (type(key) is bytes and (len(key) == 33 or len(key) == 65)):
|
||||||
return key
|
return key
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
def check_script(script):
|
def check_script(script):
|
||||||
if (type(script) is str):
|
if (type(script) is str):
|
||||||
script = hex_str_to_bytes(script) # Assuming this is hex string
|
script = hex_str_to_bytes(script) # Assuming this is hex string
|
||||||
if (type(script) is bytes or type(script) is CScript):
|
if (type(script) is bytes or type(script) is CScript):
|
||||||
return script
|
return script
|
||||||
assert False
|
assert False
|
||||||
|
Reference in New Issue
Block a user