Smart contract data processing method and device for block chain, equipment, storage medium and program product
By using pre-trained natural language processing models to generate and segment smart contracts, the problem of inefficiency of smart contracts in actual applications is solved, and the efficient generation, storage and execution of smart contracts is achieved.
Patent Information
- Application Number
- CN202411973633.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-12-30
AI Technical Summary
In actual applications, smart contracts have low efficiency problems from generation to storage to blockchain and later use.
By using pre-trained natural language processing models, smart contracts are quickly generated and divided into multiple code blocks. Each code block has a corresponding hash value, only different hash values and corresponding code blocks are stored. Only one code block with the same hash value is stored, and the same strategy is adopted when reading and calling smart contracts.
It improves the generation, storage and reading efficiency of smart contracts, and thus improves the execution efficiency of smart contracts.
Smart Images

Figure CN119829681A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a smart contract data processing method, device, equipment, storage medium and program product for blockchain. Background Art
[0002] As the application of blockchain technology increases, smart contracts are becoming more and more widely used on blockchain due to their high accuracy and reliability, high degree of automation and efficiency, as well as the convenience and cost reduction for users.
[0003] The inventors found that in practical applications, smart contracts have low efficiency from generation to storage on the blockchain and subsequent use. Therefore, a method for processing blockchain smart contract data is urgently needed to solve the above technical problems. Summary of the invention
[0004] The present application provides a smart contract data processing method, device, equipment, storage medium and program product for blockchain, which solves the problem of low efficiency of smart contracts from generation to storage on blockchain and subsequent use in practical applications.
[0005] In a first aspect, the present application provides a smart contract data processing method for blockchain, comprising:
[0006] Obtain pre-trained natural language processing models and smart contract development requirements information;
[0007] Performing data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and constructing a smart contract to be stored according to the smart contract text information;
[0008] Input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored;
[0009] Store each contract code snippet to be stored and a corresponding hash value into the blockchain storage space in turn;
[0010] When a hash value is detected to exist in the blockchain storage space with the same hash value, only the hash value is stored in the blockchain storage space until the storage of the smart contract to be stored is completed;
[0011] Obtaining call information for the smart contract to be stored, and determining at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model;
[0012] A corresponding contract code snippet is read from the blockchain storage space in turn according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0013] In a second aspect, the present application provides a smart contract data processing device for blockchain, comprising:
[0014] Acquisition module, used to obtain pre-trained natural language processing models and smart contract development requirements information;
[0015] A smart contract construction module, used to perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and to construct a smart contract to be stored according to the smart contract text information;
[0016] A smart contract storage module, used to input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored;
[0017] The smart contract storage module is further used to store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space in sequence;
[0018] The smart contract storage module is further configured to store only the hash value in the blockchain storage space when it is detected that a hash value exists in the blockchain storage space, until the storage of the smart contract to be stored is completed;
[0019] A smart contract reading module, used to obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model;
[0020] The smart contract reading module is also used to read a corresponding contract code fragment from the blockchain storage space according to each hash value to be indexed in turn, until the contract code fragment corresponding to the last hash value to be indexed is read, and during this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code fragment corresponding to the previous hash value to be indexed can be directly called.
[0021] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the processor;
[0022] The memory stores computer-executable instructions;
[0023] The processor executes the computer-executable instructions stored in the memory to implement the method described in the first aspect.
[0024] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the method described in the first aspect.
[0025] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements the method described in the first aspect when executed by a processor.
[0026] The present application provides a method, device, equipment, storage medium and program product for smart contract data processing for blockchain. The method uses a pre-trained natural language processing model to quickly generate smart contracts, and divides the smart contract into multiple code blocks, each code block has a corresponding hash value, and only stores different hash values and corresponding code blocks. Only one code block with the same hash value is stored. The same strategy is also used when reading and calling smart contracts. When encountering the same hash value, it is directly called from the read code block. The efficiency of smart contract generation is improved, and the efficiency of storage and reading of smart contracts is also improved, thereby improving the execution efficiency of smart contracts. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0028] Figure 1 A schematic diagram of an application scenario of a smart contract data processing method for blockchain provided in an embodiment of the present application;
[0029] Figure 2 A flowchart of a smart contract data processing method for blockchain provided in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a smart contract data processing device for blockchain provided in an embodiment of the present application;
[0031] Figure 4 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.
[0032] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0033] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0034] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with the relevant laws, regulations and standards of the relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0035] In addition, this application involves conducting big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.), and using artificial intelligence technology to make automated decisions, and making technical solutions that have a significant impact on personal rights and interests based on the results of automated decisions. The application provides users with corresponding operation entrances for them to choose to agree or reject the results of automated decisions; if the user chooses to reject, the expert decision-making process will be entered.
[0036] It should be noted that the smart contract data processing method, device, equipment, storage medium and program product for blockchain provided in this application can be used in the field of blockchain technology, and can also be used in any field outside the field of blockchain technology. The application field of the smart contract data processing method, device, equipment, storage medium and program product for blockchain in this application is not limited.
[0037] The inventors found in actual applications that smart contracts are stored and read as a whole, and the code and data of smart contracts are usually large. Therefore, during the chain-up and call processes of smart contracts, one-time loading and parsing will consume a large amount of computing resources and network bandwidth, resulting in low processing efficiency of smart contracts.
[0038] In order to solve the above technical problems, the inventors provide the following inventive concept: first, the smart contract to be stored is automatically generated according to the smart contract creation requirement information through the natural language processing model pre-trained for the smart contract, and then the trained natural language processing model is used to predict and split the smart contract to be stored, and then the hash value and the split smart contract code fragment are matched one by one, and the hash value and the corresponding smart contract code fragment are stored. When the stored hash value is the same, only the hash value is stored, which improves the storage efficiency. When reading the stored smart contract, it is only necessary to quickly index to the corresponding smart contract code fragment by reading the hash value, without reading the entire smart contract code, which improves the reading efficiency. The efficiency of subsequent calls to smart contracts is also improved.
[0039] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0040] Figure 1 Schematic diagram of the application scenario of the smart contract data processing method for blockchain provided in the embodiment of the present application. Figure 1 As shown, the application scenario includes: an operation terminal 101 and a blockchain 102.
[0041] The operation terminal 101 may be a server capable of training a large artificial intelligence model or other computer devices with similar functions. The operation terminal 101 may receive the development requirements of the smart contract, automatically encode and generate the smart contract according to the development requirements, and then store the smart contract on the blockchain 102. The process of deploying the smart contract on the blockchain 102 is the process of storing the smart contract. In addition, the operation terminal 101 may also be used to read the smart contract for the smart contract to call the operation.
[0042] Figure 2 The following is a flow chart of a smart contract data processing method for blockchain provided in an embodiment of the present application. Figure 2 As shown, the execution subject of the smart contract data processing method for blockchain provided in the embodiment of the present application is Figure 1 The operation terminal 101 shown can, of course, also be other computer-related devices with the same control function, which is not limited in this embodiment.
[0043] like Figure 2 As shown, the smart contract data processing method for blockchain includes:
[0044] S201: Obtain pre-trained natural language processing models and smart contract development requirements information.
[0045] In this embodiment, the pre-trained natural language processing model can use the training data related to the smart contract to train the machine learning model to obtain a model with text recognition and data processing functions. The smart contract development requirement information can be the development requirements such as the steps to be executed and the tasks to be completed of the smart contract proposed by the business party.
[0046] Specifically, in an optional embodiment of the present application, step S201 includes:
[0047] S201a: Acquire existing smart contract data and pre-stored contract split mark data, and perform text format conversion processing based on the existing smart contract data to obtain contract text data.
[0048] In an optional embodiment of the present application, in step S201a, text format conversion is performed according to the existing smart contract data to obtain contract text data, including:
[0049] Step a1: Perform text recognition processing based on the existing smart contract data to obtain a first vocabulary.
[0050] In this embodiment, the first vocabulary may include all possible words and phrases, keywords, variable names, function names, and data types used in the smart contract code.
[0051] For example, the first vocabulary may be as follows:
[0052] Keywords: function, conditional statement if, selection statement else, return return, unsigned integer uint, address address.
[0053] Variable name: balance, user owner.
[0054] Function name: transfer, withdraw.
[0055] Data type: Boolean bool.
[0056] Step a2: A mapping relationship between special characters in the first vocabulary and the existing smart contract data and a mapping relationship between keywords and data types are established based on the first vocabulary and the existing smart contract data.
[0057] In this embodiment, a mapping relationship between the vocabulary and the special characters, keywords and data types in the smart contract code is established. A mapping relationship is associated between each entry in the vocabulary and its corresponding text.
[0058] Step a3: traverse each part of the existing smart contract data, and replace each element in the existing smart contract data with the corresponding text content according to the mapping relationship between the first vocabulary and the special characters in the existing smart contract data and the mapping relationship between the keywords and the data types to obtain the contract text data.
[0059] In this embodiment, each element in the existing smart contract is replaced with the corresponding text content through the mapping relationship, so that the obtained contract text data is more accurate, providing more accurate data for subsequent model training, thereby improving the accuracy of the pre-trained natural language processing model.
[0060] S201b: Perform word segmentation processing based on the contract text data to obtain a contract word sequence.
[0061] Specifically, in an optional embodiment of the present application, step S201b includes:
[0062] Step b1: Perform identification processing based on the contract text data to obtain the text format type.
[0063] Step b2: Select a target word segmentation tool from a pre-stored word segmentation tool library according to the text format type.
[0064] In this embodiment, the pre-stored word segmentation tool library contains many open source word segmentation tools to choose from, such as: the jieba library that focuses on Chinese word segmentation, the natural language toolkit library NLTK, or word segmentation libraries of other languages. If you are processing Chinese text, you can choose jieba; for English, you can choose the natural language toolkit library NLTK or use the natural language processing tool spaCy as a word segmentation tool.
[0065] Step b3: Use a target word segmentation tool to segment the contract text data into word sequences consisting of words and / or tokens.
[0066] In this embodiment, the contract text data is segmented into a word sequence consisting of words, a word sequence consisting of tags, and a word sequence consisting of words and tags by a target word segmentation tool.
[0067] For example, if the input text format contract is "Smart contracts are used to manage assets. They contain multiple functions, such as transfer, deposit and withdrawal", the word sequence obtained after word segmentation can be "['smart contract', 'used for', 'management', 'digital', 'assets', '.', 'contains', 'multiple', 'functions', 'such as', 'transfer', '、', 'deposit', 'withdrawal', '.'].
[0068] In this embodiment, by selecting different target word segmentation tools, the obtained contract word sequence is made more accurate and more conducive to subsequent model training.
[0069] S201c: Perform model training on the initial model according to the contract word sequence, the basic model and the pre-labeled contract split data to obtain a transitional natural language processing model.
[0070] In this embodiment, the initial model can be an open source text processing model in the field of artificial intelligence, such as: NLP model or other deep learning model with text recognition function, recurrent neural network RNN or deep learning model Transformer based on self-attention mechanism. The transitional natural language processing model can be an initial model after preliminary training, which can process simple smart contract related data.
[0071] S201d: Use the pre-stored contract split labeled data as a validation set and a test set to perform model adjustment training on the transition natural language processing model to obtain a pre-trained natural language processing model.
[0072] In this embodiment, the pre-trained natural language processing model is trained by using the contract word sequence obtained through text conversion and word segmentation, and then the model is adjusted using the pre-stored contract split labeled data as the verification set and test set. The final pre-stored natural language processing model has a higher accuracy rate and is more efficient in generating smart contracts to be stored.
[0073] S202: Perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain the smart contract text information, and construct the smart contract to be stored according to the smart contract text information.
[0074] In this embodiment, data processing can be a process of using a pre-stored natural language processing model to perform text recognition and organization on smart contract creation requirement information.
[0075] Specifically, in an optional embodiment of the present application, in step S202, data processing is performed on the smart contract development requirement information according to the pre-trained natural language processing model to obtain the smart contract text information including:
[0076] S201a: Perform text recognition processing on the smart contract creation requirement information according to the pre-trained natural language processing model to obtain the overall contract text information.
[0077] S201b: Split the overall contract text information according to the contract steps based on the pre-trained natural language processing model to obtain contract text information consisting of multiple smart contract text fragments.
[0078] In this embodiment, the text recognition process may be a process of identifying key text content related to the compilation of the smart contract in the smart contract creation requirement information. The splitting process may be a process of splitting the key text content related to the smart contract into text fragments related to a single execution step according to the execution steps of the smart contract. For example: a text content containing 10 natural paragraphs, each natural paragraph of the text content corresponds to an execution step, and the text content of the 10 natural paragraphs obtained by splitting corresponds to 10 smart contract text fragments.
[0079] In this embodiment, the text recognition processing of the smart contract is performed by using a pre-trained natural language processing model, which is more efficient than manual interpretation and recognition.
[0080] In an optional embodiment of the present application, the smart contract text information includes multiple smart contract text fragments, and the multiple smart contract text fragments are sorted according to the contract steps; accordingly, in step S201, the smart contract to be stored is constructed according to the smart contract text information, including:
[0081] S202c: Execute a contract encoding operation according to the multiple smart contract text fragments to obtain multiple code fragments, wherein each code fragment has one and only one corresponding smart contract text fragment.
[0082] S202d: Sort and combine all code snippets according to the contract steps to construct the smart contract to be stored.
[0083] In this embodiment, the process of constructing a smart contract to be stored may be a process of generating a smart contract code package using a smart contract code compilation tool.
[0084] S203: Input the smart contract to be stored into the pre-trained natural language processing model to obtain the split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored.
[0085] In this embodiment, the pre-trained natural language processing model can identify and split the functions, keywords, and marking symbols in the code of the contract to be stored, and split the smart contract to be stored into multiple contract code fragments to be stored. In this embodiment, according to the smart contract code fragment to be stored, determining a hash value can be to generate a fixed-length output of the input smart contract code fragment through a hash algorithm, and the fixed-length output is the hash value. Only the same code fragment can obtain the same hash value. Any modification to the smart contract will result in a change in the hash value.
[0086] S204: Store each contract code snippet to be stored and a corresponding hash value into the blockchain storage space in turn.
[0087] In this embodiment, starting from the first smart contract code fragment to be stored of the smart contract to be stored, the first smart contract code fragment to be stored and the corresponding hash value are stored in the blockchain storage space, and then the second smart contract code fragment to be stored and the corresponding hash value are stored in the blockchain storage space, and so on.
[0088] S205: When it is detected that a hash value has the same hash value in the blockchain storage space, only the hash value is stored in the blockchain storage space until the smart contract to be stored is stored.
[0089] In this embodiment, whenever a hash value and a smart contract code snippet to be stored are stored, it is necessary to detect whether the hash value already stored in the blockchain storage space is the same as the hash value to be stored. If there is an identical hash value, then the hash value only needs to be stored in the blockchain storage space. On the contrary, if it is detected that there is no identical hash value, the same method as in step S204 is used to store the hash value and the smart contract code snippet to be stored corresponding to the hash value in the blockchain storage space until the smart contract to be stored is stored.
[0090] In this embodiment, storage completion may mean that all hash values corresponding to all the smart contract code fragments to be stored of the smart contract to be stored are stored in the blockchain storage space.
[0091] S206: Obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model.
[0092] Specifically, in an optional embodiment of the present application, step S206 includes:
[0093] S206a: Perform intent recognition processing using a pre-trained natural language processing model according to the call information of the smart contract to be stored to obtain a prediction result.
[0094] S206b: Determine the contract execution information of the smart contract to be stored according to the prediction result.
[0095] S206c: Determine at least one hash value to be indexed according to the contract execution information.
[0096] In this embodiment, the call information may be the description information of a task in the smart contract to be queried and read, for example, the description information of the deposit task in the smart contract. It is necessary to determine the keywords of the execution steps of the smart contract related to the deposit task through the pre-trained natural language processing model, and determine at least one hash value to be indexed based on these keywords. One hash value to be indexed corresponds to one contract code snippet.
[0097] In this embodiment, the intention recognition process can be a process of performing text recognition processing based on the call information, selecting some keywords from the text, and generating a prediction result corresponding to the call information. The prediction result can be a description content corresponding to the call information and reflecting the intention of the smart industry research.
[0098] In this embodiment, the contract execution information may be the steps to be executed by the smart contract to be stored or the smart contract code snippet to be called and the corresponding calling order.
[0099] In this embodiment, a prediction is first performed through a pre-trained natural language processing model, and then the contract execution information is determined based on the pre-stored results, and then at least one hash value to be indexed is determined, thereby improving the accuracy and efficiency of determining the hash value to be indexed.
[0100] S207: Read a corresponding contract code snippet from the blockchain storage space according to each hash value to be indexed in turn, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
[0101] In this embodiment, a hash value to be indexed may be identical to at least one of the hash values already stored in the blockchain storage space. By matching the same hash value, the contract code fragment corresponding to the hash value can be further indexed.
[0102] In order to make the blockchain smart contract processing method provided in the embodiment of the present application easier for those skilled in the art to understand, the storage process of the entire digital asset management smart contract is used as an example to illustrate:
[0103] 1. Obtain the smart contract development requirement information of the digital asset management smart contract sent by the business party.
[0104] 2. Use the pre-trained natural language processing model to process the smart contract development demand information to obtain the smart contract text information, and build the smart contract to be stored based on the smart contract text information.
[0105] 3. Use the pre-trained natural language processing model to split the input smart contract to be stored into five smart contract code snippets to be stored. These five smart contract code snippets to be stored represent the five operation steps of deposit, A's outward transfer, withdrawal, deposit and A's outward transfer.
[0106] 4. Use the hash algorithm based on the five smart contract code snippets to be stored to generate three hash values in sequence, namely Hash1 corresponding to the first deposit operation step, Hash2 corresponding to the first A outward transfer operation step, Hash3 corresponding to the withdrawal operation step, Hash1 corresponding to the second deposit operation step, and Hash2 corresponding to the second A outward transfer operation step.
[0107] 5. When storing the hash value and the smart contract snippet to be stored in step 4, first store Hash1 corresponding to the first deposit operation step and the smart contract code snippet 1 to be stored in the blockchain storage space, and then store Hash2 corresponding to the first A outward transfer operation step and the smart contract code snippet 2 to be stored in the blockchain storage space. When storing the fourth Hash1, it is detected that there is already a Hash1 in the blockchain storage space. At this time, there is no need to store the smart code snippet 4 to be stored, only Hash1 is needed, because the smart code snippet 4 to be stored is the same as the smart contract code snippet 1 to be stored, and there is no need to store it repeatedly. By analogy, the smart contract code snippets to be stored in the blockchain storage space include: [smart contract code snippet 1 to be stored, smart contract code snippet 2 to be stored, smart contract code snippet 3 to be stored]. The index hash values in the blockchain storage space include: [Hash1, Hash2, Hash3, Hash1, Hash2].
[0108] 6. Obtain the user's deposit task call information for the digital asset management smart contract, then determine at least one hash value Hash1 to be indexed based on the deposit task call information and the pre-trained natural language processing model, and then query and read the same smart contract code snippet 1 to be stored in the blockchain storage space twice to complete the call of the digital asset management smart contract.
[0109] Based on the above embodiment, the smart contract data processing method for blockchain provided in an optional embodiment of the present application further includes:
[0110] Step A: Regularly obtain different types of smart contract sample data.
[0111] Step B: Perform text recognition processing on each type of smart contract sample data to obtain a corresponding second vocabulary.
[0112] Step C: Merge all the second vocabulary lists with the first vocabulary list to obtain an updated first vocabulary list.
[0113] In this embodiment, the smart contract sample data may be data related to smart contracts of different fields, types and mission purposes. The smart contract sample data includes codes of different types of smart contracts and smart contract creation requirement information.
[0114] In this embodiment, the principle of step B is similar to the principle of step a1 in the above embodiment, so this embodiment will not be repeated here. The process of merging all the second vocabulary tables with the first vocabulary table in step C refers to the process of adding the keywords, symbols, data types and other data in the second vocabulary table that are different from the first vocabulary table to the first vocabulary table to obtain the updated first vocabulary table.
[0115] In this embodiment, by updating the first vocabulary, different types of vocabularies are used for the subsequent generation and storage of different types of smart contracts, thereby further improving accuracy and efficiency.
[0116] Optionally, based on the above embodiment, the smart contract data processing method for blockchain provided in a possible implementation of the first embodiment of the present application further includes:
[0117] Step D: Regularly obtain new smart contract creation demand information, and perform data processing on the new smart contract creation demand information according to the pre-trained natural language processing model to obtain new smart contract text information.
[0118] Step E: Construct a new smart contract to be stored based on the new smart contract text information.
[0119] Step F: Perform contract detection on the new smart contract to be stored and obtain the detection result.
[0120] Step G: Adjust the pre-trained natural language processing model according to the detection result to obtain an adjusted pre-trained natural language processing model.
[0121] In this embodiment, the principles of step D and step E are similar to those of step S201 to step S202 in the above embodiment, so they are not described again in this embodiment.
[0122] It should be noted that the purpose of contract detection for new smart contracts to be stored is to detect whether the new smart contracts to be stored are generated according to the needs of the business party, and whether they are close to or even the same as the smart contracts actually required by the business party.
[0123] In this embodiment, by regularly improving the target natural language processing model, the generation and storage efficiency of subsequent smart contracts can be higher, and the generated smart contracts are more in line with development requirements.
[0124] In summary, the embodiment of the present application provides a smart contract data processing method for blockchain, which quickly generates smart contracts by using a pre-trained natural language processing model, and divides the smart contract into multiple code blocks, each code block has a corresponding hash value, and only stores different hash values and corresponding code blocks. Only one code block with the same hash value is stored, and the same strategy is adopted when reading and calling smart contracts. When encountering the same hash value, it is directly called from the read code block. The efficiency of smart contract generation is improved, and the efficiency of storage and reading of smart contracts is also improved, thereby improving the execution efficiency of smart contracts.
[0125] Figure 3 A schematic diagram of the structure of a smart contract data processing device for blockchain provided in an embodiment of the present application.
[0126] like Figure 3 As shown, the smart contract data processing device for blockchain provided in an embodiment of the present application includes: an acquisition module 31, a smart contract construction module 32, a smart contract storage module 33 and a smart contract reading module 34.
[0127] Among them, the acquisition module 31 is used to obtain the pre-trained natural language processing model and smart contract development requirement information.
[0128] The smart contract construction module 32 is used to perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain the smart contract text information, and to construct the smart contract to be stored according to the smart contract text information.
[0129] The smart contract storage module 33 is used to input the smart contract to be stored into the pre-trained natural language processing model to obtain the split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored.
[0130] The smart contract storage module 33 is also used to store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space in sequence.
[0131] The smart contract storage module 33 is also used to store only the hash value in the blockchain storage space when it is detected that a hash value exists in the blockchain storage space, until the smart contract to be stored is stored.
[0132] The smart contract reading module 34 is used to obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed based on the call information of the smart contract to be stored and the pre-trained natural language processing model.
[0133] The smart contract reading module 34 is also used to read a corresponding contract code fragment from the blockchain storage space according to each hash value to be indexed in turn, until the contract code fragment corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code fragment corresponding to the previous hash value to be indexed can be directly called.
[0134] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: acquire existing smart contract data and pre-stored contract splitting and marking data, and perform text format conversion processing based on the existing smart contract data to obtain contract text data; perform word segmentation processing based on the contract text data to obtain a contract word sequence; perform model training on the initial model based on the contract word sequence, the basic model and the pre-marked contract splitting data to obtain a transitional natural language processing model; use the pre-stored contract splitting and marking data as a verification set and a test set to perform model adjustment training on the transitional natural language processing model to obtain a pre-trained natural language processing model.
[0135] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: perform text recognition processing based on the existing smart contract data to obtain a first vocabulary; establish a mapping relationship between the first vocabulary and special characters in the existing smart contract data and a mapping relationship between keywords and data types based on the first vocabulary and the existing smart contract data; traverse each part of the existing smart contract data, and replace each element in the existing smart contract data with corresponding text content based on the mapping relationship between the first vocabulary and special characters in the existing smart contract data and the mapping relationship between keywords and data types to obtain contract text data.
[0136] In an optional embodiment of the present application, the acquisition module 31 is specifically used to: perform recognition processing based on the contract text data to obtain a text format type; select a target word segmentation tool from a pre-stored word segmentation tool library based on the text format type; and divide the contract text data into a word sequence consisting of words and / or tags through the target word segmentation tool.
[0137] In an optional embodiment of the present application, the smart contract text information includes multiple smart contract text fragments, and the multiple smart contract text fragments are sorted according to the contract steps; accordingly, the smart contract construction module 32 is specifically used to: perform contract encoding operations according to the multiple smart contract text fragments to obtain multiple code fragments, wherein each code fragment has one and only one corresponding smart contract text fragment; sort and combine all the code fragments according to the contract steps to construct the smart contract to be stored.
[0138] In an optional embodiment of the present application, the smart contract reading module 34 is specifically used to: use a pre-trained natural language processing model to perform intent recognition processing based on the call information of the smart contract to be stored to obtain a prediction result; determine the contract execution information of the smart contract to be stored based on the prediction result; and determine at least one hash value to be indexed based on the contract execution information.
[0139] In an optional embodiment of the present application, the acquisition module 31 is also used to: regularly acquire different types of smart contract sample data; perform text recognition processing on each type of smart contract sample data to obtain a corresponding second vocabulary; and merge all second vocabulary with the first vocabulary to obtain an updated first vocabulary.
[0140] In an optional embodiment of the present application, the acquisition module 31 is also used to periodically obtain new smart contract creation requirement information, and perform data processing on the new smart contract creation requirement information according to the pre-trained natural language processing model to obtain new smart contract text information; construct a new smart contract to be stored according to the new smart contract text information; perform contract detection processing on the new smart contract to be stored to obtain a detection result; adjust the pre-trained natural language processing model according to the detection result to obtain an adjusted pre-trained natural language processing model.
[0141] The smart contract data processing device for blockchain provided in this embodiment can be used to execute the above Figure 2 The technical solution of the method embodiment shown has similar implementation principles and technical effects, and will not be described in detail in this embodiment.
[0142] Figure 4 The hardware structure diagram of the electronic device provided in the embodiment of the present application is shown in FIG. Figure 4 As shown, the electronic device includes: at least one processor 401 , and a memory 402 communicatively connected to the processor 401 .
[0143] The memory 402 stores computer-executable instructions.
[0144] The processor 401 executes the computer-executable instructions stored in the memory 402 to implement the various steps involved in the method embodiment of the method for processing smart contract data for blockchain as described above. For details, please refer to the relevant description in the above method embodiment.
[0145] Optionally, the memory 402 may be independent or integrated with the processor 401 .
[0146] When the memory 402 is independently provided, the electronic device further includes a bus 403 for connecting the memory 402 and the processor 401 .
[0147] The embodiment of the present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the above-mentioned smart contract data processing method for blockchain is implemented.
[0148] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the above-mentioned smart contract data processing method for blockchain.
[0149] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0150] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0151] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0152] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0153] If the integrated unit / module is implemented in the form of hardware, the hardware may be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor may be any appropriate hardware processor, such as a CPU, a GPU, an FPGA, a DSP, an ASIC, etc. Unless otherwise specified, the storage unit may be any appropriate magnetic storage medium or magneto-optical storage medium, such as a resistive random access memory (RRAM), a dynamic random access memory (DRAM), a static random access memory (SRAM), an enhanced dynamic random access memory (EDRAM), a high-bandwidth memory (HBM), a hybrid memory cube (HMC), etc.
[0154] If the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0155] In the above embodiments, the description of each embodiment has its own emphasis. For the part not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0156] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0157] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A smart contract data processing method for blockchain, characterized in that: include: Obtain pre-trained natural language processing models and smart contract development requirements information; Performing data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and constructing a smart contract to be stored according to the smart contract text information; Input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored; Store each contract code snippet to be stored and a corresponding hash value into the blockchain storage space in turn; When a hash value is detected to exist in the blockchain storage space with the same hash value, only the hash value is stored in the blockchain storage space until the storage of the smart contract to be stored is completed; Obtaining call information for the smart contract to be stored, and determining at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model; A corresponding contract code snippet is read from the blockchain storage space in turn according to each hash value to be indexed, until the contract code snippet corresponding to the last hash value to be indexed is read. During this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code snippet corresponding to the previous hash value to be indexed can be directly called.
2. The method according to claim 1, characterized in that The obtaining of a pre-trained natural language processing model comprises: Obtain existing smart contract data and pre-stored contract splitting mark data, and perform text format conversion processing according to the existing smart contract data to obtain contract text data; Perform word segmentation processing on the contract text data to obtain a contract word sequence; Performing model training on the initial model according to the contract word sequence, the basic model and the pre-labeled contract split data to obtain a transitional natural language processing model; The pre-stored contract split labeled data is used as a verification set and a test set to perform model adjustment training on the transition natural language processing model to obtain a pre-trained natural language processing model.
3. The method according to claim 2, characterized in that The text format conversion process is performed according to the existing smart contract data to obtain the contract text data, including: Performing text recognition processing on the existing smart contract data to obtain a first vocabulary; Establishing a mapping relationship between special characters in the first vocabulary and the existing smart contract data and a mapping relationship between keywords and data types according to the first vocabulary and the existing smart contract data; Each part of the existing smart contract data is traversed, and each element in the existing smart contract data is replaced with corresponding text content according to the mapping relationship between the first vocabulary and special characters in the existing smart contract data and the mapping relationship between keywords and data types to obtain contract text data.
4. The method according to claim 2, characterized in that: The word segmentation processing is performed according to the contract text data to obtain a contract word sequence, including: Performing identification processing according to the contract text data to obtain a text format type; Selecting a target word segmentation tool from a pre-stored word segmentation tool library according to the text format type; The contract text data is segmented into word sequences consisting of words and / or tokens by the target word segmentation tool.
5. The method according to claim 1, characterized in that: The smart contract text information includes a plurality of smart contract text fragments, and the plurality of smart contract text fragments are sorted according to contract steps; Accordingly, constructing a smart contract to be stored according to the smart contract text information includes: Execute a contract encoding operation according to the multiple smart contract text fragments to obtain multiple code fragments, wherein each code fragment has one and only one corresponding smart contract text fragment; All code snippets are sorted and combined according to the contract steps to construct the smart contract to be stored.
6. The method according to claim 1, characterized in that The determining at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model includes: Performing intent recognition processing using the pre-trained natural language processing model according to the call information of the smart contract to be stored to obtain a prediction result; Determine the contract execution information of the smart contract to be stored according to the prediction result; At least one hash value to be indexed is determined according to the contract execution information.
7. The method according to claim 3, characterized in that Also includes: Regularly obtain different types of smart contract sample data; Perform text recognition processing on each type of smart contract sample data to obtain a corresponding second vocabulary; All second vocabulary lists are merged with the first vocabulary list to obtain an updated first vocabulary list.
8. The method according to any one of claims 1 to 7, characterized in that Also includes: Regularly obtain new smart contract creation demand information, and perform data processing on the new smart contract creation demand information according to the pre-trained natural language processing model to obtain new smart contract text information; Constructing a new smart contract to be stored according to the new smart contract text information; Performing contract detection processing on the new smart contract to be stored to obtain a detection result; The pre-trained natural language processing model is adjusted according to the detection result to obtain an adjusted pre-trained natural language processing model.
9. A smart contract data processing device for blockchain, characterized in that: include: Acquisition module, used to obtain pre-trained natural language processing models and smart contract development requirements information; A smart contract construction module, used to perform data processing on the smart contract development requirement information according to the pre-trained natural language processing model to obtain smart contract text information, and to construct a smart contract to be stored according to the smart contract text information; A smart contract storage module, used to input the smart contract to be stored into a pre-trained natural language processing model to obtain split contract code fragments to be stored, and determine a hash value according to each contract code fragment to be stored; The smart contract storage module is further used to store each contract code fragment to be stored and a corresponding hash value into the blockchain storage space in sequence; The smart contract storage module is further configured to store only the hash value in the blockchain storage space when it is detected that a hash value exists in the blockchain storage space, until the storage of the smart contract to be stored is completed; A smart contract reading module, used to obtain call information for the smart contract to be stored, and determine at least one hash value to be indexed according to the call information of the smart contract to be stored and the pre-trained natural language processing model; The smart contract reading module is also used to read a corresponding contract code fragment from the blockchain storage space according to each hash value to be indexed in turn, until the contract code fragment corresponding to the last hash value to be indexed is read, and during this period, when it is detected that the hash value to be indexed is repeated with the previous hash value to be indexed, the contract code fragment corresponding to the previous hash value to be indexed can be directly called.
10. An electronic device, characterized in that: include: at least one processor, and a memory in communication with the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 8 when being executed by a processor.
Citation Information
Patent Citations
Intelligent contract acquisition method and device, electronic equipment and storage medium
CN110825363A
Block chain smart contract storage method and device
CN114091111A
Smart contract deployment method and device, equipment, medium and program product
CN114201116A
Block chain smart contract generation method and device, and electronic equipment
CN115268847A
Intelligent contract template recommendation method and device based on code representation and electronic equipment
CN117473170A