mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
tests: add more fields to TaprootInfo
This commit is contained in:
parent
2478c6730a
commit
5140825096
1 changed files with 9 additions and 8 deletions
|
@ -805,20 +805,20 @@ def taproot_tree_helper(scripts):
|
||||||
h = TaggedHash("TapLeaf", bytes([version]) + ser_string(code))
|
h = TaggedHash("TapLeaf", bytes([version]) + ser_string(code))
|
||||||
if name is None:
|
if name is None:
|
||||||
return ([], h)
|
return ([], h)
|
||||||
return ([(name, version, code, bytes())], h)
|
return ([(name, version, code, bytes(), h)], h)
|
||||||
elif len(scripts) == 2 and callable(scripts[1]):
|
elif len(scripts) == 2 and callable(scripts[1]):
|
||||||
# Two entries, and the right one is a function
|
# Two entries, and the right one is a function
|
||||||
left, left_h = taproot_tree_helper(scripts[0:1])
|
left, left_h = taproot_tree_helper(scripts[0:1])
|
||||||
right_h = scripts[1](left_h)
|
right_h = scripts[1](left_h)
|
||||||
left = [(name, version, script, control + right_h) for name, version, script, control in left]
|
left = [(name, version, script, control + right_h, leaf) for name, version, script, control, leaf in left]
|
||||||
right = []
|
right = []
|
||||||
else:
|
else:
|
||||||
# Two or more entries: descend into each side
|
# Two or more entries: descend into each side
|
||||||
split_pos = len(scripts) // 2
|
split_pos = len(scripts) // 2
|
||||||
left, left_h = taproot_tree_helper(scripts[0:split_pos])
|
left, left_h = taproot_tree_helper(scripts[0:split_pos])
|
||||||
right, right_h = taproot_tree_helper(scripts[split_pos:])
|
right, right_h = taproot_tree_helper(scripts[split_pos:])
|
||||||
left = [(name, version, script, control + right_h) for name, version, script, control in left]
|
left = [(name, version, script, control + right_h, leaf) for name, version, script, control, leaf in left]
|
||||||
right = [(name, version, script, control + left_h) for name, version, script, control in right]
|
right = [(name, version, script, control + left_h, leaf) for name, version, script, control, leaf in right]
|
||||||
if right_h < left_h:
|
if right_h < left_h:
|
||||||
right_h, left_h = left_h, right_h
|
right_h, left_h = left_h, right_h
|
||||||
h = TaggedHash("TapBranch", left_h + right_h)
|
h = TaggedHash("TapBranch", left_h + right_h)
|
||||||
|
@ -830,13 +830,14 @@ def taproot_tree_helper(scripts):
|
||||||
# - negflag: whether the pubkey in the scriptPubKey was negated from internal_pubkey+tweak*G (bool).
|
# - negflag: whether the pubkey in the scriptPubKey was negated from internal_pubkey+tweak*G (bool).
|
||||||
# - tweak: the tweak (32 bytes)
|
# - tweak: the tweak (32 bytes)
|
||||||
# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
|
# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
|
||||||
TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,internal_pubkey,negflag,tweak,leaves")
|
# - merkle_root: the script tree's Merkle root, or bytes() if no leaves are present
|
||||||
|
TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,internal_pubkey,negflag,tweak,leaves,merkle_root,output_pubkey")
|
||||||
|
|
||||||
# A TaprootLeafInfo object has the following fields:
|
# A TaprootLeafInfo object has the following fields:
|
||||||
# - script: the leaf script (CScript or bytes)
|
# - script: the leaf script (CScript or bytes)
|
||||||
# - version: the leaf version (0xc0 for BIP342 tapscript)
|
# - version: the leaf version (0xc0 for BIP342 tapscript)
|
||||||
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
|
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
|
||||||
TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch")
|
TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash")
|
||||||
|
|
||||||
def taproot_construct(pubkey, scripts=None):
|
def taproot_construct(pubkey, scripts=None):
|
||||||
"""Construct a tree of Taproot spending conditions
|
"""Construct a tree of Taproot spending conditions
|
||||||
|
@ -858,8 +859,8 @@ def taproot_construct(pubkey, scripts=None):
|
||||||
ret, h = taproot_tree_helper(scripts)
|
ret, h = taproot_tree_helper(scripts)
|
||||||
tweak = TaggedHash("TapTweak", pubkey + h)
|
tweak = TaggedHash("TapTweak", pubkey + h)
|
||||||
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
|
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
|
||||||
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch)) for name, version, script, merklebranch in ret)
|
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
|
||||||
return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves)
|
return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
|
||||||
|
|
||||||
def is_op_success(o):
|
def is_op_success(o):
|
||||||
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)
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue