8

I'm looking for the format of the LDB files in order to fetch all the contracts created by my account.

I read in a post on reddit (https://www.reddit.com/r/ethereum/comments/64hhp1/getting_block_data_from_ldb_files/) that I may want to use the Go API. But I am not able to find an API that does not goes through the RPC-Geth service. This is a problem because: a) RPC service does not provides this kind of service. b) Even if it does, it would probably be too slow.

Can anybody point me to an existent solution, or a Go API library, or to explain me what part of Geth accesses the chain files, for being able to develop it myself?

Thanks a lot!!

1
  • I thought about taking this approach for my work on QuickBlocks.io, but I decided against it because I would be at the mercy of the go (or Rust) code. I think it's a much better idea to use the RPC. It is slow, but it works, and you could always cache the data if you wanted to. That's exactly what we did with QuickBlocks. May 2, 2017 at 15:37

1 Answer 1

3

...or a Go API library, or to explain me what part of Geth accesses the chain files, for being able to develop it myself?

Have a look at Geth's database.go, which is part of the ethdb package.

For the actual interface that's provided, check interface.go:

type Database interface {
    Put(key []byte, value []byte) error
    Get(key []byte) ([]byte, error)
    Delete(key []byte) error
    Close()
    NewBatch() Batch
}

bench_test.go might be useful for examples of how to use the provided functions.


If you'd like an idea of something to copy, then there's a tutorial of how to read the ldb data using Node.js, here. Clearly you'd have to port the ideas across, but it might help with an understanding of how the data is laid out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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