Bitcoin Forum
December 13, 2024, 03:41:32 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Methods of decoding a bitcoin block stored in windows  (Read 157 times)
supermankid (OP)
Jr. Member
*
Offline Offline

Activity: 31
Merit: 12


View Profile
March 27, 2022, 05:53:01 PM
Merited by vapourminer (1)
 #1

Hello everyone,
Started doing some research on bitcoin blocks, when i run a node the blocks are stored on  => ...\BTC\blocks (windows)
I opened with hex viewer and I could indeed see the infamous"chancelor..." in the genesis block.
How can the transaction history be decoded from this block.

Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.
n0nce
Hero Member
*****
Offline Offline

Activity: 910
Merit: 5935


not your keys, not your coins!


View Profile WWW
March 27, 2022, 06:56:31 PM
Last edit: March 27, 2022, 07:07:38 PM by n0nce
Merited by ABCbits (9), BlackHatCoiner (4), vapourminer (3), pooya87 (2), PrimeNumber7 (1)
 #2

Hello everyone,
Started doing some research on bitcoin blocks, when i run a node the blocks are stored on  => ...\BTC\blocks (windows)
I opened with hex viewer and I could indeed see the infamous"chancelor..." in the genesis block.
How can the transaction history be decoded from this block.
You need all blocks to get full transaction history. Wink
If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

For doing it manually, I like to follow along code such as the one from the link above. As you can see, there is this hex code that you should be able to find in your .dat file, which separates blocks. If you count the bytes between these separators, it should be always around 1MB.
Code: (https://github.com/alecalve/python-bitcoin-blockchain-parser/blob/d763ca6dc2357cdf2e885f3e6790eeab1aeaa0a8/blockchain_parser/blockchain.py#L30)
BITCOIN_CONSTANT = b"\xf9\xbe\xb4\xd9"

In line 46, in get_blocks(), you can see how one blk....dat file is split up and the raw bytes of each block are returned.

For decoding that block manually, you can have a look into the codebase of the above project or refer to the Block structure according to Bitcoin Wiki.
Here's the block header and the corresponding Bitcoin Core code is found here.
Code: (https://github.com/bitcoin/bitcoin/blob/2f0f056e08cd5a1435120592a9ecd212fcdb915b/src/primitives/block.h#L20)
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;

Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.
That's because one such file contains more than one block.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
ABCbits
Legendary
*
Offline Offline

Activity: 3094
Merit: 8176


Crypto Swap Exchange


View Profile
March 28, 2022, 12:23:28 PM
Merited by NeuroticFish (3), vapourminer (2), pooya87 (2)
 #3

Secondly the blocks are not 1MB they are like 127MB.
How do block explorer or a normal person decode this information from these blocks?
Thanks in advance.

I'd like to mention Bitcoin protocol doesn't specify how you store blockchain on your device. If you use different full node software (Bitcoin Core isn't the only one), it's possible they store blockchain differently.

If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

Those script haven't updated in a while, so i have concern it can't parse taproot transaction/block correctly. Bitcoin Core is safer option unless OP willing to test those script and also offer to return raw hex of the block.

Code:
getblock [HASH_OF_THE_BLOCK] 0

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
n0nce
Hero Member
*****
Offline Offline

Activity: 910
Merit: 5935


not your keys, not your coins!


View Profile WWW
March 28, 2022, 12:34:17 PM
 #4

If you mean decoding the block and such, honestly the best tool is just using Bitcoin Core which you seem to have installed.
But if you want to decode individual blk files, I found this small program that might do the trick!

python-bitcoin-blockchain-parser]This repository actually looks a bit better to me, since it has more features and it's Python 3-based so you won't need to compile it!

Those script haven't updated in a while, so i have concern it can't parse taproot transaction/block correctly. Bitcoin Core is safer option unless OP willing to test those script and also offer to return raw hex of the block.

Code:
getblock [HASH_OF_THE_BLOCK] 0
Yes, true, makes sense; however it appeared to me that they're trying to do it semi-manually at least. For that purpose, the Python code is easier / more accessible to copy out parts of it into own scripts or play around with them without recompilation of a big software like Bitcoin Core. Of course Core can decode any block ('honestly the best tool is just using Bitcoin Core'); but since he mentioned trying to just decode the genesis block, the old scripts should work.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
supermankid (OP)
Jr. Member
*
Offline Offline

Activity: 31
Merit: 12


View Profile
March 28, 2022, 04:08:03 PM
 #5

Thanks for all your valuable insights. My ₿ journey gets more interesting everyday. A little late but I guess better late than never...
ymgve2
Full Member
***
Offline Offline

Activity: 162
Merit: 230


View Profile
March 29, 2022, 02:43:15 AM
 #6

One important thing to note is that those .blk files do not necessarily contain the blocks in the correct order, as they are written to the files as they are received, and during bootstrapping and syncing, lots of blocks are coming all at once. The files also might contain orphaned blocks.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!