Skip to content

multi should be parsed as terminal #8

@darosior

Description

@darosior

When parsing a multi from Script we treat it as a non-terminal fragment. It's a terminal so it should be treated as such.

In this function:

def parse_nonterm_3_elems(expr_list, idx):
"""
Try to parse a non-terminal node from *at least* three elements of
{expr_list}, starting from {idx}.
Return the new expression list on success, None if there was no match.
"""

# FIXME: multi is a terminal!
# Match against a multi.
try:
k = stack_item_to_int(expr_list[idx])
except ScriptNumError:
return
if k is None:
return
# <k> (<key>)* <m> CHECKMULTISIG
if k > len(expr_list[idx + 1 :]) - 2:
return
# Get the keys
keys = []
i = idx + 1
while idx < len(expr_list) - 2:
if not isinstance(expr_list[i], fragments.Pk):
break
keys.append(expr_list[i].pubkey)
i += 1
if expr_list[i + 1] == OP_CHECKMULTISIG:
if k > len(keys):
return
try:
m = stack_item_to_int(expr_list[i])
except ScriptNumError:
return
if m is None or m != len(keys):
return
node = fragments.Multi(k, keys)
expr_list[idx : i + 2] = [node]
return expr_list

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions