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

Function taproot_construct

test/functional/test_framework/script.py:1057–1078  ·  view source on GitHub ↗

Construct a tree of Taproot spending conditions pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes) scripts: a list of items; each item is either: - a (name, CScript or bytes, leaf version) tuple - a (name, CScript or bytes) tuple (defaulting to leaf ver

(pubkey, scripts=None)

Source from the content-addressed store, hash-verified

1055TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash")
1056
1057def taproot_construct(pubkey, scripts=None):
1058 """Construct a tree of Taproot spending conditions
1059
1060 pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes)
1061 scripts: a list of items; each item is either:
1062 - a (name, CScript or bytes, leaf version) tuple
1063 - a (name, CScript or bytes) tuple (defaulting to leaf version 0xc0)
1064 - another list of items (with the same structure)
1065 - a list of two items; the first of which is an item itself, and the
1066 second is a function. The function takes as input the Merkle root of the
1067 first item, and produces a (fictitious) partner to hash with.
1068
1069 Returns: a TaprootInfo object
1070 """
1071 if scripts is None:
1072 scripts = []
1073
1074 ret, h = taproot_tree_helper(scripts)
1075 tweak = TaggedHash("TapTweak/elements", pubkey + h)
1076 tweaked, negated = tweak_add_pubkey(pubkey, tweak)
1077 leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
1078 return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
1079
1080def is_op_success(o):
1081 return o == 80 or o == 98 or (o >= 137 and o <= 138) or (o >= 141 and o <= 142) or (o >= 149 and o <= 151) or (o >= 187 and o <= 191) or (o >= 229 and o <= 254)

Callers 7

create_taproot_utxoMethod · 0.90
create_taproot_utxoMethod · 0.90
compute_taproot_addressFunction · 0.90
spenders_taproot_activeFunction · 0.90
gen_test_vectorsMethod · 0.90

Calls 4

taproot_tree_helperFunction · 0.85
tweak_add_pubkeyFunction · 0.85
TaggedHashFunction · 0.70
CScriptClass · 0.70

Tested by

no test coverage detected