[Ethereum] Decoding ethereum leveldb keys and values

cpp-ethereumleveldbparser

I've created a simple script to read ethereum data from the leveldb using C++. Basically this testing program would print all keys in leveldb to the console.

#include <cassert>
#include <iostream>
#include "leveldb/db.h"
using namespace std;
// g++ leveldb_test.cpp -o test -lleveldb
int main(int argc, const char *argv[]) {
    leveldb::DB* db;
    leveldb::Options options;
    options.create_if_missing = true;
    leveldb::Status status = leveldb::DB::Open(options, "/home/user/.ethereum/rinkeby/geth/chaindata", &db);

    if (!status.ok()){
        cerr << status.ToString() << endl;
        delete db;
        return 0;
    }
    leveldb::Iterator* it = db->NewIterator(leveldb::ReadOptions());
    for (it->SeekToFirst(); it->Valid(); it->Next()) {
        cout << it->key().ToString() << endl; 
    }
    delete it;
    delete db;
    return 1;
}

but the results are encoded like this.

console output image

How can I output a readable output? Is there a way to decode the ethereum leveldb data? (may be a c++ library?)

Best Answer

Not sure if it really helps you, i have tried reading statetrie following https://medium.com/cybermiles/diving-into-ethereums-world-state-c893102030ed. My output is something like this,

key:9bd9f586100bd06ef90756fd3aaad9e2ab641443d22cb185d364d627964c1855
[ <Buffer 09>,
  <Buffer 03 2e db 3c fb 1d 5c 00>,
  <Buffer 56 e8 1f 17 1b cc 55 a6 ff 83 45 e6 92 c0 f8 6e 5b 48 e0 1b 99 6c ad c0 01 62 2f b5 e3 63 b4 21>,
  <Buffer c5 d2 46 01 86 f7 23 3c 92 7e 7d b2 dc c7 03 c0 e5 00 b6 53 ca 82 27 3b 7b fa d8 04 5d 85 a4 70> ]
Related Topic