Skip to content

Commit 7d4ea7c

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23120: test: Remove unused and confusing main parameter from script_util
fa54efd test: pep-8 touched test (MarcoFalke) fa46768 test: Remove unused and confusing main parameter from script_util (MarcoFalke) Pull request description: ACKs for top commit: fanquake: ACK fa54efd Tree-SHA512: 124e888e16c92bb24ab4d6f68a768d295500a48f8c6c0b4f069493effcd761f80be78dd93b31edbb529ebe4c8aaca764aaff48d1e3b23659dde722981dc787a5
2 parents 3c776fd + fa54efd commit 7d4ea7c

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

test/functional/test_framework/script_util.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Useful Script constants and utils."""
6-
from test_framework.script import CScript, hash160, sha256, OP_0, OP_DUP, OP_HASH160, OP_CHECKSIG, OP_EQUAL, OP_EQUALVERIFY
6+
from test_framework.script import (
7+
CScript,
8+
hash160,
9+
sha256,
10+
OP_0,
11+
OP_DUP,
12+
OP_HASH160,
13+
OP_CHECKSIG,
14+
OP_EQUAL,
15+
OP_EQUALVERIFY,
16+
)
717

818
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
919
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
@@ -25,58 +35,69 @@
2535
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
2636
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
2737

28-
def keyhash_to_p2pkh_script(hash, main = False):
38+
39+
def keyhash_to_p2pkh_script(hash):
2940
assert len(hash) == 20
3041
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])
3142

32-
def scripthash_to_p2sh_script(hash, main = False):
43+
44+
def scripthash_to_p2sh_script(hash):
3345
assert len(hash) == 20
3446
return CScript([OP_HASH160, hash, OP_EQUAL])
3547

36-
def key_to_p2pkh_script(key, main = False):
48+
49+
def key_to_p2pkh_script(key):
3750
key = check_key(key)
38-
return keyhash_to_p2pkh_script(hash160(key), main)
51+
return keyhash_to_p2pkh_script(hash160(key))
3952

40-
def script_to_p2sh_script(script, main = False):
53+
54+
def script_to_p2sh_script(script):
4155
script = check_script(script)
42-
return scripthash_to_p2sh_script(hash160(script), main)
56+
return scripthash_to_p2sh_script(hash160(script))
57+
4358

44-
def key_to_p2sh_p2wpkh_script(key, main = False):
59+
def key_to_p2sh_p2wpkh_script(key):
4560
key = check_key(key)
4661
p2shscript = CScript([OP_0, hash160(key)])
47-
return script_to_p2sh_script(p2shscript, main)
62+
return script_to_p2sh_script(p2shscript)
63+
4864

49-
def program_to_witness_script(version, program, main = False):
65+
def program_to_witness_script(version, program):
5066
if isinstance(program, str):
5167
program = bytes.fromhex(program)
5268
assert 0 <= version <= 16
5369
assert 2 <= len(program) <= 40
5470
assert version > 0 or len(program) in [20, 32]
5571
return CScript([version, program])
5672

57-
def script_to_p2wsh_script(script, main = False):
73+
74+
def script_to_p2wsh_script(script):
5875
script = check_script(script)
59-
return program_to_witness_script(0, sha256(script), main)
76+
return program_to_witness_script(0, sha256(script))
77+
6078

61-
def key_to_p2wpkh_script(key, main = False):
79+
def key_to_p2wpkh_script(key):
6280
key = check_key(key)
63-
return program_to_witness_script(0, hash160(key), main)
81+
return program_to_witness_script(0, hash160(key))
82+
6483

65-
def script_to_p2sh_p2wsh_script(script, main = False):
84+
def script_to_p2sh_p2wsh_script(script):
6685
script = check_script(script)
6786
p2shscript = CScript([OP_0, sha256(script)])
68-
return script_to_p2sh_script(p2shscript, main)
87+
return script_to_p2sh_script(p2shscript)
88+
6989

7090
def check_key(key):
7191
if isinstance(key, str):
72-
key = bytes.fromhex(key) # Assuming this is hex string
92+
key = bytes.fromhex(key) # Assuming this is hex string
7393
if isinstance(key, bytes) and (len(key) == 33 or len(key) == 65):
7494
return key
7595
assert False
7696

97+
7798
def check_script(script):
7899
if isinstance(script, str):
79-
script = bytes.fromhex(script) # Assuming this is hex string
100+
script = bytes.fromhex(script) # Assuming this is hex string
80101
if isinstance(script, bytes) or isinstance(script, CScript):
81102
return script
82103
assert False

0 commit comments

Comments
 (0)