A kind of block chain dynamic compression access method
Technical field
The present invention relates to digital cash such as bit coin wallet class software, specifically a kind of data processing method when digital cash wallet program is run.
Background technology
Existing enciphered digital currency is current main flow enciphered digital currency bit coin such as, is the digital cash of a kind of a kind of decentration attribute integrating P2P, the Internet, encryption principle.In enciphered digital currency wallet program, the money of form of ownership is all agreement (Allformsofmoneyareprotocol), the formal description of the rule that namely all of money must comply with before being traded.If bit coin is exactly the agreement of a kind of higher form, it utilizes Internet technology and cryptography design, and cryptographic application ensure that the safety of payment system.So, bit coin does not have too big difference with other currency in this respect.What bit coin was unique is a bit its general ledger system (ledgersystem) is decentration, and other currency has a central office to issue currency.
First digital cash user installs this digital cash wallet program on computers, and this Program Generating wallet such as ratio treats that coin is saved in computer with wallet.dat form.Wallet generates multiple bit coin addresses, and address is that the account of external disclosure is for receiving the bit coin that others sends.Just there are the corresponding private key in this address and PKI in wallet Program Generating enciphered digital currency address, and current private key and PKI are included in wallet archives (wallet.dat).In enciphered digital currency, private key (privatekey) is stored in a string information in wallet.In bit coin, private key is just saved in wallet archives wallet.dat.The effect of private key is used to produce PKI (this PKI can derive bit coin address), and is used for the digital signature transacted business.This signature ensure that the reliability of transaction, is not tampered with, undeniable integrity.All of transaction record all can be broadcast to customer group, and is confirmed by the whole network in the next stipulated time, and this process is also called digs ore deposit (Mining).
At present, disclosed in the transaction of all enciphered digital currency is all, in bit coin, All Activity confirms just to be integrated into once the whole network " total account book is disclosed " (sharedpublicledger), it is again block chain (Blockchain), the surplus (Balance) of each wallet independent record, is all through the Transaction Information of block chain and calculates owner and take in the surplus of payment.Block chain is through encryption and learns and integrate according to transaction record and time sequencing." transaction of bit coin " is exactly that the value between each bit coin wallet turns money record and is incorporated in block chain.But, along with constantly carrying out of transaction, the data of block chain are inevitable more and more huger, and this brings inconvenience to user.
Summary of the invention
For above-mentioned technical problem, the present invention provide a kind of the block chain of digital cash wallet program can be carried out dynamic compression method, provide the user facility.
This invention address that the technical scheme that above-mentioned technical problem adopts is: a kind of block chain dynamic compression access method, it comprises the following steps:
(1) digital cash wallet program is run;
(2), when having new block data write block chain in digital cash wallet program operation process, this block data is carried out dynamic compression;
(3) on the block of compression, identification information is created;
(4) then when digital cash wallet program is run, above-mentioned establishment have the block data of the compression of identification information be stored in block chain data base.
As preferably, when needing to read certain block in block chain in digital cash wallet program operation process, dynamically decompressing this block according to identification information.
As preferably, in digital cash wallet program, block data is compressed by embedded compression function.
As preferably, preserving embedded described compression function in the function of block in digital cash wallet program.
As preferably, the block of described compression creates identification information by described compression function.
As preferably, described identification information includes the size before block compression and dictionary size.
As preferably, in digital cash wallet program, the block creating the compression having identification information is decompressed by embedded decompression function.
As preferably, reading embedded described decompression function in the function of block in digital cash wallet program.
As preferably, the block of compression is decompressed by described decompression function according to identification information.
As can be known from the above technical solutions, block is carried out dynamic compression by embedded compression function by the present invention in the running of digital cash wallet program, by embedded decompression function, the block of compression is decompressed simultaneously, under ensureing the premise not damaging data, not only make whole block chain data capacity diminish, be greatly saved memory space;And improve the transmission speed of block chain data, shorten the transmission time.
Detailed description of the invention
The present invention is described more detail below, and illustrative examples and explanation in this present invention are used for explaining the present invention, but not as a limitation of the invention.
A kind of block chain dynamic compression access method, it comprises the following steps:
Run digital cash wallet program, this program realize such function: for bit coin, if B want pay 100 bit coin to C, then B not only need on trading card indicate the amount of money, and need indicate these 100 bit coin source.If the 100 of B bit coin are in fact from A, being that B passes through transaction and 0 obtains, transaction 0 here has already been through the certification of the whole network user, is saved in the block chain data base of digital cash wallet program of user computer.The information filled on trading card for completing transaction 1, B to need includes: the source of 100 bit coin, here for the ID of trading card 0;The PKI of C, namely the bit coin gathering address of C;Then the PKI of the content of trading card 0 and C is inputted hash function, obtain string number.B this string numeral of the encrypted private key of oneself, is placed in trading card 1 as digital signature.C is after receiving trading card 1, it is possible to finds trading card 0 by the ID wherein deposited, and obtains the PKI of B.C can use this PKI that the digital signature in trading card 1 is decrypted.Meanwhile, C the content of the PKI of oneself and trading card 0, can input hash function in the same way, and the result of the numeral obtained with digital signature deciphering is compared, if comparison success, then concluding the business successfully, transaction record will be saved in block chain.
When digital cash wallet program operation process has new block data write block chain, this block data is carried out dynamic compression;Preserve embedded compression function in the function of block specifically in digital cash wallet program this block data is compressed, in WriteToDisk function, namely add herein below:
boolWriteToDisk(unsignedint&nFileRet,unsignedint&nBlockPosRet)
{
... // omit, code originally
nSize=pack_block(this,sRzt);//pack_block is compression function, and nSize is the block data size after compression, and sRzt is the block data after compression
fileout.write(sRzt.c_str(),nSize);// block counts after compression is saved in block chain database file
... // omit, code originally
};
Thus achieve the purpose of dynamic compression.
In implementation process, also need to creating identification information on the block of compression, identification information can be created by above-mentioned compression function, and identification information generally comprises the parameters such as the amount of capacity before block compression, compression dictionary size, and these information are used for decompressing;After creating identification information, the block data of compression is saved in block chain data base, thus ensureing the reliability of block data.
The present invention also reads embedded decompression function in the function of block and decompresses creating the block of compression having identification information in digital cash wallet program;Time in digital cash wallet program operation process as read the block of certain compression in block chain, decompression function dynamically decompresses this block according to identification information, thus reducing the block data of correspondence, is conducive to user accurately to read.As added the decompression function of herein below in the function of ReadFromDisk reading block:
boolReadFromDisk(unsignedintnFile,unsignedintnBlockPos,boolfReadTransactions=true)
{
... // omit, code originally
getCBlockByFilePos(filein,nBlockPos,this);// in getCBlockByFilePos function according to nBlockPos reduce block
... // omit, code originally
};
Thus achieve the purpose of dynamically decompression.The visible present invention realizes the dynamic compression to block data and decompression in digital cash wallet program operation process, is not only damaged from data, and is greatly saved storage area.
The technical scheme above embodiment of the present invention provided is described in detail, principle and the embodiment of the embodiment of the present invention are set forth by specific case used herein, and the explanation of above example is only applicable to help to understand the principle of the embodiment of the present invention;Simultaneously for one of ordinary skill in the art, according to the embodiment of the present invention, all will change in detailed description of the invention and range of application, in sum, this specification content should not be construed as limitation of the present invention.