<blockquote>
<p>I assumed that Block Index record will have details of the file (blk000????.dat) where to look for the block but it doesn't have anything</p>
</blockquote>
<p>As described in the answer by a Bitcoin Core developer, the Block Index database contains all the information of the block and where the block is located (in which file blk). This is required because the is no order of the blocks received from the bitcoin network.</p>
<blockquote>
<p>I tried fetching value for all below but its NULL always. Am I doing something wrong?</p>
</blockquote>
<p>Read the information from the level DB is a little bit tricky because there is a special format as described in the link post. However, with your example, there is no way to find the problem in your code, because there is no code posted.</p>

CC BY-SA 4.0
2021-05-18T13:30:29.503Z
I fetched the block data from Index DB and it doesnt have any reference to the blk file. Is that a derived information?
Ankit
CC BY-SA 4.0
2021-05-18T14:05:31.103Z
you have sored the number of the file, like in the source code is reported   https://github.com/bitcoin/bitcoin/blob/f914f1a746d7f91951c1da262a4a749dd3ebfa71/src/chain.h#L111
vincenzopalazzo
CC BY-SA 4.0
2021-05-18T16:17:00.453Z
The value in block index does not actually contains nFile. I believe itit must be calculated field but not sure about how it is done https://github.com/bitcoin/bitcoin/blob/f914f1a746d7f91951c1da262a4a749dd3ebfa71/src/chain.h#L171
Ankit
CC BY-SA 4.0
2021-05-18T16:30:32.740Z
The value is 88 bytes and the values it has are MagicId, Length, Version, PrevBlockHash, MarkleRoot, Timestamp, Difficulty, Nounce
Ankit
CC BY-SA 4.0
2021-05-18T10:26:38.247Z
2021-05-18T10:26:38.247Z
vincenzopalazzo
<p>Following the <a href="https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair">article</a> I tried reading the flag value for txindex in the Block Index database but was not able to fetch the values. I tried fetching value for all below but its NULL always. Am I doing something wrong?</p>
<pre><code>    private readonly byte[] TRANSACTIONINDEX_ENABLED = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 1 }; // F8txindex
    private readonly byte[] TRANSACTIONINDEX_ENABLED1 = new byte[] { 70, 7, 116, 120, 105, 110, 100, 101, 120, 1 }; // F7txindex
    private readonly byte[] TRANSACTIONINDEX_ENABLED2 = new byte[] { 70, 7, 1, 120, 101, 100, 110, 105, 120, 116 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED21 = new byte[] { 70, 7, 120, 101, 100, 110, 105, 120, 116, 1 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED3 = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 1 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED31 = new byte[] { 70, 8, 120, 101, 100, 110, 105, 120, 116, 1 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 0 }; // F8txindex
    private readonly byte[] TRANSACTIONINDEX_DISABLED1 = new byte[] { 70, 7, 116, 120, 105, 110, 100, 101, 120, 0 }; // F7txindex
    private readonly byte[] TRANSACTIONINDEX_DISABLED2 = new byte[] { 70, 7, 0, 120, 101, 100, 110, 105, 120, 116 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED21 = new byte[] { 70, 7, 120, 101, 100, 110, 105, 120, 116, 0 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED3 = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 0 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED31 = new byte[] { 70, 8, 120, 101, 100, 110, 105, 120, 116, 0 }; // F8txindex little endian
</code></pre>
<p>Additionally, how to fetch the mapping between data fetched from block index and the bat file where details of the block are. I assumed that Block Index record will have details of the file (blk000????.dat) where to look for the block but it doesnt have anything</p>

<bitcoin-core><block>
BTC - Block Index - Reading the flag values in Level DB
Ankit
# BTC - Block Index - Reading the flag values in Level DB

(Asked by: username_0 on 2021-05-17)

Following the [article](https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair) I tried reading the flag value for txindex in the Block Index database but was not able to fetch the values. I tried fetching value for all below but its NULL always. Am I doing something wrong?

```
    private readonly byte[] TRANSACTIONINDEX_ENABLED = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 1 }; // F8txindex
    private readonly byte[] TRANSACTIONINDEX_ENABLED1 = new byte[] { 70, 7, 116, 120, 105, 110, 100, 101, 120, 1 }; // F7txindex
    private readonly byte[] TRANSACTIONINDEX_ENABLED2 = new byte[] { 70, 7, 1, 120, 101, 100, 110, 105, 120, 116 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED21 = new byte[] { 70, 7, 120, 101, 100, 110, 105, 120, 116, 1 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED3 = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 1 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_ENABLED31 = new byte[] { 70, 8, 120, 101, 100, 110, 105, 120, 116, 1 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 0 }; // F8txindex
    private readonly byte[] TRANSACTIONINDEX_DISABLED1 = new byte[] { 70, 7, 116, 120, 105, 110, 100, 101, 120, 0 }; // F7txindex
    private readonly byte[] TRANSACTIONINDEX_DISABLED2 = new byte[] { 70, 7, 0, 120, 101, 100, 110, 105, 120, 116 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED21 = new byte[] { 70, 7, 120, 101, 100, 110, 105, 120, 116, 0 }; // F7txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED3 = new byte[] { 70, 8, 116, 120, 105, 110, 100, 101, 120, 0 }; // F8txindex little endian
    private readonly byte[] TRANSACTIONINDEX_DISABLED31 = new byte[] { 70, 8, 120, 101, 100, 110, 105, 120, 116, 0 }; // F8txindex little endian

```

Additionally, how to fetch the mapping between data fetched from block index and the bat file where details of the block are. I assumed that Block Index record will have details of the file (blk000????.dat) where to look for the block but it doesnt have anything

**Tags:** bitcoin-core, block


---

## 1 answers

### Answer by username_1 on 2021-05-18. Score: 1

> I assumed that Block Index record will have details of the file (blk000????.dat) where to look for the block but it doesn't have anything

As described in the answer by a Bitcoin Core developer, the Block Index database contains all the information of the block and where the block is located (in which file blk). This is required because the is no order of the blocks received from the bitcoin network.

> I tried fetching value for all below but its NULL always. Am I doing something wrong?

Read the information from the level DB is a little bit tricky because there is a special format as described in the link post. However, with your example, there is no way to find the problem in your code, because there is no code posted.

> **Comments:**
> **username_0**: I fetched the block data from Index DB and it doesnt have any reference to the blk file. Is that a derived information?  
> **username_1**: you have sored the number of the file, like in the source code is reported   https://github.com/bitcoin/bitcoin/blob/f914f1a746d7f91951c1da262a4a749dd3ebfa71/src/chain.h#L111  
> **username_0**: The value in block index does not actually contains nFile. I believe itit must be calculated field but not sure about how it is done https://github.com/bitcoin/bitcoin/blob/f914f1a746d7f91951c1da262a4a749dd3ebfa71/src/chain.h#L171  
> **username_0**: The value is 88 bytes and the values it has are MagicId, Length, Version, PrevBlockHash, MarkleRoot, Timestamp, Difficulty, Nounce  

---

