8

I'm creating a non-mainstream client that processes and validates Bitcoin transactions and need to track transactions in my database.

  • How is the TxID generated and when does it change?

Specifically, since sequence is intended to update a transaction, and if the transactions hash were to change I would assume the txid hash would change s well.

When I look at this image of a Tx, it appears that the txid is marked as TxIn (VI)

  • Is it possible or useful for a script to verify the TxID and signature hash?
makerofthings7
  • 12,726
  • 11
  • 62
  • 130

1 Answers1

7

TxID is just a SHA256 hash of binary transation data, so it changes upon any modification of transaction. Therefore, one cannot include verification of TxID in the script in same transaction (if I correctly understood what you want to achieve).

aland
  • 1,398
  • 8
  • 19
  • Maybe I'm confused... Where is the TxID? – makerofthings7 Dec 20 '12 at 23:08
  • 4
    The transaction id is used to refer to a transaction; it is not part of it. – Pieter Wuille Dec 20 '12 at 23:20
  • @PieterWuille Is the TxID a simple Sha256 hash of the tx data in it's entirety? Does that mean the TxID changes if the sequence # changes? How should I track revisions (new sequences) of the same tx? – makerofthings7 Dec 21 '12 at 06:17
  • @makerofthings7 Yes, it is just hash of all data. If tx data changes then it is NOT the same tx. – aland Dec 21 '12 at 08:13
  • 1
    It is a double-SHA256 of the serialized transaction. So indeed, the sequence number is part of. Changing the sequence number means you get a new transaction, but there is some (currently disabled) code in the reference client which can detect one transaction as a 'new version' of another, and replace it. – Pieter Wuille Dec 21 '12 at 10:39
  • @PieterWuille does generating txid mean you hash the scriptSif & scriptPubKey as well ? – Haddar Macdasi Apr 29 '15 at 16:09
  • Yes, any change at all, including any non-sensical or irrelevant change, will change the transaction id. – Pieter Wuille Apr 30 '15 at 05:58