CN115033549A - File link storage method and device based on block chain - Google Patents

File link storage method and device based on block chain Download PDF

Info

Publication number
CN115033549A
CN115033549A CN202210696241.9A CN202210696241A CN115033549A CN 115033549 A CN115033549 A CN 115033549A CN 202210696241 A CN202210696241 A CN 202210696241A CN 115033549 A CN115033549 A CN 115033549A
Authority
CN
China
Prior art keywords
file
algorithm
hash value
target
original
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210696241.9A
Other languages
Chinese (zh)
Inventor
原超
孙英男
王炜煜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Encryption Native Technology Co ltd
Original Assignee
Shanghai Encryption Native Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Encryption Native Technology Co ltd filed Critical Shanghai Encryption Native Technology Co ltd
Priority to CN202210696241.9A priority Critical patent/CN115033549A/en
Publication of CN115033549A publication Critical patent/CN115033549A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/14Details of searching files based on file metadata
    • G06F16/148File search processing
    • G06F16/152File search processing using file content signatures, e.g. hash values
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files

Abstract

The embodiment of the application discloses a method and a device for storing file links based on block links, wherein the method comprises the steps of storing original file hash values of files stored in a distributed file system into a block link network in advance according to a first algorithm in an intelligent contract deployed in the block link network; the intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier; responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from a blockchain network according to a first algorithm; and generating a content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file. According to the file link storage method and device, the original file hash value with less byte number is stored to finish storage of the file link, so that data storage capacity is reduced, and storage cost is greatly reduced.

Description

File link storage method and device based on block chain
Technical Field
The embodiment of the application relates to the technical field of internet, in particular to a file link storage method and device based on a block chain.
Background
In applications of a blockchain network, it is generally necessary to store Uniform Resource Identifier (URI) links pointing to files, and in order to make items more decentralized, many items may choose to store Content Identifiers (CID) corresponding to a distributed file system to implement addressing of Content, and specifically, the Content identifiers may be directly stored in a form of a character string, for example, ERC721URI storage implemented by Open Zeppelin corporation. And storing data on the block chain network, and paying a certain Gas fee according to the size of the data volume. In the prior art, the content identifier of a file is generally stored in a block chain network, however, the content identifier is obtained through a series of algorithms, the number of bytes is large, the data storage amount is large, a large amount of cost needs to be paid, and the problem of high storage cost exists.
Disclosure of Invention
In view of the foregoing problems, the present application provides a block chain-based file link storage method, apparatus, computing device, and computer storage medium, which are used to solve the following problems: the existing file link storage method has the problems of large data storage capacity, high storage cost and the like.
According to an aspect of the embodiments of the present application, there is provided a block chain-based file link storage method, including:
storing an original file hash value of a file stored in a distributed file system into a blockchain network according to a first algorithm in an intelligent contract deployed in the blockchain network; the intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier;
responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from a blockchain network according to a first algorithm;
and generating a content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file.
Further, after generating the content identifier of the target file according to the original file hash value and the second algorithm in the intelligent contract, the method further comprises:
and generating a file link of the target file according to the content identifier of the target file, and returning the file link of the target file to the user.
Further, storing the original file hash value of the file stored in the distributed file system into the blockchain network according to the first algorithm in the intelligent contract deployed in the blockchain network further comprises:
aiming at each file stored in the distributed file system, acquiring a file identifier of the file;
calculating the original file hash value of the file by utilizing a first preset hash algorithm;
constructing a data key value pair corresponding to the file identifier of the file according to a first algorithm and the hash value of the original file of the file, and storing the data key value pair into a block chain network; and the data key value corresponding to the file identifier of the file comprises the hash value of the original file of the file.
Further, according to the first algorithm and the hash value of the original file of the file, constructing a data key value pair corresponding to the file identifier of the file, and storing the data key value pair in the block chain network further includes:
according to a first algorithm, taking the file identifier of the file as a data key, and taking the original file hash value of the file as a data value corresponding to the data key to obtain a data key value pair corresponding to the file identifier of the file;
and storing the data key-value pairs into an intelligent contract deployed in the blockchain network.
Further, in response to a file link reading request of a user for a target file, obtaining an original file hash value of the target file from the blockchain network according to the first algorithm further includes:
according to a first algorithm, extracting a file identifier of a target file from a file link reading request, acquiring a data key value pair corresponding to the file identifier of the target file from a block chain network, and obtaining an original file hash value of the target file according to the data key value pair corresponding to the file identifier of the target file.
Further, obtaining a data key value pair corresponding to the file identifier of the target file from the blockchain network, and obtaining the original file hash value of the target file according to the data key value pair corresponding to the file identifier of the target file further includes:
searching a data key value pair which takes the file identifier of the target file as a data key from an intelligent contract deployed in a block chain network, wherein the data key value pair is used as a data key corresponding to the file identifier of the target file;
and extracting a data value in a data key value pair corresponding to the file identifier of the target file as an original file hash value of the target file.
Further, the second algorithm comprises: a preset decoding algorithm, a second preset hash algorithm and a preset encoding algorithm;
generating the content identifier of the target file according to the original file hash value and the second algorithm in the intelligent contract further comprises:
decoding the hash value of the original file by using a preset decoding algorithm to obtain a first byte code;
encoding the first byte code by utilizing a second preset Hash algorithm to obtain a second byte code;
and encoding the second byte code by using a preset encoding algorithm to obtain the content identifier of the target file.
Further, the method also includes:
the intelligent contracts are deployed into the blockchain network in advance by sending transactions into the blockchain network.
Further, the distributed file system includes an interplanetary file system.
According to another aspect of the embodiments of the present application, there is provided a block chain-based file link storage apparatus, including:
the storage module is used for storing the original file hash value of the file stored in the distributed file system into the block chain network according to a first algorithm in an intelligent contract deployed in the block chain network; the intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier;
the acquisition module is used for responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from a blockchain network according to a first algorithm;
and the generating module is used for generating the content identifier of the target file according to the original file hash value and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file.
According to another aspect of embodiments of the present application, there is provided a computing device including: the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the block chain-based file link storage method.
According to another aspect of the embodiments of the present application, there is provided a computer storage medium, in which at least one executable instruction is stored, and the executable instruction causes a processor to perform an operation corresponding to the above block chain-based file link storage method.
According to the file link storage method and device based on the block chain, provided by the embodiment of the application, the original file hash value of a file stored in a distributed file system is stored in the block chain network in advance according to a first algorithm in an intelligent contract deployed in the block chain network; the intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier; responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from a block chain network according to a first algorithm; and generating a content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file. According to the method and the device, the file link is stored by storing the original file hash value with less byte number, and when a user requests to read the file link of the target file, the content identifier of the target file is generated in real time according to the first algorithm and the second algorithm which are deployed in the intelligent contract in advance, so that the user can obtain the target file from the distributed file system by using the content identifier of the target file, the data storage amount is effectively reduced, and the storage cost is greatly reduced.
The foregoing description is only an overview of the technical solutions of the embodiments of the present application, and the embodiments of the present application can be implemented according to the content of the description in order to make the technical means of the embodiments of the present application more clearly understood, and the detailed description of the embodiments of the present application will be given below in order to make the foregoing and other objects, features, and advantages of the embodiments of the present application more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the embodiments of the present application. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 is a flowchart illustrating a block chain based file link storage method according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a block chain-based file link storage method according to another embodiment of the present application;
FIG. 3 is a block diagram illustrating a block chain based file linking storage apparatus according to an embodiment of the present application;
fig. 4 shows a schematic structural diagram of a computing device according to an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
First, the noun terms to which one or more embodiments of the present application relate are explained.
Interplanetary File System (Inter planet File System, IPFS): a distributed system for storing and accessing files, websites, applications and data.
Content identifier CID: content identifiers, which are self-describing in a distributed system, typically use cryptographic hashes to achieve content addressing.
Intelligent contract: the system is deployed in a blockchain network and used for executing a computer transaction protocol of a specific logic, wherein the computer transaction protocol comprises a code function and can complete decision execution, fund storage, data reading and writing and the like.
Solid: a contractual programming language for Ethernet Virtual Machines (EVMs) is used for realizing intelligent contracts.
Gas: refers to a unit that measures the computational effort required to perform a particular operation on a blockchain network; since each transaction on the blockchain requires computational resources to execute, each transaction requires a charge, Gas refers to the cost required to successfully conduct the transaction on the blockchain.
Open Zeppelin: well-known companies in the block chain industry provide a large number of modular, reusable, secure intelligent contract libraries in the ethernet network, written in the Solidity language.
Fig. 1 is a flowchart illustrating a block chain-based file link storage method according to an embodiment of the present application, where as shown in fig. 1, the method includes the following steps S101-S103:
step S101: and storing the original file hash value of the file stored in the distributed file system into the blockchain network according to a first algorithm in an intelligent contract deployed in the blockchain network.
In this embodiment, each file stored in the distributed file system has a corresponding file Identifier (ID), and the file identifier corresponding to each file and the hash value of the original file of each file may be stored in the blockchain network in advance; specifically, a data key value pair corresponding to the file identifier of the file may be constructed according to the first algorithm and the hash value of the original file of the file, and the data key value pair is stored in the blockchain network; the file identification of each file and the hash value of the original file are in one-to-one correspondence.
Specifically, in order to reduce the data storage amount and the storage cost, a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier are developed in the intelligent contract, and then the intelligent contract is deployed to the blockchain network by initiating a transaction to the blockchain network, wherein the first algorithm is used for storing the hash value of the original file of each file; and the second algorithm is used for generating CID corresponding to the file link according to the hash value of the original file. In this step, the original file hash value of the file stored in the distributed file system is stored in the blockchain network according to the first algorithm in the intelligent contract.
Step S102: and responding to a file link reading request of a user for the target file, and acquiring an original file hash value of the target file from the blockchain network according to a first algorithm.
The target file refers to a file that a user wants to obtain from the distributed file system. In this step, when a user needs to obtain a certain target file from the distributed file system, the user needs to first request the blockchain network and send a file link reading request for the target file to read a content identifier or a file link of the target file in the distributed file system, where the file link reading request carries a file identifier of the target file; since the file identifier of each file and the original file hash value of each file are stored correspondingly in the blockchain network, the original file hash value of the target file can be conveniently obtained from the blockchain network according to the first algorithm in the intelligent contract and the file identifier of the target file in response to the file link reading request.
Step S103: and generating a content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file.
Specifically, a CID corresponding to the file link is generated according to the original file hash value of the target file through a second algorithm, a user can determine the file link of the target file through the CID, and the target file is obtained from the distributed file system according to the file link of the target file.
Compared with the prior art in which the CID is directly stored, in the embodiment, the original file hash value with a smaller number of bytes is stored in the block chain network, the file link reading request of the user for the target file is responded, and the original file hash value is converted into the CID in real time through the first algorithm and the second algorithm, so that the data storage capacity is reduced, and Gas cost generated by storage is greatly reduced.
According to the file link storage method based on the block chain, the file link is stored by storing the original file hash value with less byte number, and when a user requests to read the file link of the target file, the content identifier of the target file is generated in real time according to the first algorithm and the second algorithm which are deployed in the intelligent contract in advance, so that the user can obtain the target file from the distributed file system by using the content identifier of the target file, the data storage amount is effectively reduced, and the storage cost is greatly reduced.
Fig. 2 is a flowchart illustrating a block chain-based file link storage method according to another embodiment of the present application, and as shown in fig. 2, the method includes the following steps S201 to S206:
step S201: the intelligent contracts are deployed into the blockchain network in advance by sending transactions into the blockchain network.
In this step, an intelligent contract provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the CID from the hash value of the original file is deployed into the blockchain network by sending a transaction into the blockchain network in advance.
Step S202: the method comprises the steps of obtaining a file identifier of each file stored in a distributed file system, and calculating an original file hash value of each file by using a first preset hash algorithm.
The first preset hash algorithm is an algorithm used for calculating the original file hash value of the corresponding file according to file information such as file size, time, file type, file creator and the like; the file identification is identification information for identifying a file, and may be a file ID or the like, for example. Specifically, for each file stored in the distributed file system, a file ID of the file is obtained, the file information of the file is calculated by using a first preset hash algorithm, and an original file hash value of the file is calculated. The first predetermined Hash Algorithm may be a Secure Hash Algorithm (SHA), or the like.
Step S203: and constructing a data key value pair corresponding to the file identifier of the file according to a first algorithm in the intelligent contract and the original file hash value of the file, and storing the data key value pair into the block chain network.
And the data key value corresponding to the file identifier of the file comprises the hash value of the original file of the file.
In an optional implementation, step S203 further includes: according to a first algorithm, taking the file identifier of the file as a data key, and taking the original file hash value of the file as a data value corresponding to the data key to obtain a data key value pair corresponding to the file identifier of the file; and storing the data key-value pairs into an intelligent contract deployed in the block chain network.
In this step, a data key value pair corresponding to the file identifier of the file may be constructed, where the data key value pair includes the original file hash value of the file, and specifically, the file identifier of the file is used as a data key, the original file hash value of the file is used as a data value corresponding to the data key, a data key value pair key-value corresponding to the file identifier of the file is obtained, and the data key value pair key-value is stored in an intelligent contract deployed in the block chain network. For example, the data key-value pair format may be (key, value), with each file having a corresponding data key-value pair. In this embodiment, the original file hash value of the file may be a 256-bit hash value calculated by a secure hash algorithm, which is abbreviated as SHA256 hash value, so that the data key value pair may also be expressed as (file ID, SHA256 hash value); the file ID is the data key in the data key value pair, and the SHA256 hash value is the data value in the data key value pair.
Step S204: and responding to a file link reading request of a user for the target file, and acquiring an original file hash value of the target file from the blockchain network according to a first algorithm.
Specifically, a file identifier of a target file is extracted from a file link reading request; because the data key value pair corresponding to the file identifier of each file in the distributed file system is stored in the blockchain network by executing the step S202 and the step S203, after the file identifier of the target file is extracted, the data key value pair corresponding to the file identifier of the target file can be obtained from the blockchain network according to the file identifier of the target file, and the original file hash value of the target file is extracted from the data key value pair according to the first algorithm. For example, if the data key value pair is stored in an intelligent contract deployed in the blockchain network, a data key value corresponding to a data key value using a file identifier of the target file as a file identifier of the target file may be searched for from the intelligent contract deployed in the blockchain network; and extracting a data value in a data key value pair corresponding to the file identifier of the target file as an original file hash value of the target file.
When a user needs to acquire a certain target file from a distributed file system, the user needs to send a file link reading request aiming at the target file by requesting a block chain network so as to read a content identifier or a file link of the target file in the distributed file system, wherein the file link reading request carries a file identifier of the target file; then in response to the file link read request, extracting a file identifier of the target file from the file link read request, for example, the extracted file identifier is file ID1, searching a data key value pair with file ID1 as a data key from an intelligent contract deployed in the blockchain network, and then extracting a data value from the data key value pair, thereby obtaining an original file hash value of the target file, assuming that the data key value pair is (file ID1, SHA256 hash value 1), where SHA256 hash value 1 is the original file hash value of the target file.
Step S205: and generating the content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract.
In an alternative embodiment, the second algorithm may comprise: a preset decoding algorithm, a second preset hash algorithm and a preset encoding algorithm. Step S205 further includes: decoding the hash value of the original file by using a preset decoding algorithm to obtain a first byte code; encoding the first byte code by utilizing a second preset Hash algorithm to obtain a second byte code; and coding the second byte code by using a preset coding algorithm to obtain the content identifier of the target file.
Specifically, the preset decoding algorithm may include algorithms such as a Hex decoding algorithm, and specifically, the Hex encoding algorithm is an encoding mode for converting data into a data format conforming to the Intel Hex file, that is, the hexadecimal content represented by each byte is displayed by a string; for example, the data after "99, 105, 224, 7" is encoded by the Hex encoding algorithm is: "6369 e 007" is a character string; the coded character string can be decoded by a Hex decoding algorithm to obtain an original byte; therefore, in this embodiment, a Hex decoding algorithm may be selected as the preset decoding algorithm to decode the hash value of the original file, so as to obtain the first bytecode.
Further, the second predetermined hash algorithm may include multiple hash algorithms (multiple hash algorithms). The traditional hash algorithm is proved to have certain insecurity, the CID stored by the general hash algorithm changes along with the prolonging of the storage time, the generated file link is not accurate, and the content addressing in IPFS and other distributed systems is not enough; the multi-hash algorithm is that the self-description hash itself contains metadata describing two lengths of the self-description hash and what encryption algorithm is generated, so that the CID storing various formats has a function of never being outdated through the encoding of the multi-hash algorithm, and in this embodiment, the multi-hash algorithm can be selected as a second preset hash algorithm to encode the hash value of the decoded original file, that is, the first bytecode is encoded, so as to obtain a second bytecode.
The preset encoding algorithm can comprise algorithms such as a Base64 algorithm, a Base58 algorithm and the like; the Base64 algorithm is a common readable encoding algorithm, and the Base64 means that 64 characters are used in the encoding process: capital letters "a" to "Z", lowercase letters "a" to "Z", numerals "0" to "9", "+" and "/". Base58 is a coding mode used in Bitcoin (Bitcoin), and is mainly used for generating a wallet address of Bitcoin; in contrast to the Base64 algorithm, the Base58 algorithm does not use the number "0", the capital letter "O", the capital letter "I", and the lowercase letter "I", as well as the "+" and "/" symbols. In the present embodiment, for IPFS, the Base58 algorithm may be used as the pre-set encoding algorithm.
The CID has two versions, namely CID V0 and CID V1; wherein CID V0 applies to the encoding rules and encryption algorithms default to IPFS. In this embodiment, taking IPFS as an example, IPFS generally uses CID V0 algorithm, CID V0 algorithm can convert the hash value of the original file of the file into a CID corresponding to the file link through multiple decoding and encoding, and a user can search for the file corresponding to the CID in the IPFS by linking the CID corresponding to the file link.
Taking the example that the preset decoding algorithm is a Hex decoding algorithm, the second preset hash algorithm is a multi-hash algorithm, and the preset encoding algorithm is a Base58 algorithm, firstly, the SHA256 hash value of the file is decoded by the Hex to obtain an original first byte code X, then the first byte code X is encoded by the multi-hash algorithm to obtain a second byte code Y, and the second byte code Y is encoded by the Base58 algorithm to obtain a final result, namely the CID of the target file; that is, the user can find the corresponding file in the IPFS by the CID of the target file. In the encoding process of the CID V0 algorithm, compared with the CID of the target file, the byte number of the CID of the target file is about 1.3 times or more than the byte number of the SHA256 hash value of the target file in the SHA256 hash value of the target file, so that compared with the prior art that a file link or CID is directly stored, the embodiment completes storage of the file link by storing the SHA256 hash value of the file, and can effectively reduce storage cost.
Step S206: and generating a file link of the target file according to the content identifier of the target file, and returning the file link of the target file to the user.
In this step, the file link of the target file is generated according to the CID of the target file, taking IPFS as an example, the file link of the target file can be directly generated by adding "IPFS://" to the CID, the file link of the target file is returned to the user, and the user can read the target file from the IPFS through the file link.
According to the file link storage method based on the block chain provided by the embodiment of the application, a first algorithm and a second algorithm are written in an intelligent contract, when a user requests to read a file link of a target file, a file identifier of the target file is extracted from the file link reading request, a data key value pair corresponding to the file identifier of the target file is obtained from a block chain network, an original file hash value of the target file is extracted from the data key value pair corresponding to the file identifier of the target file according to the first algorithm, and a CID or a file link of the target file is generated in real time according to the original file hash value and the second algorithm in the intelligent contract, so that the file link is stored by storing the original file hash value with less bytes, the reading effect same as that of a CID directly stored file is obtained, and on the basis of ensuring the reading effect, the data storage capacity is effectively reduced, the storage cost is greatly reduced, and the file link storage mode is optimized.
Fig. 3 is a block diagram illustrating a structure of a block chain-based file link storage apparatus according to an embodiment of the present application, where the apparatus includes, as shown in fig. 3: storage module 301, obtaining module 302, and generating module 303:
the storage module 301 is configured to store, according to a first algorithm in an intelligent contract deployed in the blockchain network, an original file hash value of a file stored in the distributed file system into the blockchain network.
The intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier.
In an alternative embodiment, the storage module 301 is further configured to: aiming at each file stored in the distributed file system, acquiring a file identifier of the file; calculating the original file hash value of the file by utilizing a first preset hash algorithm; constructing a data key value pair corresponding to the file identifier of the file according to the first algorithm and the original file hash value of the file, and storing the data key value pair into a block chain network; and the data key value corresponding to the file identifier of the file comprises the hash value of the original file of the file.
In an alternative embodiment, the storage module 301 is further configured to: according to a first algorithm, taking the file identifier of the file as a data key, and taking the original file hash value of the file as a data value corresponding to the data key to obtain a data key value pair corresponding to the file identifier of the file; and storing the data key-value pairs into an intelligent contract deployed in the blockchain network.
In an alternative embodiment, the storage module 301 is further configured to: the intelligent contracts are deployed into the blockchain network in advance by sending transactions into the blockchain network.
An obtaining module 302, configured to, in response to a file link read request of a user for a target file, obtain an original file hash value of the target file from a blockchain network according to a first algorithm.
In an optional implementation, the obtaining module 302 is further configured to: according to a first algorithm, extracting a file identifier of a target file from a file link reading request, acquiring a data key value pair corresponding to the file identifier of the target file from a block chain network, and obtaining an original file hash value of the target file according to the data key value pair corresponding to the file identifier of the target file.
In an optional implementation, the obtaining module 302 is further configured to: searching a data key value pair which takes the file identifier of the target file as a data key from an intelligent contract deployed in a block chain network, wherein the data key value pair is used as a data key corresponding to the file identifier of the target file; and extracting a data value in a data key value pair corresponding to the file identifier of the target file as an original file hash value of the target file.
The generating module 303 is configured to generate a content identifier of the target file according to the hash value of the original file and a second algorithm in the intelligent contract, so that a user may obtain the target file from the distributed file system by using the content identifier of the target file.
In an alternative embodiment, the generating module 303 is further configured to: and generating a file link of the target file according to the content identifier of the target file, and returning the file link of the target file to the user.
In an alternative embodiment, the second algorithm comprises: a preset decoding algorithm, a second preset hash algorithm and a preset encoding algorithm; the generating module 303 is further configured to: decoding the hash value of the original file by using a preset decoding algorithm to obtain a first byte code; encoding the first byte code by utilizing a second preset Hash algorithm to obtain a second byte code; and encoding the second byte code by using a preset encoding algorithm to obtain the content identifier of the target file.
In an alternative embodiment, the distributed file system comprises an interplanetary file system.
The descriptions of the modules refer to the corresponding descriptions in the method embodiments, and are not repeated herein.
According to the file link storage device based on the block chain provided by the embodiment of the application, a first algorithm and a second algorithm are written in an intelligent contract, when a user requests to read a file link of a target file, a file identifier of the target file is extracted from the file link reading request, a data key value pair corresponding to the file identifier of the target file is obtained from a block chain network, an original file hash value of the target file is extracted from the data key value pair corresponding to the file identifier of the target file according to the first algorithm, and a CID or a file link of the target file is generated in real time according to the original file hash value and the second algorithm in the intelligent contract, so that the file link is stored by storing the original file hash value with less bytes, the reading effect same as that of a CID directly stored file is obtained, and on the basis of ensuring the reading effect, the data storage capacity is effectively reduced, the storage cost is greatly reduced, and the file link storage mode is optimized.
The embodiment of the present application further provides a non-volatile computer storage medium, where the computer storage medium stores at least one executable instruction, and the executable instruction may execute the block chain-based file link storage method in any method embodiment described above.
Fig. 4 is a schematic structural diagram of a computing device according to an embodiment of the present application, and a specific embodiment of the present application does not limit a specific implementation of the computing device.
As shown in fig. 4, the computing device may include: a processor (processor)402, a Communications Interface 404, a memory 406, and a Communications bus 408.
Wherein:
the processor 402, communication interface 404, and memory 406 communicate with each other via a communication bus 408.
A communication interface 404 for communicating with network elements of other devices, such as clients or other servers.
The processor 402 is configured to execute the program 410, and may specifically perform relevant steps in the above embodiment of the block chain-based file link storage method.
In particular, program 410 may include program code comprising computer operating instructions.
The processor 402 may be a central processing unit CPU, or an application Specific Integrated circuit asic, or one or more Integrated circuits configured to implement embodiments of the present application. The computing device includes one or more processors, which may be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 406 for storing a program 410. Memory 406 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 410 may be specifically configured to enable the processor 402 to execute the block chain based file link storage method in any of the above-described method embodiments. For specific implementation of each step in the program 410, reference may be made to corresponding steps and corresponding descriptions in units in the above embodiment of the block chain-based file link storage method, which are not described herein again. It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described devices and modules may refer to the corresponding process descriptions in the foregoing method embodiments, and are not described herein again.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. In addition, embodiments of the present application are not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the embodiments of the present application as described herein, and any descriptions of specific languages are provided above to disclose the best modes of the embodiments of the present application.
In the description provided herein, numerous specific details are set forth. It can be appreciated, however, that the embodiments of the application may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the present application, various features of the embodiments of the present application are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that is, the claimed embodiments of the application require more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of an embodiment of this application.
Those skilled in the art will appreciate that the modules in the devices in an embodiment may be adaptively changed and arranged in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the embodiments of the application and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the present application may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components in accordance with the embodiments of the present application. Embodiments of the present application may also be implemented as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing embodiments of the present application may be stored on a computer readable medium or may be in the form of one or more signals. Such a signal may be downloaded from an internet website, or provided on a carrier signal, or provided in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the embodiments of the application, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The embodiments of the application can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (12)

1. A file link storage method based on a block chain comprises the following steps:
storing an original file hash value of a file stored in a distributed file system into a blockchain network according to a first algorithm in an intelligent contract deployed in the blockchain network; the intelligent contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating the content identifier;
responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from the block chain network according to the first algorithm;
and generating a content identifier of the target file according to the original file hash value and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file.
2. The method of claim 1, wherein after the generating the content identifier of the target file in accordance with the original file hash value and the second algorithm in the smart contract, the method further comprises:
and generating a file link of the target file according to the content identifier of the target file, and returning the file link of the target file to the user.
3. The method of claim 1 or 2, wherein storing the raw file hash value of the file stored in the distributed file system into the blockchain network according to the first algorithm in the smart contract deployed in the blockchain network further comprises:
acquiring a file identifier of each file stored in the distributed file system;
calculating the original file hash value of the file by utilizing a first preset hash algorithm;
constructing a data key value pair corresponding to the file identifier of the file according to the first algorithm and the original file hash value of the file, and storing the data key value pair into the block chain network; and the data key value corresponding to the file identifier of the file comprises the hash value of the original file of the file.
4. The method of claim 3, wherein constructing a data key-value pair corresponding to a file identifier of the file according to the first algorithm and an original file hash value of the file, and storing the data key-value pair in the blockchain network further comprises:
according to the first algorithm, taking the file identification of the file as a data key, taking the original file hash value of the file as a data value corresponding to the data key, and obtaining a data key value pair corresponding to the file identification of the file;
storing the data key-value pairs into an intelligent contract deployed in the blockchain network.
5. The method according to any one of claims 1-4, wherein the obtaining the original file hash value of the target file from the blockchain network according to the first algorithm in response to a file link read request of a user for the target file further comprises:
and according to the first algorithm, extracting the file identifier of the target file from the file link reading request, acquiring the data key value pair corresponding to the file identifier of the target file from the block chain network, and obtaining the original file hash value of the target file according to the data key value pair corresponding to the file identifier of the target file.
6. The method according to claim 5, wherein the obtaining the data key value pair corresponding to the file identifier of the target file from the blockchain network, and obtaining the original file hash value of the target file according to the data key value pair corresponding to the file identifier of the target file further comprises:
searching a data key value pair taking the file identifier of the target file as a data key from an intelligent contract deployed in the block chain network, wherein the data key value pair is used as a data key corresponding to the file identifier of the target file;
and extracting a data value in a data key value pair corresponding to the file identifier of the target file as an original file hash value of the target file.
7. The method of any of claims 1-6, wherein the second algorithm comprises: a preset decoding algorithm, a second preset hash algorithm and a preset encoding algorithm;
the generating the content identifier of the target file according to the original file hash value and the second algorithm in the intelligent contract further comprises:
decoding the hash value of the original file by using the preset decoding algorithm to obtain a first byte code;
encoding the first byte code by using the second preset Hash algorithm to obtain a second byte code;
and encoding the second bytecode by using the preset encoding algorithm to obtain the content identifier of the target file.
8. The method of any of claims 1-7, wherein the method further comprises:
and deploying the intelligent contract into the blockchain network in advance by sending a transaction into the blockchain network.
9. The method as recited in any one of claims 1-8, wherein the distributed file system comprises an interplanetary file system.
10. A block chain based file link storage device, comprising:
the storage module is used for storing the original file hash value of the file stored in the distributed file system into the block chain network according to a first algorithm in an intelligent contract deployed in the block chain network; the intelligent contract is provided with a first algorithm for storing hash values of original files and a second algorithm for generating content identifiers;
the acquisition module is used for responding to a file link reading request of a user for a target file, and acquiring an original file hash value of the target file from the block chain network according to the first algorithm;
and the generating module is used for generating the content identifier of the target file according to the original file hash value and a second algorithm in the intelligent contract, so that a user can acquire the target file from the distributed file system by using the content identifier of the target file.
11. A computing device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the file link storage method based on the block chain in any one of claims 1-9.
12. A computer storage medium having at least one executable instruction stored therein, the executable instruction causing a processor to perform operations corresponding to a block chain based file link storage method according to any one of claims 1 to 9.
CN202210696241.9A 2022-06-20 2022-06-20 File link storage method and device based on block chain Pending CN115033549A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210696241.9A CN115033549A (en) 2022-06-20 2022-06-20 File link storage method and device based on block chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210696241.9A CN115033549A (en) 2022-06-20 2022-06-20 File link storage method and device based on block chain

Publications (1)

Publication Number Publication Date
CN115033549A true CN115033549A (en) 2022-09-09

Family

ID=83124654

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210696241.9A Pending CN115033549A (en) 2022-06-20 2022-06-20 File link storage method and device based on block chain

Country Status (1)

Country Link
CN (1) CN115033549A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115694841A (en) * 2022-11-09 2023-02-03 中煤科工集团信息技术有限公司 Block chain and IPFS network-based metadata circulation method and device and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115694841A (en) * 2022-11-09 2023-02-03 中煤科工集团信息技术有限公司 Block chain and IPFS network-based metadata circulation method and device and storage medium
CN115694841B (en) * 2022-11-09 2024-01-26 中煤科工集团信息技术有限公司 Metadata circulation method, device and storage medium based on blockchain and IPFS network

Similar Documents

Publication Publication Date Title
CN109040341B (en) Intelligent contract address generation method and device, computer equipment and readable storage medium
CN107577427B (en) data migration method, device and storage medium for blockchain system
CN107391632B (en) Database storage processing method and device, computing equipment and computer storage medium
CN110737659A (en) Graph data storage and query method, device and computer readable storage medium
CN110489466B (en) Method and device for generating invitation code, terminal equipment and storage medium
CN104025502A (en) Instructions processors, methods, and systems to process BLAKE secure hashing algorithm
KR102111871B1 (en) Method and apparatus for generating random string
KR20190064621A (en) Method and device for encoding and decoding binary data
CN112015806A (en) Method and device for storing data by block chain
CN111143446A (en) Data structure conversion processing method and device of data object and electronic equipment
CN115033549A (en) File link storage method and device based on block chain
CN111651695A (en) Method and device for generating and analyzing short link
CN110147653B (en) Application program security reinforcing method and device
CN108712486B (en) Workload proving method and device
CN114201756A (en) Vulnerability detection method and related device for intelligent contract code segment
CN111324645B (en) Block chain data processing method and device
CN107562533B (en) Data loading processing method and device
CN116204612A (en) Text similarity calculation method and system
KR101253700B1 (en) High Speed Encoding Apparatus for the Next Generation Sequencing Data and Method therefor
CN107491460B (en) Data mapping method and device of adaptation system
CN113537392A (en) Similar image identification method and device, computing equipment and computer storage medium
CN115276889A (en) Decoding processing method, decoding processing device, computer equipment and storage medium
US9176972B1 (en) Implied M83 names in alternate name generation in directories supporting multiple naming protocols
WO2018193707A1 (en) Information processing device, program, information processing method, and data structure
CN114499465A (en) Hash algorithm, circuit and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination