0

I am trying to iterate through the ethereum ldb files. When I run this code my iterator believes there is nothing stored on the ropsten's testnet blockchain. There are no errors, and the iter gets to the for loop's test for whether it hasNext(). So it loads the DB properly, just doesn't recognize the keys.

I am using Dain's LevelDB API.

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    Options options = new Options();
    options.createIfMissing(false);
    ReadOptions ROoptions = new ReadOptions();
    try {
        DB db = factory.open(new File("chaindata"), options);
        ROoptions.snapshot(db.getSnapshot());
        try {
            // Use the db in here....
            System.out.println("Creating itr");
            DBIterator iterator = db.iterator(ROoptions);
            try {
                System.out.println("Testing itr");
                for (iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
                    String key = asString(iterator.peekNext().getKey());
                    String value = asString(iterator.peekNext().getValue());
                    System.out.println(key + " = " + value);
                }
            } finally {
                // Make sure you close the iterator to avoid resource leaks.
                iterator.close();
            }

        } finally {
            // Make sure you close the db to shutdown the
            // database and avoid resource leaks.
            db.close();
        }
    } catch (FileNotFoundException E) {
        System.out.println("File not found! " + E);
        throw new FileNotFoundException();
    }

}

}
  • I doubt somebody could help you with this one, you put the code and said "it doesn't work", this doesn't help us. Run a debugger, watch the variables, and then if you have a specific question, post it – Nulik Oct 8 '17 at 3:38
0

Two things were wrong with my code.

  1. The source of the folder was incorrect, so I was not grabbing the right files.

  2. Dain's levelDB only works with .sst files and not .ldb. LevelDB updated because of a conflict with the Windows core files. This caused me issues after I fixed the folder issue.

I hope this helps someone else in the future.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.