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

fix: make Transaction.from_raw() able to parse unsigned segwit tx #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hcleonis
Copy link

Although Transaction.from_raw() is able to parse a signed or unsigned legacy tx, it is only able to correctly parse signed segwit txs because it assumes the presence of witnesses in the tx payload.
But unsigned segwit tx payloads do not have any witness field.

This PR proposes to fix that by checking the number of remaining bytes between the end of the last output and the end of the tx payload and by skipping the witnesses parsing if that number is not greater than 4 (i.e. last tx field i.e. locktime length).

hcleonis added 2 commits June 27, 2024 16:58
Although Transaction.from_raw() is able to parse a signed or unsigned
legacy tx, it is only able to correctly parse signed segwit txs because
it assumes the presence of witnesses in the tx payload. But unsigned
segwit tx payload do not have any witness. This PR proposes to fix that
by checking the number of remaining bytes between the end of the last
output and the end of the payload and by skipping the witnesses parsing
if that number is not greater than 4 (locktime field length).
@karask
Copy link
Owner

karask commented Jul 3, 2024

Hi @hcleonis ! Looks good. Can you add a test (in tests) with the example you used to test it? I will then review and merge.

Thank you

@hcleonis
Copy link
Author

hcleonis commented Jul 8, 2024

Hi @hcleonis ! Looks good. Can you add a test (in tests) with the example you used to test it? I will then review and merge.

Thank you

Great! I'm on something else right now but I'll do that as soon as I can.

@boris-on
Copy link

boris-on commented Aug 20, 2024

Great job, thank you for fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants