Blockchain development topic (data structure analysis of digital currency)

Source: Internet
Author: User
Tags hash
Blockchain Enthusiast (qq:53016353)
As the core concept of Bitcoin, digital currency (data chunks, data blocks, data block chains) plays an important role in understanding the structure of Bitcoin. In what is data chunks, the editor simply introduces the concept of data chunks from the point of view of distributed transaction records in data chunks. Today, the editor analyzes the details of what is being recorded in the data block from the program structure of the data block.


Location of the data chunk file
If you are using a BITCOIN-QT client, then the data chunk information exists in your computer. Every time you turn on BITCOIN-QT, the data blocks will be synchronized with the entire peer-network distributed database. Depending on the operating system, the data block directory blocks general storage path is:


Windows:%appdata%\bitcoin\
linux:~/.bitcoin/
Mac OS: ~/library/application support/bitcoin/


Open Data Chunk file
When we open the Blocks folder, we can see a lot of files called BlkXXX.dat, which hold the legendary data chunk records.




The BlkXXX.dat file can be opened with hexdump under the terminal.
Hexdump-n 10000-c Blk00000.dat


Data block structure
The Hexdump program translates the data block file into a hexadecimal +ascii representation, which the editor explains: Each chunk of data records six items: Magic number, chunk size, header information for data chunks, transaction count, transaction details. In this, the hash value of the header information of the data block is the reference target number of the hash value of the next new district block, and the last transaction detail records all the transactions in the block (the editor will elaborate on the structure of the transaction later).
The data block structure is shown below:


Data Block Header structure
The header structure of the data Block records: Version number, record of the previous chunk, root value of Merkle tree, timestamp, target eigenvalue, random number.
The process of mining in a Bitcoin miner is the process of generating a new chunk of data (as the editor will explain later), which requires a comparison of the hash value and the random number in the head of the previous data block, and a new chunk if certain conditions are met. The root value of the Merkle tree is the hash value of the root node of all recorded transactions in the block, and the Nakamoto uses a hash tree to digitally sign each transaction to ensure that each transaction is not counterfeit and does not repeat the transaction, Merkle tree is a hash tree. The head structure of the data block is shown below:




Transaction history


The transaction is like an accounting book, recording all the bitcoin transaction information, each Bitcoin player's bitcoin revenue and expenditure situation is permanently embedded in the data block for others to query, which is why every BBT currency transactions can be queried. The transaction data in these data blocks is stored in the client node of each Bitcoin player, and all of these nodes form the bitcoin and its tough distributed database system. The destruction of data on any one node does not affect the normal functioning of the entire database, as the rest of the healthy nodes have a complete database.
In this article, the editor will parse the structure of the transactions in the data block in detail.


Transaction structure
The transaction history of the data block details the bitcoin transactions and related details. In the details of bitcoin revenue and expenditure, the Bitcoin address and the value of the Merkle node are recorded, so the details of revenue and expenditure are the most important part of the transaction record.
The complete transaction structure is shown in the following table:




Structure of Bitcoin spending and receiving transactions
In the data block, the Bitcoin expenditure and the received transaction are written together, and the entire revenue and expenditure record includes a lot more than the record. Each record has its own index number for querying.


Each record includes details such as the build time, the hash value of the reference transaction, the transaction index number, the Bitcoin expense address, and the number of expense addresses. Each revenue and expenditure transaction has a Merkle node value, which is part of the entire Merkle tree, which determines that each address cannot be duplicated and forged.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.