Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: FabioCarpi on January 14, 2015, 07:39:09 PM



Title: block raw decode
Post by: FabioCarpi on January 14, 2015, 07:39:09 PM
get the raw of block 0
Code:
f9beb4d9 - mainnet
1d010000 - lenght (varint)
01000000 - versao
0000000000000000000000000000000000000000000000000000000000000000 - hash
3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a - merkle
29ab5f49 - time
ffff001d - bits
1dac2b7c - nonce
01 - tx count
   01000000 - tx version
   01 - in count
      0000000000000000000000000000000000000000000000000000000000000000 - prev_hash
      ffffffff - vout
      4d - script count (77)
      04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73 - script sig
      ffffffff - sequence
   01 - out count
      00f2052a01000000 - value
      4341 - script count
      04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac - script key
   00000000 - lock time
have a easy way to get the raw of each tx?
i miss a byte like "tx lengh" after the tx count...
my dificult is because the script count maybe 1 or 2 bytes...


Title: Re: block raw decode
Post by: grau on January 14, 2015, 07:45:58 PM
No need for tx length. Parse transactions starting afte rthe block header following https://en.bitcoin.it/wiki/Protocol_specification#tx


Title: Re: block raw decode
Post by: johoe on January 14, 2015, 09:03:14 PM
have a easy way to get the raw of each tx?
i miss a byte like "tx lengh" after the tx count...

You have to parse the transaction.

my dificult is because the script count maybe 1 or 2 bytes...

the script length is a varint (https://en.bitcoin.it/wiki/Protocol_specification#Variable_length_integer).  You got the parsing a wrong in the second script.

43 is the length of the script. The script is 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4ce f38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac, the first opcode (0x41) pushes the next 0x41 bytes (public key), the second opcode is 0xac (OP_CHECKSIG)



Title: Re: block raw decode
Post by: amaclin on January 15, 2015, 07:59:06 AM
Quote
f9beb4d9 - mainnet
1d010000 - lenght (varint)
01000000 - versao

block length is not varint