3

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.

Murch
  • 75,206
  • 34
  • 186
  • 622
Noureddine
  • 163
  • 6
  • This may help you https://bitcoin.stackexchange.com/a/52167/30668 – sr_gi May 16 '17 at 09:15
  • I already see it, but how the transaction id is transformed from 246c5a81b6ad0dfc0dbc0b2ff5bde65ee1913f75a47d409b8ff8074a27ec1000 to c0010ec274a07f88f9b407da4753f91e15ee6bdf52f0bbc0dfc0dadb6815a6c24 ?? – Noureddine May 16 '17 at 10:10
  • 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 May 16 '17 at 10:17
  • 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 May 16 '17 at 10:33
  • What about the sender address, how I can search for transaction by sender address? – Noureddine May 16 '17 at 10:34
  • 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 May 16 '17 at 10:44

0 Answers0