Blockchain-based file link storage method and device

By storing the original file hash value of the file in the blockchain network and generating a content identifier, the problems of large data storage volume and high storage cost are solved, and efficient file link storage is achieved.

CN115033549BActive Publication Date: 2025-09-23SHANGHAI ENCRYPTION TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210696241.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-20
Publication Date
2025-09-23
Estimated Expiration
2042-06-20

AI Technical Summary

Technical Problem

Existing file link storage methods have the problems of large data storage volume and high storage cost in blockchain networks.

Method used

By storing the original file hash values ​​of files in the distributed file system in the blockchain network and using the algorithm in the smart contract to generate content identifiers, the amount of data directly stored in the content identifiers is reduced and storage costs are reduced.

Benefits of technology

It effectively reduces the amount of data storage and significantly reduces storage costs, while ensuring the reading effect of file links.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115033549B_ABST
    Figure CN115033549B_ABST
Patent Text Reader

Abstract

The present application discloses a blockchain-based file link storage method and device. The method pre-stores the original file hash value of a file stored in a distributed file system in the blockchain network according to a first algorithm in a smart contract deployed in the blockchain network. The smart contract is provided with a first algorithm for storing the original file hash value and a second algorithm for generating a content identifier. In response to a user's file link read request for a target file, the original file hash value of the target file is obtained from the blockchain network according to the first algorithm. Based on the original file hash value and the second algorithm in the smart contract, a content identifier of the target file is generated, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system. The present application completes the storage of file links by storing original file hash values ​​with fewer bytes, thereby reducing the amount of data storage and significantly lowering storage costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of Internet technology, and specifically to a file link storage method and device based on blockchain. Background Art

[0002] In the application of blockchain networks, it is usually necessary to store Uniform Resource Identifier (URI) links pointing to files. In order to make the project more decentralized, many projects will choose to store the content identifier (Content-ID, CID) corresponding to the distributed file system to achieve content addressing. Specifically, the content identifier can be directly stored in the form of a string, such as the ERC721URIStorage implemented by Open Zeppelin. To store data on the blockchain network, a certain gas fee needs to be paid according to the amount of data. In the existing technology, the content identifier of the file is generally stored in the blockchain network. However, the content identifier is obtained through a series of algorithms, and its number of bytes is large, the data storage volume is large, and it needs to pay more fees, which has the problem of high storage costs. Summary of the Invention

[0003] In view of the above problems, this application proposes a blockchain-based file link storage method, device, computing equipment and computer storage medium to solve the following problems: the existing file link storage method has problems such as large data storage volume and high storage cost.

[0004] According to one aspect of an embodiment of the present application, a blockchain-based file link storage method is provided, comprising:

[0005] storing an original file hash value of a file stored in a distributed file system in the blockchain network according to a first algorithm in a smart contract deployed in the blockchain network, wherein the smart contract is provided with a first algorithm for storing the original file hash value and a second algorithm for generating a content identifier;

[0006] In response to a user's file link read request for a target file, obtaining an original file hash value of the target file from the blockchain network according to a first algorithm;

[0007] A content identifier of the target file is generated based on the hash value of the original file and the second algorithm in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system.

[0008] Furthermore, after generating a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract, the method further includes:

[0009] A file link of the target file is generated according to the content identifier of the target file, and the file link of the target file is returned to the user.

[0010] Furthermore, according to the first algorithm in the smart contract deployed in the blockchain network, storing the original file hash value of the file stored in the distributed file system in the blockchain network further includes:

[0011] For each file stored in the distributed file system, obtain a file identifier of the file;

[0012] Calculate the original file hash value of the file using a first preset hash algorithm;

[0013] According to the first algorithm and the original file hash value of the file, a data key-value pair corresponding to the file identifier of the file is constructed, and the data key-value pair is stored in the blockchain network; wherein the data key-value pair corresponding to the file identifier of the file includes the original file hash value of the file.

[0014] Furthermore, 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 in the blockchain network further includes:

[0015] According to the first algorithm, the file identifier of the file is used as a data key and the original file hash value of the file is used as the data value corresponding to the data key to obtain a data key-value pair corresponding to the file identifier of the file;

[0016] Store data key-value pairs in smart contracts deployed on the blockchain network.

[0017] Furthermore, in response to a user's file link read request 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:

[0018] According to the first algorithm, the file identifier of the target file is extracted from the file link read request, and the data key-value pair corresponding to the file identifier of the target file is obtained from the blockchain network. Based on the data key-value pair corresponding to the file identifier of the target file, the original file hash value of the target file is obtained.

[0019] Furthermore, 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 based on the data key-value pair corresponding to the file identifier of the target file further includes:

[0020] Searching for a data key-value pair with the file identifier of the target file as the data key from the smart contract deployed in the blockchain network as the data key-value corresponding to the file identifier of the target file;

[0021] The data value in the data key-value pair corresponding to the file identifier of the target file is extracted as the original file hash value of the target file.

[0022] Furthermore, the second algorithm includes: a preset decoding algorithm, a second preset hash algorithm, and a preset encoding algorithm;

[0023] Generating a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract further includes:

[0024] Decode the original file hash value using a preset decoding algorithm to obtain a first bytecode;

[0025] Encoding the first bytecode using a second preset hash algorithm to obtain a second bytecode;

[0026] The second bytecode is encoded using a preset encoding algorithm to obtain a content identifier of the target file.

[0027] Furthermore, the method further comprises:

[0028] Deploy smart contracts to the blockchain network in advance by sending transactions to the blockchain network.

[0029] Furthermore, the distributed file system includes the InterPlanetary File System.

[0030] According to another aspect of an embodiment of the present application, a blockchain-based file link storage device is provided, comprising:

[0031] a storage module configured to store the original file hash value of the file stored in the distributed file system in the blockchain network according to a first algorithm in a smart contract deployed in the blockchain network; wherein the smart contract is configured with the first algorithm for storing the original file hash value and the second algorithm for generating the content identifier;

[0032] an acquisition module, configured to respond to a user's file link read request for a target file and obtain an original file hash value of the target file from the blockchain network according to a first algorithm;

[0033] The generation module is used to generate a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system.

[0034] According to another aspect of an embodiment of the present application, a computing device is provided, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus;

[0035] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform operations corresponding to the above-mentioned blockchain-based file link storage method.

[0036] According to another aspect of an embodiment of the present application, a computer storage medium is provided, wherein the storage medium stores at least one executable instruction, and the executable instruction causes a processor to perform operations corresponding to the above-mentioned blockchain-based file link storage method.

[0037] According to an embodiment of the present application, a blockchain-based file link storage method and device is provided. According to a first algorithm in a smart contract deployed in the blockchain network, the original file hash value of a file stored in a distributed file system is pre-stored in the blockchain network; the smart contract is provided with a first algorithm for storing the original file hash value and a second algorithm for generating a content identifier; in response to a user's file link read request for a target file, the original file hash value of the target file is obtained from the blockchain network according to the first algorithm; based on the original file hash value and the second algorithm in the smart contract, a content identifier of the target file is generated, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system. The present application completes the storage of file links by storing original file hash values ​​with fewer bytes. When a user requests to read the file link of a target file, the content identifier of the target file is generated in real time according to the first algorithm and the second algorithm pre-deployed in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system, thereby effectively reducing the amount of data storage and significantly reducing storage costs.

[0038] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation method of the embodiment of the present application is specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the embodiments of the present application. The same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0040] Figure 1 A flowchart of a blockchain-based file link storage method according to an embodiment of the present application is shown;

[0041] Figure 2A flowchart of a blockchain-based file link storage method according to another embodiment of the present application is shown;

[0042] Figure 3 The following is a structural block diagram of a file link storage device based on blockchain according to one embodiment of the present application;

[0043] Figure 4 A schematic structural diagram of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0044] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0045] First, the terms involved in one or more embodiments of the present application are explained.

[0046] Inter Planetary File System (IPFS): A distributed system for storing and accessing files, websites, applications, and data.

[0047] Content Identifier CID: A self-describing content identifier in a distributed system, generally using cryptographic hashing to implement content addressing.

[0048] Smart contract: A computer transaction protocol deployed in a blockchain network to execute specific logic. It contains code functions that can execute decisions, store funds, read and write data, etc.

[0049] Solidity: A contract-based programming language for the Ethereum Virtual Machine (EVM) used to implement smart contracts.

[0050] Gas: refers to the unit of measurement of the amount of computing work required to perform a specific operation on the blockchain network; since each transaction on the blockchain requires computing resources to execute, each transaction requires a fee, and Gas refers to the fee required to successfully conduct a transaction on the blockchain.

[0051] Open Zeppelin: A well-known company in the blockchain industry, it provides a large number of modular, reusable, and secure smart contract libraries for the Ethereum network, written in the Solidity language.

[0052] Figure 1A flowchart of a file link storage method based on blockchain according to an embodiment of the present application is shown as follows: Figure 1 As shown, the method includes the following steps S101-S103:

[0053] Step S101: According to the first algorithm in the smart contract deployed in the blockchain network, the original file hash value of the file stored in the distributed file system is stored in the blockchain network.

[0054] In this embodiment, each file stored in the distributed file system has its corresponding file identification (ID), and the file identification corresponding to each file and the original file hash value of each file can be pre-stored in the blockchain network in correspondence; specifically, a data key-value pair corresponding to the file identification of the file can be constructed based on the first algorithm and the original file hash value of the file, and the data key-value pair can be stored in the blockchain network; wherein, the file identification and the original file hash value of each file are in a one-to-one correspondence.

[0055] Specifically, to reduce data storage and lower storage costs, a first algorithm for storing original file hash values ​​and a second algorithm for generating content identifiers were developed within a smart contract. The smart contract was then deployed to the blockchain network by initiating a transaction to the network. The first algorithm stored the original file hash value for each file, while the second algorithm generated a CID corresponding to the file link based on the original file hash value. In this step, the original file hash values ​​of files stored in the distributed file system were stored on the blockchain network according to the first algorithm in the smart contract.

[0056] Step S102: In response to a user's file link read request for a target file, an original file hash value of the target file is obtained from the blockchain network according to a first algorithm.

[0057] The target file refers to the file that the user wants to obtain from the distributed file system. In this step, when the user needs to obtain a target file from the distributed file system, the user needs to first send a file link read request for the target file to the blockchain network to read the content identifier or file link of the target file in the distributed file system, wherein the file link read request carries the file identifier of the target file; since the file identifier of each file and the original file hash value of each file are stored in correspondence 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 smart contract and the file identifier of the target file in response to the file link read request.

[0058] Step S103: Generate a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system.

[0059] Specifically, the CID corresponding to the file link is generated according to the original file hash value of the target file through the second algorithm. The user can determine the file link of the target file through the CID, and then obtain the target file from the distributed file system according to the file link of the target file.

[0060] Compared with the direct storage of CID in the prior art, this embodiment stores the original file hash value with fewer bytes in the blockchain network. In response to the user's file link read request for the target file, the original file hash value is converted into a CID in real time through the first algorithm and the second algorithm, thereby reducing the amount of data storage and significantly reducing the gas fees generated by storage.

[0061] According to the blockchain-based file link storage method provided in the embodiment of the present application, the storage of the file link is completed by storing the original file hash value with fewer bytes. When the 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 pre-deployed in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system, thereby effectively reducing the data storage amount and significantly reducing the storage cost.

[0062] Figure 2 A flowchart of a file link storage method based on blockchain according to another embodiment of the present application is shown as follows: Figure 2 As shown, the method includes the following steps S201-S206:

[0063] Step S201: Deploy the smart contract to the blockchain network in advance by sending a transaction to the blockchain network.

[0064] In this step, a smart contract provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating a CID based on the hash value of the original file is deployed to the blockchain network in advance by sending a transaction to the blockchain network.

[0065] Step S202: For each file stored in the distributed file system, obtain the file identifier of the file, and calculate the original file hash value of the file using a first preset hash algorithm.

[0066] The first preset hash algorithm is used to calculate the original file hash value of the corresponding file based on file information such as file size, time, file type, and file creator. The file identifier is identification information used to identify the file, such as a file ID. Specifically, for each file stored in the distributed file system, the file ID of the file is obtained, and the first preset hash algorithm is used to operate on the file information of the file to calculate the original file hash value of the file. The first preset hash algorithm can be a Secure Hash Algorithm (SHA), etc.

[0067] Step S203: According to the first algorithm in the smart contract and the original file hash value of the file, a data key-value pair corresponding to the file identifier of the file is constructed, and the data key-value pair is stored in the blockchain network.

[0068] The data key-value pair corresponding to the file identifier of the file includes the original file hash value of the file.

[0069] In an optional embodiment, step S203 further includes: according to the first algorithm, using the file identifier of the file as the data key and the original file hash value of the file as the 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 pair in a smart contract deployed in the blockchain network.

[0070] In this step, a data key-value pair corresponding to the file identifier of the file can be constructed. The data key-value pair includes the original file hash value of the file. Specifically, the file identifier of the file is used as the data key key, and the original file hash value of the file is used as the data value value corresponding to the data key key. The data key-value pair corresponding to the file identifier of the file is obtained, and the data key-value pair key-value is stored in the smart contract deployed in the blockchain network. For example, the data key-value pair format can be (key, value), and each file has a corresponding data key-value pair. In this embodiment, the original file hash value of the file can be a 256-bit hash value calculated by a secure hash algorithm, referred to as a SHA256 hash value. Therefore, the data key-value pair can also be expressed as (file ID, SHA256 hash value); wherein the file ID is the data key key in the data key-value pair, and the SHA256 hash value is the data value value in the data key-value pair.

[0071] Step S204: In response to the user's file link read request for the target file, the original file hash value of the target file is obtained from the blockchain network according to the first algorithm.

[0072] Specifically, the file identifier of the target file is extracted from the file link read request; since the data key-value pairs corresponding to the file identifiers of each file in the distributed file system are stored in the blockchain network by executing steps S202 and S203, after extracting the file identifier of the target file, the data key-value pair corresponding to the file identifier of the target file can be obtained from the blockchain network based on the file identifier of the target file, and the original file hash value of the target file can be extracted from the data key-value pair according to the first algorithm. For example, if the data key-value pair is stored in a smart contract deployed in the blockchain network, the data key-value pair with the file identifier of the target file as the data key can be searched from the smart contract deployed in the blockchain network as the data key value corresponding to the file identifier of the target file; the data value in the data key-value pair corresponding to the file identifier of the target file is extracted as the original file hash value of the target file.

[0073] When a user needs to obtain a target file from a distributed file system, the user needs to first make a request to the blockchain network and send a file link read request for the target file to read the content identifier or file link of the target file in the distributed file system, wherein the file link read request carries the file identifier of the target file; then, in response to the file link read request, the file identifier of the target file is extracted from the file link read request. For example, if the extracted file identifier is file ID1, a data key-value pair with file ID1 as the data key is searched from the smart contract deployed in the blockchain network, and then the data value is extracted from the data key-value pair to obtain the original file hash value of the target file. Assume 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.

[0074] Step S205: Generate a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract.

[0075] In an optional embodiment, the second algorithm may include: 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 using the preset decoding algorithm to obtain a first bytecode; encoding the first bytecode using the second preset hash algorithm to obtain a second bytecode; and encoding the second bytecode using the preset encoding algorithm to obtain a content identifier of the target file.

[0076] Specifically, the preset decoding algorithm may include algorithms such as the Hex decoding algorithm. Specifically, the Hex encoding algorithm is an encoding method that converts data into a data format that conforms to the data format in the Intel Hex file, that is, the hexadecimal content represented by each byte is displayed as a string; for example, the data after "99, 105, 224, 7" is encoded by the Hex encoding algorithm is: "6369e007", which is a string; the encoded string can be decoded by the Hex decoding algorithm to obtain the original bytes; therefore, in this embodiment, the Hex decoding algorithm can be selected as the preset decoding algorithm to decode the original file hash value to obtain the first byte code.

[0077] Furthermore, the second preset hash algorithm may include a multi-hash algorithm and other algorithms. Traditional hash algorithms have been proven to be somewhat insecure. As the storage time increases, the CID stored by the general hash algorithm will change, and the generated file link will be inaccurate, which is insufficient to implement content addressing in IPFS and other distributed systems. The multihash algorithm is a self-describing hash that contains metadata describing its two lengths and the encryption algorithm used to generate it. Therefore, the CID stored in various formats has a timeless function through the encoding of the multihash algorithm. In this embodiment, the multihash algorithm can be selected as the second preset hash algorithm to encode the decoded original file hash value, that is, to encode the first bytecode to obtain the second bytecode.

[0078] The preset encoding algorithm may include algorithms such as the Base64 algorithm and the Base58 algorithm; among them, the Base64 algorithm is a common readability encoding algorithm, and Base64 refers to the use of 64 characters in the encoding process: uppercase letters "A" to "Z", lowercase letters "a" to "z", numbers "0" to "9", "+" and " / ". Base58 is an encoding method used in Bitcoin, mainly used to generate Bitcoin wallet addresses; compared with the Base64 algorithm, the Base58 algorithm does not use the number "0", uppercase letter "O", uppercase letter "I", and lowercase letter "i", as well as the "+" and " / " symbols. In this embodiment, for IPFS, the Base58 algorithm can be used as the preset encoding algorithm.

[0079] There are two versions of CID: CID V0 and CID V1. CID V0 applies to the default encoding rules and encryption algorithm of IPFS. In this embodiment, IPFS generally uses the CID V0 algorithm. The CID V0 algorithm converts the original file hash value of a file into the CID corresponding to the file link through various decoding and encoding methods. Users can use the CID corresponding to the file link to find the file corresponding to the CID in IPFS.

[0080] Taking the preset decoding algorithm as the Hex decoding algorithm, the second preset hash algorithm as the multihash algorithm, and the preset encoding algorithm as the Base58 algorithm as an example, the SHA256 hash value of the file is first decoded using Hex to obtain the original first byte code X. The first byte code X is then encoded using the multihash algorithm to obtain the second byte code Y. The second byte code Y is then encoded using the Base58 algorithm, and the final result is the CID of the target file. In other words, the user can use the CID of the target file to find the corresponding file in IPFS. Because the SHA256 hash value of the target file is approximately 1.3 times the number of bytes of the SHA256 hash value of the target file during the encoding process of the CID V0 algorithm, compared with the CID of the target file, the byte number of the target file CID is approximately 1.3 times the number of bytes of the SHA256 hash value of the target file. Therefore, compared with the prior art that directly stores file links or CIDs, this embodiment can effectively reduce storage costs by storing the file link by storing the SHA256 hash value of the file.

[0081] Step S206: Generate a file link of the target file according to the content identifier of the target file, and return the file link of the target file to the user.

[0082] In this step, a file link of the target file is generated based on the CID of the target file. Taking IPFS as an example, "IPFS: / / " can be added to the CID to directly generate a file link of the target file. The file link of the target file is returned to the user, and the user can read the target file from IPFS through the file link.

[0083] According to the blockchain-based file link storage method provided by the embodiment of the present application, a first algorithm and a second algorithm are written into the smart contract. When a user requests to read the file link of a target file, the file identifier of the target file is extracted from the file link reading request, and a data key-value pair corresponding to the file identifier of the target file is obtained from the blockchain network. According to the first algorithm, the 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. Based on the original file hash value and the second algorithm in the smart contract, the CID or file link of the target file is generated in real time, thereby achieving the storage of the file link by storing the original file hash value with fewer bytes, and obtaining the same reading effect as directly storing the file CID. On the basis of ensuring the reading effect, the data storage amount is effectively reduced, the storage cost is greatly reduced, and the file link storage method is optimized.

[0084] Figure 3 The block diagram shows a structural diagram of a file link storage device based on blockchain according to an embodiment of the present application. Figure 3 As shown, the device includes: a storage module 301, an acquisition module 302 and a generation module 303:

[0085] The storage module 301 is used to store the original file hash value of the file stored in the distributed file system in the blockchain network according to the first algorithm in the smart contract deployed in the blockchain network.

[0086] The smart contract is provided with a first algorithm for storing the hash value of the original file and a second algorithm for generating a content identifier.

[0087] In an optional embodiment, the storage module 301 is further used to: obtain a file identifier of each file stored in the distributed file system; calculate the original file hash value of the file using a first preset hash algorithm; construct a data key-value pair corresponding to the file identifier of the file based on the first algorithm and the original file hash value of the file, and store the data key-value pair in the blockchain network; wherein the data key-value pair corresponding to the file identifier of the file includes the original file hash value of the file.

[0088] In an optional embodiment, the storage module 301 is further used to: according to the first algorithm, use the file identifier of the file as the data key and the original file hash value of the file as the data value corresponding to the data key to obtain a data key-value pair corresponding to the file identifier of the file; and store the data key-value pair in a smart contract deployed in the blockchain network.

[0089] In an optional embodiment, the storage module 301 is further used to: deploy the smart contract to the blockchain network by sending a transaction to the blockchain network in advance.

[0090] The acquisition module 302 is used to respond to a file link read request from a user for a target file and obtain an original file hash value of the target file from the blockchain network according to a first algorithm.

[0091] In an optional embodiment, the acquisition module 302 is further used to: extract the file identifier of the target file from the file link read request according to the first algorithm, and obtain the data key-value pair corresponding to the file identifier of the target file from the blockchain network, and obtain the original file hash value of the target file based on the data key-value pair corresponding to the file identifier of the target file.

[0092] In an optional embodiment, the acquisition module 302 is further used to: search for a data key-value pair with the file identifier of the target file as the data key from the smart contract deployed in the blockchain network as the data key value corresponding to the file identifier of the target file; and extract the data value in the data key-value pair corresponding to the file identifier of the target file as the original file hash value of the target file.

[0093] The generation module 303 is used to generate a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system.

[0094] In an optional implementation, the generating module 303 is further configured to: generate a file link of the target file according to the content identifier of the target file, and return the file link of the target file to the user.

[0095] In an optional embodiment, the second algorithm includes: a preset decoding algorithm, a second preset hash algorithm and a preset encoding algorithm; the generation module 303 is further used to: use the preset decoding algorithm to decode the hash value of the original file to obtain a first bytecode; use the second preset hash algorithm to encode the first bytecode to obtain a second bytecode; use the preset encoding algorithm to encode the second bytecode to obtain a content identifier of the target file.

[0096] In an optional embodiment, the distributed file system includes the InterPlanetary File System.

[0097] The description of each module above refers to the corresponding description in the method embodiment and will not be repeated here.

[0098] According to the blockchain-based file link storage device provided by the embodiment of the present application, a first algorithm and a second algorithm are written into the smart contract. When a user requests to read the file link of a target file, the file identifier of the target file is extracted from the file link reading request, and a data key-value pair corresponding to the file identifier of the target file is obtained from the blockchain network. According to the first algorithm, the 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. Based on the original file hash value and the second algorithm in the smart contract, the CID or file link of the target file is generated in real time, thereby achieving the storage of the file link by storing the original file hash value with fewer bytes, and obtaining the same reading effect as directly storing the file CID. On the basis of ensuring the reading effect, the data storage amount is effectively reduced, the storage cost is greatly reduced, and the file link storage method is optimized.

[0099] An embodiment of the present application also provides a non-volatile computer storage medium, which stores at least one executable instruction, and the executable instruction can execute the blockchain-based file link storage method in any of the above method embodiments.

[0100] Figure 4 A schematic structural diagram of a computing device according to an embodiment of the present application is shown. The specific embodiments of the present application do not limit the specific implementation of the computing device.

[0101] like Figure 4 As shown, the computing device may include: a processor 402 , a communications interface 404 , a memory 406 , and a communication bus 408 .

[0102] in:

[0103] The processor 402 , the communication interface 404 , and the memory 406 communicate with each other via a communication bus 408 .

[0104] The communication interface 404 is used to communicate with other devices such as clients or other servers.

[0105] Processor 402 is used to execute program 410, and specifically can execute the relevant steps in the above-mentioned blockchain-based file link storage method embodiment.

[0106] Specifically, the program 410 may include program codes, which include computer operation instructions.

[0107] Processor 402 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs, or may be processors of different types, such as one or more CPUs and one or more ASICs.

[0108] The memory 406 is used to store the program 410. The memory 406 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.

[0109] Program 410 can specifically be used to cause processor 402 to execute the blockchain-based file link storage method in any of the above-described method embodiments. The specific implementation of each step in program 410 can be found in the corresponding descriptions of the corresponding steps and units in the above-described blockchain-based file link storage method embodiments, and will not be repeated here. Those skilled in the art will clearly understand that for ease and brevity of description, the specific operating processes of the devices and modules described above can refer to the corresponding process descriptions in the above-described method embodiments, and will not be repeated here.

[0110] The algorithm and display provided herein are not inherently relevant to any particular computer, virtual system or other device. Various general-purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing this type of system. In addition, the embodiments of the present application are not directed to any specific programming language yet. It should be understood that various programming languages ​​can be utilized to realize the content of the embodiments of the present application described herein, and the description of the specific languages ​​above is for the purpose of disclosing the best mode of implementation of the embodiments of the present application.

[0111] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures, and techniques are not shown in detail so as not to obscure the understanding of this description.

[0112] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present application, the various features of the embodiments of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed embodiments of the present application require more features than the features explicitly recited in each claim. More precisely, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the embodiments of the present application.

[0113] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition may be divided into multiple submodules or subunits or subcomponents. All features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed herein may be combined in any combination, except that at least some of such features and / or processes or units are mutually exclusive. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0114] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features that are included in other embodiments but not other features, combinations of features from different embodiments are intended to be within the scope of the present invention and to form different embodiments. For example, in the claims below, any of the claimed embodiments may be used in any combination.

[0115] The various component embodiments of the embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all of the functions of some or all of the components in the embodiments of the present application. The embodiments of the present application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for performing a part or all of the methods described herein. Such a program implementing the embodiments of the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0116] It should be noted that the above embodiments illustrate rather than limit the embodiments of the present application, and that a person skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbols placed between brackets should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The embodiments of the present application may be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names.

Claims

1. A file link storage method based on blockchain, comprising: storing an original file hash value of a file stored in a distributed file system in the blockchain network according to a first algorithm in a smart contract deployed in the blockchain network; wherein the smart contract is provided with a first algorithm for storing the original file hash value and a second algorithm for generating a content identifier based on the original file hash value; and wherein the number of bytes of the original file hash value is less than the number of bytes of the content identifier; In response to a user's file link read request for a target file, obtaining an original file hash value of the target file from the blockchain network according to the first algorithm; Generate a content identifier of the target file based on the hash value of the original file and the second algorithm in the smart contract, so that the user can use the content identifier of the target file to obtain the target file from the distributed file system; The step of storing the original file hash value of the file stored in the distributed file system in the blockchain network according to the first algorithm in the smart contract deployed in the blockchain network further includes: For each file stored in the distributed file system, obtaining a file identifier of the file; Calculate the original file hash value of the file using a first preset hash algorithm; According to the first algorithm and the original file hash value of the file, a data key-value pair corresponding to the file identifier of the file is constructed, and the data key-value pair is stored in the blockchain network; wherein the data key-value pair corresponding to the file identifier of the file includes the original file hash value of the file.

2. The method according to claim 1, wherein After generating the content identifier of the target file according to the hash value of the original file and the second algorithm in the smart contract, the method further includes: A file link of the target file is generated according to the content identifier of the target file, and the file link of the target file is returned to the user.

3. The method according to claim 1, wherein 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 in the blockchain network further includes: According to the first algorithm, the file identifier of the file is used as a data key, and the original file hash value of the file is used as the data value corresponding to the data key, to obtain a data key-value pair corresponding to the file identifier of the file; The data key-value pairs are stored in a smart contract deployed in the blockchain network.

4. The method according to claim 1, wherein In response to a user's file link read request for a target file, obtaining the original file hash value of the target file from the blockchain network according to the first algorithm further includes: According to the first algorithm, the file identifier of the target file is extracted from the file link read request, and the data key-value pair corresponding to the file identifier of the target file is obtained from the blockchain network. Based on the data key-value pair corresponding to the file identifier of the target file, the original file hash value of the target file is obtained.

5. The method according to claim 4, wherein The step of obtaining a data key-value pair corresponding to the file identifier of the target file from the blockchain network, and obtaining an original file hash value of the target file based on the data key-value pair corresponding to the file identifier of the target file further includes: Searching for a data key-value pair with the file identifier of the target file as a data key from a smart contract deployed in the blockchain network as the data key-value corresponding to the file identifier of the target file; The data value in the data key-value pair corresponding to the file identifier of the target file is extracted as the original file hash value of the target file.

6. The method according to any one of claims 1 to 5, wherein: The second algorithm includes: 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 hash value of the original file and the second algorithm in the smart contract further includes: Decoding the original file hash value using the preset decoding algorithm to obtain a first bytecode; Encoding the first bytecode using the second preset hash algorithm to obtain a second bytecode; The second bytecode is encoded using the preset encoding algorithm to obtain a content identifier of the target file.

7. The method according to any one of claims 1 to 5, wherein: The method further comprises: The smart contract is deployed to the blockchain network in advance by sending a transaction to the blockchain network.

8. The method according to any one of claims 1 to 5, wherein: The distributed file system includes the InterPlanetary File System.

9. A file link storage device based on blockchain, comprising: a storage module configured to store an original file hash value of a file stored in a distributed file system in the blockchain network according to a first algorithm in a smart contract deployed in the blockchain network; wherein the smart contract is configured with a first algorithm for storing the original file hash value and a second algorithm for generating a content identifier based on the original file hash value; and the number of bytes of the original file hash value is less than the number of bytes of the content identifier; an acquisition module, configured to, in response to a user's file link read request for a target file, acquire an original file hash value of the target file from the blockchain network according to the first algorithm; a generation module, configured to generate a content identifier of the target file based on the hash value of the original file and a second algorithm in the smart contract, so that a user can use the content identifier of the target file to obtain the target file from the distributed file system; Wherein, the storage module is further used for: For each file stored in the distributed file system, obtaining a file identifier of the file; Calculate the original file hash value of the file using a first preset hash algorithm; According to the first algorithm and the original file hash value of the file, a data key-value pair corresponding to the file identifier of the file is constructed, and the data key-value pair is stored in the blockchain network; wherein the data key-value pair corresponding to the file identifier of the file includes the original file hash value of the file.

10. A computing device comprising: A processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the blockchain-based file link storage method according to any one of claims 1 to 8.

11. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction causes a processor to perform operations corresponding to the blockchain-based file link storage method according to any one of claims 1 to 8.

12. A computer program product comprising at least one executable instruction, wherein the executable instruction causes a processor to perform operations corresponding to the blockchain-based file link storage method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Knowledge graph storage and verification method based on blockchain and IPFS

    CN111177080A

  • Information recommendation method and system based on block chain and localized differential privacy protection

    CN111931233A

  • Real estate data processing method and device and electronic equipment

    CN112214456A