A method, system, and medium for portable file storage based on blockchain
By splitting files into sub-files and calculating hash values on the blockchain, and combining non-fungible tokens and directed acyclic graph records, the problems of blockchain storage resource consumption and security risks are solved, achieving secure and reliable portable file storage.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-01
- Publication Date
- 2026-03-20
AI Technical Summary
Storing ordinary files in the blockchain requires a lot of resources, and hashing on the chain poses security risks. Traditional centralized storage of file hashes is risky, while IPFS storage lacks a disaster recovery mechanism.
By splitting a file into sub-files using smart contracts on the blockchain, calculating the hash value of each sub-file and storing it in a tree structure, issuing non-fungible tokens to represent file assets, and using a directed acyclic graph to construct event records, the secure storage and revision of files can be achieved.
It reduces the storage pressure on the blockchain, avoids the risks of centralized storage, ensures file security and reliability, and achieves reliability and security for portable file storage.
Smart Images

Figure CN113901005B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data storage, and in particular to a method and system for portable file storage based on a blockchain, and a medium. BACKGROUND
[0002] Blockchain technology is a technology that allows any number of nodes in a participating system to calculate and record all information exchange data in the system within a period of time through a cryptographic algorithm to generate a fingerprint of the data block for linking to the next data block and checking, and all participating nodes in the system jointly determine whether the record is true. The data is usually stored in a KV key-value database, a relational database, a normal file, etc. Among them, the data structure and interface of the KV key-value database are relatively simple, have high read-write performance and good scalability, and can support large-scale concurrent read-write requests of key-value pairs; the normal file stores the original ledger blockchain data, which is usually serialized into a binary byte array in the protocol buffer encoding format after consensus, and then written into a file for persistent storage; the relational database (Relational Database Management System) is based on a strict relational model to represent and organize structured data, supports SQL statements for adding, deleting, modifying and querying operations, and provides complex transaction processing mechanisms that can meet the ACID principle.
[0003] When the blockchain network requires all users to maintain the same ledger, in order to ensure its non-tamperability, each user needs to keep a backup of the ledger locally, but when the ledger content changes, it needs to be stored again, which will consume a large amount of storage resources. In addition, only the file hash value can be stored in the blockchain, and the file to be stored is stored in a centralized database and / or a file storage server. In this way, storage becomes a short board in decentralized applications, which easily destroys the trust system built by the blockchain.
[0004] At present, there is no effective solution to the problems of consuming a large amount of resources for ordinary file storage and security risks of hash chaining in the related art. SUMMARY
[0005] The embodiments of the present application provide a method, system and medium for portable file storage based on a blockchain, to at least solve the problems of consuming a large amount of resources for ordinary file storage and security risks of hash chaining in the related art.
[0006] In a first aspect, the embodiments of the present application provide a method for portable file storage based on a blockchain, which comprises:
[0007] Call the splitting logic in the smart contract deployed on the blockchain to split the target file according to the preset storage capacity, and obtain corresponding sub-files;
[0008] Call the computing logic in the smart contract to calculate each of the sub-files to obtain the hash values of the sub-files, write the hash values in leaf nodes of a tree structure in sequence, and perform hierarchical calculation on the hash values to obtain a root hash value;
[0009] Call the storage logic in the smart contract to store the sub-files in the account book of the blockchain in sequence;
[0010] Call the asset logic in the smart contract to issue a non-fungible token for the target file, the non-fungible token representing the file asset of the transaction initiator of the target file, construct a file asset object according to a preset data structure, the file asset object having a plurality of immutable metadata attributes, the metadata attributes including the non-fungible token and the root hash value of the sub-file, and construct an event record in a preset direction sequence.
[0011] In some embodiments, calling the splitting logic in the smart contract deployed on the blockchain to split the target file according to the preset storage capacity to obtain corresponding sub-files includes:
[0012] Obtain the target file through the blockchain, and call the smart contract deployed on the blockchain to perform preset encoding on the target file;
[0013] Call the splitting logic in the smart contract deployed on the blockchain to split the string of the preset encoded target file according to the block capacity and / or transaction capacity of the blockchain, store the split sub-strings in an array in sequence, and obtain the sub-files corresponding to the target file.
[0014] In some embodiments, calling the asset logic in the smart contract to issue a non-fungible token for the target file, the non-fungible token representing the file asset of the transaction initiator of the target file, constructing a file asset object according to a preset data structure, the file asset object having a plurality of immutable metadata attributes, the metadata attributes including the non-fungible token and the root hash value of the sub-file, and constructing an event record in a preset direction sequence includes:
[0015] Call the asset logic in the smart contract to create a file asset belonging to the transaction initiator of the target file according to the file information of the target file;
[0016] calling asset logic in the smart contract, constructing a file asset object according to a preset data structure, storing several immutable metadata attributes into the file asset object, and constructing an event record using a directed acyclic graph, wherein the metadata attributes include the file asset, the type of the target file, the hash value of the target file, the root hash of the sub-file, and the certificate of the transaction initiator.
[0017] In some embodiments, after constructing the event record in the preset direction sequence, the method further comprises:
[0018] obtaining a revision file of the target file through the blockchain, calling revision logic in the smart contract deployed on the blockchain, obtaining sub-files of the target file, combining the sub-files in sequence, and calculating a root hash value corresponding to the combination;
[0019] In the case where the root hash value corresponding to the combination is consistent with the root hash value in the file asset object, according to revision events in the event record, sequentially obtaining difference information of the target file, and obtaining a new target file by restoring the difference information one by one through a difference algorithm;
[0020] calculating a difference value between the revision file and the new target file through a difference algorithm, and storing the difference value into a ledger of the blockchain;
[0021] calling the smart contract to write revision information into the file asset object of the target file according to a preset data structure, and recording the revision event in the event record.
[0022] In some embodiments, after constructing the event record in the preset direction sequence, the method further comprises:
[0023] obtaining a signature file of the target file through the blockchain, calling signature logic in the smart contract deployed on the blockchain, according to revision events and / or signature events in the event record, sequentially obtaining difference information and / or redundant information of the target file, and obtaining a new target file by restoring the difference information and / or redundant information one by one through a difference algorithm and / or an appending algorithm;
[0024] comparing the signature file and the new target file to obtain a redundant value, and storing the redundant value into a ledger of the blockchain;
[0025] calling the smart contract to write signature information into the file asset object of the target file according to a preset data structure, and recording the signature event in the event record.
[0026] In some embodiments, after the revision event or the signature event, the method further comprises:
[0027] The blockchain responds to file read requests, invokes the file read logic in the smart contract deployed on the blockchain, reads the sub-files of the target file, combines the sub-files in sequence, and calculates the root hash value of the sub-files.
[0028] Based on the revision events and / or signature events in the event log, read the difference information and / or redundant information of the target file sequentially, and restore the target file one by one through the differential algorithm and / or append algorithm;
[0029] The target file to be read is transmitted to the party requesting the read request.
[0030] In some embodiments, after constructing the event logs in a preset directional order, the method further includes:
[0031] Construct an access control list from the file information of the target file;
[0032] The certificate of the transaction initiator is obtained through the smart contract and written into the access control list in the file asset object;
[0033] When the transaction initiator grants authorization, it obtains the certificate of the authorized party through a smart contract and writes the certificate and permissions of the authorized party into the access control list, wherein the permissions include owner, read-only, revision and signature.
[0034] In some embodiments, after constructing the event logs in a preset directional order, the method further includes:
[0035] The smart contract is invoked to modify the description in the public ownership record of the target file, promoting the asset sale.
[0036] The smart contract agrees to preset sale conditions and calls the transfer logic in the smart contract to transfer the assets.
[0037] Secondly, embodiments of this application provide a system for portable file storage based on blockchain. The system includes a file storage module, a file revision module, a file signing module, a file reading module, a file asset transfer module, and a file sharing and permission module. The file storage module includes a segmentation unit, a computing unit, a storage unit, and an asset unit.
[0038] The segmentation unit calls the segmentation logic in the smart contract deployed on the blockchain to segment the target file according to the preset storage capacity, and obtains several corresponding sub-files;
[0039] The computing unit invokes computing logic in the smart contract, respectively computes a plurality of the sub-files to obtain hash values of the sub-files, writes the plurality of hash values in leaf nodes of a tree structure in sequence, and performs step-by-step computation on the hash values to obtain a root hash value;
[0040] The storage unit invokes storage logic in the smart contract, and stores the sub-files in a ledger of the blockchain in sequence;
[0041] The asset unit invokes asset logic in the smart contract, issues a non-fungible token for the target file, the non-fungible token represents a file asset of a transaction initiator of the target file, constructs a file asset object according to a preset data structure, the file asset object has a plurality of immutable metadata attributes, the metadata attributes include the non-fungible token and the root hash value of the sub-file, and constructs an event record in a preset direction sequence.
[0042] In a third aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the method for storing a portable file based on a blockchain according to the first aspect.
[0043] Compared with the related art, the method, system and medium for storing a portable file based on a blockchain provided by the embodiments of the present application invoke segmentation logic in a smart contract deployed on a blockchain, segment a target file according to a preset storage capacity to obtain a plurality of corresponding sub-files, invoke computing logic in the smart contract to respectively compute the plurality of sub-files to obtain hash values of the sub-files, write the plurality of hash values in leaf nodes of a tree structure in sequence, perform step-by-step computation on the hash values to obtain a root hash value, invoke storage logic in the smart contract to store the sub-files in a ledger of the blockchain in sequence, and invoke asset logic in the smart contract to issue a non-fungible token for the target file, the non-fungible token represents a file asset of a transaction initiator of the target file, construct a file asset object according to a preset data structure, the file asset object has a plurality of immutable metadata attributes, and construct an event record in a preset direction sequence. The method, system and medium solve the problem that a large amount of resources are consumed for storing an ordinary file in a blockchain and there is a security risk in hashing a file to a chain, reduce the pressure of blockchain storage, and achieve direct storage of a file in a blockchain ledger after a smart contract of the blockchain processes a service, so as to avoid risks brought to a file itself by traditional centralized storage of a file hash to a chain. BRIEF DESCRIPTION OF DRAWINGS
[0044] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and serve to explain the present application. In the drawings:
[0045] Figure 1 is a step flow chart of a portable file storage method based on a blockchain according to an embodiment of the present application;
[0046] Figure 2 is a flowchart of calculating a sub-file root hash value through a Merkle tree;
[0047] Figure 3 is a specific diagram of event records of a directed acyclic graph structure;
[0048] Figure 4 is a structural block diagram of a portable file storage system based on a blockchain according to an embodiment of the present application;
[0049] Figure 5 is a flowchart of storing a portable file based on a blockchain according to a specific embodiment of the present application;
[0050] Figure 6 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application.
[0051] BRIEF DESCRIPTION OF DRAWINGS: 41, file storage module; 42, file revision module; 43, file signature module; 44, file reading module; 45, file asset transfer module; 46, file sharing and permission module; 51, segmentation unit; 52, calculation unit; 53, storage unit; 54, asset unit. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and explained below in combination with the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of the present application.
[0053] Obviously, the drawings in the following description are only some examples or embodiments of the present application, and for those of ordinary skill in the art, the present application can also be applied to other similar scenarios without creative labor on the basis of these drawings. In addition, it can be understood that although the efforts made in this development process can be complex and lengthy, for those of ordinary skill in the art related to the content disclosed in the present application, some design, manufacture or production changes based on the technical content disclosed in the present application are only routine technical means and should not be understood as insufficient disclosure of the present application.
[0054] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment that is mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0055] Unless otherwise defined, the technical or scientific terms used in this application shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms “a,” “an,” “an,” “the,” and similar words used in this application do not indicate quantity limitation and may indicate singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units not listed, or may include other steps or units inherent to these processes, methods, products, or devices. The terms “connected,” “linked,” “coupled,” and similar words used in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following objects are in an "or" relationship. The terms "first," "second," and "third" used in this application are merely to distinguish similar objects and do not represent a specific ordering of the objects.
[0056] The inventors discovered that, taking public blockchains as an example, common blockchain storage requires all users to maintain the same ledger. To ensure its immutability, each user needs to keep a local backup of the ledger. Imagine there are 10,000 users on the network. A 1MB electronic labor contract requires 10GB of network resources. Then, after the employee signs it, the stored electronic labor contract information is modified, requiring further storage, again needing at least 10GB of resources. Next, the employer signs the document after the employee's signature, requiring another 10GB of resources. In summary, simply storing a 1MB electronic labor contract and meeting the signing requirements of all parties requires at least 30GB of resources.
[0057] In addition, a compromise solution is to only store the file hash value in the blockchain, and store the file to be stored in a centralized database and / or file storage server. In this way, storage becomes a short board in the decentralized application, which is a weak link in the network and is easy to destroy the trust system built by the blockchain. For example, when a labor dispute occurs between a laborer and an employer, if the information contained in the labor contract is not beneficial to the employer, the employer can delete the labor contract file stored in the aforementioned centralized database and / or file storage server through some means, and the file hash value stored on the chain cannot guarantee the rights and interests of the laborer.
[0058] In addition, there is a solution to store file data using IPFS (InterPlanetary File System). IPFS is a distributed file system, and its goal is to link all computing devices to the same file system, thereby becoming a global unified storage system, and realizing a global file storage system that is permanently available and data can be permanently saved on the Internet.
[0059] However, IPFS also faces the problem of lack of disaster recovery mechanism. Disaster recovery refers to when an IT system stops working due to an accident (such as fire, earthquake, etc.), the entire application system can be switched to another place, so that the system function can continue to work normally. IPFS / Filecoin does not provide a reliable disaster recovery and recovery mechanism for storage users, and the storage users centrally handle the disaster recovery backup and recovery work, which not only increases the redundancy of storage space by 2-3 times. Moreover, IPFS stores large files in different blocks, which inevitably has a hidden danger, that is, if all the nodes storing the file are offline and unavailable, and there is no backup for the file, the entire file is unavailable and permanently unrecoverable. Therefore, for an electronic contract, an insurance policy, or even some higher value but less frequently used files that need to be stored for 3 years, 5 years, 10 years, or 30 years, the potential storage risk brought by IPFS storage based on the timeline is too high.
[0060] Therefore, based on the problems existing in the above solutions, the present application provides a Blockchain Portable File Storage (BPFS) method based on a blockchain. The portable file refers to text, image and graphic data organized in the form of pages, and metadata that helps to identify, understand and present the data, and the electronic representation of the collection formed by the portable file. This representation can be reproduced on paper or displayed without causing significant loss of information content.
[0061] The embodiment of the present application provides a Blockchain Portable File Storage method based on a blockchain, Figure 1is a step flow chart of a blockchain-based portable file storage method according to an embodiment of the present application, the method comprising the following steps:
[0062] Step S102, calling the splitting logic in the smart contract deployed on the blockchain, splitting the target file according to the preset storage capacity to obtain corresponding sub-files;
[0063] Step S104, calling the calculation logic in the smart contract, calculating the hash values of the sub-files respectively to obtain the hash values of the sub-files, writing the hash values in the leaf nodes of the tree structure in sequence, and calculating the root hash value of the hash values step by step;
[0064] Specifically, Figure 2 is a flow diagram for calculating the root hash value of the sub-file by the Merkle tree, as Figure 2 shown, the hash values of the sub-files are calculated respectively, the hash values are written in the leaf nodes of the tree structure in sequence, and the root hash value (Root Hash) is calculated step by step.
[0065] Step S106, calling the storage logic in the smart contract, storing the sub-files in the account book of the blockchain in sequence;
[0066] Optionally, the sub-files after the target file is split are stored as private data of the transaction initiator on the blockchain.
[0067] Optionally, the encryption logic in the smart contract deployed on the blockchain is called before being stored in the account book, and the sub-files are encrypted by using symmetric and / or asymmetric encryption methods.
[0068] Optionally, the root hash value of the sub-file and the serial number of the sub-file are used as the index value of the state data, so as to quickly obtain the stored sub-file transaction from the "world state".
[0069] Step S108, calling the asset logic in the smart contract, issuing a non-fungible token for the target file, the non-fungible token representing the file asset of the transaction initiator of the target file, constructing a file asset object according to a preset data structure, the file asset object having a plurality of immutable metadata attributes, wherein the metadata attributes include the non-fungible token and the root hash value of the sub-file, and constructing an event record in a preset direction sequence.
[0070] It should be noted that the non-fungible token (Non-Fungible Token, NFT for short) has the characteristics of non-divisibility, non-substitutability, and uniqueness.
[0071] Through steps S102 to S108 in the embodiments of the present application, the problems that large files cannot be stored due to block size limitation, a large amount of resources is consumed for storing ordinary files in a blockchain, and there are security risks in hashing and chaining are solved, the pressure of blockchain storage is reduced, and after the business is processed by the blockchain smart contract, the file is directly stored in the blockchain ledger, so as to avoid the risks brought to the file itself by traditional centralized storage file hashing and chaining.
[0072] In some embodiments, step S102, the splitting logic in the smart contract deployed on the blockchain is called to split the target file according to a preset storage capacity to obtain corresponding subfiles, including:
[0073] The target file is obtained through the blockchain, and the smart contract deployed on the blockchain is called to pre-encode the target file;
[0074] The splitting logic in the smart contract deployed on the blockchain is called to split the string of the pre-encoded target file according to the block capacity and / or transaction capacity of the blockchain, and the split sub-strings are sequentially stored in an array to obtain the subfiles corresponding to the target file.
[0075] Specifically, the target file is obtained through the blockchain, and the smart contract is called to encode the target file, and the encoding method is usually Base64 encoding;
[0076] The smart contract is called to split the encoded string, and the sub-strings after the string splitting are not greater than the block and / or transaction capacity of the blockchain, and the aforementioned split sub-strings are sequentially stored in an array in order to obtain the subfiles corresponding to the target file.
[0077] In some embodiments, step S108, the asset logic in the smart contract is called to issue a non-fungible token for the target file, the non-fungible token represents the file asset of the transaction initiator of the target file, a file asset object is constructed according to a preset data structure, the file asset object has several immutable metadata attributes, the metadata attributes include the non-fungible token and the root hash value of the subfile, and an event record is constructed in a preset direction order, including:
[0078] The asset logic in the smart contract is called to create the file asset of the transaction initiator of the target file according to the file information of the target file;
[0079] The asset logic in the smart contract is called to build a file asset object according to a preset data structure, a plurality of immutable metadata attributes are stored in the file asset object, and a directed acyclic graph is used to build an event record, wherein the metadata attributes include a file asset, a type of a target file, a hash value of the target file, a root hash of a subfile, and a certificate of a transaction initiator.
[0080] Specifically, Figure 3 A specific diagram of the event record in a directed acyclic graph structure is as shown in Figure 3 As shown in the figure, the target file is divided into a plurality of subfiles to obtain a corresponding file version [0]; after revising the target file (file revision content [0]) (file version [0]), a corresponding file version [1] is obtained; after revising the file version [1] (file revision content [1]), a corresponding file version [2] is obtained; after signing the file version [2] (file signature content [0]), a corresponding file version [3] is obtained; and after signing the file version [3] (file signature content [1]), a corresponding file version [4] is obtained.
[0081] It should be noted that the storage, revision and signature events are recorded by using a one-way acyclic structure diagram, so that the file content can be restored in sequence. Because each block stores subcontent, for example, the file is revised twice and then signed. First, all the subfiles of the original file are obtained, sorted and restored to the original file; then the content of the first revision is obtained and restored by difference calculation to obtain the first revised file; then the content of the second revision is obtained and restored by difference calculation with the first revised file to obtain the second revised file; and then the signature content is appended to obtain the final complete file.
[0082] The stored hash value of the target file can be used to verify the change information of the file when the file is used; the stored root hash of the subfile can be used to determine whether the string of the divided and stored file block is sorted in the correct order, so as to restore the full string of the encoded file; and the stored certificate of the transaction initiator can be used to compare the certificate of the initiator with the certificate in the file information to ensure whether the other party has the right to operate the file when the transaction is initiated.
[0083] In some embodiments, after the event record is constructed in the preset direction sequence in step S108, the file revision method further includes:
[0084] The revision file of the target file is obtained by using the blockchain, the revision logic in the smart contract deployed on the blockchain is called, the subfiles of the target file are obtained, the subfiles are combined in sequence, and the root hash value corresponding to the combination is calculated;
[0085] In the case of combining the corresponding root hash value with the root hash value in the file asset object, according to the revision event in the event record, the difference information of the target file is obtained in sequence, and the new target file is obtained by difference algorithm one by one;
[0086] The difference value between the revised file and the new target file is calculated by the difference algorithm, and the difference value is stored in the ledger of the blockchain;
[0087] The smart contract is called to write the revision information into the file asset object of the target file according to the preset data structure, and the revision event is recorded in the event record.
[0088] Specifically, the revision file of the target file is obtained through the blockchain, the revision logic in the smart contract deployed on the blockchain is called, the subfiles of the target file are obtained according to the index of the target file, the subfiles are combined in sequence, and the root hash value corresponding to the combination is calculated by the Merkle tree;
[0089] When the calculated root hash value is consistent with the root hash value in the file asset object (indicating that the file is correct and there is no missing or arrangement error of subfiles), the revised file of the target file after revision is Base64 encoded through the smart contract;
[0090] The difference value between the revision file encoding and the target file encoding is calculated by the difference algorithm, and the difference value is further written into the ledger of the read-write storage of the blockchain;
[0091] Optionally, when the target file is revised multiple times, the smart contract deployed on the blockchain retrieves the target file according to the event record of the directed acyclic graph structure, and under the premise that there is a file revision event (i.e. there is a revision file for the target file), the target file is obtained first, then the recorded revision content is obtained in sequence, then the revised revision file is calculated by the difference algorithm, and the difference value is compared with the final revision file to obtain the difference value, and the difference value is further stored in the ledger of the blockchain;
[0092] The smart contract is called to write the revision information into the file asset object of the target file according to the preset data structure, and the revision event is recorded in the event record of the directed acyclic graph structure.
[0093] The calculation method of the difference algorithm includes calculating the difference content of the subfile, without calculating the difference of the full file.
[0094] In some embodiments, after constructing the event record in the preset direction sequence in step S108, the file signature method is further included:
[0095] The signature file of the target file is obtained through the blockchain, the signature logic in the smart contract deployed on the blockchain is called, the difference information and / or redundant information of the target file is sequentially obtained according to the revision event and / or signature event in the event record, and a new target file is obtained by sequentially restoring the difference information and / or redundant information through a difference algorithm and / or an appending algorithm.
[0096] The signature file and the new target file are compared to obtain redundant values, and the redundant values are stored in the ledger of the blockchain.
[0097] The smart contract is called to write the signature information into the file asset object of the target file according to a preset data structure, and the signature event is recorded in the event record.
[0098] Specifically, the transaction initiator obtains a target file or a final revision file thereof and performs signature, wherein the signature refers to a digital signature for authenticating the identity of a user and the validity of the file content.
[0099] The blockchain obtains the signed target file or the final revision file thereof, calls the signature logic in the smart contract deployed on the blockchain, compares the signature file and the aforementioned target file (or the final revision file), and writes the redundant values obtained by the aforementioned calculation into the ledger of the read-write storage of the blockchain.
[0100] The smart contract is called to write the electronic signature information into the file asset object of the target file according to a preset data structure, and the signature event is recorded in the event record of the directed acyclic graph structure.
[0101] Optionally, if the signature file adopts an appending signature mode, the new information after signature is usually appended to the tail of the original version.
[0102] In some embodiments, the method further includes a file reading method after the revision event or the signature event:
[0103] The blockchain responds to a file reading request, calls the file reading logic in the smart contract deployed on the blockchain, reads the sub-files of the target file, sequentially combines the sub-files, and calculates the root hash value of the sub-files.
[0104] The difference information and / or redundant information of the target file is sequentially read according to the revision event and / or signature event in the event record, and a target reading file is obtained by sequentially restoring the difference information and / or redundant information through a difference algorithm and / or an appending algorithm.
[0105] The target reading file is transmitted to the requester of the reading request.
[0106] Specifically, the requester initiates a read request, the blockchain responds to the read request, calls file read logic in the smart contract deployed on the blockchain to read sub-file content, and combines the sub-files in sequence to obtain the root hash value corresponding to the Merkle tree calculator;
[0107] According to the revision events and / or signature events recorded in the directed acyclic graph, the difference information and / or redundant information of the file is read one by one, and the foregoing difference algorithm and / or appending algorithm is used to restore the difference information and / or redundant information to obtain a new file after restoration;
[0108] The restored file is transmitted to the requester.
[0109] In some embodiments, after constructing the event records in the preset direction and sequence, a file sharing and permission setting method is further included:
[0110] An access control list is constructed in the file information of the target file;
[0111] The certificate of the transaction initiator is obtained through the smart contract, and is written into the access control list in the file asset object;
[0112] When the transaction initiator performs authorization permission, the certificate of the authorized permission party is obtained through the smart contract, and the certificate of the authorized permission party and the permission are written into the access control list, wherein the permission includes owner, read-only, revision, and signature.
[0113] Specifically, an access control list is constructed in the file information of the target file;
[0114] When the transaction initiator performs a file storage operation, the certificate information of the foregoing transaction initiator is obtained through the smart contract deployed on the blockchain, and is written into the access control list in the foregoing file asset object.
[0115] When the transaction initiator performs authorization permission, the certificate of the authorized permission party is obtained through the smart contract deployed on the blockchain, and the certificate of the authorized permission party and the permission are written into the access control list in the foregoing file asset object, and the permission includes:
[0116] The owner refers to the owner of all permissions of the file, which can read, revise, or sign the file, and can authorize operations for others;
[0117] Read-only refers to an authorized permission that can only obtain the file from the blockchain, and cannot revise or sign the file;
[0118] Revision refers to an authorized permission party that can not only obtain the file from the blockchain, but also revise the file;
[0119] Signing refers to the fact that the authorized party can not only obtain the file from the blockchain, but also sign the file;
[0120] When an authorized party modifies or signs a file, the smart contract obtains the authorized party's certificate and performs a search operation on the access control list in the file asset object. It verifies whether the authorized party's certificate matches the certificate in the aforementioned access control list. If the certificates match, it further verifies whether the corresponding permissions are consistent with the current operation. If the permissions are consistent, the subsequent operation is allowed; otherwise, the operation request is rejected.
[0121] In some embodiments, after the event logs are constructed in a preset directional order, a file asset transfer method is also included:
[0122] The smart contract is invoked to modify the description in the public ownership record of the target file, promoting the asset sale.
[0123] The smart contract agrees to the preset sale conditions and calls the transfer logic in the smart contract to transfer the assets.
[0124] Specifically, the asset owner invokes a smart contract deployed on the blockchain to change the description in the public ownership record, thus announcing the asset for sale;
[0125] The buyer and seller agree on the same price and reach an agreement on the transfer details through a smart contract deployed on the blockchain.
[0126] After the buyer and seller agree on the same price, the asset owner invokes the transfer logic in the smart contract deployed on the blockchain to transfer the asset to the buyer.
[0127] It should be noted that the steps shown in the above process or in the flowchart of the accompanying figures can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0128] This application provides a blockchain-based portable file storage system. Figure 4 This is a structural block diagram of a blockchain-based portable file storage system according to an embodiment of this application, such as... Figure 4 As shown, the system includes a file storage module 41, a file revision module 42, a file signing module 43, a file reading module 44, a file asset transfer module 45, and a file sharing and permission module 46. The file storage module includes a segmentation unit 51, a calculation unit 52, a storage unit 53, and an asset unit 54.
[0129] The splitting unit 51 invokes splitting logic in the smart contract deployed on the blockchain, splits the target file according to a preset storage capacity, and obtains corresponding sub-files;
[0130] The computing unit 52 invokes computing logic in the smart contract, respectively computes the sub-files, obtains hash values of the sub-files, writes the hash values in leaf nodes of a tree structure in sequence, and obtains a root hash value by performing level-by-level computation on the hash values;
[0131] The storage unit 53 invokes storage logic in the smart contract, and stores the sub-files in the ledger of the blockchain in sequence;
[0132] The asset unit 54 invokes asset logic in the smart contract, issues a non-fungible token for the target file, the non-fungible token represents a file asset of a transaction initiator of the target file, constructs a file asset object according to a preset data structure, the file asset object has a plurality of immutable metadata attributes, the metadata attributes include the non-fungible token and the root hash value of the sub-file, and constructs an event record in a preset direction sequence.
[0133] It should be noted that the above-mentioned various modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above-mentioned various modules can be located in the same processor; or the above-mentioned various modules can also be located in different processors in any combination.
[0134] The following specific embodiments use the Hyperledger Fabric blockchain network, and the smart contract is written in the go language. However, it should be clear to those skilled in the art that the selection of the blockchain network and the selection of the smart contract programming language do not affect the implementation of the method of the present application, and the present application is also applicable to other public chains, alliance chains and private chains, and the program language for writing the smart contract includes but is not limited to go, Java, Node.js and Solidity languages.
[0135] The specific embodiments of the present application provide a method for storing portable files based on a blockchain, Figure 5 is a flowchart of storing a portable file based on a blockchain according to the specific embodiments of the present application, and the portable file is stored through a smart contract, and the specific steps are as follows:
[0136] Step 1: A client application or a smart contract initiates a transaction request to the blockchain, and the transaction request contains a file to be stored.
[0137] Step two, the smart contract deployed on the blockchain responds to the target transaction request, calls the verification logic in the smart contract deployed on the blockchain, and verifies the legality of the file. The specific verification includes but is not limited to checking whether the file corresponding to the hash value of the original file in the transaction request exists, and if it exists, it is not allowed to store.
[0138] Step three, if the legality verification passes, further call the segmentation logic in the smart contract, and the specific segmentation steps are:
[0139] Encode the target file through the smart contract deployed on the blockchain, if the file itself is encoded in Base64 for transmission, only check its legality;
[0140] According to the capacity of the block and / or transaction pre-set by the blockchain, segment the Base64 encoded file string, each segmented file substring is not greater than the pre-set block and / or transaction capacity, and store the segmented file substring in the string array in the order, to obtain the sub-file array corresponding to the target file;
[0141] Call the calculation logic in the smart contract, use the Merkle tree to calculate the segmented sub-file of the target file, write the segmented sub-file string of the target file into the leaf node of the tree structure in order, calculate the hash value of the leaf node, and then obtain the final root hash value through the level-by-level calculation of the hash value.
[0142] Step four, call the storage logic in the smart contract to store the sub-file string in the sub-file array one by one, the smart contract calls the PutState method for writing operation, the PutState method receives the root hash value and the subscript corresponding to the sub-file array as the key name, receives the array content corresponding to the subscript of the sub-file array as the key value, and returns the transaction hash of this storage.
[0143] Optionally, the sub-file can be stored by using the private data mode, that is, the smart contract calls the PutPrivateData method to store the sub-file.
[0144] Optionally, the sub-file can be encrypted by using symmetric and / or asymmetric encryption method to ensure storage security.
[0145] Step five, call the asset logic in the smart contract to create assets for the target file. Issue an NFT for the file, which represents the file asset with a specific owner, build a file asset object, and set some immutable metadata attribute values. Among them, the asset ID is the hash of the target file to ensure that the same file does not generate multiple assets; the owner organization is the client organization ID obtained by the smart contract getClientOrgID method, and its permission is set to "owner"; the file index is the root hash value calculated by using the Merkle tree, and the original target subfile character array can be obtained by searching the root hash and subfile array indexes [0], [1], [2], [3]…, and the original target file Base64 encoded string can be restored by concatenating the subfile array in order; other information of the file can also be written in the file asset, such as file format, size, and file public description. Further, a directed acyclic graph structure is used to create file storage events and ordered indexes of corresponding subfiles. After the smart contract is processed by the json.Marshal method, the PutState method is called for writing operation.
[0146] The specific embodiment of the present application provides a method for storing portable files based on a blockchain, which stores the revised content of the portable file through a smart contract, and the specific steps are as follows:
[0147] The client application or the smart contract initiates a transaction request to the blockchain, and the transaction request contains the revised file and the hash value of the original file;
[0148] The smart contract deployed on the blockchain responds to the transaction request and calls the verification logic in the smart contract deployed on the blockchain to verify the legality of the file. The specific verification includes but is not limited to whether the file corresponding to the hash value of the original file in the transaction request exists; whether the revised file is different from the original file, i.e. there is a revision. Further, it is checked whether there is the client organization ID in the file asset, and the organization permission is "owner" or "revision", otherwise the file cannot be revised;
[0149] If the legality verification is passed, the revision logic in the smart contract is further called to obtain the subfiles stored in the original file and restore them into the original file. Further, it is checked whether there is a revision event in the file by using the event stored in the directed acyclic graph structure, and if there is, the final version is restored in order; if there is a signature event, the revised file is not allowed to be revised, otherwise the validity of the file signature will be damaged;
[0150] The difference algorithm in the smart contract is called to calculate the difference value between the revised file after Base64 encoding and the final version of the stored file, and PutState is called to write it to the block.
[0151] Optionally, the smart contract calls PutPrivateData to write it into private data.
[0152] The smart contract writes the current revision event into the directed acyclic graph of the file asset object according to the predetermined data structure.
[0153] The embodiment of the application provides a portable file storage method based on a block chain, and the portable file electronic signature content is stored through a smart contract. The specific steps are as follows:
[0154] The client application or the smart contract initiates a transaction request to the block chain, and the transaction request contains a signed file and a hash value of the original file.
[0155] The smart contract deployed on the block chain responds to the target transaction request, calls the verification logic in the smart contract deployed on the block chain, and performs legality verification on the file. The specific verification includes but is not limited to whether the file corresponding to the hash value of the original file in the transaction request exists; whether the signed file is different from the original file, that is, the signature is correct. Further, it is further retrieved whether the client organization ID exists in the file asset, and the organization permission is "owner" or "signature", otherwise the file signature storage is not allowed.
[0156] If the legality verification passes, the signature logic in the smart contract is further called, the sub-file stored in the original file is obtained and spliced to restore the original file. And through the event stored by using the directed acyclic graph structure, it is further retrieved whether the file has a revision and / or signature event, if there is, it is sequentially restored into the final version one by one.
[0157] The smart contract is called to perform Base64 encoding on the signed file, and then the excess value of the final version of the stored file after restoration is compared and calculated, and PutState is called to write the excess value into the block. The file signature generally adopts an additional signature mode, otherwise the file integrity may be damaged.
[0158] Optionally, the smart contract calls PutPrivateData to write it into private data.
[0159] The smart contract writes the current signature event into the directed acyclic graph of the file asset object according to the predetermined data structure.
[0160] The embodiment of the application provides a portable file storage method based on a block chain, and the portable file electronic signature content is stored through a smart contract. The specific steps are as follows:
[0161] The smart contract deployed on the blockchain responds to the file reading request, acquires the client organization ID through the GetMSPID method, and further checks whether the client ID exists in the owner organization of the file asset. If not, the file is not allowed to be read.
[0162] After the reading permission is granted, the smart contract acquires all stored subfiles through the file index, calculates the root hash value of the acquired subfile through the Merkle tree, and further checks whether the root hash value is consistent with the root hash value in the file asset to determine whether the file is restored in sequence.
[0163] If the calculated and stored root hash values are consistent, the revised content is further read according to the revision event stored in the directed acyclic graph structure, the difference algorithm in the smart contract is called, the file revision content is restored one by one, and the final revision content is obtained.
[0164] According to the signature event stored in the directed acyclic graph structure, the signature content is further read and restored to the tail of the file content in sequence, and the final signature content is obtained.
[0165] The final file content is returned to the transaction requester.
[0166] Embodiments of the present application provide a portable file storage method based on a blockchain. The smart contract transfers the portable file asset, and the specific steps are as follows:
[0167] The current owner of the file asset updates the asset public description by calling the smart contract deployed on the blockchain.
[0168] The smart contract adds the asking price of the seller to the seller's private and private data set.
[0169] The smart contract adds the bid of the buyer to the private and private data set of the buyer.
[0170] The smart contract allows the buyer to verify the asset attributes according to the private and private data set of the owner.
[0171] When the current owner of the file asset calls the smart contract to check the transfer conditions, that is, checks whether the current client organization owns the asset and whether the price has been agreed upon by both parties, the asset state is then transferred to the buyer.
[0172] The smart contract further performs public and private state updates for the transferred file asset.
[0173] Embodiments of the present application provide a portable file storage method based on a blockchain. The smart contract sets up portable file sharing and permissions, and the specific steps are as follows:
[0174] When the current client organization initiates a file storage transaction to the blockchain, the smart contract deployed on the blockchain obtains the client organization ID through the GetMSPID method, and further calls the PutState method to write the client organization ID into the access control list of the file asset, and the corresponding permission is "owner".
[0175] The client organization with the permission of "owner" in the access control list of the file asset can further call the smart contract to write other client organization IDs into the access control list of the file asset, and can set the permissions as "owner", "read only", "signature" and "revision" respectively. The PutState method is called to update the file asset through the smart contract.
[0176] In combination with the method for storing portable files based on the blockchain in the above embodiments, an embodiment of the present application can provide a storage medium for implementation. The storage medium stores a computer program. When the computer program is executed by a processor, any method for storing portable files based on the blockchain in the above embodiments is implemented.
[0177] In one embodiment, a computer device can be provided, which can be a terminal. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is configured to communicate with external terminals through network connection. The computer program is executed by the processor to implement a method for storing portable files based on the blockchain. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad or mouse, etc.
[0178] In one embodiment, Figure 6 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application, as Figure 6 shown, an electronic device can be provided, which can be a server, and the internal structure diagram of the electronic device can be as Figure 6As shown. The electronic device includes a processor, a network interface, an internal memory and a non-volatile memory connected through an internal bus, wherein the non-volatile memory stores an operating system, a computer program and a database. The processor is used to provide computing and control capabilities, the network interface is used to communicate with external terminals through network connection, the internal memory is used to provide an environment for the operation of the operating system and the computer program, the computer program is executed by the processor to implement a method for storing portable files based on a blockchain, and the database is used to store data.
[0179] Those skilled in the art can understand that Figure 6 The structure shown in the figure is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0180] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. Any reference to memory, storage, database or other medium used in the embodiments provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM) and the like.
[0181] Those skilled in the art should understand that each technical feature of the above-mentioned embodiments can be combined arbitrarily. In order to make the description simple, all possible combinations of each technical feature in the above-mentioned embodiments are not described, but as long as the combination of technical features does not exist, it should be considered as the scope of the present application.
[0182] The above-described embodiments are merely illustrative of several embodiments of the present application, which are described in more detail and in a specific manner, but should not be construed as limiting the scope of the patent. It should be noted that for those skilled in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. A method for portable file storage based on blockchain, characterized in that, The method includes: The splitting logic in the smart contract deployed on the blockchain is invoked to split the target file according to the preset storage capacity, resulting in several corresponding sub-files; The calculation logic in the smart contract is invoked to calculate the hash values of the sub-files respectively, and the hash values are written into the leaf nodes of the tree structure in sequence. The root hash value is obtained by calculating the hash values level by level. The storage logic in the smart contract is invoked to store the sub-files sequentially into the ledger of the blockchain; The asset logic in the smart contract is invoked to issue a non-fungible token (NFT) for the target file. This NFT represents the file asset of the transaction initiator of the target file. A file asset object is constructed according to a preset data structure. This file asset object has several immutable metadata attributes, including the NFT and the root hash value of the sub-file. Event records are then constructed in a preset directional order, including: The asset logic in the smart contract is invoked to create a file asset belonging to the transaction initiator of the target file based on the file information of the target file; The asset logic in the smart contract is invoked to construct a file asset object according to a preset data structure. Several immutable metadata attributes are stored in the file asset object, and an event record is constructed using a directed acyclic graph. The metadata attributes include the file asset, the type of the target file, the hash value of the target file, the root hash of the sub-file, and the certificate of the transaction initiator.
2. The method according to claim 1, characterized in that, The segmentation logic within a smart contract deployed on the blockchain is invoked to segment the target file according to a preset storage capacity, resulting in several corresponding sub-files, including: The target file is obtained through the blockchain, and a smart contract deployed on the blockchain is invoked to perform a preset encoding on the target file. The segmentation logic in the smart contract deployed on the blockchain is invoked to segment the string of the target file after pre-encoding, based on the block capacity and / or transaction capacity of the blockchain. The segmented substrings are then stored in an array in sequence to obtain the subfiles corresponding to the target file.
3. The method according to claim 1, characterized in that, After constructing the event records in a preset directional order, the method further includes: The revised file of the target file is obtained through the blockchain, the revision logic in the smart contract deployed on the blockchain is called, the sub-files of the target file are obtained, the sub-files are combined in sequence, and the root hash value corresponding to the combination is calculated. If the root hash value corresponding to the combination is consistent with the root hash value in the file asset object, the difference information of the target file is obtained sequentially according to the revision events in the event record, and the new target file is obtained by restoring it one by one through the differential algorithm; The difference between the revised file and the new target file is calculated using a differential algorithm, and the difference is stored in the ledger of the blockchain. The smart contract is invoked to write the revision information into the file asset object of the target file according to the preset data structure, and the revision event is recorded in the event log.
4. The method according to claim 1, characterized in that, After constructing the event records in a preset directional order, the method further includes: The signature file of the target file is obtained through the blockchain, the signature logic in the smart contract deployed on the blockchain is called, and the difference information and / or redundant information of the target file are obtained sequentially according to the revision event and / or signature event in the event record. The new target file is then restored one by one through the difference algorithm and / or append algorithm. The signature file and the new target file are compared to obtain a redundant value, and the redundant value is stored in the ledger of the blockchain; The smart contract is invoked to write the signature information into the file asset object of the target file according to the preset data structure, and the signature event is recorded in the event log.
5. The method according to claim 3 or 4, characterized in that, Following a revision event or a signature event, the method further includes: The blockchain responds to file read requests, invokes the file read logic in the smart contract deployed on the blockchain, reads the sub-files of the target file, combines the sub-files in sequence, and calculates the root hash value of the sub-files. Based on the revision events and / or signature events in the event log, read the difference information and / or redundant information of the target file sequentially, and restore the target file one by one through the differential algorithm and / or append algorithm; The target file to be read is transmitted to the party requesting the read request.
6. The method according to claim 1, characterized in that, After constructing the event records in a preset directional order, the method further includes: Construct an access control list from the file information of the target file; The certificate of the transaction initiator is obtained through the smart contract and written into the access control list in the file asset object; When the transaction initiator grants authorization, it obtains the certificate of the authorized party through a smart contract and writes the certificate and permissions of the authorized party into the access control list, wherein the permissions include owner, read-only, revision and signature.
7. The method according to claim 1, characterized in that, After constructing the event records in a preset directional order, the method further includes: The smart contract is invoked to modify the description in the public ownership record of the target file, promoting the asset sale. The smart contract agrees to preset sale conditions and calls the transfer logic in the smart contract to transfer the assets.
8. A system for portable file storage based on blockchain, characterized in that, The system includes a file storage module, a file revision module, a file signing module, a file reading module, a file asset transfer module, and a file sharing and permissions module. The file storage module includes a segmentation unit, a calculation unit, a storage unit, and an asset unit. The segmentation unit calls the segmentation logic in the smart contract deployed on the blockchain to segment the target file according to the preset storage capacity, and obtains several corresponding sub-files; The computing unit calls the computing logic in the smart contract to calculate the hash values of the sub-files respectively, writes the hash values into the leaf nodes of the tree structure in sequence, and calculates the root hash value level by level. The storage unit calls the storage logic in the smart contract to store the sub-files sequentially into the ledger of the blockchain; The asset unit invokes the asset logic in the smart contract to issue a non-fungible token (NFT) for the target file. The NFT represents the file asset of the transaction initiator of the target file. A file asset object is constructed according to a preset data structure. This file asset object has several immutable metadata attributes, including the NFT and the root hash value of the sub-file. Event records are then constructed in a preset directional order, including: The asset logic in the smart contract is invoked to create a file asset belonging to the transaction initiator of the target file based on the file information of the target file; The asset logic in the smart contract is invoked to construct a file asset object according to a preset data structure. Several immutable metadata attributes are stored in the file asset object, and an event record is constructed using a directed acyclic graph. The metadata attributes include the file asset, the type of the target file, the hash value of the target file, the root hash of the sub-file, and the certificate of the transaction initiator.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method for blockchain-based portable file storage as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Artwork auction method and system based on block chain
CN111639924A
Efficient industrial big data file chaining method and device based on blockchain
CN113055431A