python-bitcoin-utils icon indicating copy to clipboard operation
python-bitcoin-utils copied to clipboard

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

Open hcleonis opened this issue 1 year ago • 3 comments

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 avatar Jun 27 '24 14:06 hcleonis

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

karask avatar Jul 03 '24 12:07 karask

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.

hcleonis avatar Jul 08 '24 09:07 hcleonis

Great job, thank you for fix

boris-on avatar Aug 20 '24 15:08 boris-on

PR rebased onto 0.7.2. Will add a test soon.

hcleonis avatar Mar 17 '25 08:03 hcleonis

Hello @karask :wave: I've added a test that validates the unsigned segwit tx parsing with Transaction.from_raw(). It ran OK on my side. I'll let you review & merge as you see fit.

hcleonis avatar Apr 01 '25 09:04 hcleonis