What is the structure of bitcoin block?

0

1

If I understand correctly block consists of:

  • block header,
  • transactions counter,
  • list of signed transactions.

Each signed transaction consists of transaction itself and appended signature.

Each transaction consists of:

  • transaction version no,
  • number of inputs,
  • inputs themselves,
  • number of outputs,
  • outputs themselves and
  • locktime.

Each input consists of:

  • Reference to its outputing transaction
  • index of output in that transaction
  • scriptSig

Each output consists of:

  • output value
  • scriptPubKey

Is this structure correct?

croraf

Posted 2017-11-10T18:04:22.593

Reputation: 1 112

Where did you get 81 bytes from?Anonymous 2017-11-10T21:22:58.073

Found that figure on several places for example here: http://bitexperts.com/Question/Detail/3333/what-is-bitcoin-block-header-size-in-bytes, although 80 is more commonly shown. But here https://en.bitcoin.it/wiki/Block I find now there is more to the structure.

croraf 2017-11-11T10:17:47.077

It’s 80 bytes, not 81. They’re calling the number of transactions part of the header (and assuming its one byte), which it’s not.Anonymous 2017-11-11T10:19:05.070

So in general it is 1-9 bytes, is not part of the header and shows the actual number of transactions in this block (and not always 0)?croraf 2017-11-11T10:20:35.873

1Right. It’s just part of the way it’s encoded though, that varint for the number of transactions isn’t included in any hash. It means you don’t know the size of the block until you’ve parsed every single transaction too.Anonymous 2017-11-11T10:22:14.120

Don't you know the size from the block size field https://chat.stackexchange.com/rooms/68577/room-for-croraf-and-eponymous

croraf 2017-11-11T10:33:33.527

Answers

1

I'd like to partially answer your question on the tx structure: in general you are right, here some more detail, and yes, you can have several TX_INs and TX_OUTs:

VERSION
TX_IN COUNT
  TX_IN[0] OutPoint hash
  TX_IN[0] OutPoint index
  TX_IN[0] Script Length
  TX_IN[0] Script Sig
  TX_IN[0] Sequence      

TX_OUT COUNT
  TX_OUT[0] Value/Amount in Satoshi
  TX_OUT[0] PK_Script Length
  TX_OUT[0] pk_script     
 LOCK_TIME

So in general the VERSION field at the very beginning and the LOCKTIME at the end is an additional piece. For sure you find further details in the developper section of bitcoin.org, and in Andreas' book "Mastering Bitcoin" (also online available). Avery good overview of the details was also provided here: http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html I am not experienced enough to answer the part on the blocks, but it is also mentioned in the links.

pebwindkraft

Posted 2017-11-10T18:04:22.593

Reputation: 4 568