I'm new here :)

I'm writing a c++ program that parses ethereum chain data. As of present I was able to get the key value pairs by using leveldb::ReadOptions command (as illustrated in the below code) and convert them into hex. I know there is some sort of RLP encoding to encode the "value" Values and hex prefix encoding to encode the "key" values. Some sort of hashing might also be used.

My issues are:

  1. How can i know what data i'm getting

  2. How can i verify the data is correct

The below code is what i have written so far:

leveldb::DB* db;

leveldb::Options options;

leveldb::Status status;

leveldb::ReadOptions readOptions;

options.error_if_exists = false;

options.create_if_missing = false;

status = db->Open(options, path, &db);

if (!status.ok()) {

    std::cout << status.ToString() << std::endl;

    return -1;

try {

    leveldb::Iterator* iterator = db->NewIterator(leveldb::ReadOptions());


    while (iterator->Valid() && iterator->status().ok()) {

        leveldb::Slice key = iterator->key();
        leveldb::Slice value = iterator->value();
        std::string keyString = key.ToString();
        std::string valueString = value.ToString();
        const char* keyData = key.data();
        const char* valueData = value.data();
        std::cout << "Key: " << GetHex(key.ToString()) << std::endl 
        std::cout << "Value: " << GetHex(value.ToString()) << std::endl;             
catch (const std::exception& e) {

    std::cout << e.what();

Thanks In Advance and sorry if the code is not really readable but this is the first time i'm writing a post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.