How to directly query leveldb database to get get a record by transaction hash or by sender's address?

3

1

I learned that the blocks and transactions are stored locally in .bitcoin/blocks/index and .bitcoin/chainstate databases, respectively. I want to make a direct query to those databases to measure the response time. However, I found it hard to understand the format and the best way to access to the data. I am using Plyvel, but I couldn't formulate the exact query, for example to search for a particular transaction identified by its hash value, or searching for the all transactions made by a particular sender identified by the hash of its public address.

Any help, please.

Noureddine

Posted 2017-05-16T09:04:37.533

Reputation: 63

This may help you https://bitcoin.stackexchange.com/a/52167/30668

sr-gi 2017-05-16T09:15:58.857

I already see it, but how the transaction id is transformed from 246c5a81b6ad0dfc0dbc0b2ff5bde65ee1913f75a47d409b8ff8074a27ec1000 to c0010ec274a07f88f9b407da4753f91e15ee6bdf52f0bbc0dfc0dadb6815a6c24 ??Noureddine 2017-05-16T10:10:24.740

You should change the endianness. While txids are displayed in blockexplorers as big endian values, they are stored in the LevelDB in their little endian representation.sr-gi 2017-05-16T10:17:53.287

Ah ok, I see. Then I have to convert txid from big to little endian before making the query. May be this can help in the conversion: http://stackoverflow.com/questions/13155570/reorder-byte-order-in-hex-string-python

Noureddine 2017-05-16T10:33:35.883

What about the sender address, how I can search for transaction by sender address?Noureddine 2017-05-16T10:34:20.803

To my knowledge, You can't, at least by querying the LevelDB. The purpose of the UTXO set stored in the DB is identify which transactions are unspent in order to make it easier to validate a transaction that tries to redeem one. If you want to know the addresses (or more generally the scripts) involved in each UTXO you will need to parse the information obtained when querying the DB by the txids.sr-gi 2017-05-16T10:44:20.770

Let us continue this discussion in chat.

sr-gi 2017-05-16T10:48:33.423

No answers