Getting transaction id from raw transaction of a multisig address

0

I am able to get the tx id (or transaction hash) of almost any transaction but the one where the script starts with an "OP_O" (which is, I think, the null dummy introduced here https://github.com/bitcoin/bitcoin/pull/3843)

For example:

https://www.blockchain.com/btc/tx/97d1b00fcef1f19531a19bb1722635341a9f2ad261ecf6eed89eca2cbd3bb3ee

How am I suppose to get the txid of this transaction? And how is it different from a regular (without multisig) one?

Kevin P

Posted 2018-10-24T16:29:04.783

Reputation: 49

Answers

1

How am I suppose to get the txid of this transaction?

The same way you get the txid of any other transaction, by hashing it (unless it is segwit). Note that the transaction you linked to is not a segwit transaction, so you can just take its hash.

If the transaction is a segwit transaction (as indicated by the marker and flag bytes of 0x0001 following the version bytes), then you need to only hash the parts that are non-segwit. Specifically, you drop all of the segwit parts (so the marker and flag and any witnesses which can be found between the last output and the locktime), and hash what is left. This is described in BIP 144.

And how is it different from a regular (without multisig) one?

There isn't.

Andrew Chow

Posted 2018-10-24T16:29:04.783

Reputation: 40 910

Thank you, I will double-check my code. I tested it on a full block (about 2k txs) and the only times the txid didn't match (20 times) was when a "OP_0" appeared in one of the inputs scripts.Kevin P 2018-10-24T18:07:56.720

Also, I don't simply hash the transaction as it is. I parse it, store all its elements in a data structure, and then append them back and hash them (I use the tx id as an error check).Kevin P 2018-10-24T18:11:38.997

OP_0 is used in segwit transactions too, so that may be your problem.Andrew Chow 2018-10-24T19:30:50.093

Problem solved: I had a problem with my "varint" function... Thank you!Kevin P 2018-10-25T06:29:05.760