How can I get the key of blockindex

2018-06-24 05:17:56

According to this post: What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?

One type of the keys in leveldb of bitcoin is formed in the following way

'b' + 32-byte block hash

I wrote the following code in go but I got "not found".

genesisBlockHash := "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"

hashBytes, _ := hex.DecodeString(genesisBlockHash)

keyBytes := append([]byte("b"), hashBytes...)

data, err := db.Get(keyBytes, nil)

Where did I do wrong? How can I add 'b' to the hash?

Tried a simple case:

'R' -> 1-byte boolean ('1' if true): whether we're in the process of reindexing.

Go code

data, err := db.Get([]byte("R"), nil)

But I still got "not found". Why...

Tried file.

'f' + 4-byte file number -> file information record.

I could get some data. I think the following code should retrieve the "blk00000.dat" block file information, right?

readFile(db, []byte{0, 0, 0, 0})

func readFile(db