Summary of the invention
The embodiment of the invention provides a kind of date storage method and device based on block chain, for improving data storage
Safety.
The first aspect of the embodiment of the present invention provides a kind of date storage method based on block chain, is applied to block chain
System, comprising: the block catenary system generates block subchain, and the block subchain includes file uplink time, on the file
The biography time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;The block catenary system is logical
It crosses block main chain and inquires the token quantity of this address and whether meet the quantitative requirement for uploading file destination, the token is used for institute
State the remuneration that IPFS payment uploads the file destination;If the quantity that the token quantity meets the upload file destination is wanted
It asks, then the file destination is uploaded to the IPFS by the block catenary system;The block catenary system receives the IPFS hair
The target cryptographic Hash sent.
In a kind of possible embodiment, if the token quantity is unsatisfactory for uploading the quantitative requirement of the file destination,
Then the block catenary system stops upload task and prompts to supplement the token.
It is described after the block catenary system receives the cryptographic Hash that the IPFS is sent in a kind of possible embodiment
Method further include: the file destination is checked according to the target cryptographic Hash.
It is described after the block catenary system receives the cryptographic Hash that the IPFS is sent in a kind of possible embodiment
Method further include: the file destination is obtained according to the target cryptographic Hash.
In a kind of possible embodiment, the structure of the block subchain includes block size, block head, file counter
And file content;Wherein, the data structure of the block head include version, father's block head cryptographic Hash, Merkel Merkle root, when
Between stamp, difficulty target and random number N once.
The second aspect of the embodiment of the present invention provides a kind of data storage device based on block chain, is applied to block chain
System, comprising: generation unit, for generating block subchain, the block subchain includes file uplink time, and the file uploads
Time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;Query unit, for passing through
Whether the token quantity that block main chain inquires this address meets the quantitative requirement for uploading file destination, and the token is used for described
IPFS payment uploads the remuneration of the file destination;Uploading unit, if the token quantity, which meets, uploads the file destination
Quantitative requirement, then for the file destination to be uploaded to the IPFS;Receiving unit, the mesh sent for receiving the IPFS
Mark cryptographic Hash.
In a kind of possible embodiment, the data storage device further include: stop unit, if the token quantity is not
Meet the quantitative requirement for uploading the file destination, then stop upload task for the block catenary system and prompts described in supplement
Token.
In a kind of possible embodiment, the data storage device further include: unit is checked, for according to the target
Cryptographic Hash checks the file destination.
In a kind of possible embodiment, the data storage device further include: acquiring unit, for according to the target
Cryptographic Hash obtains the file destination.
In a kind of possible embodiment, the structure of the block subchain includes block size, block head, file counter
And file content;Wherein, the data structure of the block head include version, father's block head cryptographic Hash, Merkel Merkle root, when
Between stamp, difficulty target and random number N once.
Third aspect present invention provides a kind of electronic equipment, including memory, processor, which is characterized in that the place
Reason device realized when being used to execute the computer management class method stored in memory as described in above-mentioned any one based on block
The step of datum number storage of chain is according to method.
Fourth aspect present invention provides a kind of computer readable storage medium, is stored thereon with computer management class
Sequence, it is characterised in that: when the computer management class method is executed by processor realize as described in above-mentioned any one based on
The step of date storage method of block chain.
As can be seen from the above technical solutions, the embodiment of the present invention has the advantage that block catenary system generates block
Chain, block subchain include file uplink time, and file uplink time, which is used to indicate, uploads to interspace file transmission for file destination
The initial time of system IPFS;Whether block catenary system meets upload target by the token quantity that block main chain inquires this address
The quantitative requirement of file, token are used to pay the remuneration for uploading file destination to IPFS;If token quantity, which meets, uploads target text
The quantitative requirement of part, then file destination is uploaded to IPFS by block catenary system;Block catenary system receives the target that IPFS is sent and breathes out
Uncommon value.The embodiment of the present invention realizes the HC hard copy of block chain storage file, leaves file record, can not maliciously delete,
Improve the safety of data storage.And the big file that interspace document transmission system IPFS node uploads is cut into small point
Block, downloading when, can obtain simultaneously from multiple servers, and the network of IPFS is unfixed, fine-grained, distributed
Network, IPFS are no longer concerned about the position of central server, reduce carrying cost, improve storage efficiency.
Specific embodiment
The embodiment of the invention provides a kind of date storage method and device based on block chain, for improving data storage
Safety.
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, those skilled in the art's every other implementation obtained without making creative work
Example, shall fall within the protection scope of the present invention.
The description and claims of this application and term " first ", " second ", " third ", " in above-mentioned attached drawing
The (if present)s such as four " are to be used to distinguish similar objects, without being used to describe a particular order or precedence order.It should manage
The data that solution uses in this way are interchangeable under appropriate circumstances, so that the embodiments described herein can be in addition to illustrating herein
Or the sequence other than the content of description is implemented.In addition, term " includes " and " having " and their any deformation, it is intended that
Cover it is non-exclusive include, for example, containing the process, method, system, product or equipment of a series of steps or units need not limit
In step or unit those of is clearly listed, but may include be not clearly listed or for these process, methods, produce
The other step or units of product or equipment inherently.
Referring to Fig. 1, be the flow chart of the date storage method provided in an embodiment of the present invention based on block chain, it is specific to wrap
It includes:
101, block catenary system generates block subchain.
Block catenary system generates block subchain, and block subchain includes file uplink time, and file uplink time is used to indicate
File destination is uploaded to the initial time of interspace document transmission system IPFS.
It should be noted that increasing a storage assembly (Storage Task) in block catenary system, it is distributed in networking
Comprising the storage assembly that can be called by block chain node in formula system structure, storage assembly includes interspace document transmission system
(interplanetary file system, IPFS) program and corresponding library file etc..
Block catenary system may include application service layer, kernel service layer and protocol layer, wherein application service layer includes number
According to transmission assembly, authentication component, data Synchronization Component, data protection component, Software Development Kit (software
Development kit, SDK) and application programming interface (Application Programming Interface,
API), kernel service layer include dynamic common recognition (Dynamic Consensus) component, safety (Safty Strategy) component,
It calculates power and plans as a whole (CoC Planning) component, AI collaboration (Artificial Intelligence Synergism) component and body
Part certification (Identity Authentication) component;Protocol layer includes registration/certification agreement, authorized agreement, data reading
Write/exchange agreement, trust management framework, data storage/protection, intelligent contract, network communication protocol and basis storage agreement.
It is understood that block catenary system needs to configure storage assembly and initializes before generating block subchain, tool
Body, a control of the storage assembly as block chain is installed, ipfs automatically in the complete client of installation block chain
For program name.For example, ipfs init can be in storage assembly for installing the complete client of block chain in Linux system
Local storage space is initialized when primary operation, and default storage space such as 2G is set;Initialization is completed to execute order ipfs
Daemon, starter node server are added IPFS network, wait IPFS subsequent commands to be processed.
102, block catenary system uploads file destination by the way that whether the token quantity that block main chain inquires this address meets
Quantitative requirement.
Whether block catenary system meets the quantity for uploading file destination by the token quantity that block main chain inquires this address
It is required that the token is used to pay the remuneration for uploading file destination to IPFS.If token quantity meets the quantity for uploading file destination
It is required that thening follow the steps 103.The space that IPFS shares is combined by each IPFS contributes, and needs the remuneration certain to universe network
It just can be carried out upload.
It should be noted that the structure of block subchain includes block size, block head, file counter and file content,
The length of block size field is 4 bytes, with the block size after the field of byte representation;The length of block head file is
80 bytes, several fields including forming block head;The length of file counter field is 1-9 byte, the sheet which includes
Block quantity of documents;The indefinite length of file content field, the file information being recorded in block use primary the file information
Format, and the position in file must be with the leaf node sequence consensus of Merkel tree tree.
Wherein, the data structure of block head includes version, father's block head cryptographic Hash, Merkel Merkle root, timestamp, difficulty
Spend target and random number N once.The length of version field is 4 bytes, records block version number, indicates the verifying that this block is abided by
Rule;The length of father's block head cryptographic Hash is that 32 bytes are calculated for indicating the cryptographic Hash of previous block using SHA256;It is silent
The length of Ke Er Merkle root is 32 bytes, and the Merkle tree root cryptographic Hash of the block All Files is equally counted using SHA256
It calculates;The length of timestamp is 4 bytes, which generates time proximity, be accurate to the UNIX timestamp of second, must be strictly larger than preceding 11
The intermediate value of a block time, full node can also refuse those blocks for exceeding oneself 2 hour timestamp;The length of difficulty target
For 4 bytes, the difficulty target of the block proof of work algorithm is encoded using special algorithm;The length of random number N once is 4
Byte meets random number set by difficulty target to find, and is used for adjustment difficulty, and adjustment is packaged block time interval.
For example, the structure of single file storage data include version field, input counter field, file Hash field,
Transaction output index field, sequence number field, file home address field, file size field, file uplink time field, lock
Determine Script Field, locking time field.Wherein, the length of version field is 4 bytes, is used to indicate the rule of this transaction reference
Then;The length for inputting counter field is 1-9 byte, is used to indicate the file input quantity for including;The length of file Hash field
Degree is 32 bytes, the file hash value calculated by SHA256 ();The length of transaction output index field is 4 bytes, and format is solid
It is set to 0xFFFFFFFF;The length of sequence number field is 4 bytes, value all 1, format 0xFFFFFFFF;File ownership place
The length of location field is 1-9 byte, the address comprising file owner;The length of file size field is 8 bytes, with byte table
The file space size shown;The length of file uplink time field is 4 bytes, when indicating that file is added to the starting of IPFS system
Between;The indefinite length for locking Script Field defines the script of condition needed for file shifts;It is 4 that locking time field, which obtains length,
Byte is a block number or specified UNIX timestamp.
If 103, token quantity meets the quantitative requirement for uploading file destination, block catenary system uploads to file destination
IPFS。
File destination is uploaded to IPFS by block catenary system.
For example, passing through instruction addition file to IPFS, specific instruction such as ipfs add-r " file or directory name ".It can be with
Understand, a Hash hash value is directly returned to if it is single file, multiple files return to multiple hash values respectively.
104, block catenary system receives the target cryptographic Hash that IPFS is sent.
Block catenary system receives the target cryptographic Hash that IPFS is sent.
In the embodiment of the present invention, block catenary system generates block subchain, and block subchain includes file uplink time, on file
The biography time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;Block catenary system passes through area
Whether the token quantity that block main chain inquires this address meets the quantitative requirement for uploading file destination, and token is used to pay to IPFS
Pass the remuneration of file destination;If token quantity meets the quantitative requirement for uploading file destination, block catenary system is by file destination
Upload to IPFS;Block catenary system receives the target cryptographic Hash that IPFS is sent.The embodiment of the present invention realizes block chain storage text
The HC hard copy of part, leaves file record, can not maliciously delete, and improves the safety of data storage.
Optionally, on the basis of above-mentioned Fig. 1 corresponding embodiment, the number provided in an embodiment of the present invention based on block chain
According in the alternative embodiment of storage method, the method also includes:
If token quantity is unsatisfactory for uploading the quantitative requirement of the file destination, block catenary system stops upload task simultaneously
Prompt supplement token.
Optionally, on the basis of above-mentioned Fig. 1 corresponding embodiment, the number provided in an embodiment of the present invention based on block chain
According in the alternative embodiment of storage method, after the cryptographic Hash that the block catenary system receives that the IPFS is sent, the side
Method further include:
File destination is checked according to target cryptographic Hash.
For example, checking file destination to IPFS by instruction ipfs cat/ipfs/ " cryptographic Hash that step 203 returns ".
Optionally, on the basis of above-mentioned Fig. 1 corresponding embodiment, the number provided in an embodiment of the present invention based on block chain
According in the alternative embodiment of storage method, after the cryptographic Hash that the block catenary system receives that the IPFS is sent, the side
Method further include:
The file destination is obtained according to the target cryptographic Hash.
For example, instruction ipfs get/ipns/ " cryptographic Hash that step 203 returns " downloading mesh can be passed through at an arbitrary position
Mark file.
Optionally, on the basis of above-mentioned Fig. 1 corresponding embodiment, the number provided in an embodiment of the present invention based on block chain
According in the alternative embodiment of storage method, the structure of block subchain includes in block size, block head, file counter and file
Hold;
Wherein, the data structure of block head includes version, father's block head cryptographic Hash, Merkel Merkle root, timestamp, difficulty
Spend target and random number N once.
The embodiment of the present invention is described from the angle of the date storage method based on block chain above, below from base
The embodiment of the present invention is described in the angle of the data storage device of block chain.
Referring to Fig. 2, Fig. 2 is the possible data storage device based on block chain of one kind provided in an embodiment of the present invention
Embodiment schematic diagram, wherein being somebody's turn to do the data storage device based on block chain includes:
Generation unit 201, for generating block subchain, the block subchain includes file uplink time, on the file
The biography time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;
Whether query unit 202, the token quantity for inquiring this address by block main chain meet upload file destination
Quantitative requirement, the token is used to upload the remuneration of the file destination to IPFS payment;
Uploading unit 203, if the token quantity meets the quantitative requirement for uploading the file destination, being used for will be described
File destination uploads to the IPFS;
Receiving unit 204, the target cryptographic Hash sent for receiving the IPFS.
Optionally, in some possible implementations, the data storage device further include:
Stop unit 205, if the token quantity is unsatisfactory for uploading the quantitative requirement of the file destination, for described
Block catenary system stops upload task and prompts to supplement the token.
Optionally, in some possible implementations, the data storage device further include:
Unit 206 is checked, for checking the file destination according to the target cryptographic Hash.
Optionally, in some possible implementations, the data storage device further include:
Acquiring unit 207, for obtaining the file destination according to the target cryptographic Hash.
Optionally, in some possible implementations, the structure of block subchain includes block size, block head, file
Counter and file content;Wherein, the data structure of the block head includes version, father's block head cryptographic Hash, Merkel
Merkle root, timestamp, difficulty target and random number N once.
Referring to Fig. 3, Fig. 3 is the embodiment schematic diagram of electronic equipment provided in an embodiment of the present invention.
As shown in figure 3, the embodiment of the invention provides a kind of electronic equipment, including memory 310, processor 320 and deposit
The computer program 311 that can be run on memory 320 and on the processor 320 is stored up, processor 320 executes computer program
Block catenary system is performed the steps of when 311 and generates block subchain, and block subchain includes file uplink time, when file uploads
Between be used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;Block catenary system passes through block master
Whether the token quantity of this address of chain query meets the quantitative requirement for uploading file destination, and token, which is used to pay to IPFS, uploads mesh
Mark the remuneration of file;If token quantity meets the quantitative requirement for uploading file destination, block catenary system uploads file destination
To IPFS;Block catenary system receives the target cryptographic Hash that IPFS is sent.
In the embodiment of the present invention, block catenary system generates block subchain, and block subchain includes file uplink time, on file
The biography time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;Block catenary system passes through area
Whether the token quantity that block main chain inquires this address meets the quantitative requirement for uploading file destination, and token is used to pay to IPFS
Pass the remuneration of file destination;If token quantity meets the quantitative requirement for uploading file destination, block catenary system is by file destination
Upload to IPFS;Block catenary system receives the target cryptographic Hash that IPFS is sent.The embodiment of the present invention realizes block chain storage text
The HC hard copy of part, leaves file record, can not maliciously delete, and improves the safety of data storage.
Optionally, in a kind of possible embodiment, the processor 320 is also used to:
If the token quantity is unsatisfactory for uploading the quantitative requirement of the file destination, on the block catenary system stops
Biography task simultaneously prompts to supplement the token.
Optionally, in a kind of possible embodiment, the processor 320 is specifically also used to:
The file destination is checked according to the target cryptographic Hash.
Optionally, in a kind of possible embodiment, the processor 320 is specifically also used to:
The file destination is obtained according to the target cryptographic Hash.
Optionally, in a kind of possible embodiment, the processor 320 is specifically also used to:
Configuration storage assembly is simultaneously initialized.
Optionally, in a kind of possible embodiment, the structure of the block subchain includes block size, block head, text
Part counter and file content;Wherein, the data structure of the block head includes version, father's block head cryptographic Hash, Merkel
Merkle root, timestamp, difficulty target and random number N once.
Since the electronic equipment that the present embodiment is introduced is to implement a kind of data based on block chain in the embodiment of the present invention
Equipment used by storage device, so based on method described in the embodiment of the present invention, those skilled in the art's energy
The specific embodiment and its various change form of the electronic equipment of solution the present embodiment much of that, so being set herein for the electronics
It is standby how to realize that the method in the embodiment of the present invention is no longer discussed in detail, as long as those skilled in the art implement the present invention in fact
Equipment used by the method in example is applied, the range of the invention to be protected is belonged to.
Referring to Fig. 4, Fig. 4 is a kind of embodiment signal of computer readable storage medium provided in an embodiment of the present invention
Figure.
As shown in figure 4, present embodiments providing a kind of computer readable storage medium 400, it is stored thereon with computer journey
Sequence 411, the computer program 411 realize following steps when being executed by processor: block catenary system generates block subchain, block
Chain includes file uplink time, and file uplink time, which is used to indicate, uploads to interspace document transmission system IPFS's for file destination
Initial time;Whether block catenary system meets the quantity for uploading file destination by the token quantity that block main chain inquires this address
It is required that token is used to pay the remuneration for uploading file destination to IPFS;If the quantity that token quantity meets upload file destination is wanted
It asks, then file destination is uploaded to IPFS by block catenary system;Block catenary system receives the target cryptographic Hash that IPFS is sent.
In the embodiment of the present invention, block catenary system generates block subchain, and block subchain includes file uplink time, on file
The biography time is used to indicate the initial time that file destination is uploaded to interspace document transmission system IPFS;Block catenary system passes through area
Whether the token quantity that block main chain inquires this address meets the quantitative requirement for uploading file destination, and token is used to pay to IPFS
Pass the remuneration of file destination;If token quantity meets the quantitative requirement for uploading file destination, block catenary system is by file destination
Upload to IPFS;Block catenary system receives the target cryptographic Hash that IPFS is sent.The embodiment of the present invention realizes block chain storage text
The HC hard copy of part, leaves file record, can not maliciously delete, and improves the safety of data storage.
Optionally, in a kind of possible embodiment, it is specifically used for realizing when which is executed by processor
Following steps: if the token quantity is unsatisfactory for uploading the quantitative requirement of the file destination, the block catenary system stops
Upload task simultaneously prompts to supplement the token.
Optionally, in a kind of possible embodiment, it is specifically used for realizing when which is executed by processor
Following steps: the file destination is checked according to the target cryptographic Hash.
Optionally, in a kind of possible embodiment, it is specifically used for realizing when which is executed by processor
Following steps: the file destination is obtained according to the target cryptographic Hash.
Optionally, in a kind of possible embodiment, it is specifically used for realizing when which is executed by processor
Following steps: configuration storage assembly is simultaneously initialized.
Optionally, in a kind of possible embodiment, the structure of the block subchain includes block size, block head, text
Part counter and file content;Wherein, the data structure of the block head includes version, father's block head cryptographic Hash, Merkel
Merkle root, timestamp, difficulty target and random number N once.
It should be noted that in the above-described embodiments, all emphasizing particularly on different fields to the description of each embodiment, in some embodiment
The part being not described in may refer to the associated description of other embodiments.
It should be understood by those skilled in the art that, the embodiment of the present invention can provide as method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the present invention
Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the present invention, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
The present invention be referring to according to the method for the embodiment of the present invention, the process of equipment (system) and computer program product
Figure and/or block diagram describe.It should be understood that each process in flowchart and/or the block diagram can be realized by computer program instructions
And/or the combination of the process and/or box in box and flowchart and/or the block diagram.It can provide these computer programs to refer to
Enable the processor of general purpose computer, special purpose computer, embedded computer or other programmable data processing devices to produce
A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real
The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
Although preferred embodiments of the present invention have been described, it is created once a person skilled in the art knows basic
Concept, then additional changes and modifications may be made to these embodiments.So it includes preferred that the following claims are intended to be interpreted as
Embodiment and all change and modification for falling into the scope of the invention.
Obviously, various changes and modifications can be made to the invention without departing from essence of the invention by those skilled in the art
Mind and range.In this way, if these modifications and changes of the present invention belongs to the range of the claims in the present invention and its equivalent technologies
Within, then the invention is also intended to include including these modification and variations.