test: add script_util helper for creating bare multisig scripts

This commit is contained in:
Sebastian Falbesoner
2021-10-18 22:25:04 +02:00
parent 22a9018649
commit 4718897ce3
5 changed files with 23 additions and 18 deletions

View File

@@ -5,7 +5,9 @@
"""Useful Script constants and utils."""
from test_framework.script import (
CScript,
CScriptOp,
OP_0,
OP_CHECKMULTISIG,
OP_CHECKSIG,
OP_DUP,
OP_EQUAL,
@@ -41,6 +43,17 @@ def key_to_p2pk_script(key):
return CScript([key, OP_CHECKSIG])
def keys_to_multisig_script(keys, *, k=None):
n = len(keys)
if k is None: # n-of-n multisig by default
k = n
assert k <= n
op_k = CScriptOp.encode_op_n(k)
op_n = CScriptOp.encode_op_n(n)
checked_keys = [check_key(key) for key in keys]
return CScript([op_k] + checked_keys + [op_n, OP_CHECKMULTISIG])
def keyhash_to_p2pkh_script(hash):
assert len(hash) == 20
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])