Contract code debugging method and device, equipment and storage medium
By using simulated blockchain nodes in the code editor for contract code debugging, the problems of long debugging time and difficult to detect security vulnerabilities in the existing technology are solved, efficient debugging and problem investigation are achieved, and contract code quality and R&D are improved. efficiency.
Patent Information
- Application Number
- CN202310921625.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2025-02-07
AI Technical Summary
During the contract code debugging process, due to the long consensus time and large log data, the problem detection time is long, making it difficult to comprehensively check security vulnerabilities in the contract code, which reduces R&D efficiency and contract code quality.
By using simulated blockchain nodes in the code editor for contract code debugging, the simulated blockchain node does not perform consensus services, and directly returns the execution results, reducing debugging time, and displaying the execution results in the code editor for problem investigation.
It reduces the time overhead during the contract code debugging process, improves debugging efficiency, simplifies problem investigation, reduces the number of security vulnerabilities in the contract code, and improves the quality and R&D efficiency of contract code.
Smart Images

Figure CN119396692A_ABST
Abstract
Description
Background Art
[0002] With the development of science and technology, various tasks can be realized through blockchain technology. At present, blockchain realizes tasks by running contract code, so the security of contract code determines the security of business. In order to ensure the security of contract code, contract code needs to be debugged to reduce contract code errors and improve contract code quality.
[0003] Currently, the code languages of contract codes are divided into: native high-level languages that run with the help of Docker containers and are scheduled with blockchain projects, and specific blockchain languages that run with the help of virtual machines and are scheduled with blockchain projects. Therefore, when debugging contract codes, the contract codes need to be moved to Docker containers or virtual machines for running.
[0004] When running through a Docker container or virtual machine, the contract code must be executed and the running results must be returned in the form of logs after consensus is reached, so that problems can be troubleshooted based on the obtained logs. Since consensus takes a long time and the amount of log data is large, it takes a long time to troubleshoot problems and is prone to troubleshooting errors, which further reduces the efficiency of contract code development and makes it impossible to fully troubleshoot security vulnerabilities in contract code.
[0005] Therefore, how to improve the efficiency of contract code development, reduce the number of security vulnerabilities in contract code, and improve the quality of contract code are technical problems that need to be solved at present. Summary of the invention
[0006] The embodiments of the present application provide a contract code debugging method, apparatus, device and storage medium to improve the efficiency of contract code development, reduce the number of security vulnerabilities in contract code, and improve the quality of contract code.
[0007] In a first aspect, an embodiment of the present application provides a contract code debugging method, which is applied to a code editor, and the method includes:
[0008] Based on the target code added to the project code, the contract code is determined; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node;
[0009] When the set trigger conditions are met, the contract code is executed; when the call statement is executed, the simulated blockchain node is called to execute the method matching the call statement and obtain the corresponding execution result; when the interrupt instruction triggered by the execution operation is detected, the contract code is stopped and the execution result corresponding to the code before the interrupt instruction is obtained; the simulated blockchain node is used for contract code debugging;
[0010] Displays execution results in the code editor.
[0011] In a second aspect, an embodiment of the present application provides a contract code debugging device, which is applied to a code editor, and the device includes:
[0012] A determination unit, used to determine the contract code based on the target code added in the project code; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node;
[0013] An execution unit is used to execute the contract code when the set trigger conditions are met; when executing a call statement, the simulated blockchain node is called to execute the method matching the call statement and obtain the corresponding execution result; when an interrupt instruction triggered by the execution operation is detected, the contract code is stopped and the execution result corresponding to the code before the interrupt instruction is obtained; the simulated blockchain node is used for contract code debugging;
[0014] The display unit is used to display the execution results in the code editor.
[0015] In a possible implementation, the code editor is built based on an integrated development environment.
[0016] In a possible implementation, the trigger condition is set to include:
[0017] The contract code is successfully deployed on the simulated blockchain node;
[0018] Receive task execution instructions.
[0019] In a possible implementation, the calling statement for the simulated blockchain node includes: calling a contract software development kit SDK statement and a cross-contract calling statement.
[0020] In a possible implementation, if the calling statement is a contract SDK calling statement;
[0021] When the execution unit executes the call statement, it is specifically used to:
[0022] When executing the call contract SDK statement, call the simulated blockchain contract SDK. Through the simulated blockchain contract SDK, call the simulated blockchain node to perform the following operations:
[0023] When determining that the target method that matches the call contract SDK statement is to access storage, check whether the storage access key exists in the simulated blockchain node;
[0024] After determining that the storage access key exists, based on the storage access key, a target value matching the storage access key is acquired in the memory, and the target value is returned to the code editor.
[0025] In a possible implementation, the execution unit is specifically used for:
[0026] After determining that the storage access key exists in the Bloom filter and cache of the simulated blockchain node, obtaining a target value matching the storage access key in the cache based on the storage access key; or,
[0027] After determining that the storage access key exists in the bloom filter of the simulated blockchain node and in the database, a target value matching the storage access key is obtained in the database based on the storage access key, and the target value is stored in the cache.
[0028] In a possible implementation, if the call statement is a cross-contract call statement;
[0029] When the execution unit executes the call statement, it is specifically used to:
[0030] When executing a cross-contract call statement, the simulated blockchain node is called and the following operations are performed through the simulated blockchain node:
[0031] When it is determined that there is a contract method indicated by a cross-contract call statement in the simulated blockchain node, a contract process is started for the contract method;
[0032] Based on the contract process, execute the contract method and return the corresponding execution result;
[0033] Among them, the contract method is pre-deployed into the simulated blockchain node.
[0034] In a possible implementation, the execution unit is specifically used for:
[0035] Determine the contract name and version information of the contract method stored in the bloom filter of the simulated blockchain node; and,
[0036] Make sure the contract method exists in the database.
[0037] In one possible implementation, if the trigger condition is that the contract code is successfully deployed on the simulated blockchain node;
[0038] When the set trigger conditions are met, before executing the contract code, the execution unit is also used to:
[0039] In response to the code deployment request, the contract code is stored in the database of the simulated blockchain node, and the contract name and version information of the contract code are stored in the Bloom filter of the simulated blockchain node.
[0040] In a possible implementation, the target code further includes: an end statement, and the execution unit is further configured to:
[0041] When executing to the end statement, obtain the comprehensive execution result;
[0042] When the comprehensive execution result is determined to be correct according to the flag bit in the comprehensive execution result, the comprehensive execution result is returned to the superior caller.
[0043] In a third aspect, an embodiment of the present application provides a computing device, comprising: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the computer program to implement the steps of the contract code debugging method provided in the embodiment of the present application.
[0044] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the contract code debugging method provided in the embodiment of the present application are implemented.
[0045] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium; when the processor of the computing device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the computing device executes the steps of the contract code debugging method provided in the embodiment of the present application.
[0046] The beneficial effects of this application are as follows:
[0047] The embodiments of the present application provide a contract code debugging method, device, equipment and storage medium, which relate to the fields of computer technology and blockchain technology. In the present application, a technical solution is proposed to realize contract code debugging by cooperating with a code editor and a simulated blockchain node, wherein the simulated blockchain node is used to save basic block, contract and task processing data during the contract code debugging process without performing consensus services, that is, the simulated blockchain node is used for contract code debugging;
[0048] When debugging contract code, first write the target code in the code editor and add the target code to the project code to generate the debugged contract code, where the target code at least includes the call statement for the simulated blockchain node, and the project code provides functional support for the operation of the target code; then, when the set trigger conditions are met, the contract code is executed. Run the contract code locally in the code editor without deploying the local contract code to a Docker container or simulator;
[0049] During the execution of the contract code, when the call statement for the simulated blockchain node in the contract code is executed, the simulated blockchain node is called, the method matching the call statement is executed by the simulated blockchain node, and the execution result returned by the simulated blockchain node is obtained, and the execution result is displayed in the code editor; since the simulated blockchain node does not perform consensus services, there is no need to wait for all contract codes to be executed and return the result, that is, in the embodiment of the present application, after obtaining the execution result, the simulated blockchain node can directly return the execution result to the code editor, thereby reducing the code running time and the time spent on consensus, further reducing the time spent on the debugging process, and improving the debugging efficiency; at the same time, the execution result of the method matching the call statement is returned and displayed, so as to troubleshoot problems based on the displayed execution result. Compared with the execution results of all contract codes, the obtained execution result has a smaller amount of data, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, further reducing the number of security vulnerabilities in the contract code, improving the quality of the contract code, and improving the efficiency of contract code research and development; and,
[0050] During the execution of the contract code, when an interrupt instruction triggered by the execution operation of the contract code is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained, and the execution result is displayed in the code editor. When debugging the contract code through the code editor, the code can be interrupted and the execution result can be obtained when the code is halfway executed, and then the problem can be troubleshooted. There is no need to wait until all contract codes are executed and the execution results are returned before troubleshooting. The amount of data to be checked is small, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, which further reduces the number of security vulnerabilities in the contract code, improves the quality of the contract code, and improves the efficiency of contract code research and development.
[0051] Other features and advantages of the present application will be described in the subsequent description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0053] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0054] Figure 2Another application scenario diagram provided for the implementation of this application;
[0055] Figure 3 A schematic diagram of the structure of a contract project library component provided in an embodiment of the present application;
[0056] Figure 4 A schematic diagram of a structure of a simulated blockchain node provided in an embodiment of the present application;
[0057] Figure 5 A flow chart of a contract code debugging method provided in an embodiment of the present application;
[0058] Figure 6 A flow chart of a method for deploying contract code in a simulated blockchain node provided in an embodiment of the present application;
[0059] Figure 7 A schematic diagram of the first architecture for contract code debugging provided in an embodiment of the present application;
[0060] Figure 8 A schematic diagram of a second architecture for contract code debugging provided in an embodiment of the present application;
[0061] Fig. 9 A flow chart of a method for calling a simulated blockchain node based on a contract SDK statement provided in an embodiment of the present application;
[0062] Fig.10 A flowchart of a method for simulating a blockchain node to execute a target method that matches a contract SDK statement and obtains an execution result provided in an embodiment of the present application;
[0063] Fig.11 A schematic diagram of a third architecture for contract code debugging provided in an embodiment of the present application;
[0064] Fig.12 A flow chart of a method for calling a simulated blockchain node based on a cross-contract call statement provided in an embodiment of the present application;
[0065] Fig.13 A schematic diagram of a fourth architecture for contract code debugging provided in an embodiment of the present application;
[0066] Fig.14 A flowchart of a specific implementation method for contract code debugging provided in an embodiment of the present application;
[0067] Fig.15 A structural diagram of a contract code debugging device provided in an embodiment of the present application;
[0068] Fig.16 A structural diagram of a computing device provided in an embodiment of the present application;
[0069] Fig.17 A structural diagram of another computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] In order to make the purpose, technical solution and beneficial effects of this application clearer, the technical solution in the embodiment of this application will be clearly and completely described below in conjunction with the drawings in the embodiment of this application. Obviously, the described embodiment is only a part of the embodiment of this application, not all the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0071] Some of the terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0072] Blockchain is a distributed ledger technology in the field of information technology. It is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission (P2P transmission), consensus mechanism, transaction blocks, cryptographic identity security, etc. Because the ledger is distributed and the blocks are consensus-based, it has the characteristics of being tamper-proof, traceable, and jointly maintained. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block.
[0073] An Integrated Development Environment (IDE) is an application used in a program development environment, generally including a code editor, compiler, debugger, and graphical user interface tool. It is an integrated development software service suite that integrates code writing, analysis, and compilation functions. All software or software suites with this feature can be called IDEs. The program can run independently or in conjunction with other programs. IDEs provide convenience for users to use modern programming languages such as VisualBasic, Java, and PowerBuilder. Every tool that has basic coding and debugging functions can be called an IDE.
[0074] Software Development Kit (SDK): Generally, it is a collection of development tools that software engineers use to build application software for a specific software package, software framework, hardware platform, operating system, etc. Including in a broad sense, it refers to a collection of related documents, examples and tools that assist in the development of a certain type of software. It can simply provide some files of the Application Programming Interface (API) for a certain programming language, but it may also include complex hardware that can communicate with a certain embedded system. General tools include utilities for debugging and other purposes.
[0075] Contract code is also known as smart contract. Smart contract code is a computer protocol designed to transmit, verify or execute contracts in an information-based manner. Smart contracts allow trusted transactions without a third party.
[0076] Bloom filter: Bloom filter is a data structure used to quickly check whether an element belongs to a set. It is implemented by using multiple hash functions and bit arrays. When an element is added to a set, it is hashed multiple times and the corresponding bits are set to 1. When checking whether an element is in a set, it is hashed multiple times and the corresponding bits are checked to see if they are all 1. If any bit is 0, the element is not in the set. Due to the uncertainty of the hash function, the Bloom filter may misjudge that an element is in a set, but it will not misjudge that an element is not in a set. Therefore, it is often used in scenarios where it is necessary to quickly check whether an element is in a set, such as caching, preventing duplicate submissions, etc.
[0077] The word “exemplary” is used hereinafter to mean “serving as an example, example, or illustration.” Any embodiment described as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0078] The terms "first" and "second" in this document are used for descriptive purposes only and should not be understood as explicitly or implicitly indicating relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more features. In the description of the embodiments of this application, unless otherwise specified, the meaning of "multiple" is two or more.
[0079] The following is a brief introduction to the design concept of the embodiments of the present application.
[0080] With the development of science and technology, various tasks can be realized through blockchain technology. For the current blockchain, all tasks are run based on contract code, that is, blockchain realizes tasks by running contract code, so the security of contract code determines the security of business. In order to ensure the security of contract code, contract code needs to be debugged to reduce contract code errors and improve contract code quality.
[0081] At present, there are two types of contract code languages. One is native high-level languages, such as Golang and Java. These languages are usually run with the help of Docker and are scheduled according to blockchain projects. The other is blockchain-specific languages, such as Solidity. These languages are usually run with the help of virtual machines, such as evm, and are also scheduled according to blockchain projects.
[0082] Therefore, when debugging contract code, it is necessary to move the contract code of the huge blockchain project to a Docker container or virtual machine locally to run it and check it through logs. It is impossible to use IDEs such as code editors with basic coding and debugging functions for debugging. It is difficult to support single-step debugging functions. For example, it is impossible to interrupt and obtain the values of all variables when the code is halfway executed, troubleshoot problems, write unit tests, etc., which brings great R&D difficulties and security risks.
[0083] When running through a Docker container or virtual machine, the contract code must be executed and the running results must be returned in the form of logs after consensus is reached, so that problems can be troubleshooted based on the obtained logs. Since consensus takes a long time and the amount of log data is large, it takes a long time to troubleshoot problems and is prone to errors, which brings great trouble to smart contract developers, further reduces the efficiency of contract code development, and makes it impossible to fully troubleshoot security vulnerabilities in contract codes.
[0084] Therefore, how to improve the efficiency of contract code development, reduce the number of security vulnerabilities in contract code, and improve the quality of contract code are technical problems that need to be solved at present.
[0085] In view of this, the embodiments of the present application provide a method, device, equipment and storage medium for contract code debugging, which relate to the fields of computer technology and blockchain technology. In the present application, single-step debugging of contract code, printing of variables in the execution process, and local rapid location of problems are supported, thereby reducing the number of security vulnerabilities in the contract code, improving the efficiency of contract code development, and improving the quality of contract code.
[0086] In the embodiments of the present application, a technical solution is mainly proposed to realize contract code debugging through the cooperation of a code editor and a simulated blockchain node, wherein the code editor is built based on an integrated development environment, supports coding and debugging functions, and simulates blockchain nodes for contract code debugging. During the contract code debugging process, basic block, contract and task processing data are saved without performing consensus services and complex network services.
[0087] In the embodiment of the present application, when debugging the contract code, first write the target code in the code editor, and add the target code to the project code to generate the debugged contract code, where the target code at least includes the call statement for the simulated blockchain node, and the project code provides functional support for the operation of the target code; then, when the set trigger condition is met, execute the contract code. Run the contract code locally in the code editor without deploying the local contract code to a Docker container or virtual machine for operation;
[0088] During the execution of the contract code, when the call statement for the simulated blockchain node in the contract code is executed, the simulated blockchain node is called, the method matching the call statement is executed by the simulated blockchain node, and the execution result returned by the simulated blockchain node is obtained, and the execution result is displayed in the code editor; since the simulated blockchain node does not perform consensus services, there is no need to wait for all contract codes to be executed and return the result, that is, in the embodiment of the present application, after obtaining the execution result, the simulated blockchain node can directly return the execution result to the code editor, thereby reducing the code running time and the time spent on consensus, further reducing the time spent on the debugging process, and improving the debugging efficiency; at the same time, the execution result of the method matching the call statement is returned and displayed, so as to troubleshoot problems based on the displayed execution result. Compared with the execution results of all contract codes, the obtained execution result has a smaller amount of data, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, further reducing the number of security vulnerabilities in the contract code, improving the quality of the contract code, and improving the efficiency of contract code research and development; and,
[0089] During the execution of the contract code, when an interrupt instruction triggered by the execution operation of the contract code is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained, and the execution result is displayed in the code editor. When debugging the contract code through the code editor, the code can be interrupted and the execution result can be obtained when the code is halfway executed, and then the problem can be troubleshooted. There is no need to wait until all contract codes are executed and the execution results are returned before troubleshooting. The amount of data to be checked is small, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, which further reduces the number of security vulnerabilities in the contract code, improves the quality of the contract code, and improves the efficiency of contract code research and development.
[0090] After introducing the design concept of the embodiment of the present application, the application scenario set in the present application is briefly described below. It should be noted that the following scenario is only used to illustrate the embodiment of the present application and is not limited. In the specific implementation, the technical solution provided by the embodiment of the present application can be flexibly applied according to actual needs.
[0091] See also Figure 1 , Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application. Since the simulated blockchain node in the embodiment of the present application does not perform consensus and is only used for contract code debugging, the application scenario includes: a terminal device 100 and a simulated blockchain node 110; wherein the terminal device 100 and the simulated blockchain node 110 can communicate with each other through a communication network.
[0092] Considering that when setting a simulated blockchain node, if the simulated blockchain node fails, the contract code debugging will not be able to continue, the embodiment of the present application provides another application scenario, in which a simulated blockchain node cluster is set, and the simulated blockchain node cluster includes multiple simulated blockchain nodes, see Figure 2 , Figure 2 Another application scenario diagram provided for an embodiment of the present application. The application scenario includes: a terminal device 100 and multiple simulated blockchain nodes 110; wherein the terminal device 100 and the simulated blockchain node 110 can communicate through a communication network, and the simulated blockchain nodes can also communicate through the communication network. In this application scenario, when the simulated blockchain node currently being debugged fails or has insufficient resources, a normal simulated blockchain node with sufficient resources can be reselected in the simulated blockchain node cluster to continue code debugging.
[0093] It should be noted that in the embodiment of the present application, only one simulated blockchain node is involved in code debugging.
[0094] In an optional embodiment, the communication network may be a wired network or a wireless network. Exemplarily, the terminal device 100 and the simulated blockchain node 110 may be directly or indirectly connected via wired or wireless communication. For example, the terminal device 100 may be indirectly connected to the simulated blockchain node 110 via a wireless access point, or the terminal device 100 may be directly connected to the simulated blockchain node 110 via the Internet, and this application does not limit this.
[0095] In the embodiment of the present application, the terminal device 100 is a terminal device with a code editor installed or running, and the simulated blockchain node 110 is a server for contract code debugging; wherein, the terminal device 100 includes but is not limited to mobile phones, tablet computers, laptops, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals and other devices; the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0096] In an embodiment of the present application, the code editor includes a contract project library component, and the contract code debugging is mainly achieved by interacting with the simulated blockchain node through the contract project library component.
[0097] In a possible implementation, the contract project library component includes at least: a simulation call module 1000, a network module 1010, a code writing module 1020, a comprehensive contract SDK module 1030, and an interaction module 1040; see Figure 3 , Figure 3 A schematic diagram of the structure of a contract project library component provided in an embodiment of the present application; wherein:
[0098] The simulation call module 1000 is used to receive various requests during the contract code debugging process, including: a contract deployment interface 1001 and a task execution interface 1002; wherein, the contract deployment interface 1001 is used to receive a contract deployment request, and the task execution interface 1002 is used to receive a task execution request; illustratively, the contract deployment request is received through the contract deployment interface 1001, and the contract deployment request is transmitted to the network module 1010, so as to deploy the contract code to the corresponding blockchain node through the network module; or, the task execution request is received through the task execution interface 1002, and the task execution request is sent to the network module 1010, and when the blockchain node call needs to be executed, the corresponding blockchain node is called through the network module.
[0099] The network module 1010 is used to communicate with the blockchain node, including: a real network module 1011 and a simulated network module 1012; wherein, the real network module 1011 is used to communicate with the real blockchain node; the simulated network module 1012 is used to communicate with the simulated blockchain node.
[0100] The code writing module 1020 is used to obtain the target code written by the developer; wherein the target code at least includes: calling statements for the simulated blockchain node, specifically including: calling contract SDK statements and cross-contract calling statements.
[0101] The comprehensive contract SDK module 1030 provides nodes for the implementation of contract code, such as obtaining values, obtaining block information, and obtaining task senders; it mainly stores project codes that provide functional support for the target code, including: real blockchain contract SDK 1031 and simulated blockchain contract SDK 1032; among them, the real blockchain contract SDK 1031 is a contract SDK for interacting with real blockchain nodes; the simulated blockchain contract SDK 1032 is a contract SDK for interacting with simulated blockchain nodes.
[0102] The interaction module 1040 is used for network interaction with blockchain nodes, including: a real blockchain client 1041 and a simulated blockchain client 1042; wherein, the real blockchain client 1041 is used to interact with real blockchain nodes, and the simulated blockchain client 1042 is used to interact with simulated blockchain nodes.
[0103] In the embodiment of the present application, the contract project library in the code editor is transformed. The contract project library provided by the embodiment of the present application can not only interact with the real blockchain node and the scheduler, but also interact with the simulated blockchain node, so that the contract project library implements the real logic and the simulated logic respectively, so that the corresponding logic can be selected in the code editor for application in different environments, that is, application based on the real logic in the production environment, and application based on the simulated logic in the debugging environment.
[0104] In a possible implementation, the simulated blockchain node 110 includes at least: a network module 1100, an interface module 1110, and a storage module 1120; see Figure 4 , Figure 4 A schematic diagram of a simulated blockchain node structure provided in an embodiment of the present application; wherein:
[0105] The network module 1100 is used to communicate with the contract project component in the code editor.
[0106] The interface module 1110 is used to connect to the network module 1100 and call corresponding services; it includes: contract interface 1111, block interface 1112, task interface 1113 and data interface 1114; among them, the contract interface 1111 is used to execute services related to the contract code; the block interface 1112 is used to execute services related to the block, such as obtaining the block timestamp, block height, etc.; the task interface 1113 is used to execute services related to the task, such as obtaining the transaction hash, transaction timestamp, etc. The data interface 1114 is used to execute services related to data interaction, such as querying data, obtaining data in batches, etc.
[0107] The storage module 1120 is used to store the block data of the simulated blockchain node, including: a Bloom filter 1121, a cache 1122 and a database 1123; wherein the Bloom filter 1121 retains the data structure of whether the data exists in the memory. If the data does not exist, the data definitely does not exist, and if the data exists, it is possible that the data does not exist; the data stored in the memory by the cache 1122 is limited in size and follows a first-in-first-out elimination strategy; the database 1123 stores the full amount of debugging contract-related data.
[0108] The embodiments of the present application can ensure that users or developers can quickly debug and verify contract codes by simulating blockchain nodes instead of huge blockchains and scheduling projects. It can ensure dynamic switching between the production environment and the debugging environment in the contract project library component, ensure that the contract code has been fully debugged and troubleshooted, and maximize the completeness and security of the contract code, which can be widely reused in the industry.
[0109] Based on the above application scenarios, combined with the application scenarios described above, the contract code debugging method provided by the exemplary embodiment of the present application is described according to the accompanying drawings. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this regard. In addition, although the operations of the method of the present application are described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, certain steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.
[0110] In order to support the single-step debugging function of the contract code, print the variables of the execution process, quickly locate the problem, reduce the number of security vulnerabilities in the contract code, improve the efficiency of contract code development, and improve the quality of the contract code. In the embodiment of the present application, a code editor that supports the operation of the contract code and is built based on an integrated development environment, as well as a simulated blockchain node for contract code debugging, the simulated blockchain node does not support consensus and complex network services. And a technical solution for debugging the contract code by cooperating with the code editor and the simulated blockchain node is proposed.
[0111] See also Figure 5 , Figure 5 A flow chart of a contract code debugging method provided in an embodiment of the present application is applied to a code editor, and the method includes:
[0112] Step S500, determining the contract code based on the target code added in the project code; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node.
[0113] In the embodiment of the present application, the target code is first written in the code editor, and the target code includes at least a call statement for the simulated blockchain node. In order to make the target code run normally and obtain the corresponding running results, the project code needs to provide functional support for the target code, so the target code needs to be added to the project code to obtain the contract code for implementing the task.
[0114] Among them, the project code is the fixed code provided by the contract project library component in the code editor and does not need to be modified; for example, the target code includes a call SDK statement, and the project code includes fixed code for implementing the SDK function.
[0115] Step S501, when the set trigger conditions are met, execute the contract code; when executing the call statement, call the simulated blockchain node to execute the method matching the call statement, and obtain the corresponding execution result; when an interrupt instruction triggered by the execution operation is detected, stop executing the contract code, and obtain the execution result corresponding to the code before the interrupt instruction; the simulated blockchain node is used for contract code debugging.
[0116] In an embodiment of the present application, the set trigger conditions include: the contract code is successfully deployed on the simulated blockchain node, or a task execution instruction is received.
[0117] Below, based on the specific implementation method, the execution of the contract code when the above two trigger conditions are met is explained.
[0118] Implementation method 1: After determining that the contract code is successfully deployed on the simulated block node, execute the contract initialization method in the contract code.
[0119] In one possible implementation, if the trigger condition is that the contract code is successfully deployed on the simulated blockchain node; then when the set trigger condition is met, before executing the contract code, it is necessary to deploy the contract code to the simulated blockchain node, and obtain the deployment result fed back by the simulated blockchain node, and determine whether to execute the contract initialization method according to the deployment result; wherein the deployment result carries an identifier for indicating whether the deployment is successful or failed.
[0120] Specifically, after the contract code is successfully deployed on the simulated blockchain node according to the identification information in the deployment result, the contract initialization method in the contract code is executed to determine the initial information of the task; for example, for a transfer task, the contract initialization method is executed to determine the balance of the payer's account and the balance of the payee's account;
[0121] According to the identification information in the deployment result, it is determined that after the contract code fails to be deployed in the simulated blockchain node, the deployment failure or deployment error information is displayed in the code editor.
[0122] In one possible implementation, the contract code is deployed to the simulated blockchain node only after receiving a code deployment request. Figure 6 , Figure 6 A flow chart of a method for deploying contract code in a simulated blockchain node provided in an embodiment of the present application includes the following steps:
[0123] Step S600: The code editor obtains a code deployment request.
[0124] In an embodiment of the present application, the code editor receives a code deployment request through a contract deployment interface that simulates a call module in a contract project library component; that is, a user or developer triggers a contract deployment request by calling a contract deployment interface that simulates a call module in a contract project library component.
[0125] Step S601: The code editor sends a deployment contract request carrying the contract code to the simulated blockchain node.
[0126] In an embodiment of the present application, the code editor calls the simulated network module in the network module through the contract project library component, and sends a deployment contract request carrying the contract code to the network module simulating the blockchain node.
[0127] Step S602, after the simulated blockchain node receives the contract deployment request carrying the contract code sent by the code editor, the contract code is stored in the database, and the contract name and version information of the contract code are stored in the Bloom filter.
[0128] In an embodiment of the present application, after the simulated blockchain node receives a contract deployment request carrying the contract code, it calls the storage module, stores the contract code in the database of the storage module, and stores the contract name and version information in the Bloom filter of the storage module.
[0129] Step S603, after the simulated blockchain node stores the contract code in the database and stores the contract name and version information of the contract code in the Bloom filter, it determines the deployment result.
[0130] Step S604, simulating the blockchain node to send the deployment result to the code editor.
[0131] In an embodiment of the present application, the simulated blockchain node sends the deployment result to the network module of the contract project library component in the code editor through the network module.
[0132] based on Figure 6 The method flow chart of deploying contract code in a simulated blockchain node is shown in the embodiment of the present application. The embodiment of the present application also provides an architecture for debugging contract code; see Figure 7 , Figure 7 The first architectural diagram for contract code debugging provided in the embodiment of the present application is shown in FIG. Figure 7 It can be seen that:
[0133] The contract project library component receives the code deployment request submitted by the user or developer through the contract deployment interface of the simulated calling module, and transmits the code deployment request to the network module. After receiving the code deployment request, the network module calls the simulated network module, and sends the deployment contract request carrying the contract code to the network module of the simulated blockchain node through the simulated network module.
[0134] Correspondingly, after the simulated blockchain node receives a contract deployment request carrying the contract code through the network module, it calls the storage module and transfers the contract code to the storage module to store the contract code in the database of the storage module, and stores the contract name and version information of the contract code in the Bloom filter of the storage module. After the storage is completed, the deployment result is sent to the contract project library component through the network module.
[0135] Implementation method 2: After receiving the task execution instruction, execute the contract initialization method in the contract code and the contract method corresponding to the task execution instruction.
[0136] In one possible implementation, the code editor receives a task execution request through the task execution interface of the simulated calling module in the contract project library component; after receiving the task execution request, it determines that the contract code needs to be executed, and first executes the contract initialization method in the contract code, and after the contract initialization method is executed, executes the contract method corresponding to the task execution request.
[0137] For details, see Figure 8 , Figure 8 The second architecture diagram for contract code debugging provided in the embodiment of the present application is as follows. Figure 8 It can be seen that:
[0138] The code editor receives the task execution request submitted by the user or developer through the task execution interface of the simulated calling module in the contract project library component, and transmits the task execution request to the network module. After receiving the task execution request, the network module calls the simulated network module to execute the contract initialization method through the simulated network module. After the contract initialization method is executed, the contract method corresponding to the task execution request is executed.
[0139] In an embodiment of the present application, the calling statements for simulating a blockchain node include: calling SDK statements and cross-contract calling statements.
[0140] Different calling statements have different execution processes for simulated blockchain nodes. The following is a detailed description of different calling statements.
[0141] Case 1: The calling statement is a contract SDK calling statement.
[0142] See also Fig. 9 , Fig. 9 A flowchart of a method for calling a simulated blockchain node based on a contract SDK statement provided in an embodiment of the present application includes the following steps:
[0143] Step S900: The code editor determines that the current execution statement is a statement for calling the contract SDK.
[0144] Step S901, the code editor calls a simulated blockchain node.
[0145] In one possible implementation, after the code editor determines that the current execution statement is a contract SDK call statement, the simulated blockchain contract SDK is called through the comprehensive contract SDK module of the contract project library component, and the simulated blockchain node is called through the simulated blockchain contract SDK.
[0146] Step S902, simulating the blockchain node to determine the target method that matches the call contract SDK statement.
[0147] Step S903, simulating the blockchain node to execute the target method and obtain the execution result.
[0148] Step S904, the simulated blockchain node returns the execution result to the code editor.
[0149] In a possible implementation, when simulating a blockchain node to execute a target method and obtaining the execution result of the fragrance, it is first determined whether the target method is to access storage, and then the operation is performed based on the determination result.
[0150] Exemplarily, if the target method is to access storage, then continue to obtain data from the storage module of the simulated blockchain node, and return the obtained data as the execution result. If no data is obtained, return an error message indicating that the access does not exist to the code editor;
[0151] If the target method is not to access storage, the contract process is started, the target method is executed, the corresponding execution result is obtained, and the execution result is returned to the code editor.
[0152] See also Fig.10 , Fig.10 A method flow chart of simulating a blockchain node to execute a target method that matches a call contract SDK statement and obtains an execution result provided in an embodiment of the present application includes the following steps:
[0153] Step S1000, simulating the blockchain node to determine the target method that matches the call contract SDK statement;
[0154] Step S1001, the simulated blockchain node determines whether the target method matching the call contract SDK statement is access storage, if so, execute step S1002, otherwise execute step S1008;
[0155] Step S1002, the simulated blockchain node determines whether the Bloom filter has a storage access key that matches the access storage, if so, execute step S1003, otherwise execute step S1007;
[0156] S1003, simulating a blockchain node to determine whether the cache has a storage access key that matches the access storage, if so, execute step S1004, otherwise execute step S1005;
[0157] Step S1004, simulating the blockchain node to obtain a target value matching the storage access key from the cache, and return the target value to the code editor;
[0158] Step S1005, simulating the blockchain node to determine whether the database has a storage access key that matches the access storage, if so, execute step S1006, otherwise execute step S1007;
[0159] Step S1006, simulating the blockchain node to obtain a target value matching the storage access key from the database, putting the obtained target value into a cache, and returning the target value to the code editor;
[0160] Step S1007, simulating the blockchain node to return an error message indicating that the access does not exist to the code editor;
[0161] Step S1008, simulating the blockchain node to execute the target method that matches the call contract SDK statement and obtain the corresponding execution result;
[0162] Step S1009, the simulated blockchain node returns the execution result to the code editor.
[0163] based on Fig. 9 and Fig.10 The method flow chart shown in the embodiment of the present application also provides an architecture for contract code debugging; see Fig.11 , Fig.11 The third architectural diagram for contract code debugging provided in the embodiment of the present application is shown in FIG. Fig.11 It can be seen that:
[0164] The code editor receives the task execution request submitted by the user or developer through the task execution interface of the simulation calling module in the contract project library component, and transmits the task execution request to the network module. After receiving the task execution request, the network module calls the simulation network module to execute the contract initialization method through the simulation network module, and after the contract initialization method is executed, the contract method corresponding to the task execution request is executed; in the process of executing the contract method corresponding to the task execution request: when the current execution statement is a call contract SDK statement, the simulated blockchain contract SDK is called through the comprehensive contract SDK module, and the simulated blockchain is called through the simulated blockchain contract SDK.
[0165] Correspondingly, the simulated blockchain node calls the target method that matches the calling contract SDK statement through the interface module, and when it is determined that the target method is to access storage, calls the storage module to query the storage module's Bloom filter, cache, and database to see whether there is a storage access key that matches the access storage, and after determining that the storage access key exists, obtains the target value based on the storage access key, and returns the target value to the contract project library component through the network module.
[0166] Case 2: The call statement is a cross-contract call statement.
[0167] See also Fig.12 , Fig.12 A flow chart of a method for calling a simulated blockchain node based on a cross-contract call statement provided in an embodiment of the present application includes the following steps:
[0168] Step S1200, the code editor determines that the current execution statement is a cross-contract call statement;
[0169] Step S1201, the code editor calls a simulated blockchain node;
[0170] Step S1202, the simulated blockchain node determines whether there is a contract method indicated by a cross-contract call statement, if so, execute step S1203, otherwise execute step S1206;
[0171] Step S1203, simulating the blockchain node to start the contract process for the contract method;
[0172] Step S1204, simulating the blockchain node to execute the contract method based on the contract process and obtain the corresponding execution result;
[0173] Step S1205, simulating the blockchain node to return the execution result to the code editor;
[0174] Step S1206, the simulated blockchain node returns an error message to the code editor indicating that the called contract method does not exist.
[0175] In a possible implementation, when the simulated blockchain node determines whether there is a contract method indicated by a cross-contract call statement, it first determines whether there is a contract name and version information of the contract method indicated by the cross-contract call statement in the contract name and version information stored in the Bloom filter. If so, it continues to determine whether there is a contract method indicated by the cross-contract call statement in the database. Otherwise, it returns an error message indicating that the called contract method does not exist.
[0176] If it is determined that the contract method indicated by the cross-contract call statement exists in the database, the contract method is determined to exist and loaded into the contract memory, otherwise an error message is returned indicating that the called contract method does not exist.
[0177] based on Fig.12 The method flow chart shown in the embodiment of the present application also provides an architecture for contract code debugging; see Fig.13 , Fig.13 The fourth architecture diagram for contract code debugging provided in the embodiment of the present application is shown in FIG. Fig.13 It can be seen that:
[0178] The code editor receives the task execution request submitted by the user or developer through the task execution interface of the simulated call module in the contract project library component, and transmits the task execution request to the network module. After receiving the task execution request, the network module calls the simulated network module to execute the contract initialization method through the simulated network module. After the contract initialization method is executed, the contract method corresponding to the task execution request is executed; in the process of executing the contract method corresponding to the task execution request: when the current execution statement is a cross-contract call statement, the simulated blockchain node is called.
[0179] Correspondingly, the simulated blockchain node calls the storage module to query the Bloom filter of the storage module and whether the contract method indicated by the cross-contract call statement exists in the database. After determining that the contract method exists, the contract process is started to execute the contract method, the execution result of the contract method is obtained, and the execution result of the contract method is returned to the contract project library component through the network module.
[0180] Taking into account that the real blockchain environment is relatively complex and there are scenarios where multiple contracts call each other, the embodiments of the present application provide a debugging solution for cross-contract calls, which simulates cross-contract calls by simulating the blockchain node to self-start the called contract, thereby meeting the contract debugging needs of most scenarios.
[0181] Above Figure 7 , Figure 8 , Fig.11 as well as Fig.13 The system architecture for debugging contract code based on simulated blockchain nodes is described. In the contract code debugging system, the full life cycle process of the contract code debugging solution based on simulated blockchain is designed, including: contract simulation deployment process (the process of deploying contract code to simulated blockchain nodes through contract project library components and executing initialization methods), contract simulation debugging process (the process of executing contract methods and debugging contract code), and contract simulation cross-contract call process (the operation involves calls between multiple contracts and the process of cross-contract calls). The design of these processes can ensure the stable and efficient operation of the contract code debugging solution based on simulated blockchain.
[0182] In one possible implementation, the target code also includes: an end statement; therefore, in the process of executing the contract code, when the end statement is executed, the comprehensive execution result corresponding to the contract code is obtained, and according to the flag bit in the comprehensive execution result, it is judged whether the comprehensive execution result is correct, and when it is determined that the comprehensive execution result is correct, the comprehensive execution result is returned to the superior caller.
[0183] Exemplarily, determine whether the comprehensive execution result carries an error (error) flag. If it carries error, determine that the comprehensive execution result is wrong, otherwise determine that the comprehensive execution result is correct; or, determine whether the comprehensive execution result carries a correct (true) flag. If it carries true, determine that the comprehensive execution result is correct, otherwise determine that the comprehensive execution result is wrong.
[0184] In an embodiment of the present application, the interrupt instruction may be pre-set in the contract code, or may be triggered by operating a code editor during the execution of the contract code.
[0185] Step S502: display the execution result in the code editor.
[0186] In an embodiment of the present application, after the execution result is obtained, the execution result is displayed in the code editor so as to quickly locate the problem in the contract code in the code editor.
[0187] Taking receiving a task execution request and executing the contract code as an example, the contract debugging method of the embodiment of the present application is specifically described. Fig.14 , Fig.14 A flowchart of a specific implementation method for contract code debugging provided in an embodiment of the present application, applied to a code editor, includes the following steps:
[0188] Step S1400, receiving a task execution request through a simulation call module in a contract project library component;
[0189] Step S1401, calling the simulated network module through the network module to execute the contract initialization method;
[0190] Step S1402, after determining that the contract initialization method is executed, the contract method corresponding to the task execution request is executed;
[0191] Step S1403, execute the statements in sequence:
[0192] Step S14030, determine whether the current statement is an end statement, if so, execute step S14031, otherwise execute step S14034;
[0193] Step S14031, determine whether the result is correct, if so, execute step S14032, otherwise execute step S14033;
[0194] Step S14032, returning the correct result to the superior caller;
[0195] Step S14033, returning an error result to the superior caller;
[0196] Step S14034, determine whether the current statement is a cross-contract call statement, if so, execute step S14035, otherwise execute step S14036;
[0197] Step S14035, calling the simulated blockchain node to execute the contract method indicated by the cross-contract call statement, and obtaining information fed back by the simulated blockchain node;
[0198] Step S14036, determine whether the current statement is a statement for calling the contract SDK, if so, execute step S14037, otherwise execute step S14038;
[0199] Step S14037, calling the simulated blockchain node to execute the target method matched by the call contract SDK statement, and obtaining the result returned by the simulated blockchain node;
[0200] Step S14038, continue executing the current statement and return to step S14030.
[0201] It should be noted that Fig.14 The steps shown are just simple instructions. For detailed operations, see Figure 5 to Figure 13 ; and the order of determining what the current statement is is not fixed. For example, you can first determine whether the current statement is a contract SDK call statement, and then determine whether the current statement is a cross-contract call statement.
[0202] In the present application, when the set trigger conditions are met, the contract code is run locally in the code editor, and there is no need to deploy the local contract code to a Docker container or a virtual machine for execution; in the process of executing the contract code, when the call statement for the simulated blockchain node in the contract code is executed, the simulated blockchain node is called, and the method matching the call statement is executed by the simulated blockchain node, and the execution result returned by the simulated blockchain node is obtained, and the execution result is displayed in the code editor; since the simulated blockchain node does not perform consensus services, there is no need to wait for all contract codes to be executed and return the result, that is, in the embodiment of the present application, after obtaining the execution result, the simulated blockchain node can directly return the execution result to the code editor, reducing the code running time and the time spent on consensus, further reducing the time spent on the debugging process, and improving the debugging efficiency; at the same time, the execution result of the method matching the call statement is returned and displayed, so as to troubleshoot problems based on the displayed execution result. Compared with the execution results of all contract codes, the obtained execution result has a smaller amount of data, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, further reducing the number of security vulnerabilities in the contract code, improving the quality of the contract code, and improving the efficiency of contract code research and development; and,
[0203] During the execution of the contract code, when an interrupt instruction triggered by the execution operation of the contract code is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained, and the execution result is displayed in the code editor. When debugging the contract code through the code editor, the code can be interrupted and the execution result can be obtained when the code is halfway executed, and then the problem can be troubleshooted. There is no need to wait until all contract codes are executed and the execution results are returned before troubleshooting. The amount of data to be checked is small, and the troubleshooting is more convenient and detailed, and the time spent on troubleshooting is reduced, which further reduces the number of security vulnerabilities in the contract code, improves the quality of the contract code, and improves the efficiency of contract code research and development.
[0204] Based on the same inventive concept, the embodiment of the present application also provides a contract code debugging device; Fig.15 As shown, the contract code debugging device 1500 includes:
[0205] The determination unit 1501 is used to determine the contract code based on the target code added in the project code; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node;
[0206] The execution unit 1502 is used to execute the contract code when the set trigger condition is met; when executing the call statement, the simulated blockchain node is called to execute the method matching the call statement, and the corresponding execution result is obtained; when an interrupt instruction triggered by the execution operation is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained; the simulated blockchain node is used for contract code debugging;
[0207] The display unit 1503 is used to display the execution result in the code editor.
[0208] In a possible implementation, the code editor is built based on an integrated development environment.
[0209] In a possible implementation, the trigger condition is set to include:
[0210] The contract code is successfully deployed on the simulated blockchain node;
[0211] Receive task execution instructions.
[0212] In a possible implementation, the calling statement for the simulated blockchain node includes: calling a contract software development kit SDK statement and a cross-contract calling statement.
[0213] In a possible implementation, if the calling statement is a contract SDK calling statement;
[0214] When the execution unit 1502 executes the call statement, it is specifically used to:
[0215] When executing the call contract SDK statement, call the simulated blockchain contract SDK. Through the simulated blockchain contract SDK, call the simulated blockchain node to perform the following operations:
[0216] When determining that the target method that matches the call contract SDK statement is to access storage, check whether the storage access key exists in the simulated blockchain node;
[0217] After determining that the storage access key exists, based on the storage access key, a target value matching the storage access key is acquired in the memory, and the target value is returned to the code editor.
[0218] In a possible implementation, the execution unit 1502 is specifically configured to:
[0219] After determining that the storage access key exists in the Bloom filter and cache of the simulated blockchain node, obtaining a target value matching the storage access key in the cache based on the storage access key; or,
[0220] After determining that the storage access key exists in the bloom filter of the simulated blockchain node and in the database, a target value matching the storage access key is obtained in the database based on the storage access key, and the target value is stored in the cache.
[0221] In a possible implementation, if the call statement is a cross-contract call statement;
[0222] When the execution unit 1502 executes the call statement, it is specifically used to:
[0223] When executing a cross-contract call statement, the simulated blockchain node is called and the following operations are performed through the simulated blockchain node:
[0224] When it is determined that there is a contract method indicated by a cross-contract call statement in the simulated blockchain node, a contract process is started for the contract method;
[0225] Based on the contract process, execute the contract method and return the corresponding execution result;
[0226] Among them, the contract method is pre-deployed into the simulated blockchain node.
[0227] In a possible implementation, the execution unit 1502 is specifically configured to:
[0228] Determine the contract name and version information of the contract method stored in the bloom filter of the simulated blockchain node; and,
[0229] Make sure the contract method exists in the database.
[0230] In one possible implementation, if the trigger condition is that the contract code is successfully deployed on the simulated blockchain node;
[0231] When the set triggering condition is met, before executing the contract code, the execution unit 1502 is also used to:
[0232] In response to the code deployment request, the contract code is stored in the database of the simulated blockchain node, and the contract name and version information of the contract code are stored in the Bloom filter of the simulated blockchain node.
[0233] In a possible implementation, the target code further includes: an end statement, and the execution unit 1502 is further configured to:
[0234] When executing to the end statement, obtain the comprehensive execution result;
[0235] When the comprehensive execution result is determined to be correct according to the flag bit in the comprehensive execution result, the comprehensive execution result is returned to the superior caller.
[0236] It should be noted that although several units (or modules) of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units (or modules) described above can be concretized in one unit (or module). Conversely, the features and functions of one unit (or module) described above can be further divided into multiple units (or modules) for concretization. Of course, when implementing the present application, the functions of each unit (or module) can also be implemented in the same one or more software or hardware.
[0237] After introducing the contract code debugging method and apparatus according to an exemplary embodiment of the present application, another exemplary embodiment of the present application, a computing device, is introduced next.
[0238] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0239] Based on the same inventive concept as the above method embodiment, a computing device is also provided in the present application embodiment. In one embodiment, the computing device may be a server. In this embodiment, the structure of the computing device is as follows: Fig.16 As shown, it may include at least a memory 1601 , a communication module 1603 , and at least one processor 1602 .
[0240] The memory 1601 is used to store computer programs executed by the processor 1602. The memory 1601 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0241] The memory 1601 may be a volatile memory, such as a random-access memory (RAM); the memory 1601 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 1601 may be any other medium that can be used to carry or store a desired computer program in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 1601 may be a combination of the above memories.
[0242] The processor 1602 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 1602 is used to implement the above-mentioned contract code debugging method when calling the computer program stored in the memory 1601.
[0243] The communication module 1603 is used to communicate with terminal devices and other servers.
[0244] The specific connection medium between the memory 1601, the communication module 1603 and the processor 1602 is not limited in the embodiment of the present application. Fig.16 In the embodiment, the memory 1601 and the processor 1602 are connected via a bus 1604. The bus 1604 is connected to the processor 1602 via a bus 1604. Fig.16 The connections between the other components are only for illustration and are not intended to be limiting. The bus 1604 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Fig.16 The diagram shows that only one thick line is used, but this does not mean that there is only one bus or only one type of bus.
[0245] The memory 1601 stores a computer storage medium, and the computer storage medium stores computer executable instructions, and the computer executable instructions are used to implement the contract code debugging method of the embodiment of the present application. The processor 1602 is used to execute the above-mentioned contract code debugging method.
[0246] In another embodiment, the computing device may also be other computing devices, such as a terminal device. In this embodiment, the structure of the computing device may be as follows: Fig.17 As shown, it includes: a communication component 1710, a memory 1720, a display unit 1730, a camera 1740, a sensor 1750, an audio circuit 1760, a Bluetooth module 1770, a processor 1780 and other components.
[0247] The communication component 1710 is used to communicate with the server. In some embodiments, a circuit wireless fidelity (Wireless Fidelity, WiFi) module may be included.
[0248] The memory 1720 can be used to store software programs and data. The processor 1780 executes various functions and data processing of the terminal device by running the software programs or data stored in the memory 1720. The memory 1720 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. The memory 1720 stores an operating system that enables the terminal device to run. In the present application, the memory 1720 can store an operating system and various application programs, and can also store a computer program for executing the contract code debugging method of the embodiment of the present application.
[0249] The display unit 1730 can also be used to display information input by the object or information provided to the object and a graphical user interface (GUI) of various menus of the terminal device. Specifically, the display unit 1730 may include a display screen 1732 disposed on the front of the terminal device. The display screen 1732 may be configured in the form of a liquid crystal display, a light emitting diode, etc.
[0250] The display unit 1730 can also be used to receive input digital or character information and generate signal input related to the object setting and function control of the terminal device. Specifically, the display unit 1730 may include a touch screen 1731 arranged on the front of the terminal device, which can collect touch operations of objects on or near it, such as clicking a button, dragging a scroll box, etc.
[0251] The touch screen 1731 may be covered on the display screen 1732, or the touch screen 1731 and the display screen 1732 may be integrated to realize the input and output functions of the terminal device, and the integrated touch screen may be referred to as a touch display screen.
[0252] The camera 1740 can be used to capture static images, and the subject can publish the images taken by the camera 1740 through the application. The camera 1740 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the processor 1780 to convert it into a digital image signal.
[0253] The terminal device may further include at least one sensor 1750, such as an acceleration sensor 1751, a distance sensor 1752, a fingerprint sensor 1753, and a temperature sensor 1754. The terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.
[0254] The audio circuit 1760, the speaker 1761, and the microphone 1762 can provide an audio interface between the object and the terminal device. The audio circuit 1760 can transmit the electrical signal converted from the received audio data to the speaker 1761, which is converted into a sound signal for output. The terminal device can also be equipped with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 1762 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1760 and converted into audio data, and then the audio data is output to the communication component 1710 to be sent to, for example, another terminal device, or the audio data is output to the memory 1720 for further processing.
[0255] The Bluetooth module 1720 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 1720 to exchange data.
[0256] The processor 1780 is the control center of the terminal device. It uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal device and processes data by running or executing software programs stored in the memory 1720 and calling data stored in the memory 1720. In some embodiments, the processor 1780 may include one or more processing units; the processor 1780 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the baseband processor mainly processes wireless communications. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 1780. In the present application, the processor 1780 can run the operating system, application programs, user interface display and touch response, as well as the contract code debugging method of the embodiment of the present application. In addition, the processor 1780 is coupled to the display unit 1730.
[0257] In some possible implementations, various aspects of the contract code debugging method provided by the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on a computing device, the program code is used to enable the computing device to execute the steps of the contract code debugging method according to various exemplary implementations of the present application described above in this specification.
[0258] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0259] The program product of the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a computing device. However, the program product of the present application is not limited to this. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, device or device.
[0260] The readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein the readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.
[0261] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0262] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user equipment, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device via any type of network including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0263] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0264] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program commands. These computer program commands can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable device to generate a machine, so that the commands executed by the processor of the computer or other programmable device generate commands for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0265] These computer program commands may also be stored in a computer-readable memory capable of directing a computer or other programmable device to operate in a specific manner, so that the commands stored in the computer-readable memory produce an article of manufacture comprising a command device, the command device implementing the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0266] These computer program commands can also be loaded onto a computer or other programmable device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the commands executed on the computer or other programmable device provide the instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0267] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0268] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A contract code debugging method, characterized in that: Applied to a code editor, the method includes: Determine the contract code based on the target code added to the project code; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node; When the set trigger condition is met, the contract code is executed; wherein, when the call statement is executed, the simulated blockchain node is called to execute the method matching the call statement, and the corresponding execution result is obtained; when an interrupt instruction triggered by the execution operation is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained; the simulated blockchain node is used for contract code debugging; The execution result is displayed in the code editor.
2. The method according to claim 1, characterized in that The code editor is built based on an integrated development environment.
3. The method according to claim 1, characterized in that The set triggering conditions include: The contract code is successfully deployed on the simulated blockchain node; Receive task execution instructions.
4. The method according to any one of claims 1 to 3, characterized in that: The calling statements for the simulated blockchain node include: calling contract software development kit SDK statements and cross-contract calling statements.
5. The method according to claim 4, characterized in that If the calling statement is a contract SDK calling statement; Then, when the call statement is executed, the simulated blockchain node is called to execute the method matching the call statement, and the corresponding execution result is obtained, including: When the call contract SDK statement is executed, the simulated blockchain contract SDK is called, and through the simulated blockchain contract SDK, the simulated blockchain node is called to perform the following operations: When determining that the target method matching the call contract SDK statement is access to storage, detecting whether a storage access key exists in the simulated blockchain node; After determining that the storage access key exists, based on the storage access key, a target value matching the storage access key is acquired in a memory, and the target value is returned to the code editor.
6. The method according to claim 5, characterized in that After determining that the storage access key exists, obtaining a target value matching the storage access key in a memory based on the storage access key includes: After determining that the storage access key exists in the Bloom filter and cache of the simulated blockchain node, obtaining a target value matching the storage access key in the cache based on the storage access key; or, After determining that the storage access key exists in the Bloom filter and the database of the simulated blockchain node, a target value matching the storage access key is obtained in the database based on the storage access key, and the target value is stored in the cache.
7. The method according to claim 4, characterized in that If the call statement is a cross-contract call statement; Then, when the call statement is executed, the simulated blockchain node is called to execute the method matching the call statement, and the corresponding execution result is obtained, including: When the cross-contract call statement is executed, the simulated blockchain node is called, and the following operations are performed through the simulated blockchain node: When determining that a contract method indicated by the cross-contract call statement exists in the simulated blockchain node, starting a contract process for the contract method; Based on the contract process, execute the contract method and return the corresponding execution result; Wherein, the contract method is pre-deployed into the simulated blockchain node.
8. The method according to claim 7, characterized in that The determining that there is a contract method indicated by the cross-contract call statement in the simulated blockchain node includes: Determine that the contract name and version information of the contract method are stored in the Bloom filter of the simulated blockchain node; and, Determine whether the contract method exists in the database.
9. The method according to any one of claims 1 to 3, characterized in that: If the trigger condition is that the contract code is successfully deployed on the simulated blockchain node; When the set triggering conditions are met, before executing the contract code, it also includes: In response to the code deployment request, the contract code is stored in the database of the simulated blockchain node, and the contract name and version information of the contract code are stored in the Bloom filter of the simulated blockchain node.
10. The method according to any one of claims 1 to 3, characterized in that: The target code also includes: an end statement, and the method further includes: When the execution reaches the end statement, the comprehensive execution result is obtained; When it is determined according to the flag bit in the comprehensive execution result that the comprehensive execution result is correct, the comprehensive execution result is returned to the superior caller.
11. A contract code debugging device, characterized in that: Applied to a code editor, the device comprises: A determination unit, configured to determine a contract code based on a target code added to a project code; the project code provides functional support for the target code; the target code at least includes: a call statement for a simulated blockchain node; An execution unit, configured to execute the contract code when a set trigger condition is met; wherein, when the call statement is executed, the simulated blockchain node is called to execute the method matching the call statement, and the corresponding execution result is obtained; when an interrupt instruction triggered for the execution operation is detected, the execution of the contract code is stopped, and the execution result corresponding to the code before the interrupt instruction is obtained; the simulated blockchain node is used for contract code debugging; A display unit is used to display the execution result in the code editor.
12. A computing device, characterized in that: The computing device comprises: a processor and a memory, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to implement the method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.
14. 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 10 when executed by a processor.