@@ -805,20 +805,20 @@ def taproot_tree_helper(scripts):
805805 h = TaggedHash ("TapLeaf" , bytes ([version ]) + ser_string (code ))
806806 if name is None :
807807 return ([], h )
808- return ([(name , version , code , bytes ())], h )
808+ return ([(name , version , code , bytes (), h )], h )
809809 elif len (scripts ) == 2 and callable (scripts [1 ]):
810810 # Two entries, and the right one is a function
811811 left , left_h = taproot_tree_helper (scripts [0 :1 ])
812812 right_h = scripts [1 ](left_h )
813- left = [(name , version , script , control + right_h ) for name , version , script , control in left ]
813+ left = [(name , version , script , control + right_h , leaf ) for name , version , script , control , leaf in left ]
814814 right = []
815815 else :
816816 # Two or more entries: descend into each side
817817 split_pos = len (scripts ) // 2
818818 left , left_h = taproot_tree_helper (scripts [0 :split_pos ])
819819 right , right_h = taproot_tree_helper (scripts [split_pos :])
820- left = [(name , version , script , control + right_h ) for name , version , script , control in left ]
821- right = [(name , version , script , control + left_h ) for name , version , script , control in right ]
820+ left = [(name , version , script , control + right_h , leaf ) for name , version , script , control , leaf in left ]
821+ right = [(name , version , script , control + left_h , leaf ) for name , version , script , control , leaf in right ]
822822 if right_h < left_h :
823823 right_h , left_h = left_h , right_h
824824 h = TaggedHash ("TapBranch" , left_h + right_h )
@@ -830,13 +830,14 @@ def taproot_tree_helper(scripts):
830830# - negflag: whether the pubkey in the scriptPubKey was negated from internal_pubkey+tweak*G (bool).
831831# - tweak: the tweak (32 bytes)
832832# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
833- TaprootInfo = namedtuple ("TaprootInfo" , "scriptPubKey,internal_pubkey,negflag,tweak,leaves" )
833+ # - merkle_root: the script tree's Merkle root, or bytes() if no leaves are present
834+ TaprootInfo = namedtuple ("TaprootInfo" , "scriptPubKey,internal_pubkey,negflag,tweak,leaves,merkle_root,output_pubkey" )
834835
835836# A TaprootLeafInfo object has the following fields:
836837# - script: the leaf script (CScript or bytes)
837838# - version: the leaf version (0xc0 for BIP342 tapscript)
838839# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
839- TaprootLeafInfo = namedtuple ("TaprootLeafInfo" , "script,version,merklebranch" )
840+ TaprootLeafInfo = namedtuple ("TaprootLeafInfo" , "script,version,merklebranch,leaf_hash " )
840841
841842def taproot_construct (pubkey , scripts = None ):
842843 """Construct a tree of Taproot spending conditions
@@ -858,8 +859,8 @@ def taproot_construct(pubkey, scripts=None):
858859 ret , h = taproot_tree_helper (scripts )
859860 tweak = TaggedHash ("TapTweak" , pubkey + h )
860861 tweaked , negated = tweak_add_pubkey (pubkey , tweak )
861- leaves = dict ((name , TaprootLeafInfo (script , version , merklebranch )) for name , version , script , merklebranch in ret )
862- return TaprootInfo (CScript ([OP_1 , tweaked ]), pubkey , negated + 0 , tweak , leaves )
862+ leaves = dict ((name , TaprootLeafInfo (script , version , merklebranch , leaf )) for name , version , script , merklebranch , leaf in ret )
863+ return TaprootInfo (CScript ([OP_1 , tweaked ]), pubkey , negated + 0 , tweak , leaves , h , tweaked )
863864
864865def is_op_success (o ):
865866 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 )
0 commit comments