Skip to content

Commit 18246ed

Browse files
committed
Fix and improve taproot_construct comments
1 parent 5009159 commit 18246ed

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

test/functional/test_framework/script.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,21 +824,33 @@ def taproot_tree_helper(scripts):
824824
h = TaggedHash("TapBranch", left_h + right_h)
825825
return (left + right, h)
826826

827+
# A TaprootInfo object has the following fields:
828+
# - scriptPubKey: the scriptPubKey (witness v1 CScript)
829+
# - inner_pubkey: the inner pubkey (32 bytes)
830+
# - negflag: whether the pubkey in the scriptPubKey was negated from inner_pubkey+tweak*G (bool).
831+
# - tweak: the tweak (32 bytes)
832+
# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
827833
TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,inner_pubkey,negflag,tweak,leaves")
834+
835+
# A TaprootLeafInfo object has the following fields:
836+
# - script: the leaf script (CScript or bytes)
837+
# - version: the leaf version (0xc0 for BIP342 tapscript)
838+
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
828839
TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch")
829840

830841
def taproot_construct(pubkey, scripts=None):
831842
"""Construct a tree of Taproot spending conditions
832843
833-
pubkey: an ECPubKey object for the internal pubkey
844+
pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes)
834845
scripts: a list of items; each item is either:
835-
- a (name, CScript) tuple
836-
- a (name, CScript, leaf version) tuple
846+
- a (name, CScript or bytes, leaf version) tuple
847+
- a (name, CScript or bytes) tuple (defaulting to leaf version 0xc0)
837848
- another list of items (with the same structure)
838-
- a function, which specifies how to compute the hashing partner
839-
in function of the hash of whatever it is combined with
849+
- a list of two items; the first of which is an item itself, and the
850+
second is a function. The function takes as input the Merkle root of the
851+
first item, and produces a (fictitious) partner to hash with.
840852
841-
Returns: script (sPK or redeemScript), tweak, {name:(script, leaf version, negation flag, innerkey, merklepath), ...}
853+
Returns: a TaprootInfo object
842854
"""
843855
if scripts is None:
844856
scripts = []

0 commit comments

Comments
 (0)