I'm writing a parser for the blockchain for my myself. I've been following the specs at
https://en.bitcoin.it/wiki/Genesis_blockhttps://en.bitcoin.it/wiki/Protocol_specificationand
https://en.bitcoin.it/wiki/TransactionsI've got to the point where I can follow the chain down to block #29664.
My problem is that I don't know how to infer the length of certain data entries, namely:
- The number of transactions in a block
- The number of inputs to a transaction
- The number of outputs to a transaction
- The length of the transaction input script
- The length of the transaction output script
All of these entries are stated to be of length 1-9 bytes in the protocol specs.
But surely we need to have some way of predicting what length to read for these entries, in order to parse the chain successfully.
The (obviously flawed) assumption that they are always 1 byte long, fails at block #29664.
The only solution I can think of is trial and error until the block is parsed successfully (i.e. the magic bytes are correctly found at the start of the next block), but this seems really unsatisfactory.
Anyone know the solution to this problem?