mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 18:53:21 +01:00
test: add script_util helper for creating bare multisig scripts
This commit is contained in:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user