Code development method and device for smart contract, equipment, medium and program product

By compiling and verifying the smart contract source code, translating it according to the target blockchain type and generating executable code, it solves the problems of long smart contract development cycle and high threshold, and achieves efficient blockchain development.

CN118778938APending Publication Date: 2024-10-15CHINA UNITED NETWORK COMM GRP CO LTD +2
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410977565.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

The development cycle of smart contract code is long, the development workload is heavy, and the development threshold is high, which hinders blockchain development.

Method used

By obtaining the Java smart contract source code, compiling and verifying it, it translates it according to the underlying chain type and language type of the target blockchain to generate executable smart contract code for the target blockchain, reducing development difficulty and error probability.

Benefits of technology

It realizes the development of smart contracts for various blockchain platforms through Java language, reducing development workload and improving development efficiency and code executability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118778938A_ABST
    Figure CN118778938A_ABST
Patent Text Reader

Abstract

The invention provides a code development method and device for a smart contract, equipment, a medium and a program product, and is applied to the field of block chain development. The method comprises the steps that a to-be-translated smart contract source code is acquired, the smart contract source code is compiled, and the smart contract source code is a Java code; after the intelligent contract source code is compiled, verifying the intelligent contract source code; and after the verification of the smart contract source code is passed, translation information of the smart contract source code is obtained, and according to the translation information, the smart contract source code is translated to obtain a smart contract code which is a code of the target language type executable by a target block chain of the smart contract source code. According to the method provided by the invention, the development difficulty of the smart contract is reduced, meanwhile, the probability of errors in subsequent on-chain environment testing is reduced, the development efficiency of the smart contract is improved, and the development workload of the smart contract is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain development, and in particular to a method, device, equipment, medium and program product for developing a smart contract code. Background Art

[0002] Smart contracts are a set of digital protocols with specific rules predefined by computer source code. They are applications running on the blockchain. Smart contracts can be applied to different industries and fields, such as smart homes, e-commerce, and asset management. As their application scenarios continue to expand, the complexity of blockchain smart contracts is also increasing.

[0003] In the existing smart contract code development methods, the development and debugging of smart contract codes need to rely on the blockchain environment, and the chain code needs to be packaged, deployed, initialized, upgraded, and then the written smart contract code needs to be tested. Different blockchain platforms may support different language types of smart contract codes, and developers of smart contract codes often need to learn and master multiple smart contract languages.

[0004] This method of developing smart contract code results in a long development cycle, heavy development workload, and high development threshold for smart contract code, which hinders the development of blockchain. Summary of the invention

[0005] The present application provides a smart contract code development method, device, equipment, medium and program product to solve the technical problems of long development cycle, large development workload and high development threshold of smart contract code.

[0006] In a first aspect, the present application provides a method for developing a smart contract code, comprising:

[0007] Obtaining the smart contract source code to be translated, and compiling the smart contract source code, wherein the smart contract source code is Java code;

[0008] After the smart contract source code is compiled, the smart contract source code is verified;

[0009] After the smart contract source code is verified, the translation information of the smart contract source code is obtained, and the smart contract source code is translated according to the translation information to obtain the smart contract code, wherein the translation information includes the underlying chain type and the target language type of the target blockchain of the smart contract source code, and the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

[0010] Optionally, translating the smart contract source code according to the translation information of the smart contract source code to obtain the smart contract code includes:

[0011] According to the smart contract source code, obtain a set of attributes and a first set of method codes of multiple domain models in the smart contract source code, wherein the domain model is a class or an object in the smart contract source code;

[0012] According to the first method code set, a plurality of internal codes and a plurality of external interfaces are obtained, and according to the translation information, a translated internal code corresponding to each of the internal codes and a translated external interface corresponding to each of the external interfaces are obtained;

[0013] According to each of the translated internal codes and each of the translated external interfaces, obtaining a translated second method code set;

[0014] For any one of the multiple domain models, translating the domain model into a data structure of the target blockchain and its index identifier according to the attribute set of the domain model and the translation information;

[0015] According to each of the data structures and their index identifiers and the second method code set, obtaining a search identifier of each of the internal codes of the smart contract code index identifier;

[0016] According to each of the search identifiers and the translation information, obtaining a translated internal code corresponding to the internal code in an internal code translation dictionary set;

[0017] According to each of the external interfaces and its interface information, obtaining a translation external interface corresponding to each of the external interfaces;

[0018] The step of obtaining a translated second method code set according to each of the translated internal codes and each of the translated external interfaces includes:

[0019] Obtaining method information of each first method code in the first method code set, wherein the method information of the first method code includes a method name and method parameters of the first method code;

[0020] For any first method code in the first method code set, the method information of the first method code is concatenated with the translated internal code and the translated external interface corresponding to the first method code to obtain a second method code corresponding to the first method code.

[0021] Optionally, translating the domain model into a data structure corresponding to the target blockchain and its index identifier according to the attribute set of the domain model and the translation information includes:

[0022] According to the translation information, obtain a data type conversion table corresponding to the smart contract code;

[0023] Constructing a data structure of the target blockchain corresponding to the domain model according to the data type conversion relationship table and the attribute set of the domain model;

[0024] Obtain a primary key field in the attribute set of the domain model, obtain an index identifier of the data structure according to the primary key field, and store the data structure and the index identifier in association, wherein the primary key field is a field with a primary key annotation.

[0025] Optionally, obtaining the smart contract code according to each of the data structures and its index identifier and the second method code set includes:

[0026] Determine a target data structure for each second method code in the second method code set according to the smart contract source code, each of the data structures and its index identifier, and the second method code set;

[0027] Each of the second method codes is written into a target data structure of the second method code to obtain a smart contract code.

[0028] Optionally, the verifying the smart contract source code includes:

[0029] Determine whether the smart contract source code meets the preset verification conditions, wherein the preset verification conditions include that there is a target method code with an interface annotation in the smart contract source code, there is an external interface for operating a database in the target method code, the target method code complies with the interface specification for connecting to a database in the Java language, and the domain model code in the smart contract source code has a primary key annotation;

[0030] If the smart contract source code meets the preset verification condition, it is determined that the smart contract source code verification has passed;

[0031] If the smart contract source code does not meet the preset verification condition, it is determined that the smart contract source code verification has failed.

[0032] In a second aspect, the present application provides a code development device for a smart contract, comprising:

[0033] A compiling module, used to obtain the smart contract source code to be translated and compile the smart contract source code, wherein the smart contract source code is Java code;

[0034] A verification module, used to verify the smart contract source code after the smart contract source code is compiled;

[0035] A translation module is used to obtain translation information of the smart contract source code after the smart contract source code is verified, and translate the smart contract source code according to the translation information to obtain the smart contract code, wherein the translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code, and the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

[0036] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0037] The memory stores computer-executable instructions;

[0038] The processor executes the computer-executable instructions stored in the memory to implement the method according to the first aspect.

[0039] In a fourth aspect, 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.

[0040] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.

[0041] The smart contract code development method, apparatus, device, medium and program product provided by the present application obtain the smart contract source code to be translated and compile the smart contract source code, wherein the smart contract source code is Java code; after the smart contract source code is compiled, the smart contract source code is verified; after the smart contract source code is verified, the translation information of the smart contract source code is obtained, and according to the translation information, the smart contract source code is translated to obtain the smart contract code, wherein the translation information includes the underlying chain type and the target language type of the target blockchain of the smart contract source code, and the smart contract code is the target language type code executable by the target blockchain of the smart contract source code, so that developers are allowed to develop smart contracts for various blockchain platforms through Java language, which reduces the difficulty of smart contract development, reduces the probability of errors in subsequent on-chain environment testing, improves the development efficiency of smart contracts, and reduces the workload of smart contract development. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] 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.

[0043] Figure 1 A schematic diagram of an application scenario of the method for developing smart contract code provided for this application;

[0044] Figure 2 Schematic diagram of the process of developing the smart contract code provided for this application Figure 1 ;

[0045] Figure 3 Schematic diagram of the process of developing the smart contract code provided for this application Figure 2 ;

[0046] Figure 4 A schematic diagram of the structure of a code development device for a smart contract provided in this application;

[0047] Figure 5 A schematic diagram of the structure of an electronic device provided in this application.

[0048] 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

[0049] 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.

[0050] 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, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0051] Smart contracts are a set of digital protocols with specific rules predefined by computer source code. They are applications running on the blockchain. Smart contracts can be applied to different industries and fields, such as smart homes, e-commerce, and asset management. As their application scenarios continue to expand, the complexity of blockchain smart contracts is also increasing.

[0052] In the existing smart contract code development methods, the development and debugging of smart contract codes need to rely on the blockchain environment, and the chain code needs to be packaged, deployed, initialized, upgraded, and then the written smart contract code needs to be tested. Different blockchain platforms may support different language types of smart contract codes, and developers of smart contract codes often need to learn and master multiple smart contract languages.

[0053] This method of developing smart contract code results in a long development cycle, heavy development workload, and high development threshold for smart contracts, which hinders the development of blockchain.

[0054] In response to the above technical problems, the present application proposes the following technical ideas: Java is a widely used programming language with the characteristics of simplicity, object-oriented, distributed, robust, secure, platform-independent, portable, multi-threaded and dynamic. Writing smart contracts in Java can reduce the development cost and difficulty of smart contracts, but smart contracts written in Java cannot be run directly on the blockchain. In the code development stage before the smart contract is deployed, the present application translates the smart contract source code written in Java according to the underlying chain type of the blockchain platform where the smart contract is to be deployed and its executable target language type, and obtains the translated smart contract code of the target language type. The smart contract code can be executed by the blockchain platform, thereby allowing developers to develop smart contracts for various blockchain platforms in Java, reducing the difficulty of smart contract development. At the same time, the smart contract source code written in Java is precompiled and tested in the code development stage, reducing the probability of errors in subsequent on-chain environment testing, improving the development efficiency of smart contracts, and reducing the workload of smart contract development.

[0055] Figure 1 Schematic diagram of application scenarios of the method for developing smart contract code provided in the embodiment of this application. Figure 1 As shown, the scenario includes: a user terminal 101, a code translator 102 and a blockchain platform 103;

[0056] The user terminal 101 sends the smart contract source code and translation information input by the user to the code translator 102. The smart contract source code is Java code. The translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code. The code translator 102 compiles and verifies the smart contract source code. After the compilation and verification are passed, the code translator 102 translates the smart contract source code according to the translation information, translates the smart contract source code into a smart contract code of the target language type executable by the blockchain platform 103, compresses the smart contract code, and sends the compressed package of the smart contract code to the blockchain platform 103, so that the blockchain platform 103 performs subsequent compilation, testing and deployment on the smart contract.

[0057] 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.

[0058] based on Figure 1 The application scenario shown in the present application embodiment provides a method for developing a smart contract code, which is applied to Figure 1 The code translator shown. Figure 2 Schematic diagram of the process of developing the smart contract code provided in the embodiment of the present application Figure 1 ,like Figure 2 As shown, the development method of the smart contract code includes:

[0059] S201: Obtain the smart contract source code to be translated, and compile the smart contract source code.

[0060] Among them, the smart contract source code is Java code.

[0061] Specifically, the code translator receives the smart contract source code to be translated sent by the user terminal, and compiles the smart contract source code through a Java compiler to perform a preliminary syntax and semantic check on the source code.

[0062] S202: After the smart contract source code is compiled, the smart contract source code is verified.

[0063] Specifically, after the smart contract source code is compiled, the code translator globally scans and parses the smart contract source code, verifies the smart contract source code according to the preset code verification rules, and determines whether the smart contract source code complies with the preset code verification rules. If so, the smart contract source code verification passes, otherwise the smart contract source code fails the verification; the preset code verification rules may, for example, include: the method code in the smart contract code must contain an application program that operates the database, the method code in the smart contract code must comply with the interface specification of the Java connection database, and the smart contract code must contain coding information that complies with the preset verification code set, etc. The embodiment of the present application does not impose any special restrictions on the specific content of the code verification rules.

[0064] S203: After the smart contract source code is verified, the translation information of the smart contract source code is obtained, and the smart contract source code is translated according to the translation information to obtain the smart contract code.

[0065] Among them, the translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code. The underlying chain type may include BCOS chain, Changan chain, etc., and the target language type may include Go language, solidity language, etc. The embodiment of the present application does not impose any special restrictions on the specific types of the underlying chain and the target language; the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

[0066] Specifically, after the smart contract source code is verified, the code translator obtains the translation information of the smart contract source code sent by the user terminal, and translates the smart contract source code according to the underlying chain type and the target language type indicated by the translation information according to the preset translation method to obtain the smart contract code of the target language type executable by the target blockchain of the smart contract source code. After the code translator compiles the generated smart contract code, it generates a compressed package of the smart contract code, and sends the compressed package of the smart contract code to the corresponding node of the blockchain. After the corresponding node of the blockchain parses the smart contract code in the compressed package, it performs subsequent smart contract deployment and other operations; the translation method may, for example, perform semantic recognition of the smart contract source code line by line according to the semantic recognition rules of the Java language, and obtain the target code matching the semantic recognition result in the code library of the underlying chain type and the target language type through the pre-trained code matching splicing model according to the semantic recognition result of each source code statement, and splice each of the target codes according to the order of the source code it matches to obtain the translated smart contract code; the embodiment of the present application does not impose any special restrictions on the specific translation method.

[0067] The method for developing smart contract code provided in the embodiment of the present application reduces the probability of errors occurring in the subsequent on-chain environment testing of the smart contract by pre-compiling the smart contract source code written in Java language, thereby improving the development efficiency of the smart contract; by translating the smart contract source code written in Java language according to the underlying chain type of the blockchain platform on which the smart contract is to be deployed and its executable target language type, the translated smart contract code of the target language type is obtained, and the smart contract code can be executed by the blockchain platform, so that developers can develop smart contracts for various blockchain platforms using only Java language, without having to learn and master other programming languages, thereby reducing the difficulty of smart contract development.

[0068] Figure 3 Schematic diagram of the process of developing the smart contract code provided in the embodiment of the present application Figure 2 ,like Figure 3 As shown, the development method of the smart contract code includes:

[0069] S301: Obtain the smart contract source code to be translated, and compile the smart contract source code.

[0070] Among them, the smart contract source code is Java code.

[0071] The implementation method of step S301 is similar to the implementation method of step S201, and will not be described in detail in this embodiment.

[0072] S302: After the smart contract source code is compiled, determine whether the smart contract source code meets preset verification conditions.

[0073] Among them, the preset verification conditions include the presence of target method code with interface annotations in the smart contract source code, the presence of external interfaces for operating databases in the target method code, the compliance of the target method code with the interface specifications for connecting to databases in the Java language, and the presence of primary key annotations in the domain model code in the smart contract source code.

[0074] The interface annotation is a custom annotation that the developer pre-added to the method code. The interface annotation can be declared as a custom annotation named "@ChainInterface" for example; the primary key annotation is a primary key annotation that the developer pre-added to the domain model code. The primary key annotation can be declared as a custom annotation named "@ChainKey" for example; the developer can define the corresponding interface annotation and primary key annotation, as well as the method code corresponding to the above annotations according to actual needs, and can inject the written interface annotation and primary key annotation into the corresponding position of the smart contract source code through the configuration aspect. The interface annotation is used to indicate that the target method code with the interface annotation needs to interact with the external database for data, and the code translator needs to translate the external interface therein into an external interface that can be recognized and called by the target blockchain; the primary key annotation is used to indicate that the domain model code with the primary key annotation has a primary key field, and the code translator needs to use the primary key field as the index identifier of the data structure obtained by translating the domain model.

[0075] It can be understood that the target method code with interface annotations must contain an external interface for operating the database, and the target method code with interface annotations must comply with the interface specification for connecting to the database in the Java language, before the method code can be determined to be executable legal code.

[0076] Specifically, the code translator performs a global scan on the smart contract source code to determine whether the smart contract source code meets the preset verification conditions. If the smart contract source code meets the preset verification conditions, it is determined that the smart contract verification has passed; otherwise, it is determined that the smart contract verification has failed.

[0077] S303: If the smart contract source code does not meet the preset verification condition, it is determined that the smart contract source code verification has failed, and a smart contract verification failure prompt message is sent to the user terminal.

[0078] Among them, the prompt information may include, for example, a prompt text such as "The code verification failed", as well as the specific error cause and corresponding error location of the smart contract source code, so that developers can modify the code of the corresponding error location according to the prompt information of the smart contract verification failure.

[0079] S304: If the smart contract source code meets the preset verification condition, it is determined that the smart contract source code verification has passed, and the translation information of the smart contract source code is obtained.

[0080] The translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code.

[0081] Specifically, after the smart contract source code is verified, the code translator obtains the translation information of the smart contract source code sent by the user terminal.

[0082] S305: According to the smart contract source code, obtain a property set and a first method code set of multiple domain models in the smart contract.

[0083] Among them, the domain model is a class or object in the smart contract source code, and the attribute set of the domain model includes the name of each attribute field of the domain model. When an attribute field corresponds to a field value, the attribute set also includes the field value of the attribute field.

[0084] Specifically, the code translator parses the smart contract source code according to a preset parsing algorithm, and obtains a property set and a first method code set of multiple domain models in the smart contract according to the parsing result.

[0085] S306: According to the first method code set, obtain multiple internal codes and multiple external interfaces.

[0086] The internal code is the internal implementation logic in the first method code; the external interface is the interface for the first method code to interact with an external database for data, for example, it can be the JDBC standard interface provided by Java.

[0087] Optionally, the code translator may obtain the multiple internal codes and multiple external interfaces according to the method code set by the following steps:

[0088] Step 1: For any first method code in the first method code set, obtain each internal code in the first method code.

[0089] Specifically, the code translator parses the statements in the first method code according to a preset parsing algorithm, and obtains each internal code in the method code according to the parsing result and the internal code identification rule.

[0090] Step 2: Determine whether the first method code has an interface annotation.

[0091] Specifically, the code translator determines whether the statement of the first method code contains an interface annotation according to the parsing result and the interface annotation declaration format.

[0092] Step 3: If yes, then obtain the interface information of each external interface in the first method code according to the interface annotation, the first method code and the translation information.

[0093] The interface information includes a first identifier, an interface code and interface parameters of the external interface, and a second identifier of a corresponding translated external interface of the external interface.

[0094] Optionally, if the statement of the first method code carries an interface annotation, the specific method steps for the code translator to obtain the interface information of each external interface in the first method code according to the interface annotation, the first method code and the translation information may be as follows:

[0095] Step 3a: According to the interface annotation and the first method code, obtain a first identifier, an interface code and an interface parameter of each external interface in the first method code.

[0096] Specifically, the code translator obtains the first identifier of each external interface and the input and output parameters of the interface in the method code according to the interface information extraction method indicated by the interface annotation, and obtains the interface code corresponding to the external interface based on the first identifier of the external interface and the preset correspondence between the identifiers of different external interfaces and the interface codes.

[0097] Step 3b: According to each of the first identifiers and the translation information, obtain the second identifier corresponding to each of the first identifiers in a preset interface correspondence table.

[0098] Specifically, the code translator obtains a pre-established interface correspondence table at a corresponding storage location, and searches for a second identifier corresponding to the first identifier in the interface correspondence table corresponding to the translation information. The correspondence between different interface correspondence tables and different translation information can be stored in a key-value table with different translation information as keys and different interface correspondence table identifiers as key values. The interface correspondence table can be a key-value table with different first identifiers as keys and different second identifiers as key values. The first identifier is an external interface identifier of a Java language type, and the second identifier is an external interface identifier of a target language type of the smart contract.

[0099] Step 4: If not, the interface information of the external interface in the method code is not obtained.

[0100] S307: According to the translation information, obtain a translated internal code corresponding to each of the internal codes and a translated external interface corresponding to each of the external interfaces.

[0101] Optionally, the code translator may obtain the translated internal code corresponding to each of the internal codes and the translated external interface corresponding to each of the external interfaces according to the translation information by the following steps:

[0102] Step 1: Extract features of each internal code and obtain a search identifier for each internal code.

[0103] Specifically, the code translator uses a pre-trained code recognition model to perform word extraction and keyword matching on each internal code statement obtained according to a preset keyword set, obtains a feature value of the internal code statement based on the keyword matching result, and uses the feature value of the internal code as a search identifier for the internal code. The keyword set may include reserved words and operators in the Java language, and may also include keywords and operators of standard SQL statements embedded in the Java language.

[0104] Step 2: According to each of the search identifiers and the translation information, a translated internal code corresponding to the internal code is obtained from an internal code translation dictionary set.

[0105] Specifically, the code translator obtains the translated internal code template corresponding to the search identifier of each internal code statement in the internal code translation dictionary set corresponding to the translation information, and the correspondence between different internal code translation dictionary sets and different translation information can be stored in a key-value table with different translation information as keys and different internal code translation dictionary sets as key values. The internal code translation dictionary set can be a key-value table with different search identifiers as keys and different translated internal code templates as key values, and obtains the parameter name in the internal code, fills the variable name in the internal code into the corresponding position of the translated internal code template according to the corresponding information of the parameter position between the internal code and its translated internal code template, and obtains the translated internal code corresponding to the internal code.

[0106] Step 3: According to each of the external interfaces and its interface information, obtain the translated external interface corresponding to each of the external interfaces.

[0107] Specifically, for any one of the external interfaces, the code translator obtains the interface code of the external interface, where the interface code may be, for example, a standard SQL statement bound to the external interface, converts each bound standard SQL statement into a database operation statement corresponding to the target blockchain, writes each of the interface parameters into a corresponding position of the database operation statement, establishes a binding relationship between the database operation statement and the second identifier, and uses the second identifier and the database operation statement bound thereto as the translated external interface corresponding to the external interface.

[0108] S308: Acquire a translated second method code set according to each of the translated internal codes and each of the translated external interfaces.

[0109] Optionally, the code translator obtains method information of each first method code in the first method code set, where the method information of the first method code includes the method name and method parameters in the first method code; for any first method code in the first method code set, the method information of the first method code is concatenated with the translated internal code and the translated external interface corresponding to the first method code to obtain a second method code corresponding to the first method code, and the set of second method codes corresponding to each first method code is the translated second method code set.

[0110] S309: For any one of the multiple domain models, translate the domain model into a data structure of the target blockchain and its index identifier according to the attribute set of the domain model and the translation information.

[0111] Optionally, the code translator may translate the domain model into the data structure of the target blockchain and its index identifier according to the attribute set of the domain model and the translation information by the following steps:

[0112] Step 1: According to the translation information, obtain the data type conversion table corresponding to the smart contract code.

[0113] Specifically, the code translator obtains the data type conversion table corresponding to the translation information as the data type conversion table corresponding to the smart contract code based on the translation information and the correspondence between different translation information and different data type conversion tables.

[0114] Step 2: According to the data type conversion relationship table and the attribute set of the domain model, construct the data structure of the target blockchain corresponding to the domain model.

[0115] Specifically, the code translator converts the data type of each attribute field in the attribute set into the data type of the target blockchain according to the data type conversion relationship table and the attribute set of the domain model, obtains the conversion code corresponding to each attribute identification field, and writes the identification of each attribute field and its corresponding conversion code into the corresponding position in the data structure template corresponding to the target blockchain, to obtain the data structure of the target blockchain corresponding to the domain model.

[0116] Step 3: Obtain the primary key field in the attribute set of the domain model, obtain the index identifier of the data structure according to the primary key field, and store the data structure and the index identifier in association with each other.

[0117] The primary key field is a field with a primary key annotation.

[0118] Specifically, the code translator parses each attribute field in the attribute set of the domain model, obtains the attribute field with the primary key annotation as the primary key field according to the parsing result and the primary key annotation declaration format, uses the field value or field name of the primary key field as the index identifier of the data structure, and stores the data structure and the index identifier in association with each other.

[0119] S310: Obtain the smart contract code according to each of the data structures and its index identifier and the second method code set.

[0120] Optionally, the code translator may obtain the smart contract code according to each of the data structures and their index identifiers and the translated method code set by the following steps:

[0121] Step 1: Determine the target data structure of each second method code in the second method code set according to the smart contract source code, each data structure and its index identifier, and the second method code set.

[0122] Specifically, the code translator determines the target domain model corresponding to each first method code according to the smart contract source code, and uses the data structure corresponding to the target domain model as the target data structure of the second method code corresponding to the first method code.

[0123] Step 2: Write each of the second method codes into the target data structure of the second method code to obtain the smart contract code.

[0124] Specifically, the code translator obtains the location information of each first method code in the corresponding domain model according to the smart contract source code, and determines the target location of the second method code corresponding to each first method code in its target data structure according to the location information of each first method code in the corresponding domain model; writes each second method code to the target location in the target data structure of the second method code, and finally uses each data structure and its index identifier as the smart contract code. For the first method code with interface annotations, the corresponding second method code is the smart contract interface code.

[0125] S311: compress the smart contract code to generate a smart contract code compression package, and send the smart contract code compression package to the target blockchain platform.

[0126] Specifically, the code translator compresses the smart contract code to generate a smart contract code compression package, and sends the smart contract code compression package to the target blockchain platform of the smart contract source code.

[0127] The code development method for a smart contract provided in an embodiment of the present application reads the customized primary key annotations and interface annotations added in the smart contract source code, determines the categories corresponding to different smart contract source codes according to the primary key annotations and interface annotations in the smart contract source code, and adopts different translation methods and translation dictionaries for different categories of smart contract codes according to the categories corresponding to the smart contract source code and the translation information, and translates the smart contract source code into the smart contract code executable by its target blockchain, thereby realizing flexible and accurate translation of the smart contract source code, thereby reducing the difficulty of developing the smart contract code.

[0128] Figure 4 A schematic diagram of the structure of a code development device for a smart contract provided in an embodiment of the present application; Figure 4 As shown, the present application provides a device for dynamically adjusting a virtual machine memory, the device 400 for dynamically adjusting a virtual machine memory comprising:

[0129] A compiling module 401 is used to obtain the smart contract source code to be translated and compile the smart contract source code, wherein the smart contract source code is Java code;

[0130] Verification module 402, used to verify the smart contract source code after the smart contract source code is compiled;

[0131] The translation module 403 is used to obtain the translation information of the smart contract source code after the smart contract source code is verified, and translate the smart contract source code according to the translation information to obtain the smart contract code, wherein the translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code, and the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

[0132] Optionally, the translation module 403 is specifically used to obtain, according to the smart contract source code, a property set and a first method code set of multiple domain models in the smart contract source code, wherein the domain model is a class or object in the smart contract source code; according to the first method code set, obtain multiple internal codes and multiple external interfaces, and according to the translation information, obtain a translated internal code corresponding to each internal code and a translated external interface corresponding to each external interface; according to each translated internal code and each translated external interface, obtain a translated second method code set; for any one of the multiple domain models, translate the domain model into a data structure and its index identifier of the target blockchain according to the property set of the domain model and the translation information; according to each of the data structures and its index identifier and the second method code set, obtain the smart contract code.

[0133] Optionally, the translation module 403 is specifically used to obtain each internal code in any first method code in the first method code set; determine whether the first method code has an interface annotation; if so, obtain interface information of each external interface in the first method code according to the interface annotation, the first method code and the translation information, wherein the interface information includes a first identifier, an interface code and interface parameters of the external interface, and a second identifier of the corresponding translated external interface of the external interface; if not, the interface information of the external interface in the first method code is not obtained.

[0134] Optionally, the translation module 403 is specifically used to obtain the first identifier, interface code and interface parameters of each external interface in the first method code according to the interface annotation and the first method code; and obtain the second identifier corresponding to each first identifier in a preset interface correspondence table according to each first identifier and the translation information.

[0135] Optionally, the translation module 403 is specifically used to perform feature extraction on each of the internal codes and obtain a search identifier for each of the internal codes; obtain a translated internal code corresponding to the internal code in an internal code translation dictionary set according to each of the search identifiers and the translation information; obtain a translated external interface corresponding to each of the external interfaces according to each of the external interfaces and its interface information; obtain method information of each first method code in a first method code set, wherein the method information of the first method code includes a method name and method parameters of the first method code; for any first method code in the first method code set, concatenate the method information of the first method code with the translated internal code and the translated external interface corresponding to the first method code to obtain a second method code corresponding to the first method code.

[0136] Optionally, the translation module 403 is specifically used to obtain a data type conversion table corresponding to the smart contract code according to the translation information; construct a data structure of the target blockchain corresponding to the domain model according to the data type conversion relationship table and the attribute set of the domain model; obtain a primary key field in the attribute set of the domain model, obtain an index identifier of the data structure according to the primary key field, and store the data structure and the index identifier in association, wherein the primary key field is a field with a primary key annotation.

[0137] Optionally, the translation module 403 is specifically used to determine the target data structure of each second method code in the second method code set according to the smart contract source code, each of the data structures and its index identifier, and the second method code set; write each second method code into the target data structure of the second method code to obtain the smart contract code.

[0138] Optionally, the verification module 402 is specifically used to determine whether the smart contract source code meets preset verification conditions, wherein the preset verification conditions include the presence of target method code with interface annotations in the smart contract source code, the presence of external interfaces for operating databases in the target method code, the target method code conforming to the interface specification for connecting to the database in the Java language, and the domain model code in the smart contract source code having primary key annotations; when the smart contract source code meets the preset verification conditions, it is determined that the smart contract source code verification has passed; when the smart contract source code does not meet the preset verification conditions, it is determined that the smart contract source code verification has failed.

[0139] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 5As shown, the electronic device 500 includes: at least one processor 501 and a memory 502; in addition, the electronic device 500 may also have a communication interface 504 for receiving and sending instructions.

[0140] Wherein, the processor 501, the memory 502 and the communication interface 504 are connected via a bus 503;

[0141] The computer program is stored in the memory 502 and is configured to be executed by the processor 401 to implement the present application. Figure 2-Figure 3 A code development method for a smart contract provided by any corresponding embodiment;

[0142] Figure 5 The device for dynamically adjusting the virtual machine memory in the illustrated embodiment can be used to execute the technical solution of the above method embodiment, and its implementation principle and technical effect are similar and will not be described in detail here.

[0143] In addition, this embodiment also provides a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the code development method of the smart contract of the above embodiment.

[0144] In addition, this embodiment also provides a computer program product, including a computer program, which is executed by a processor to implement the code development method of the smart contract of the above embodiment.

[0145] 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.

[0146] 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.

[0147] 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.

[0148] 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.

[0149] 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.

[0150] 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.

[0151] In the above embodiments, the description of each embodiment has its own emphasis. For parts 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.

[0152] 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.

[0153] 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 method for developing smart contract code, characterized in that: The method comprises: Obtaining the smart contract source code to be translated, and compiling the smart contract source code, wherein the smart contract source code is Java code; After the smart contract source code is compiled, the smart contract source code is verified; After the smart contract source code is verified, the translation information of the smart contract source code is obtained, and the smart contract source code is translated according to the translation information to obtain the smart contract code, wherein the translation information includes the underlying chain type and the target language type of the target blockchain of the smart contract source code, and the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

2. The method according to claim 1, characterized in that The step of translating the smart contract source code according to the translation information of the smart contract source code to obtain the smart contract code includes: According to the smart contract source code, obtain a set of attributes and a first set of method codes of multiple domain models in the smart contract source code, wherein the domain model is a class or an object in the smart contract source code; According to the first method code set, a plurality of internal codes and a plurality of external interfaces are obtained, and according to the translation information, a translated internal code corresponding to each of the internal codes and a translated external interface corresponding to each of the external interfaces are obtained; According to each of the translated internal codes and each of the translated external interfaces, obtaining a translated second method code set; For any one of the multiple domain models, translating the domain model into a data structure of the target blockchain and its index identifier according to the attribute set of the domain model and the translation information; Obtain the smart contract code according to each of the data structures, its index identifier and the second method code set.

3. The method according to claim 2, characterized in that The acquiring of a plurality of internal codes and a plurality of external interfaces according to the first method code set includes: For any first method code in the first method code set, obtaining each internal code in the first method code; Determine whether the first method code has an interface annotation; If so, obtaining interface information of each external interface in the first method code according to the interface annotation, the first method code and the translation information, wherein the interface information includes a first identifier, an interface code and an interface parameter of the external interface, and a second identifier of a corresponding translated external interface of the external interface; If not, the interface information of the external interface in the first method code is not obtained.

4. The method according to claim 3, characterized in that The acquiring, according to the interface annotation, the first method code and the translation information, interface information of the external interface in each of the method codes comprises: According to the interface annotation and the first method code, obtain a first identifier, an interface code and an interface parameter of each external interface in the first method code; According to each of the first identifiers and the translation information, the second identifier corresponding to each of the first identifiers is obtained from a preset interface correspondence table.

5. The method according to claim 3, characterized in that: The step of obtaining, according to the translation information, a translated internal code corresponding to each of the internal codes and a translated external interface corresponding to each of the external interfaces comprises: Perform feature extraction on each of the internal codes to obtain a search identifier for each of the internal codes; According to each of the search identifiers and the translation information, obtaining a translated internal code corresponding to the internal code in an internal code translation dictionary set; According to each of the external interfaces and its interface information, obtaining a translation external interface corresponding to each of the external interfaces; The step of obtaining a translated second method code set according to each of the translated internal codes and each of the translated external interfaces includes: Obtaining method information of each first method code in the first method code set, wherein the method information of the first method code includes a method name and method parameters of the first method code; For any first method code in the first method code set, the method information of the first method code is concatenated with the translated internal code and the translated external interface corresponding to the first method code to obtain a second method code corresponding to the first method code.

6. The method according to claim 2, characterized in that The translating the domain model into a data structure corresponding to the target blockchain and its index identifier according to the attribute set of the domain model and the translation information includes: According to the translation information, obtain a data type conversion table corresponding to the smart contract code; Constructing a data structure of the target blockchain corresponding to the domain model according to the data type conversion relationship table and the attribute set of the domain model; Obtain a primary key field in the attribute set of the domain model, obtain an index identifier of the data structure according to the primary key field, and store the data structure and the index identifier in association, wherein the primary key field is a field with a primary key annotation.

7. The method according to claim 2, characterized in that The step of obtaining the smart contract code according to each of the data structures and their index identifiers and the second method code set includes: Determine a target data structure for each second method code in the second method code set according to the smart contract source code, each of the data structures and its index identifier, and the second method code set; Each of the second method codes is written into a target data structure of the second method code to obtain a smart contract code.

8. The method according to claim 1, characterized in that The verifying process of the smart contract source code includes: Determine whether the smart contract source code meets the preset verification conditions, wherein the preset verification conditions include that there is a target method code with an interface annotation in the smart contract source code, there is an external interface for operating a database in the target method code, the target method code complies with the interface specification for connecting to a database in the Java language, and the domain model code in the smart contract source code has a primary key annotation; If the smart contract source code meets the preset verification condition, it is determined that the smart contract source code verification has passed; If the smart contract source code does not meet the preset verification condition, it is determined that the smart contract source code verification has failed.

9. A code development device for a smart contract, characterized in that: include: A compiling module, used to obtain the smart contract source code to be translated and compile the smart contract source code, wherein the smart contract source code is Java code; A verification module, used to verify the smart contract source code after the smart contract source code is compiled; A translation module is used to obtain translation information of the smart contract source code after the smart contract source code is verified, and translate the smart contract source code according to the translation information to obtain the smart contract code, wherein the translation information includes the underlying chain type and target language type of the target blockchain of the smart contract source code, and the smart contract code is the code of the target language type executable by the target blockchain of the smart contract source code.

10. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to 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

Cited By

  • Smart contract security detection method and device, equipment, storage medium and product

    CN119830287A