Author

Topic: Blockchain parsing (Read 1824 times)

newbie
Activity: 16
Merit: 0
May 20, 2013, 08:41:37 AM
#10
Like a charm, cheers zeilap. I haz blockchain!!
newbie
Activity: 16
Merit: 0
May 20, 2013, 07:27:00 AM
#9
Anyone know the solution to this problem?

https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer

Read the first byte as uint8 and check its value, you have 4 choices,

<0xFD:          use the value as it is
  0xFD:           read 2 more bytes as uint16
  0xFE:           read 4 more bytes as uint32
  0xFF:           read 8 more bytes as uint64


Thanks Zeilap, I think I follow, I hadn't found that entry in the specification before, I'll try it out when I get a chance.
member
Activity: 112
Merit: 10
May 20, 2013, 02:09:23 AM
#8
nice I need more
full member
Activity: 154
Merit: 100
May 19, 2013, 06:08:56 PM
#7
Anyone know the solution to this problem?

https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer

Read the first byte as uint8 and check its value, you have 4 choices,

<0xFD:          use the value as it is
  0xFD:           read 2 more bytes as uint16
  0xFE:           read 4 more bytes as uint32
  0xFF:           read 8 more bytes as uint64
full member
Activity: 140
Merit: 100
Ad Infinitum Et Ultra
May 19, 2013, 01:51:52 PM
#6
looks interesting. ill be watching this
newbie
Activity: 14
Merit: 0
May 19, 2013, 01:37:50 PM
#5
I want more!
newbie
Activity: 16
Merit: 0
May 19, 2013, 12:09:31 PM
#4
Do you have taken a look on the source code of at least one random Bitcoin client?

Thanks for your reply!

I haven't, but I don't know what I would be looking for. I know what is in the data, I just don't know how long those fields are in any given block. I don't think a client code would help me.

I could have a look at another parser, but the whole reason I decided to write my own was because I couldn't find a clear simple one, and up to now it's been quite straightforward.

Any more help is welcome!
full member
Activity: 141
Merit: 100
May 19, 2013, 10:36:09 AM
#3
Do you have taken a look on the source code of at least one random Bitcoin client?
newbie
Activity: 16
Merit: 0
May 19, 2013, 09:59:20 AM
#2
Bump, help a man out!
newbie
Activity: 16
Merit: 0
May 19, 2013, 09:40:00 AM
#1

I'm writing a parser for the blockchain for my myself. I've been following the specs at

https://en.bitcoin.it/wiki/Genesis_block
https://en.bitcoin.it/wiki/Protocol_specification
and
https://en.bitcoin.it/wiki/Transactions

I'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?
Jump to: