Disclosure of Invention
In order to solve the above problems, the present application provides a transaction reconciliation method based on merck tree, comprising:
The method comprises the steps that a reconciliation party generates a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and reconciliation initiating time, wherein the hash value is a leaf node of a merck tree corresponding to a transaction time period;
Hash operation is carried out on the hash values of the two leaf nodes to generate hash values corresponding to the intermediate nodes of the merck tree, and hash operation is carried out on the hash values of the two intermediate nodes to generate hash values corresponding to the root nodes of the merck tree;
Comparing the hash values of the merck trees generated by the two parties of the reconciliation according to the nodes, if the comparison results are consistent, the reconciliation results are flat accounts, if the comparison results are inconsistent, comparing the hash values of the leaf nodes corresponding to the merck trees of the two parties of the reconciliation to obtain the hash values of the leaf nodes inconsistent in the comparison results, obtaining corresponding transaction data according to the hash values of the leaf nodes, and carrying out transaction reconciliation according to the transaction data by the two parties of the reconciliation.
Preferably, the generating, by the reconciliation parties, a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and reconciliation initiation time includes:
Selecting any one of the hash algorithms including MD5, sha1, sha256, crc32 and haval as a hash algorithm according to the preset by the two parties of the reconciliation;
and running the transaction data and the account checking initiating time through the hash algorithm to generate a hash value corresponding to each transaction.
Preferably, the transaction data includes payee, payer, transaction amount, transaction status, transaction type, transaction time, and transaction voucher number.
Preferably, hash operation is performed on hash values of two leaf nodes to generate hash values corresponding to intermediate nodes of the merck tree, hash operation is performed on hash values of two intermediate nodes, hash values corresponding to Cheng Moke r tree root nodes, and the method includes:
Pairing two adjacent leaf nodes, carrying out hash operation on hash values of the two adjacent leaf nodes, and generating a hash value corresponding to a Merker tree intermediate node;
If the number of the intermediate nodes is more than two, pairing the two adjacent intermediate nodes, carrying out hash operation on the hash values of the two adjacent intermediate nodes, and generating a hash value corresponding to a new intermediate node of the merck tree until the hash value generated by the intermediate node is unique, wherein the node corresponding to the unique hash value is the root node of the merck tree.
Preferably, the method further comprises:
If the leaf node or the intermediate node is not paired, carrying out hash operation on the leaf node or the intermediate node by a preset default hash value.
Preferably, the transaction checking is performed by the checking parties according to the transaction data, including:
And the account checking and settling parties perform confirmation and settling processing on the places where the transaction data are inconsistent.
The application also provides a transaction reconciliation system based on the merck tree, which comprises:
The system comprises a leaf node generation module, a transaction time period generation module and a transaction time period generation module, wherein the leaf node generation module is used for generating a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and the transaction initiation time by the two parties;
The Merker tree generation module is used for carrying out hash operation on the hash values of the two leaf nodes to generate hash values corresponding to the intermediate nodes of the Merker tree, carrying out hash operation on the hash values of the two intermediate nodes to generate hash values corresponding to the root nodes of the Merker tree;
The reconciliation module is used for comparing hash values corresponding to the merck tree root nodes generated by the reconciliation parties, if the comparison results are consistent, the reconciliation results are the reconciliation, if the comparison results are inconsistent, the hash values of the leaf nodes corresponding to the merck tree of the reconciliation parties are compared, the hash values of the leaf nodes inconsistent in the comparison results are obtained, corresponding transaction data are obtained according to the hash values of the leaf nodes, and the reconciliation parties conduct transaction reconciliation according to the transaction data.
Preferably, the merck tree generating module includes:
the leaf node pairing submodule is used for pairing two adjacent leaf nodes, carrying out hash operation on hash values of the two adjacent leaf nodes and generating a hash value corresponding to a merck tree intermediate node;
And the intermediate node pairing submodule is used for pairing two adjacent intermediate nodes if the intermediate nodes are more than two, carrying out hash operation on the hash values of the two adjacent intermediate nodes to generate a hash value corresponding to a new intermediate node of the merck tree until the hash value generated by the intermediate nodes is unique, wherein the node corresponding to the unique hash value is the root node of the merck tree.
Preferably, the method further comprises:
and the default pairing submodule is used for carrying out hash operation on the leaf node or the intermediate node by a preset default hash value if the leaf node or the intermediate node fails to pair.
Preferably, the reconciliation module comprises:
And the processing sub-module is used for confirming and settling the places where the transaction data are inconsistent by the account checking and accounting parties.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. The present application may be embodied in many other forms than those herein described, and those skilled in the art will readily appreciate that the present application may be similarly embodied without departing from the spirit or essential characteristics thereof, and therefore the present application is not limited to the specific embodiments disclosed below.
Fig. 1 is a flow chart of a transaction reconciliation method based on the merck tree provided by the application, and the method provided by the application is described in detail below with reference to fig. 1.
Step S101, according to a preset hash algorithm, transaction data and account checking initiation time, the account checking parties generate a hash value corresponding to each transaction, wherein the hash value is a leaf node of a merck tree corresponding to a transaction time period.
The Merker tree is also called a hash tree, and essentially is a tree-shaped data structure, and consists of data blocks, leaf nodes, intermediate nodes and root nodes, wherein any father node of the tree-shaped data structure is equal to the result of hashing after adding data of left and right child nodes, and the topmost node is called the Merker tree root, is a binary tree and has the characteristics of certainty, irreversibility, uniform length and high-efficiency retrieval ratio. Hash (hash) is a function of mapping arbitrary length data into fixed length data, including but not limited to MD5, sha1, sha256, crc32, haval, etc., and the original data is arbitrarily changed, the hash value will be changed drastically.
The method comprises the steps of selecting any one of the hash algorithms including MD5, sha1, sha256, crc32 and haval by the two parties of the reconciliation as the hash algorithm of the two parties of the reconciliation, running transaction data and reconciliation initiating time through the hash algorithm, and generating a hash value corresponding to each transaction. The hash value is a leaf node of the merck tree corresponding to the transaction time period. The transaction data comprises a payee, a payer, a transaction amount, a transaction state, a transaction type, a transaction time and a transaction voucher number.
Step S102, hash operation is carried out on the hash values of the two leaf nodes, so that hash values corresponding to the intermediate nodes of the merck tree are generated, hash operation is carried out on the hash values of the two intermediate nodes, and hash values corresponding to the root nodes of the merck tree are generated.
Pairing two adjacent leaf nodes, carrying out hash operation on hash values of the two adjacent leaf nodes to generate hash values corresponding to the Merker tree intermediate nodes, pairing the two adjacent intermediate nodes if the intermediate nodes are more than two, carrying out hash operation on the hash values of the two adjacent intermediate nodes to generate hash values corresponding to new intermediate nodes of the Merker tree until the hash values generated by the intermediate nodes are unique, wherein the unique hash value corresponds to the root node of the Merker tree.
If the leaf node or the intermediate node is not paired, carrying out hash operation on the leaf node or the intermediate node by a preset default hash value.
Step S103, comparing the hash values of the merck tree corresponding to the merck tree generated by the reconciliation parties according to the nodes, if the comparison results are consistent, the reconciliation results are flat, if the comparison results are inconsistent, comparing the hash values of the leaf nodes corresponding to the merck tree of the reconciliation parties to obtain the hash values of the leaf nodes inconsistent in the comparison results, obtaining corresponding transaction data according to the hash values of the leaf nodes, and carrying out transaction reconciliation by the reconciliation parties according to the transaction data
And when the comparison result is inconsistent, according to the acquired corresponding transaction data, confirming and translating the place where the transaction data are inconsistent by the account checking and accounting parties.
Specific examples of applications are as follows:
The main functions of the application are account checking setting, hash generation, account checking hash tree generation and account checking execution. The reconciliation setting is used for setting transaction fields for generating hash values, and comprises the setting of reconciliation types, field names, field sequences, dictionary value conversion, connectors, hash default values, reconciliation time and the like, and the customized setting can be carried out according to the dimensions of the transaction types, the transaction states, the reconciliation time and the like, so that centralized standardized management of different business reconciliation is realized. The hash generation module is triggered at the set checking time point, and performs hash calculation on the corresponding transaction records according to rules set by checking to obtain a corresponding hash value of each transaction. The generated hash values are subjected to hash calculation again in pairs, the transaction hashes which cannot be paired in pairs are paired by the hash default value set by the system, and finally a hash tree containing the whole reconciliation transaction, namely a reconciliation hash tree is generated. The downstream organization acquires the reconciliation hash tree generated by the upstream organization, firstly acquires a root node, and judges whether the root node is consistent with the root node of the reconciliation hash tree generated by the downstream organization. And according to the certainty and the irreversibility of the merck tree, if the certainty and the irreversibility are consistent, the transaction information of the two parties is consistent, and the reconciliation work is finished. If the transaction information is inconsistent, and the account is required to be settled. And then, performing subsequent traversal on the double-party account checking hash tree, comparing the traversal results, outputting leaf nodes corresponding to inconsistent hash values, further matching transaction information records corresponding to the leaf node hash, triggering a manual processing flow, and ending the account checking work.
The reconciliation setting function flow specifically comprises:
and (3) newly adding a checking setting record to the click system function page, setting information such as checking type, field name, field sequence, dictionary value conversion, connector, hash default value, hash algorithm, checking time and the like, and storing the information. When the checking record is selected and set to be effective, the system background records the setting and generates a timing task according to the checking time of the record. When the account checking record is selected and set to be invalid, the system background does not generate a timing task and only records the setting.
The hash generation function flow specifically comprises the following steps:
after the timing task generated by the checking setting module is started at a specific checking time point, the transaction information is spliced in a selective and orderly mode according to field items set by the checking, after the splicing is completed, batch processing is carried out through a agreed hash algorithm, a transaction hash value corresponding to each transaction is generated, the transaction hash value is stored in a computer, and storage positions comprise memories, caches, databases, files and the like.
The reconciliation hash tree generation function flow specifically comprises the following steps:
The adjacent transaction hash values are paired in pairs, and less than two transaction hash default values are paired with the account checking set. After the pairing connection, the hash is performed again. And taking the adjacent transaction hash as a leaf node, and taking a result obtained by re-hashing as a father node to create the merck tree. The pairing connection of the parent nodes is performed again, and the result after the pairing connection is hashed is used as a new parent node. And repeating the steps to finally obtain the reconciliation hash tree, wherein the detail is shown in figure 2.
The account checking execution function flow specifically comprises the following steps:
The downstream reconciliation mechanism obtains the data file or the character string containing the reconciliation hash tree through network request, mailbox notification and the like in an online or offline mode. Analyzing a data file or character string of the reconciliation hash tree, converting the data file or character string into a program object of a tree structure, reading a root node, judging whether the data file or character string is consistent with the root node of the reconciliation hash tree generated by the mechanism, outputting a reconciliation result as a reconciliation, ending the reconciliation execution, if the data file or character string is inconsistent, traversing the reconciliation hash tree in a subsequent traversing mode, comparing the data file or character string with the reconciliation hash tree of the mechanism, removing intermediate nodes, and outputting inconsistent leaf node transaction hashes in the reconciliation hash tree of the mechanism. And outputting the account checking result and the corresponding detail record according to the specific transaction detail record corresponding to the transaction hash query summary, and ending the account checking execution.
In the above embodiments, when both parties transact, the transaction systems of both parties splice key transaction information such as the payee, the payer, the transaction amount, the transaction state, the transaction type, the transaction time, the transaction certificate number, and the like according to the transaction data item and the data dictionary agreed in advance, and then perform hash operation in real time to obtain the unique hash value of the transaction. And then carrying out hash operation on the transaction hashes in pairs again, and generating the merck tree of the transaction information hash in a certain period according to the creation rule of the merck tree. If the transaction data of both transaction parties are completely consistent in the transaction period, namely the hash value of each transaction data is consistent, the finally generated merck tree root of the time period is necessarily consistent. According to the certainty and irreversibility of the merck tree, if the finally generated merck tree root is inconsistent, the transaction data of both transaction parties can be stated to have error account necessarily. And traversing Merck trees of both sides, searching and comparing branches with inconsistent transaction hashes, traversing the branches, determining specific transaction data hashes related to the branches, locking a specific error transaction, and triggering automatic or manual form of account checking to solve the occurring transaction error account.
According to the transaction reconciliation method provided by the application, the complex and huge transaction reconciliation file is converted into the concise and safe binary tree data format with unified format and open standard, the transmission, analysis and comparison processes are greatly improved compared with the prior processes, the network dependence is reduced, less calculation resources are consumed, the standardized analysis enables the upstream and downstream butt joint to be more convenient and efficient, and due to the certainty and irreversibility of the hash value, the data is ensured not to be tampered, so that the data reconciliation processing is safer and more accurate.
Based on the same inventive concept, the present application also provides a transaction reconciliation system 300 based on the merck tree, as shown in fig. 3, comprising:
The leaf node generating module 310 is configured to generate a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and accounting initiation time, where the hash value is a leaf node of the merck tree corresponding to the transaction time period;
the merck tree generating module 320 is configured to perform hash operation on hash values of two leaf nodes to generate hash values corresponding to intermediate nodes of the merck tree, and perform hash operation on hash values of two intermediate nodes to generate hash values corresponding to root nodes of the merck tree;
The reconciliation module 330 is configured to compare hash values corresponding to the merck tree generated by the reconciliation parties according to the nodes, if the comparison results are consistent, the reconciliation results are flat, if the comparison results are inconsistent, compare leaf node hash values corresponding to the merck tree of the reconciliation parties to obtain leaf node hash values inconsistent in comparison results, obtain corresponding transaction data according to the leaf node hash values, and the reconciliation parties perform transaction reconciliation according to the transaction data.
Preferably, the merck tree generating module includes:
the leaf node pairing submodule is used for pairing two adjacent leaf nodes, carrying out hash operation on hash values of the two adjacent leaf nodes and generating a hash value corresponding to a merck tree intermediate node;
And the intermediate node pairing submodule is used for pairing two adjacent intermediate nodes if the intermediate nodes are more than two, carrying out hash operation on the hash values of the two adjacent intermediate nodes to generate a hash value corresponding to a new intermediate node of the merck tree until the hash value generated by the intermediate nodes is unique, wherein the node corresponding to the unique hash value is the root node of the merck tree.
Preferably, the method further comprises:
and the default pairing submodule is used for carrying out hash operation on the leaf node or the intermediate node by a preset default hash value if the leaf node or the intermediate node fails to pair.
Preferably, the reconciliation module comprises:
And the processing sub-module is used for confirming and settling the places where the transaction data are inconsistent by the account checking and accounting parties.
Finally, it should be noted that the above-mentioned embodiments are only for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the above-mentioned embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the specific embodiments of the present invention without departing from the spirit and scope of the present invention, and any modifications and equivalents are intended to be encompassed in the scope of the claims of the present invention.