MCPcopy Create free account
hub / github.com/ElementsProject/elements / make_spender

Function make_spender

test/functional/feature_taproot.py:525–610  ·  view source on GitHub ↗

Helper for constructing Spender objects using the context signing framework. * tap: a TaprootInfo object (see taproot_construct), for Taproot spends (cannot be combined with pkh, witv0, or script) * witv0: boolean indicating the use of witness v0 spending (needs one of script or pkh) *

(comment, *, tap=None, witv0=False, script=None, pkh=None, p2sh=False, genesis_hash=None, spk_mutate_pre_p2sh=None, failure=None, standard=Standard.ALL, err_msg=None, sigops_weight=0, need_vin_vout_mismatch=False, **kwargs)

Source from the content-addressed store, hash-verified

523Standard = Enum('Standard', 'ALL V23 NONE')
524
525def make_spender(comment, *, tap=None, witv0=False, script=None, pkh=None, p2sh=False, genesis_hash=None, spk_mutate_pre_p2sh=None, failure=None, standard=Standard.ALL, err_msg=None, sigops_weight=0, need_vin_vout_mismatch=False, **kwargs):
526 """Helper for constructing Spender objects using the context signing framework.
527
528 * tap: a TaprootInfo object (see taproot_construct), for Taproot spends (cannot be combined with pkh, witv0, or script)
529 * witv0: boolean indicating the use of witness v0 spending (needs one of script or pkh)
530 * script: the actual script executed (for bare/P2WSH/P2SH spending)
531 * pkh: the public key for P2PKH or P2WPKH spending
532 * p2sh: whether the output is P2SH wrapper (this is supported even for Taproot, where it makes the output unencumbered)
533 * spk_mutate_pre_psh: a callable to be applied to the script (before potentially P2SH-wrapping it)
534 * failure: a dict of entries to override in the context when intentionally failing to spend (if None, no_fail will be set)
535 * standard: whether the (valid version of) spending is expected to be standard (True is mapped to Standard.ALL, False is mapped to Standard.NONE)
536 * err_msg: a string with an expected error message for failure (or None, if not cared about)
537 * sigops_weight: the pre-taproot sigops weight consumed by a successful spend
538 * need_vin_vout_mismatch: whether this test requires being tested in a transaction input that has no corresponding
539 transaction output.
540 """
541
542 if standard == True:
543 standard = Standard.ALL
544 elif standard == False:
545 standard = Standard.NONE
546
547 conf = dict()
548 global g_genesis_hash
549 if genesis_hash is None:
550 genesis_hash = g_genesis_hash
551 conf["genesis_hash"] = genesis_hash
552
553 # Compute scriptPubKey and set useful defaults based on the inputs.
554 if witv0:
555 assert tap is None
556 conf["mode"] = "witv0"
557 if pkh is not None:
558 # P2WPKH
559 assert script is None
560 pubkeyhash = hash160(pkh)
561 spk = key_to_p2wpkh_script(pkh)
562 conf["scriptcode"] = keyhash_to_p2pkh_script(pubkeyhash)
563 conf["script_witv0"] = None
564 conf["inputs"] = [getter("sign"), pkh]
565 elif script is not None:
566 # P2WSH
567 spk = script_to_p2wsh_script(script)
568 conf["scriptcode"] = script
569 conf["script_witv0"] = script
570 else:
571 assert False
572 elif tap is None:
573 conf["mode"] = "legacy"
574 if pkh is not None:
575 # P2PKH
576 assert script is None
577 pubkeyhash = hash160(pkh)
578 spk = keyhash_to_p2pkh_script(pubkeyhash)
579 conf["scriptcode"] = spk
580 conf["inputs"] = [getter("sign"), pkh]
581 elif script is not None:
582 # bare

Callers 1

add_spenderFunction · 0.85

Calls 6

key_to_p2wpkh_scriptFunction · 0.90
keyhash_to_p2pkh_scriptFunction · 0.90
script_to_p2wsh_scriptFunction · 0.90
script_to_p2sh_scriptFunction · 0.90
getterFunction · 0.85
hash160Function · 0.50

Tested by

no test coverage detected