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:
def varint(s):
n = 0
while True:
ch = read1(s)
n = (n << 7) | (ch & 0x7f)
if ch & 0x80:
n += 1
else:
return n