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)
| 1055 | TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash") |
| 1056 | |
| 1057 | def 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 | |
| 1080 | def 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) |
no test coverage detected