Title: parsing leveldb txindex Post by: ivoras on May 25, 2015, 10:41:14 PM I'm trying to parse the LevelDB txindex, i.e. fetch raw transaction data given a transaction hash.
I'm reading a key-value pair from LevelDB with 't' + hash_bytes, and e.g. for transaction 444b7ecbda319e184da1a3d68968e6e0ca9346ddcf7afd0e2b887a7949128805 the key's value is 80 58 8f c4 c8 66 80 9b 24 Now, if I'm reading the bitcoin source correctly, this should be three varints:
If I'm correctly decoding them, the 3 values are: 216 34694374 20004 -- which looks good. However, the data at offset 34694374 + 20004 in file 216 is unexpected: version: 4293214589 inCount: 93952409796607 It looks like either I'm decoding the varints the wrong way or I'm calculating the file offset wrongly? The varint read+decode code is mostly a direct port from C: Code: def varint(s): Title: Re: parsing leveldb txindex Post by: cirosantilli on February 15, 2024, 08:50:21 AM I've also opened a related thread at: https://bitcoin.stackexchange.com/questions/121888/what-is-the-data-format-layout-for-txindex-leveldb-values I've made some progress in Python, but I must still have a bug in my code.
Title: Re: parsing leveldb txindex Post by: NotATether on February 15, 2024, 10:59:05 AM Maybe this will help you parse the varints?
Code: def parse_varint_hex(data): This is what I use in my implementation. Your code looks like it's reading something else, but not a varint. I would advise you to test your function on some sample cases for which you know what the varint is supposed to decode to, because generally speaking, C and Python have slightly different semantics that might break ported code. Title: Re: parsing leveldb txindex Post by: cirosantilli on February 16, 2024, 08:45:43 AM Maybe this will help you parse the varints? Unfortunately not, that is a different varint thing: https://bitcoin.stackexchange.com/questions/121888/what-is-the-data-format-layout-for-txindex-leveldb-values/121889#121889 |