A method and device for processing blockchain information
By constructing a logical structure tree of the Json string and using the commutative law aggregation algorithm to calculate the hash value, the problem of low calculation performance and poor versatility of the Json string hash value in the existing technology is solved, and an efficient and universal hash value is achieved. calculate.
Patent Information
- Application Number
- CN202111214164.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-19
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-10-19
AI Technical Summary
The existing technology has low performance and poor versatility when calculating hash values of Json strings, especially when processing a large number of Json strings, which requires a large amount of computing resources, and different key order rules need to be defined in different application scenarios.
By building a logical structure tree of Json strings, traversing nodes recursively to determine the traversal path, splicing each path, and using an aggregation algorithm that complies with the commutative law to calculate the hash value, avoiding dependence on key order.
It improves the performance of Json string hash value calculation, reduces the consumption of computing resources, achieves no impact on the order of different keys, and enhances the versatility of the method.
Smart Images

Figure CN113989000B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of financial technology (Fintech), and in particular, to a method and device for processing blockchain information. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to financial technology. However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. In the financial field, when financial business data (such as transaction data or customer data, etc.) needs to be uploaded to the blockchain in the Json data format, it is necessary to perform a hash operation on the financial business data in the Json data format, and upload the hash value obtained by the hash operation to the blockchain, so that the data demander can verify the integrity of the financial business data in the Json data format through the hash value when obtaining the financial business data in the Json data format. However, since the Json string is a non-deterministic encoding, when the order of the same-level keys in the Json string is different, the hash value of the obtained Json string is also different. In view of this, in order to ensure the quality of financial services, how to calculate the hash value of the Json string in a timely and effective manner has become an urgent problem to be solved.
[0003] At present, before calculating the hash value of a Json string, the Json string will be sorted according to the pre-defined key order rules in the Json encoding to obtain the sorted Json string. Then, the sorted Json string is hashed to obtain the hash value of the Json string. However, this processing method consumes a lot of computing resources when sorting a huge number of Json strings, and the time complexity is high, resulting in low performance of the system when calculating the hash value of the Json string. At the same time, since different key order rules in Json encoding need to be defined in advance for different application scenarios, this processing method has poor versatility.
[0004] In summary, there is an urgent need for a method for processing blockchain information to improve the performance of the system when calculating the hash value of a Json string. Summary of the invention
[0005] The embodiments of the present invention provide a method and device for processing blockchain information, so as to improve the performance of the system when calculating the hash value of a Json string.
[0006] In a first aspect, an embodiment of the present invention provides a method for processing information on a blockchain, including:
[0007] For the Json string to be chained, a logical structure tree of the Json string to be chained is constructed; each field in the Json string to be chained corresponds to each node in the logical structure tree one by one;
[0008] By recursively traversing each node in the logical structure tree, a traversal path corresponding to each leaf node is determined;
[0009] For each traversal path, each node belonging to the traversal path is spliced to obtain a spliced field;
[0010] The hash values of each spliced field are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, and the hash value of the Json string to be uploaded to the chain is uploaded to the blockchain.
[0011] In the above technical scheme, when calculating the hash value of the Json string, the prior art scheme needs to sort the key-value pairs in the Json string according to the pre-defined key order rules in the Json encoding, and then determine the hash value of the Json string by performing a hash operation on the sorted Json string. And a certain amount of computing resources are required to sort the key-value pairs in the Json string, which results in low performance of the system when calculating the hash value of the Json string. At the same time, since the prior art scheme needs to set the corresponding key order rules for different systems or different application scenarios, the prior art scheme has poor versatility. Based on this, the technical solution in the present invention recursively traverses the logical structure tree constructed for the Json string to be chained, and aggregates the splicing fields corresponding to each traversal path through an aggregation algorithm that conforms to the commutative law, so as to accurately determine the hash value of the Json string to be chained, without having to define the key sequence rules in advance, and there is no need to sort the key-value pairs in the Json string according to the corresponding key sequence rules, thereby avoiding the influence of the key sequence in the Json string on the hash value of the Json string, having good versatility, and improving the performance of the system when calculating the hash value of the Json string. Specifically, for the Json string to be chained, a logical structure tree of the Json string to be chained is constructed, and by recursively traversing each node in the logical structure tree, the traversal path corresponding to each leaf node can be determined. Then for each traversal path, each node belonging to the traversal path is spliced to obtain the spliced field, and the hash value of each spliced field is aggregated in accordance with the commutative law to accurately obtain the hash value of the Json string to be chained, and the hash value of the Json string to be chained is uploaded to the blockchain. In this way, since the characteristics of the aggregation algorithm that satisfies the commutative law adopted by the scheme are consistent with the characteristics that the same-level keys in the Json string can be arbitrarily swapped in order, the hash values of all Json strings with the same meaning (i.e., the same actual content) determined by the scheme are unique, so the scheme does not need to define the key order rules, has good versatility, and does not need to sort the key-value pairs in the Json string, and has low time complexity, so it can reduce the computing resources consumed by sorting the Json string, thereby helping to improve the performance of the system when calculating the hash value of the Json string.
[0012] Optionally, for the Json string to be chained, constructing a logical structure tree of the Json string to be chained includes:
[0013] The logical structure tree is constructed according to the position order of each field in the Json string to be chained.
[0014] In the above technical scheme, in order to ensure that each field in the Json string to be chained can be traversed clearly and accurately in the future, so as to provide support for ensuring the uniqueness of the hash value of the Json string to be chained, the scheme first constructs a logical structure tree of the Json string to be chained according to the position order of each field in the Json string to be chained, and then recursively traverses each node in the logical structure tree to determine the traversal path corresponding to each leaf node, and for each traversal path, splices at least one node of the traversal path according to the backtracking order of the traversal path to ensure the uniqueness of the spliced field, thereby ensuring that support is provided for the uniqueness of the hash value of the Json string to be chained.
[0015] Optionally, recursively traversing each node in the logical structure tree to determine a traversal path corresponding to each leaf node includes:
[0016] For any node belonging to the first level in the logical structure tree, the node is taken as the current node, and the current node is traversed in the following manner:
[0017] If it is determined that there is an untraversed node belonging to the next level of the current node, the untraversed node is used as the current node, and the traversal is continued until the node belonging to the next level is a leaf node during the traversal process, and the traversal is stopped, thereby obtaining a traversal path for the leaf node;
[0018] The parent node of the leaf node is used as the current node to continue traversing. If it is determined that there is no untraversed node in the next level belonging to the current node, the parent node of the current node is used as the current node to continue traversing until all leaf nodes are traversed.
[0019] In the above technical scheme, each node in the logical structure tree can be recursively traversed by a depth-first traversal algorithm or a breadth-first traversal algorithm, so that each leaf node in the logical structure tree can be traversed, so that the traversal path corresponding to each leaf node can be determined, and at least one node contained in each traversal path can be determined, so as to provide support for the subsequent splicing of at least one node contained in each traversal path to accurately determine the hash value corresponding to the traversal path, and at the same time, the uniqueness of the splicing field corresponding to the traversal path can be determined based on the order of backtracking from the leaf nodes of each traversal path, so as to ensure the uniqueness of the hash value of the Json string to be chained that is subsequently calculated. Moreover, the scheme only needs to recursively traverse each node in the logical structure tree once by a depth-first traversal algorithm or a breadth-first traversal algorithm, so the time complexity of the scheme is low, the computing resources consumed are small, and the system has high performance in calculating the hash value of the Json string.
[0020] Optionally, each node belonging to the traversal path is concatenated to obtain a concatenated field, including:
[0021] Backtracking from the leaf nodes of the traversal path to obtain each node of the traversal path;
[0022] The fields of each node are concatenated in a backtracking order to obtain a concatenated field.
[0023] In the above technical scheme, for each traversal path, by backtracing back from the leaf node of the traversal path, each node of the traversal path can be accurately obtained, and at the same time, the fields of each node of the traversal path are spliced in the order of backtracing back from the leaf node of the traversal path to obtain the spliced fields corresponding to the traversal path. In this way, it can be avoided that the fields of each node are randomly spliced to affect the uniqueness of the hash value of the subsequently calculated Json string to be uploaded to the chain, thereby ensuring the uniqueness of the hash value of the Json string to be uploaded to the chain, and providing data support for the subsequent determination of the hash value of the Json string to be uploaded to the chain.
[0024] Optionally, the concatenating the fields of each node in a backtracking order to obtain a concatenated field includes:
[0025] In the backtracking order, the fields of each node are concatenated by setting symbols to obtain a concatenated field.
[0026] In the above technical solution, for each traversal path, the fields of each node of the traversal path are spliced using setting symbols in the order of backtracking starting from the leaf node of the traversal path. This can ensure the uniqueness of the spliced fields, thereby ensuring the uniqueness of the hash value of the Json string to be uploaded to the chain that is subsequently calculated.
[0027] Optionally, the concatenating the fields of each node in a backtracking order to obtain a concatenated field includes:
[0028] In the backtracking order, the fields of each node are hashed level by level to obtain the concatenated fields.
[0029] In the above technical solution, for each traversal path, the fields of each node of the traversal path are spliced in a step-by-step hashing manner in the order of backtracking from the leaf node of the traversal path to obtain a unique spliced field, thereby ensuring the uniqueness of the spliced field, thereby ensuring the uniqueness of the hash value of the Json string to be uploaded to the chain subsequently calculated.
[0030] Optionally, the hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, including:
[0031] For any splicing field, determine the hash value of the splicing field by using a set hash algorithm;
[0032] The hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain.
[0033] In the above technical scheme, after the hash value of each spliced field is determined by the set hash algorithm, the hash value of each spliced field can be aggregated by an aggregation algorithm that conforms to the commutative law. Then the scheme will not be affected by the order of the same-level keys in the Json string to be chained, that is, no matter how the order of the same-level keys in the Json string to be chained is adjusted, it will not affect the hash value of the Json string to be chained that is finally determined to be unique. In this way, a unique hash value of the Json string to be chained can be obtained, thereby ensuring the uniqueness of the hash value of the Json string to be chained.
[0034] In a second aspect, an embodiment of the present invention further provides a device for processing blockchain information, including:
[0035] A construction unit is used to construct a logical structure tree of the Json string to be chained, for the Json string to be chained; each field in the Json string to be chained corresponds to each node in the logical structure tree one by one;
[0036] The processing unit is used to determine the traversal path corresponding to each leaf node by recursively traversing each node in the logical structure tree; for each traversal path, concatenate each node belonging to the traversal path to obtain a concatenated field; aggregate the hash value of each concatenated field in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, and upload the hash value of the Json string to be uploaded to the blockchain.
[0037] Optionally, the construction unit is specifically used for:
[0038] The logical structure tree is constructed according to the position order of each field in the Json string to be chained.
[0039] Optionally, the processing unit is specifically configured to:
[0040] For any node belonging to the first level in the logical structure tree, the node is taken as the current node, and the current node is traversed in the following manner:
[0041] If it is determined that there is an untraversed node belonging to the next level of the current node, the untraversed node is used as the current node, and the traversal is continued until the node belonging to the next level is a leaf node during the traversal process, and the traversal is stopped, thereby obtaining a traversal path for the leaf node;
[0042] The parent node of the leaf node is used as the current node to continue traversing. If it is determined that there is no untraversed node in the next level belonging to the current node, the parent node of the current node is used as the current node to continue traversing until all leaf nodes are traversed.
[0043] Optionally, the processing unit is specifically configured to:
[0044] Backtracking from the leaf nodes of the traversal path to obtain each node of the traversal path;
[0045] The fields of each node are concatenated in a backtracking order to obtain a concatenated field.
[0046] Optionally, the processing unit is specifically configured to:
[0047] In the backtracking order, the fields of each node are concatenated by setting symbols to obtain a concatenated field.
[0048] Optionally, the processing unit is specifically configured to:
[0049] In the backtracking order, the fields of each node are hashed level by level to obtain the concatenated fields.
[0050] Optionally, the processing unit is specifically configured to:
[0051] For any splicing field, determine the hash value of the splicing field by using a set hash algorithm;
[0052] The hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain.
[0053] In a third aspect, an embodiment of the present invention provides a computing device, comprising at least one processor and at least one memory, wherein the memory stores a computer program, and when the program is executed by the processor, the processor executes the method for processing blockchain on-chain information as described in any of the first aspects above.
[0054] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing a computer program executable by a computing device, wherein when the program is run on the computing device, the computing device executes the method for processing blockchain information as described in any of the first aspects above. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0056] Figure 1 A flowchart of a method for processing blockchain information provided by an embodiment of the present invention;
[0057] Figure 2 A schematic diagram of a logical structure tree of a Json string provided in an embodiment of the present invention;
[0058] Figure 3 A schematic diagram of the structure of a device for processing blockchain information provided by an embodiment of the present invention;
[0059] Figure 4 A schematic diagram of the structure of a computing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0061] Figure 1 The present invention exemplarily illustrates a process of a method for processing information on a blockchain provided by an embodiment of the present invention, which process can be executed by a device for processing information on a blockchain.
[0062] like Figure 1 As shown in the figure, the process specifically includes:
[0063] Step 101: construct a logical structure tree of the Json string to be chained.
[0064] In the field of blockchain, there is usually a need to extract a unique hash value from a Json string, such as for evidence storage or transaction coding. For example, if some users or enterprises want to store electronic data, they will calculate a hash value for the electronic data, and upload the hash value of the electronic data to the blockchain to prevent the electronic data from being tampered with, while ensuring the integrity and authenticity of the electronic data. For example, assuming that the electronic data is in the Json data format, the hash value of the electronic data in the Json data format will be calculated, and the hash value of the electronic data in the Json data format will be uploaded to the blockchain. However, since the Json string is a non-deterministic encoding, the order of the same-level keys will not affect the actual content of the Json string, but will affect the hash value of the final calculated Json string. Therefore, directly calculating the hash value of the Json string cannot meet the requirement of one-to-one correspondence between the hash value and the input value, that is, if the order of the same-level keys changes, the hash value of the calculated Json string is also different, for example, taking the example shown in Table 1 as an example.
[0065] Table 1
[0066]
[0067] According to Table 1, the hash values of Json strings with the same actual content are different because the order of the keys changes. Specifically, the actual content displayed by the Json string numbered 1 is the same as the actual content displayed by the Json string numbered 2. The order of the keys in the Json string numbered 1 is "key1": "value1" first, "key2": "value2" second. The hash value obtained by performing a hash operation on the Json string numbered 1 is 5e508845eee488191df138185d83d310, while the order of the keys in the Json string numbered 1 is " key2": "value2" is in front, "key1": "value1" is in the back, and the hash value obtained by performing a hash operation on the Json string numbered 2 is bbac682c90954325450272cdcbf363f7. It can be seen that the two Json strings with the same actual content have different calculated hash values due to the different order of the keys, which is inconsistent with the requirement of one-to-one correspondence between hash values and input values, and cannot ensure the uniqueness of the hash values of Json strings with the same actual content. Therefore, in the existing technical solution for this problem, the keys in the Json string are sorted by defining the order rules of the keys in the Json string in advance, and then a hash operation is performed on the sorted Json string to determine the hash value of the Json string. In this way, the existing technical solution can meet the requirement of one-to-one correspondence between the hash value and the input value, and can ensure the uniqueness of the hash value of the Json string. However, the existing technical solutions need to consume a lot of computing resources when sorting a huge number of Json strings. For example, the existing technical solutions use a bubble sort algorithm, a quick sort algorithm, or a binary tree sort algorithm, etc., so the time complexity is high, resulting in low performance of the system when calculating the hash value of the Json string. Moreover, since different rules for the order of keys in the Json string need to be defined in advance for different systems, the existing technical solutions have poor versatility.
[0068] In view of this, the technical solution in the embodiment of the present invention, in order to solve the technical problems existing in the prior art solution, first constructs a logical structure tree for the Json string to be chained, so that only one recursive traversal is required for each node in the logical structure tree to determine the traversal path corresponding to each leaf node, so that the time complexity of the solution is also reduced, thereby improving the performance of the system when calculating the hash value of the Json string. At the same time, by constructing the logical structure tree of the Json string to be chained, it can be ensured that each field in the Json string to be chained can be clearly and accurately traversed in the future, so as to provide support for ensuring the uniqueness of the hash value of the Json string to be chained. Specifically, by following the position order of each field in the Json string to be chained, the logical structure tree of the Json string to be chained can be constructed, and then by recursively traversing each node in the logical structure tree, the traversal path corresponding to each leaf node can be determined, and for each traversal path, at least one node of the traversal path is spliced according to the backtracking order of the traversal path to ensure the uniqueness of the spliced field, thereby ensuring that the uniqueness of the hash value of the Json string to be chained is provided. Among them, each field in the Json string to be uploaded to the chain corresponds one-to-one to each node in the logical structure tree.
[0069] For example, take a Json string as an example, for example, the Json string is:
[0070]
[0071]
[0072] By expressing the logical relationship of each field in the above Json string in the form of a tree structure, that is, constructing it in sequence according to the position order of each field in the above Json string, the following can be constructed: Figure 2 The logical structure tree of the Json string shown. Among them, each field in the above Json string corresponds to each node of the logical structure tree one by one. In this way, the logical structure tree can clearly and accurately display each field in the Json string, so that each node in the logical structure tree can be recursively traversed later by a depth-first traversal algorithm or a breadth-first traversal algorithm.
[0073] Step 102, by recursively traversing each node in the logical structure tree, determine the traversal path corresponding to each leaf node.
[0074] In the embodiment of the present invention, for the logical structure tree constructed based on the Json string to be chained, each node in the logical structure tree is recursively traversed by a depth-first traversal algorithm or a breadth-first traversal algorithm, so that each leaf node in the logical structure tree can be traversed, so that the traversal path corresponding to each leaf node can be determined, and at least one node contained in each traversal path can be determined. Wherein, when recursively traversing each node in the logical structure tree by a depth-first traversal algorithm or a breadth-first traversal algorithm, it starts from the root node in the logical structure tree and traverses each node on the logical structure tree in sequence. Specifically, for any node belonging to the first level in the logical structure tree, the node is taken as the current node, and the current node is traversed in the following manner: if it is determined that there is an untraversed node belonging to the next level of the current node, the untraversed node is taken as the current node, and the traversal is continued until the node belonging to the next level is a leaf node during the traversal process, and the traversal is stopped, thereby obtaining the traversal path for the leaf node. Afterwards, the parent node of the leaf node is used as the current node to continue traversing. If it is determined that there is no untraversed node in the next level of the current node, the parent node of the current node is used as the new current node to continue traversing. If it is determined that there is an untraversed node in the next level of the new current node, the untraversed node is used as the current node to traverse until the node belonging to the next level is a leaf node during the traversal process, and then the traversal is stopped, so that the traversal path for the leaf node can be determined. Then, the parent node of the leaf node is used as the current node to continue traversing, so that each leaf node in the logical structure tree is traversed in a recursive manner to determine the end of the traversal for the logical structure tree, so that the traversal path corresponding to each leaf node can be determined. In this way, the scheme can facilitate the subsequent splicing of at least one node contained in each traversal path to accurately determine the hash value corresponding to the traversal path and provide support. At the same time, the uniqueness of the splicing field corresponding to the traversal path can be determined based on the order of backtracking from the leaf node of each traversal path, thereby ensuring the uniqueness of the hash value of the subsequently calculated Json string to be uploaded to the chain.
[0075] For example, the above Figure 2The logical structure tree shown in the figure is used as an example for description. First, the traversal starts from the root node of the logical structure tree. By traversing the root node ".", it is determined that the next level of the root node contains two untraversed nodes, namely, node "key1" and node "key5". Then, one of the two untraversed nodes can be selected as the current node to continue the traversal. For example, the node "key1" is selected as the current node to continue the traversal. When the node "key1" is traversed, it is determined that the next level of the node "key1" contains two untraversed nodes, namely, nodes "key2" and "key3". Then you can select one of the two untraversed nodes as the current node to continue traversing, for example, select node "key2" as the current node to continue traversing, when traversing the node "key2", determine that the next level of the node "key2" contains an untraversed node, namely, the node "value1", and traverse with the node "value1" as the current node. If it is determined that the node "value1" does not have a node at the next level, then you can determine that the node "value1" is a leaf node, and therefore stop traversing to the next level. In this way, you can determine the traversal path corresponding to the node "value1", namely, the traversal path from the node "key1" to the node "value1", and the traversal path contains at least one node, namely, the node "key1", the node "key2" and the node "value1".
[0076] Then, after determining that the node "value1" does not have any nodes at the next level, continue traversing with the parent node "key2" of the node "value1" as the current node. When traversing the parent node "key2", determine that there are no untraversed nodes at the next level of the parent node "key2", that is, the node "value1" at the next level of the parent node "key2" has been traversed. At this time, the parent node "key1" of the parent node "key2" will be used as the current node to continue traversing. When traversing the parent node "key1", it is determined that there are untraversed nodes in the next level of the parent node "key1", that is, the node "key3" has not been traversed. Because the node "key2" has been traversed, the node "key3" will be used as the current node to continue traversing. When traversing the node "key3", it is determined that there are untraversed nodes in the next level of the node "key3", that is, the node "key4" has not been traversed. The node "key4" will be used as the current node to continue traversing. When traversing the node "key4", it is determined that the node " There is an untraversed node in the next level of "key4", that is, the node "value2" has not been traversed. The node "value2" is used as the current node for traversal. It is determined that there is no node in the next level for the node "value2". Then it can be determined that the node "value2" is a leaf node, so the traversal to the next level will be stopped. In this way, the traversal path corresponding to the node "value2" can be determined, that is, the traversal path from the node "key1" to the node "value2", and at least one node contained in the traversal path is the node "key1", the node "key3", the node "key4" and the node "value2".
[0077] Furthermore, after determining that the node "value2" does not have a node at the next level, the parent node "key4" of the node "value2" is used as the current node to continue traversing. When traversing the parent node "key4", it is determined that there are no untraversed nodes at the next level of the parent node "key4", that is, the node "value2" at the next level of the parent node "key4" has been traversed. At this time, the parent node "key3" of the parent node "key4" is used as the current node to continue traversing. When traversing the parent node "key3", it is determined that there are no untraversed nodes at the next level of the parent node "key3", that is, the node "key4" at the next level of the parent node "key3" has been traversed. At this time, the parent node "key1" of the parent node "key3" will be used as the current node to continue traversing. When traversing the parent node "key1", it is determined that there are no untraversed nodes in the next level of the parent node "key1", that is, the nodes "key2" and "key3" in the next level of the parent node "key1" have been traversed. At this time, the traversal will continue with the parent node "·" of the parent node "key1" as the current node. When traversing the parent node "·", it is determined that there are untraversed nodes in the next level of the parent node "·", that is, the node "key5" has not been traversed. Because the node "key1" has been traversed, the traversal will continue with the node "key5" as the current node. When traversing the node "key5", it is determined that there are untraversed nodes in the next level of the node "key5", that is, the node "key6" has not been traversed. The traversal will continue with the node "key6" as the current node. When traversing the node "key6", it is determined that there are two untraversed nodes in the next level of the node "key6", namely, nodes "value3" and "value4". Then you can select one of the two untraversed nodes as the current node to continue traversing, for example, select node "value3" as the current node to continue traversing. When traversing the node "value3", it is determined that the node "value3" does not have a node at the next level, then it can be determined that the node "value3" is a leaf node, so the traversal to the next level will be stopped. In this way, the traversal path corresponding to the node "value3" can be determined, that is, the traversal path from node "key5" to node "value3", and at least one node contained in the traversal path is node "key5", node "key6" and node "value3".
[0078] Next, after determining that the node "value3" does not have a node at the next level, the traversal will continue with the parent node "key6" of the node "value3" as the current node. When traversing the parent node "key6", it is determined that there are untraversed nodes at the next level of the parent node "key6", that is, the node "value4" has not been traversed. Because the node "value3" has been traversed, the traversal will continue with the node "value4" as the current node. When traversing the node "value4", it is determined that there is no node at the next level of the node "value4", then it can be determined that the node "value4" is a leaf node, so the traversal to the next level will be stopped, so that the traversal path corresponding to the node "value4" can be determined, that is, the traversal path from the node "key5" to the node "value4", and the traversal path contains at least one node, which is the node "key5", the node "key6" and the node "value4".
[0079] Finally, after determining that the node "value4" does not have a node at the next level, the parent node "key6" of the node "value4" is used as the current node to continue traversing. When traversing the parent node "key6", it is determined that there are no untraversed nodes at the next level of the parent node "key6", that is, the nodes "value3" and "value4" at the next level of the parent node "key6" have been traversed. At this time, the parent node "key5" of the parent node "key6" is used as the current node to continue traversing. When traversing the parent node "key5", it is determined that there are no untraversed nodes at the next level of the parent node "key5", that is, the node "key6" at the next level of the parent node "key5" has been traversed. At this time, the parent node "·" of the parent node "key5" will be taken as the current node to continue traversing. When traversing the parent node "·", it is determined that there are no untraversed nodes in the next level of the parent node "·", that is to say, the nodes "key1" and "key5" in the next level of the parent node "·" have been traversed. At this point, all the nodes in the logical structure tree of the above Json string have been traversed, and the traversal of the logical structure tree is completed.
[0080] Step 103: for each traversal path, concatenate the nodes belonging to the traversal path to obtain a concatenated field.
[0081] In the embodiment of the present invention, for each traversal path, each node included in the traversal path is spliced to determine the splicing field corresponding to the traversal path. Specifically, for each traversal path, backtracking is performed from the leaf node of the traversal path to obtain each node included in the traversal path. Of course, at least one node included in each traversal path can also be recorded in real time during the traversal process. Then, the fields of each node of the traversal path are spliced in the order of backtracking from the leaf node of the traversal path to obtain the splicing field corresponding to the traversal path. Among them, there are two ways to splice the fields of each node in the backtracking order. The first splicing method is: for each traversal path, in the order of backtracking starting from the leaf node of the traversal path, the fields of each node of the traversal path are spliced using the setting symbol to obtain a unique spliced field; the second splicing method is: for each traversal path, in the order of backtracking starting from the leaf node of the traversal path, the fields of each node of the traversal path are spliced in a step-by-step hashing manner to obtain a unique splicing field. For example, assuming that the fields of each node of a traversal path are a, b and c, the above-mentioned first splicing method is used for splicing. For example, assuming that the setting symbol for splicing is ".", the fields of each node of the traversal path are spliced as a, b and c through the setting symbol ".", and the spliced field "abc" is obtained. Or assuming that the setting symbol for splicing is "*", the fields of each node of the traversal path are spliced as a, b and c through the setting symbol "*", and the spliced field "a*b*c" is obtained. Or the setting symbol can also be "@", "#", "$", "%" or "&", etc., and the embodiment of the present invention does not limit this. Alternatively, the above-mentioned first splicing method is used for splicing, and the fields of each node of the traversal path are spliced in a step-by-step hashing manner, that is, the spliced field is "hash(a, hash(b, hash(c)))".
[0082] Exemplarily, the embodiment of the present invention describes the splicing of the fields of each node of each traversal path by taking the above-mentioned first splicing method as an example. For the traversal path corresponding to the leaf node "value1" obtained above, that is, the traversal path from the node "key1" to the leaf node "value1", backtracking from the leaf node "value1" can obtain the node "key1", the node "key2" and the node "value1" in the traversal path corresponding to the leaf node "value1", and in the order of backtracking from the leaf node "value1", by setting a symbol, such as setting the symbol to ".", the node "key1", the node "key2" and the node "value1" are spliced to obtain the spliced field "value1.key2.key1". For the traversal path corresponding to the leaf node "value2" obtained above, that is, the traversal path from the node "key1" to the leaf node "value2", backtracking from the leaf node "value2" can obtain the node "key1", the node "key3", the node "key4" and the node "value2" in the traversal path corresponding to the leaf node "value2", and in the order of backtracking from the leaf node "value2", by setting a symbol, such as setting the symbol to ".", the node "key1", the node "key3", the node "key4" and the node "value2" are spliced to obtain the spliced field "value2.key4.key3.key1". For the traversal path corresponding to the leaf node "value3" obtained above, that is, the traversal path from the node "key5" to the leaf node "value3", backtracking from the leaf node "value3" can obtain the node "key5", the node "key6" and the node "value3" in the traversal path corresponding to the leaf node "value3", and in the order of backtracking from the leaf node "value3", by setting a symbol, such as setting the symbol to ".", the node "key5", the node "key6" and the node "value3" are spliced to obtain the spliced field "value3.0.key6.key5". Since value3 and value4 are elements in the same array in the above Json string, and the position order of the element value3 is ahead of the position order of the element value4, a number used to represent the position order of the elements of the same array is added to the splicing field, that is, 0 indicates that the position order of the element value3 is in the first position in the array.For the traversal path corresponding to the leaf node "value4" obtained above, that is, the traversal path from the node "key5" to the leaf node "value4", backtracking from the leaf node "value4" can obtain the node "key5", the node "key6" and the node "value4" in the traversal path corresponding to the leaf node "value4", and in the order of backtracking from the leaf node "value4", by setting a symbol, such as setting the symbol to ".", "key5", the node "key6" and the node "value4" are spliced to obtain the spliced field "value4.1.key6.key5". Since value3 and value4 are elements in the same array in the above Json string, and the position order of the element value3 is ahead of the position order of the element value4, a number used to represent the position order of the elements of the same array is added to the splicing field, that is, 1 represents that the position order of the element value4 is in the second position in the array.
[0083] It should be noted that, in addition to splicing the nodes contained in the traversal path corresponding to each leaf node, the nodes in the traversal path corresponding to the leaf node can also be spliced in the order from the starting node in the traversal path corresponding to the leaf node to the leaf node. For example, the traversal path corresponding to the leaf node "value1" obtained above is described as an example. By setting a symbol, such as setting the symbol to ".", and splicing the node "key1", the node "key2" and the node "value1" in the traversal path corresponding to the leaf node "value1" in the order from the starting node in the traversal path corresponding to the leaf node to the leaf node, the spliced field "key1.key2.value1" can be obtained. Alternatively, taking the traversal path corresponding to the leaf node "value3" obtained above as an example, by setting a symbol, such as setting the symbol to ".", and in the order from the starting node to the leaf node in the traversal path corresponding to the leaf node, the node "key5", the node "key6" and the node "value3" in the traversal path corresponding to the leaf node are spliced to obtain the spliced field "key5.key6.0.value3".
[0084] Step 104, the hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, and the hash value of the Json string to be uploaded to the chain is uploaded to the blockchain.
[0085] In an embodiment of the present invention, for each splicing field, a hash operation is performed on the splicing field by a set hash algorithm, and the hash value of the splicing field can be determined. Then, by aggregating the hash values of each splicing field in accordance with the commutative law, the hash value of the Json string to be chained can be obtained, and the hash value of the Json string to be chained is uploaded to the blockchain. In this way, the scheme aggregates the hash values of each splicing field by an aggregation algorithm that conforms to the commutative law, so the scheme will not be affected by the order of the same-level keys in the Json string to be chained, that is, no matter how the order of the same-level keys in the Json string to be chained is adjusted, it will not affect the hash value of the Json string to be chained that is finally determined to be unique, so that the unique hash value of the Json string to be chained can be obtained, thereby ensuring the uniqueness of the hash value of the Json string to be chained. Among them, the aggregation algorithm that conforms to the commutative law may include an algorithm that conforms to the commutative law of addition, an algorithm that conforms to the commutative law of XOR, or an algorithm that conforms to the commutative law of multiplication, etc.; the set hash algorithm may include the message-digest algorithm 5 (Message-Digest Algorithm 5, MD5), the SHA256 algorithm, or the SM3 (senior middle 3) cryptographic hash algorithm, etc., and the embodiments of the present invention are not limited to this.
[0086] Exemplarily, by performing hash operations on the concatenated fields corresponding to the above leaf nodes, the hash values of the concatenated fields corresponding to each leaf node can be obtained as shown in Table 2. Specifically, for the concatenated field "value1.key2.key1" corresponding to the traversal path corresponding to the leaf node "value1" obtained above, a hash operation is performed on the concatenated field "value1.key2.key1" through a set hash algorithm, such as the MD5 algorithm, to obtain the hash value 6d1eed270c682b525b4589f30629c631 of the concatenated field "value1.key2.key1". For the spliced field "value2.key4.key3.key1" corresponding to the traversal path corresponding to the leaf node "value2" obtained above, a hash operation is performed on the spliced field "value2.key4.key3.key1" through a set hash algorithm, such as the MD5 algorithm, to obtain a hash value f0237fc54d6449398aa7b1bb987b4018 of the spliced field "value2.key4.key3.key1". For the spliced field "value3.0.key6.key5" corresponding to the traversal path corresponding to the leaf node "value3" obtained above, a hash operation is performed on the spliced field "value3.0.key6.key5" through a set hash algorithm, such as the MD5 algorithm, to obtain a hash value a51eeabeff3056207bddf8257438dd80 of the spliced field "value3.0.key6.key5". For the spliced field "value4.1.key6.key5" corresponding to the traversal path corresponding to the leaf node "value4" obtained above, a hash operation is performed on the spliced field "value4.1.key6.key5" through a set hash algorithm, such as the MD5 algorithm, to obtain the hash value b4f250636291c373bbcd3f7183230ef6 of the spliced field "value4.1.key6.key5".Then, for the hash values of the above-mentioned spliced fields, the hash values of the above-mentioned spliced fields are added together through an aggregation algorithm that conforms to the commutative law, such as an algorithm that conforms to the commutative law of addition, to obtain the unique hash value of the Json string to be uploaded to the chain, which is 6d1eed270c682b525b4589f30629c631+f0237fc54d6449398aa7b1bb987b4018 +a51eeabeff3056207bddf8257438dd80+b4f250636291c373bbcd3f7183230ef6=b753a80ebb8e8e201d9873459600f2bf, where b753a80ebb8e8e201d9873459600f2bf is the unique hash value of the Json string to be uploaded to the chain.
[0087] Table 2
[0088]
[0089] The above embodiments show that, when calculating the hash value of a Json string, the prior art solution needs to first sort the key-value pairs in the Json string according to the pre-defined key order rules in the Json encoding, and then determine the hash value of the Json string by performing a hash operation on the sorted Json string. And a certain amount of computing resources are required to sort the key-value pairs in the Json string, which results in low performance of the system when calculating the hash value of the Json string. At the same time, since the prior art solution needs to set the key order rules corresponding to each system or different application scenarios, the prior art solution has poor versatility. Based on this, the technical solution in the present invention recursively traverses the logical structure tree constructed for the Json string to be chained, and aggregates the splicing fields corresponding to each traversal path through an aggregation algorithm that conforms to the commutative law, so as to accurately determine the hash value of the Json string to be chained, without having to define the key sequence rules in advance, and there is no need to sort the key-value pairs in the Json string according to the corresponding key sequence rules, thereby avoiding the influence of the key sequence in the Json string on the hash value of the Json string, having good versatility, and improving the performance of the system when calculating the hash value of the Json string. Specifically, for the Json string to be chained, a logical structure tree of the Json string to be chained is constructed, and by recursively traversing each node in the logical structure tree, the traversal path corresponding to each leaf node can be determined. Then for each traversal path, each node belonging to the traversal path is spliced to obtain the spliced field, and the hash value of each spliced field is aggregated in accordance with the commutative law to accurately obtain the hash value of the Json string to be chained, and the hash value of the Json string to be chained is uploaded to the blockchain. In this way, since the characteristics of the aggregation algorithm that satisfies the commutative law adopted by the scheme are consistent with the characteristics that the same-level keys in the Json string can be arbitrarily swapped in order, the hash values of all Json strings with the same meaning (i.e., the same actual content) determined by the scheme are unique, so the scheme does not need to define the key order rules, has good versatility, and does not need to sort the key-value pairs in the Json string, and has low time complexity, so it can reduce the computing resources consumed by sorting the Json string, thereby helping to improve the performance of the system when calculating the hash value of the Json string.
[0090] Based on the same technical concept, Figure 3 An exemplary embodiment of the present invention shows a device for processing information on a blockchain provided by an embodiment of the present invention, which can execute the process of a method for processing information on a blockchain.
[0091] like Figure 3 As shown, the device comprises:
[0092] The construction unit 301 is used to construct a logical structure tree of the Json string to be chained, wherein each field in the Json string to be chained corresponds to each node in the logical structure tree one by one;
[0093] The processing unit 302 is used to determine the traversal path corresponding to each leaf node by recursively traversing each node in the logical structure tree; for each traversal path, concatenate each node belonging to the traversal path to obtain a concatenated field; aggregate the hash value of each concatenated field in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, and upload the hash value of the Json string to be uploaded to the blockchain.
[0094] Optionally, the construction unit 301 is specifically used for:
[0095] The logical structure tree is constructed according to the position order of each field in the Json string to be chained.
[0096] Optionally, the processing unit 302 is specifically configured to:
[0097] For any node belonging to the first level in the logical structure tree, the node is taken as the current node, and the current node is traversed in the following manner:
[0098] If it is determined that there is an untraversed node belonging to the next level of the current node, the untraversed node is used as the current node, and the traversal is continued until the node belonging to the next level is a leaf node during the traversal process, and the traversal is stopped, thereby obtaining a traversal path for the leaf node;
[0099] The parent node of the leaf node is used as the current node to continue traversing. If it is determined that there is no untraversed node in the next level belonging to the current node, the parent node of the current node is used as the current node to continue traversing until all leaf nodes are traversed.
[0100] Optionally, the processing unit 302 is specifically configured to:
[0101] Backtracking from the leaf nodes of the traversal path to obtain each node of the traversal path;
[0102] The fields of each node are concatenated in a backtracking order to obtain a concatenated field.
[0103] Optionally, the processing unit 302 is specifically configured to:
[0104] In the backtracking order, the fields of each node are concatenated by setting symbols to obtain a concatenated field.
[0105] Optionally, the processing unit 302 is specifically configured to:
[0106] In the backtracking order, the fields of each node are hashed level by level to obtain the concatenated fields.
[0107] Optionally, the processing unit 302 is specifically configured to:
[0108] For any splicing field, determine the hash value of the splicing field by using a set hash algorithm;
[0109] The hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain.
[0110] Based on the same technical concept, the embodiment of the present invention also provides a computing device, such as Figure 4 As shown, it includes at least one processor 401 and a memory 402 connected to the at least one processor. The specific connection medium between the processor 401 and the memory 402 is not limited in the embodiment of the present invention. Figure 4 For example, the processor 401 and the memory 402 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0111] In an embodiment of the present invention, the memory 402 stores instructions that can be executed by at least one processor 401. By executing the instructions stored in the memory 402, at least one processor 401 can execute the steps included in the aforementioned method for processing blockchain on-chain information.
[0112] Among them, the processor 401 is the control center of the computing device, and can use various interfaces and lines to connect various parts of the computing device, and realize data processing by running or executing instructions stored in the memory 402 and calling data stored in the memory 402. Optionally, the processor 401 may include one or more processing units, and the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes the issuance of instructions. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401. In some embodiments, the processor 401 and the memory 402 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.
[0113] Processor 401 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, which may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the method for processing information on the blockchain may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0114] The memory 402 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 402 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 402 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 402 in the embodiment of the present invention can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0115] Based on the same technical concept, an embodiment of the present invention also provides a computer-readable storage medium, which stores a computer program that can be executed by a computing device. When the program runs on the computing device, the computing device executes the steps of the above-mentioned method for processing blockchain information.
[0116] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0117] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0118] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0119] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0120] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0121] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of this application and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for processing information on a blockchain, characterized in that: include: For the Json string to be chained, a logical structure tree of the Json string to be chained is constructed; each field in the Json string to be chained corresponds to each node in the logical structure tree one by one; By recursively traversing each node in the logical structure tree, a traversal path corresponding to each leaf node is determined; For each traversal path, each node belonging to the traversal path is spliced to obtain a spliced field; The hash values of each spliced field are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, and the hash value of the Json string to be uploaded to the chain is uploaded to the blockchain.
2. The method according to claim 1, characterized in that The logical structure tree of the Json string to be chained is constructed for the Json string to be chained, including: The logical structure tree is constructed according to the position order of each field in the Json string to be chained.
3. The method according to claim 1, characterized in that By recursively traversing each node in the logical structure tree, a traversal path corresponding to each leaf node is determined, including: For any node belonging to the first level in the logical structure tree, the node is taken as the current node, and the current node is traversed in the following manner: If it is determined that there is an untraversed node belonging to the next level of the current node, the untraversed node is used as the current node, and the traversal is continued until the node belonging to the next level is a leaf node during the traversal process, and the traversal is stopped, thereby obtaining a traversal path for the leaf node; The parent node of the leaf node is used as the current node to continue traversing. If it is determined that there is no untraversed node in the next level belonging to the current node, the parent node of the current node is used as the current node to continue traversing until all leaf nodes are traversed.
4. The method according to claim 3, characterized in that Each node belonging to the traversal path is concatenated to obtain a concatenated field, including: Backtracking from the leaf nodes of the traversal path to obtain each node of the traversal path; The fields of each node are concatenated in a backtracking order to obtain a concatenated field.
5. The method according to claim 4, characterized in that The fields of each node are spliced in the backtracking order to obtain the spliced fields, including: In the backtracking order, the fields of each node are concatenated by setting symbols to obtain a concatenated field.
6. The method according to claim 4, characterized in that, The fields of each node are spliced in the backtracking order to obtain the spliced fields, including: In the backtracking order, the fields of each node are hashed level by level to obtain the concatenated fields.
7. The method according to any one of claims 1 to 6, characterized in that: The hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain, including: For any splicing field, determine the hash value of the splicing field by using a set hash algorithm; The hash values of the concatenated fields are aggregated in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain.
8. A device for processing information on a blockchain, characterized in that: include: A construction unit, for constructing a logical structure tree of the Json string to be chained, according to the Json string to be chained; Each field in the Json string to be uploaded corresponds to each node in the logical structure tree one by one; A processing unit is used to determine the traversal path corresponding to each leaf node by recursively traversing each node in the logical structure tree; for each traversal path, concatenate each node belonging to the traversal path to obtain a concatenated field; and perform an aggregation process on the hash value of each concatenated field in accordance with the commutative law to obtain the hash value of the Json string to be uploaded to the chain; Upload the hash value of the Json string to be uploaded to the blockchain.
9. A computing device, characterized in that The method comprises at least one processor and at least one memory, wherein the memory stores a computer program, and when the program is executed by the processor, the processor executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computing device, and when the program is run on the computing device, the computing device executes the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for converting message format, storage medium and Android terminal
CN108882006A
Data chaining method, apparatus and device, and computer readable storage medium
CN109660356A
