MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / taproot_construct

Function taproot_construct

test/functional/test_framework/script.py:917–941  ·  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, treat_internal_as_infinity=False)

Source from the content-addressed store, hash-verified

915TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash")
916
917def taproot_construct(pubkey, scripts=None, treat_internal_as_infinity=False):
918 """Construct a tree of Taproot spending conditions
919
920 pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes)
921 scripts: a list of items; each item is either:
922 - a (name, CScript or bytes, leaf version) tuple
923 - a (name, CScript or bytes) tuple (defaulting to leaf version 0xc0)
924 - another list of items (with the same structure)
925 - a list of two items; the first of which is an item itself, and the
926 second is a function. The function takes as input the Merkle root of the
927 first item, and produces a (fictitious) partner to hash with.
928
929 Returns: a TaprootInfo object
930 """
931 if scripts is None:
932 scripts = []
933
934 ret, h = taproot_tree_helper(scripts)
935 tweak = TaggedHash("TapTweak", pubkey + h)
936 if treat_internal_as_infinity:
937 tweaked, negated = compute_xonly_pubkey(tweak)
938 else:
939 tweaked, negated = tweak_add_pubkey(pubkey, tweak)
940 leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
941 return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
942
943def is_op_success(o):
944 return o == 0x50 or o == 0x62 or o == 0x89 or o == 0x8a or o == 0x8d or o == 0x8e or (o >= 0x7e and o <= 0x81) or (o >= 0x83 and o <= 0x86) or (o >= 0x95 and o <= 0x99) or (o >= 0xbb and o <= 0xfe)

Callers 7

compute_taproot_addressFunction · 0.90
spenders_taproot_activeFunction · 0.90
sample_spendersFunction · 0.90
gen_test_vectorsMethod · 0.90
getnewdestinationFunction · 0.90

Calls 5

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

Tested by

no test coverage detected