A method and device for generating smart contracts based on graphical contract components
Through the graphical operation interface and component drag-and-drop method, smart contract development is simplified, solving the complexity and security problems of existing smart contract development, and improving the usability and security of smart contracts.
Patent Information
- Application Number
- CN202011019441.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-25
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-09-25
AI Technical Summary
Existing smart contracts have high development thresholds and are complicated to use, resulting in uncontrollable reliability and security and affecting practical applications.
Adopt a graphical smart contract generation method based on contract components. Through the smart contract component set, editing module, inspection module and code generation module, it provides a graphical operation interface, intuitive operation through drag and drop, configures component parameters, generates standard codes, and reduces contract costs. Code security risks.
It simplifies the development process of smart contracts, improves the usability and security of the contract, reduces the security risks of the contract code, and improves the development capabilities of beginners.
Smart Images

Figure CN112163949B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of blockchain technology, and specifically relates to a method, device, terminal device and computer-readable medium for generating smart contracts based on the graphical representation of contract components. Background Art
[0002] Blockchain is a novel application system based on computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. It is essentially a decentralized database, a chain of data blocks linked together using cryptographic methods. Each block contains information about a batch of network transactions, which is used to verify the validity of this information (to prevent counterfeiting) and generate the next block. In a narrow sense, blockchain is a distributed ledger that cryptographically guarantees immutability and non-forgeability by combining data blocks in a chained data structure in chronological order. In a broader sense, blockchain technology is a new distributed infrastructure and computing method that uses a block chain data structure to verify and store data, a distributed node consensus algorithm to generate and update data, cryptography to ensure secure data transmission and access, and smart contracts composed of automated script code to program and manipulate data.
[0003] The concept of a smart contract was first proposed in 1994 by American computer scientist Nick Szabo, who defined it as "a set of digitally specified promises, including protocols by which the parties can enforce those promises." Specifically, it refers to a self-executing computer program that itself is a system participant. It responds to incoming information, can receive and store value, and can also send information and value. This program acts like a trusted person, temporarily holding assets and always executing according to pre-defined rules.
[0004] Currently, smart contracts are mainly based on Ethereum smart contracts, but the contract development threshold is high and the use is complex. Developers must relearn and master a new language (Solidity). Due to factors such as the ability and level of developers, the reliability and security of smart contracts are uncontrollable, which seriously affects the practical application of smart contracts. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method and device for generating smart contracts based on the graphics of contract components, which can reduce the security risks of contract codes and improve the availability and security of contracts.
[0006] The technical solution of the invention is as follows: a method for generating smart contracts based on the graphical representation of contract components, comprising:
[0007] According to the smart contract operation mechanism and compilation mechanism, smart contract components are formulated based on business application scenarios and form a smart contract component set;
[0008] Smart contract participants log in to their blockchain accounts and determine the smart contract components to be selected based on the smart contract creation goals agreed upon by all participants;
[0009] Select the specified smart contract component from the smart contract component set area and drag it to the smart contract editing area. Enter the process logic and parameter configuration between each smart component to complete the smart contract logic formulation;
[0010] Check the process logic and parameter configuration of each smart contract component. If passed, proceed to the next step. If not, return to the previous step and redefine the smart contract logic.
[0011] Output smart contract description file, which will generate a self-description file in XML or JS format through the checked smart contract component;
[0012] The self-describing file is converted into smart contract code through the smart contract code generator to complete the generation of the smart contract.
[0013] The present invention also provides a smart contract generation device based on the graphical representation of contract components, comprising:
[0014] The smart contract component set module includes several smart contract component modules, which are used to formulate smart contract components based on the smart contract operation mechanism and compilation mechanism and business application scenarios, and form a smart contract component set;
[0015] The smart contract editing module is used to select a specified smart contract component from the smart contract component set area and drag it to the smart contract editing area, enter the process logic and parameter configuration between each smart component, and complete the smart contract logic formulation;
[0016] The smart contract checking module is used to check the process logic and parameter configuration of each smart contract component. If it passes, it will proceed to the next step. If it fails, it will return to the previous step to redefine the smart contract logic;
[0017] The smart contract description file generation module is used to output the smart contract description file. It generates a self-description file in XML or JS format based on the checked smart contract component.
[0018] The smart contract code generation module is used to convert the self-describing file into smart contract code to complete the generation of the smart contract.
[0019] The present invention also provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods when executing the computer program.
[0020] The present invention also provides a computer-readable medium, wherein the computer-readable medium stores a computer program, and when the computer program is processed and executed, the steps of any one of the methods are implemented.
[0021] The present invention's method and device for generating smart contracts based on graphical contract components create and extract contract atomic components, provide a graphical operation interface, enable intuitive operation by dragging and dropping, and configure the initial input parameters of each component. This simplifies contract creation, creates a closed-loop process, and provides clear branch flow conditions. Based on description files, standard code is generated, greatly reducing security risks in contract code and significantly improving the usability and security of the contract. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1 This is a flowchart of a method for generating a smart contract based on graphical contract components provided by an embodiment of the present invention;
[0024] Figure 2 This is a structural diagram of a smart contract generation device based on the graphical contract component provided by an embodiment of the present invention.
[0025] Figure 3 It is a schematic diagram of a terminal device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In the following description, specific details such as particular system structures and techniques are provided for purposes of illustration, not limitation, to facilitate a thorough understanding of the embodiments of the present invention. However, it will be apparent to those skilled in the art that the present invention may be practiced in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
[0027] In order to illustrate the technical solution of the present invention, specific embodiments are provided below.
[0028] See also Figure 1 , Figure 1The embodiment of the present invention provides a method for generating a smart contract based on a graphical representation of contract components, including the following contents:
[0029] S101. Based on the smart contract operation mechanism and compilation mechanism, and based on the business application scenario, smart contract components are formulated and formed into a smart contract component set; the smart contract component encapsulates a specific business processing flow, wherein the smart contract components can be combined and embedded, that is, a component can contain one or more other components, or can be nested within itself, and the smart contract component includes an input and output code set template, including component type, component name, component function description, component icon, parameters and setting method, result output, and component standard code body;
[0030] The smart contract component set includes but is not limited to an account component, a temporary account component, a temporary account asset return component, an oracle docking component, a condition judgment component, a timing component, and a transaction component.
[0031] In an embodiment of the present invention, an account component corresponds to a piece of code. The code includes a structure whose data includes blockchain account information. One account component corresponds to one contract participant. An oracle component corresponds to a piece of code. The code contains a complete network request, including the target API URL of the network request and the required request parameters corresponding to the API. An oracle component generally corresponds to a specific oracle service. A judgment component corresponds to a piece of logic judgment code. The code includes a judgment target object. The target object has several optional values, and different optional values correspond to different return results. Based on these components, according to the target of the smart contract, they can be combined to form a smart contract. For example, a betting agreement for guessing the weather is formed. Two account components are defined, one for A and one for B. An oracle component is then set to obtain tomorrow's weather information. The oracle component uses the weather information as the judgment target and sets a judgment component. If the weather is sunny, A is judged to win; if the weather is rainy, B is judged to win; if the weather is other than the weather, neither A nor B wins.
[0032] This invention adopts the smart contract component model. Compared with the traditional smart contract element model, it directly outputs the output description file, which makes it easy for beginners to master the smart contract creation method through simple training.
[0033] S102. Smart contract participants log in to their blockchain accounts and determine the smart contract components to be selected based on the smart contract creation goals agreed upon by the participants. The blockchain account includes an account address, which is obtained by performing MD5 calculation on the public key of an asymmetric encryption algorithm and then encoding it in Base58.
[0034] In one embodiment of the invention, a blockchain account serves as the transaction foundation for a blockchain distributed ledger. It consists of a public-private key pair generated by an asymmetric encryption algorithm. The account address is obtained by performing an MD5 calculation on the public key of the asymmetric encryption algorithm, followed by Base58 encoding. MD5 takes a variable-length input and outputs a fixed-length 128-bit message. Base58 is a unique encoding method. Compared to Base64, Base58 does not use the digit "0," the uppercase "O," the uppercase "I," the lowercase "l," or the "+" and " / " symbols to avoid confusion. It also lacks punctuation, and lines are typically not split in the middle. Most software supports double-clicking to select the entire string.
[0035] Smart contract participants can log in to their blockchain accounts through web pages, apps, and mini-programs, enter the smart contract creation interface, and select pending smart contract components.
[0036] S103. Select the specified smart contract component from the smart contract component set area and drag it to the smart contract editing area. Enter the process logic and parameter configuration between each smart component to complete the smart contract logic formulation.
[0037] In one embodiment of the present invention, a smart contract participant opens the smart contract editor and enters the smart contract creation interface. The left side of the interface displays the contract component set, the center is the contract editing area, and the right side displays and sets component properties. Participants drag components into the contract editing area and set basic parameters, judgment conditions, process jumps, and output results based on the component requirements.
[0038] S104: Check the process logic and parameter configuration of each smart contract component. If passed, proceed to the next step. If not, return to the previous step and redefine the smart contract logic. Specifically,
[0039] Check whether the required parameters of each smart contract component match the defined configuration parameters and source parameters;
[0040] Check whether the logic of the combination process of each smart contract component is clear and complete, and whether there is an infinite loop in the combination of each smart contract component.
[0041] Through the inspection steps, the logic between smart contract components can be ensured to be clear, the accuracy of parameter configuration can be improved, and the callability of smart contract components can be improved.
[0042] S105. Output the smart contract description file, generating a self-describing file in XML or JS format for the checked smart contract component; the self-describing file is a descriptive file composed of one or more smart contract components and their corresponding configuration parameters.
[0043] S106. The self-describing file is converted into smart contract code by a smart contract code generator to complete the generation of the smart contract. The standard smart contract code is generated by the self-describing file to improve security. The standard smart contract code will be uploaded to the blockchain network for broadcasting to facilitate the triggering or calling of the smart contract.
[0044] The present invention's smart contract generation method and device based on contract component graphics extracts contract atomic components, provides a graphical operation interface, allows intuitive operation by dragging and dropping, and configures the initial input parameters of each component. Contract production is simple, the process is closed-loop, and the branch flow conditions are clear. Based on the description file, standard code is generated, which greatly reduces the security risks of the contract code and greatly improves the usability and security of the contract.
[0045] See also Figure 2 , Figure 2 The present invention provides a smart contract generation device based on the graphical representation of contract components, comprising:
[0046] Smart contract component set module 1 is used to formulate smart contract components based on business application scenarios according to the smart contract operation mechanism and compilation mechanism, and form a smart contract component set. The smart contract component set module includes: a smart contract component module, which is used for smart contracts through the combination and embedding of modules, including component type, component name, component function description, component icon, parameters and setting method, result output, and component standard code body. The smart contract component set module 1 is mainly used to facilitate the mutual combination or nesting of components, thereby generating a variety of smart contract components with different functions that can meet needs.
[0047] Smart Contract Editing Module 2 is used to select a specific smart contract component from the smart contract component set area and drag it into the smart contract editing area. The process logic and parameter configuration between each smart component are then entered to complete the smart contract logic. The purpose of Smart Contract Editing Module 2 is to facilitate user selection and editing of smart contract components based on their needs. The Smart Contract Editing Module primarily utilizes a graphical user interface (GUI) with intuitive drag-and-drop operation, improving editing operability. The left side of the interface displays the contract component set, the center is the contract editing area, and the right side displays and sets component properties.
[0048] Smart Contract Check Module 3 is used to check the process logic and parameter configuration of each smart contract component. If it passes, it will proceed to the next step. If it fails, it will return to the previous step and redefine the smart contract logic. It also includes a rule checker to perform rule checks on the contract being edited and verify the passed smart contract settings. The Smart Contract Check Module 3 ensures that the logical order between components is clear and the parameter configuration is reasonable when they are combined or nested.
[0049] Smart contract description file generation module 4 is used to output the smart contract description file. It generates a self-describing file in XML or JS format based on the checked smart contract component. The self-describing file contains the smart contract component logic, contract business process content, execution conditions, termination conditions, version modification information, and clearly describes the modification time and modification version number.
[0050] The smart contract code generation module 5 is used to convert the self-describing file into smart contract code to complete the generation of the smart contract. The smart contract code generation module 5 mainly converts the self-describing file into the format of the standard smart contract code. When the user clicks "Generate Contract Code", it calls the smart contract code generator and outputs the intermediate code or executable code required by the smart contract. This can reduce the compilation operation of the smart contract code and improve the usability and security of the smart contract code.
[0051] The smart contract generation device also includes: a blockchain account module 6, which is used for smart contract participants in the blockchain to log in to the smart contract creation interface to create a smart contract. The blockchain account includes an account address, which is obtained by calculating the public key of the asymmetric encryption algorithm through MD5 and then encoding it with Base58.
[0052] The present invention also provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the methods when executing the computer program.
[0053] Figure 3 FIG. 1 is a schematic diagram of a terminal device provided by an embodiment of the present invention. Figure 3 As shown, the terminal device 7 of this embodiment includes: a processor 70, a memory 71, and a computer program 72 stored in the memory 71 and executable on the processor 70, such as a program for credit financing. When the processor 70 executes the computer program 72, the steps in the above method embodiment are implemented, for example, Figure 1 Alternatively, when the processor 70 executes the computer program 72, the functions of the modules / units in the above-mentioned device embodiments are realized, for example, Figure 2 Functions of modules 1 to 6 are shown.
[0054] Exemplarily, the computer program 72 may be divided into one or more modules / units, which are stored in the memory 71 and executed by the processor 70 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 72 in the terminal device 7. For example, the computer program 72 may be divided into a smart contract component set module 1, a smart contract editing module 2, and a smart contract checking module 3 (modules in a virtual device). The specific functions of each module are as follows:
[0055] Smart contract component set module 1, including several smart contract component modules, is used to formulate smart contract components based on the smart contract operation mechanism and compilation mechanism and business application scenarios, and form a smart contract component set;
[0056] Smart contract editing module 2 is used to select a specified smart contract component from the smart contract component set area and drag it to the smart contract editing area, enter the process logic and parameter configuration between each smart component, and complete the smart contract logic formulation;
[0057] Smart contract checking module 3 is used to check the process logic and parameter configuration of each smart contract component. If it passes, it will proceed to the next step. If it fails, it will return to the previous step to redefine the smart contract logic;
[0058] Smart contract description file generation module 4 is used to output the smart contract description file, generating a self-describing file in XML format or JS format from the checked smart contract component;
[0059] The smart contract code generation module 5 is used to convert the self-describing file into the smart contract code to complete the generation of the smart contract.
[0060] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device 7 may include, but is not limited to, a processor 70 and a memory 71. Those skilled in the art will appreciate that Figure 3 It is only an example of the terminal device 7 and does not constitute a limitation on the terminal device 7. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0061] The processor 70 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0062] The memory 71 can be an internal storage unit of the terminal device 7, such as the hard disk or memory of the terminal device 7. The memory 71 can also be an external storage device of the terminal device 7, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped with the terminal device 7. Furthermore, the memory 71 can include both an internal storage unit of the terminal device 7 and an external storage device. The memory 71 is used to store the computer program and other programs and data required by the terminal device 7. The memory 71 can also be used to temporarily store data that has been output or is about to be output.
[0063] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0064] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0065] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.
[0066] In the embodiments provided by the present invention, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0067] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of the solution of this embodiment according to actual needs.
[0068] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0069] If the integrated module / unit is implemented as a software functional unit and sold or used as a standalone product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the process steps in the above-mentioned method embodiments by using a computer program to instruct the relevant hardware. The computer program can be stored in a computer-readable storage medium. When executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signals, telecommunication signals, and software distribution media. It should be noted that the content of the computer-readable medium can be appropriately increased or decreased based on the requirements of legislation and patent practice within a jurisdiction. For example, in some jurisdictions, based on legislation and patent practice, computer-readable media does not include electric carrier signals and telecommunication signals.
[0070] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A method for generating smart contracts based on graphical contract components, characterized in that: include: Create smart contract components and form a smart contract component set; Determine the smart contract components to be selected based on the smart contract creation goals reached by each smart participant; Select the specified smart contract component from the smart contract component set area and drag it to the smart contract editing area, enter the process logic and parameter configuration between each smart component, and complete the smart contract logic formulation; Check the process logic and parameter configuration of each smart contract component. If passed, proceed to the next step. If not, return to the previous step to redefine the smart contract logic. Output smart contract description file, which will generate a self-description file in XML or JS format through the checked smart contract component; The self-description file is converted into smart contract code through the smart contract code generator to complete the generation of the smart contract; The checking of the process logic and parameter configuration of each smart contract component includes: Check whether the required parameters, defined configuration parameters and source parameters of each smart contract component match; Check whether the logic of the combination process of each smart contract component is clear and complete, and whether there is an infinite loop in the combination of each smart contract component; Among them, the smart contract component is a code collection template that encapsulates a specific business processing flow, including input and output, including component type, component name, component function description, component icon, parameters and setting methods, result output, and component standard code body.
2. The method for generating a smart contract based on the graphical representation of contract components according to claim 1, characterized in that: The step of creating a smart contract component and forming a smart contract component set includes: The smart contract component set includes at least one of an account component, a temporary account component, a temporary account asset return component, an oracle docking component, a condition judgment component, a timing component and a transaction component.
3. The method for generating a smart contract based on graphical contract components according to claim 2, characterized in that: The smart contract component is selected from the smart contract component set area and dragged to the smart contract editing area, and the process logic and parameter configuration between each smart component are input to complete the smart contract logic formulation, including: The smart contract components can be combined and embedded with each other.
4. The method for generating a smart contract based on the graphical representation of contract components according to claim 1, characterized in that: The smart contract participants log in to the blockchain account and determine the smart contract components to be selected according to the smart contract creation goals reached by the participants, including: The blockchain account includes an account address, and the account address is obtained by calculating the public key of the asymmetric encryption algorithm through MD5 and then encoding it with Base58.
5. A smart contract generation device based on contract component graphics, characterized in that: include: The smart contract component set module includes several smart contract component modules, which are used to formulate smart contract components based on the smart contract operation mechanism and compilation mechanism and business application scenarios, and form a smart contract component set; The smart contract editing module is used to select the specified smart contract component from the smart contract component set area and drag it to the smart contract editing area, enter the process logic and parameter configuration between each smart component, and complete the smart contract logic formulation; Smart contract checking module, used to check the process logic and parameter configuration of each smart contract component. If it passes, it will proceed to the next step. If it fails, it will return to the previous step to redefine the smart contract logic; The smart contract description file generation module is used to output the smart contract description file, which will generate a self-description file in XML format or JS format through the checked smart contract component; Smart contract code generation module, used to convert self-description files into smart contract codes to complete the generation of smart contracts; The checking of the process logic and parameter configuration of each smart contract component includes: Check whether the required parameters, defined configuration parameters and source parameters of each smart contract component match; Check whether the logic of the combination process of each smart contract component is clear and complete, and whether there is an infinite loop in the combination of each smart contract component; Among them, the smart contract component module is used for smart contracts through combination and embedding between modules, including component type, component name, component function description, component icon, parameters and setting method, result output, and component standard code body.
6. The smart contract generation device based on the graphical contract component according to claim 5 is characterized in that: Also includes: The blockchain account module is used for smart contract participants in the blockchain to log in to the smart contract creation interface to create smart contracts. The blockchain account includes an account address, which is obtained by calculating the public key of the asymmetric encryption algorithm through MD5 and then encoding it with Base58.
7. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable medium storing a computer program, characterized in that: When the computer program is processed and executed, the steps of the method according to any one of claims 1 to 4 are implemented.
