# Also use nodemessages.anySpender to create a TxOut directly
from test_framework.util import hash160
from test_framework.script import CScript, OP_0


def anyonecanspend_locking_script():
    """
    This returns an anyoneCanSpend template output CScript.  Its basically
    [OP_0, hash160([]), OP_0] (no group, hash of no script, no args)
    Use nodemessages.py: anySpender(amount) to return an anyone-can-spend TxOut.
    """
    template_script = CScript([])
    hash_template = hash160(template_script)
    return CScript([OP_0, hash_template, OP_0])


def anyonecanspend_unlocking_script():
    """
    Give the input script that spends the above anyone can spend.
    This returns a CScript that pushes an empty CScript.
    """
    return CScript([CScript([])])


# pubkeysig to p2st
def p2st_locking_script(script: CScript):
    return CScript([OP_0, hash160(script), OP_0])


def p2st_unlocking_script(script: CScript):
    return CScript([script])
