Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi should be parsed as terminal #8

Open
darosior opened this issue Aug 12, 2021 · 0 comments
Open

multi should be parsed as terminal #8

darosior opened this issue Aug 12, 2021 · 0 comments
Labels
good first issue Good for newcomers

Comments

@darosior
Copy link
Owner

darosior commented Aug 12, 2021

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

@darosior darosior added the good first issue Good for newcomers label May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant