WO2021102616A1 - Smart contract development method and device, electronic apparatus, and storage medium - Google Patents

Smart contract development method and device, electronic apparatus, and storage medium Download PDF

Info

Publication number
WO2021102616A1
WO2021102616A1 PCT/CN2019/120516 CN2019120516W WO2021102616A1 WO 2021102616 A1 WO2021102616 A1 WO 2021102616A1 CN 2019120516 W CN2019120516 W CN 2019120516W WO 2021102616 A1 WO2021102616 A1 WO 2021102616A1
Authority
WO
WIPO (PCT)
Prior art keywords
bytecode
smart contract
virtual machine
execution environment
target operation
Prior art date
Application number
PCT/CN2019/120516
Other languages
French (fr)
Chinese (zh)
Inventor
郭子雷
来鑫
陈磊
Original Assignee
深圳市网心科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市网心科技有限公司 filed Critical 深圳市网心科技有限公司
Priority to PCT/CN2019/120516 priority Critical patent/WO2021102616A1/en
Publication of WO2021102616A1 publication Critical patent/WO2021102616A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/451Execution arrangements for user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines

Definitions

  • This application relates to the field of blockchain technology, and more specifically, to a smart contract development method and device, an electronic device, and a computer-readable storage medium.
  • Blockchain technology uses block chain data structures to verify and store data, uses distributed node consensus algorithms to generate and update data, uses cryptography to ensure the security of data transmission and access, and uses intelligence composed of automated script codes.
  • the purpose of this application is to provide a smart contract development method and device, an electronic device, and a computer-readable storage medium, providing a unified blockchain platform, and supporting smart contracts developed on different types of virtual machines using different high-level languages. contract.
  • this application provides a smart contract development method, including:
  • the execution environment corresponding to the virtual machine is determined, and the bytecode is executed based on the execution environment.
  • the execution of the bytecode based on the execution environment includes:
  • API list is a list that records API interfaces supported by the virtual machine
  • the execution of the target operation based on the execution environment includes:
  • the method further includes:
  • the virtual machine includes any one or a combination of any of an evm type virtual machine, a wasm type virtual machine, and a jvm type virtual machine.
  • the determining the language type of the bytecode includes:
  • An identifier is obtained from the bytecode, and the language type of the bytecode is determined by identifying the identifier.
  • this application provides a smart contract development device, including:
  • Compilation module used to obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode
  • a determining module configured to determine the language type of the bytecode, and determine a virtual machine that executes the bytecode according to the language type
  • the execution module is used to determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  • the present application provides an electronic device, the electronic device includes a memory and a processor, the memory stores a smart contract development program that can run on the processor, the smart contract development program When executed by the processor, it is realized: obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode; determine the language type of the bytecode, and determine to execute the Bytecode virtual machine; determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  • the smart contract development program when executed by the processor, it also implements: determining an API list corresponding to the virtual machine; wherein the API list is a list that records the API interfaces supported by the virtual machine; when the When there is a target operation in the bytecode, it is determined whether there is an API interface corresponding to the target operation in the API list; if so, the target operation is executed based on the execution environment.
  • this application provides a computer-readable storage medium with a smart contract development program stored on the computer-readable storage medium.
  • the smart contract development program is executed by a processor to implement the smart contract development method as described above. A step of.
  • this application provides a computer program product, including computer instructions, which when run on a computer, enable the computer to execute any one of the smart contract development methods described above.
  • a smart contract development method includes: obtaining the smart contract source code, and using a compiler to compile the smart contract source code into bytecode; determining the language type of the bytecode, and A virtual machine that executes the bytecode is determined according to the language type; an execution environment corresponding to the virtual machine is determined, and the bytecode is executed based on the execution environment.
  • the smart contract development method provided in this application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode.
  • smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system.
  • a unified blockchain platform can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines and realize blocks.
  • the virtual machine on the chain can be adapted and plug-in.
  • This application also discloses a smart contract development device, an electronic device and a computer-readable storage medium, which can also achieve the above technical effects.
  • Figure 1 is a system architecture diagram in related technologies
  • Figure 2 is a flowchart of a smart contract development method disclosed in an embodiment of the application
  • FIG. 3 is a flowchart of another smart contract development method disclosed in an embodiment of the application.
  • FIG. 4 is a system architecture diagram of an application embodiment provided by this application.
  • Figure 5 is a structural diagram of a smart contract development device disclosed in an embodiment of the application.
  • FIG. 6 is a structural diagram of an electronic device disclosed in an embodiment of the application.
  • FIG. 7 is a structural diagram of another electronic device disclosed in an embodiment of the application.
  • evm full English name: environment virtual machine
  • EOS full English name: Enterprise Operation System, a blockchain operating system designed for commercial distributed applications
  • Used wasm full English name: Web Assembly
  • the underlying bytecodes of multiple virtual machines cannot be interoperable, and a set of codes cannot be run on multiple platforms or a single platform supports multiple bytecode formats, which restricts the promotion of smart contract applications and greatly hinders the development of blockchain technology. development of. Therefore, in this application, the smart contract is divided into different types of virtual machines for execution by identifying the language type of the bytecode.
  • a unified blockchain platform can support multiple virtual machines, compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines, and realize the adaptability and plug-inization of virtual machines on the blockchain.
  • the embodiment of the application discloses a smart contract development method, provides a unified blockchain platform, and supports smart contracts developed on different types of virtual machines using different high-level languages.
  • a flow chart of a smart contract development method disclosed in an embodiment of the present application, as shown in Fig. 2, includes:
  • S101 Obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
  • the execution subject of this embodiment is a unified blockchain platform, and the purpose is to support smart contracts developed using different high-level languages on different types of virtual machines.
  • the smart contract source code is obtained.
  • the smart contract source code includes source code written in different high-level languages, such as solidity language, C++ language, and so on.
  • the source code of different programming languages is compiled into bytecode with different compilers, and the bytecode can be executed on a virtual machine.
  • S102 Determine the language type of the bytecode, and determine a virtual machine that executes the bytecode according to the language type;
  • the purpose of this step is to select a suitable virtual machine to execute the bytecode through the language type of the bytecode.
  • the specific determination method is not limited here.
  • the use of a compiler to compile the smart contract source code into bytecode includes: using a compiler to compile the smart contract source code into bytecode, and download Adding the identifier corresponding to the language type of the bytecode to the bytecode; correspondingly, the determining the language type of the bytecode includes: obtaining the identifier from the bytecode, and identifying the The identifier determines the language type of the bytecode.
  • the compiler adds an identifier to the bytecode. For example, if the smart contract source code is written in solidity language, add ".evm" to the bytecode. If the smart contract source code is written in C++ language, Then add ".asm" to the bytecode.
  • the identifier in the bytecode can be extracted, and the virtual machine corresponding to the identifier can be determined.
  • the virtual machine corresponding to ".evm” is an evm type virtual machine
  • the virtual machine corresponding to ".asm” is a wasm type virtual machine.
  • S103 Determine an execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  • different types of virtual machines require different execution environments to parse and execute bytecodes.
  • the operating environment of each type of virtual machine on the platform can be configured separately according to actual needs. For example, a larger CPU or larger execution memory space can be allocated to a certain type of virtual machine.
  • the step of executing the bytecode based on the execution environment includes: determining an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine; When the bytecode has a target operation, it is determined whether there is an API interface corresponding to the target operation in the API list; if so, the target operation is executed based on the execution environment.
  • different types of virtual machines use their own interfaces to access blockchain system resources.
  • different virtual machines can support different API interfaces, realizing more detailed virtual machine management, that is, each type of virtual machine has a corresponding API list.
  • the API list corresponding to this type of virtual machine does not include contract transfer and data reading interfaces.
  • EOS supports super nodes
  • Ethereum does not support super nodes, etc.
  • the API list corresponding to the evm type virtual machine includes the interface to implement the super node
  • the API list corresponding to the wasm type virtual machine does not include the implementation of the super node.
  • the interface of the node When executing the bytecode, if the bytecode includes a target operation, if the API interface corresponding to the target operation exists in the API list, the target operation is executed, otherwise the target operation is rejected.
  • the step of executing the target operation based on the execution environment includes: determining the target blockchain system corresponding to the target operation, and using the API interface corresponding to the target operation to perform the target operation based on the execution environment.
  • the target operation is executed on the target blockchain system; wherein, the API interface is an API interface meeting a preset standard.
  • a unified API interface for virtual machines is provided in a unified blockchain platform to shield the underlying implementation details of the underlying blockchain platform.
  • different blockchain platforms have various APIs. For example, on platforms that support decentralized exchanges, there will be user orders and trading operation interfaces. EOS platform has trading CPU and memory. Interface and so on. The calling methods, parameters, and return values of these different interfaces are different.
  • a unified API interface that is, an API interface that meets the preset standards, contract developers do not need to care too much about the implementation details of the underlying blockchain platform, and only need to call the API.
  • the smart contract development method provided by the embodiment of the application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode.
  • smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that, in the smart contract development method provided by the embodiments of this application, a unified blockchain platform can support multiple virtual machines and is compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines.
  • the virtual machine on the blockchain can be adapted and plug-in.
  • the embodiment of the application discloses a smart contract development method. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution. specific:
  • FIG. 3 a flowchart of another smart contract development method provided by an embodiment of the present application, as shown in Fig. 3, includes:
  • S201 Obtain smart contract source code, and use a compiler to compile the smart contract source code into bytecode, and add an identifier corresponding to the language type of the bytecode to the bytecode;
  • S202 Obtain an identifier from the bytecode, and determine the language type of the bytecode by identifying the identifier;
  • S203 Determine the virtual machine corresponding to the bytecode according to the language type, and determine the execution environment corresponding to the virtual machine;
  • S204 Determine an API list corresponding to the virtual machine; where the API list is a list that records API interfaces supported by the virtual machine;
  • S205 When there is a target operation in the bytecode, determine whether there is an API interface corresponding to the target operation in the API list; if yes, go to S206; if not, go to S208;
  • S206 Determine the target blockchain system corresponding to the target operation, and use the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment; wherein, the API The interface is an API interface that meets the preset standards;
  • this embodiment divides the smart contract into different virtual machines for execution, and supports multiple types of virtual machines. Through independent virtual machine execution environment and API list, fine-grained virtual machine management and plug-in adaptation are realized. Through a unified API interface, shield the implementation details of the underlying blockchain platform and support the access of multiple blockchain systems.
  • the system includes a wasm type virtual machine and a jvm type virtual machine. As shown in FIG. 4, the following steps may be included:
  • Step 1 The source code of the smart contract is compiled into bytecode by a compiler
  • Step 2 After the recognition layer, the bytecode is passed to different virtual machines for execution;
  • Step 3 The virtual machine receives the bytecode, sets the execution environment according to the configuration, and executes the contract bytecode;
  • Step 4 During the execution of the bytecode, the virtual machine API list will be accessed, and then the blockchain system resources will be accessed through the unified API interface;
  • Step 5 Through the API interface, the corresponding operation is executed on the blockchain system of A and B and returned to the virtual machine.
  • developer A uses solidity to write a smart contract with a permission list
  • developer B can only use C++, but the permission list is required.
  • this system can be used to arrange the contracts of developers A and B on the same blockchain platform to realize resource interoperability and data sharing, which is very flexible and efficient.
  • the following describes a smart contract development device provided by an embodiment of the present application.
  • the smart contract development device described below and the smart contract development method described above can be cross-referenced.
  • a structural diagram of a smart contract development device provided by an embodiment of the present application, as shown in Fig. 5, includes:
  • the compilation module 501 is used to obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
  • the determining module 502 is configured to determine the language type of the bytecode, and determine the virtual machine that executes the bytecode according to the language type;
  • the execution module 503 is configured to determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  • the smart contract development device provided by the embodiment of the present application differentiates the smart contract for execution on different types of virtual machines by identifying the language type of the bytecode.
  • smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that, in the smart contract development device provided by the embodiments of this application, the unified blockchain platform can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines.
  • the virtual machine on the blockchain can be adapted and plug-in.
  • the execution module 503 includes:
  • the first determining unit is configured to determine the execution environment corresponding to the virtual machine
  • the second determining unit is configured to determine an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine;
  • the judging unit is configured to judge whether the API interface corresponding to the target operation exists in the API list when the target operation exists in the bytecode; if so, start the work flow of the execution unit;
  • the execution unit is configured to execute the target operation based on the execution environment.
  • the execution unit specifically determines the target blockchain system corresponding to the target operation, and uses the API interface corresponding to the target operation to pair the target blockchain system based on the execution environment.
  • the receiving module is used to receive the operation result of the target blockchain system.
  • the determining module 502 includes:
  • the third determining unit is configured to obtain an identifier from the bytecode, and determine the language type of the bytecode by identifying the identifier;
  • the fourth determining unit is configured to determine a virtual machine that executes the bytecode according to the language type.
  • the language types include solidity language and C++ language.
  • the virtual machine includes any one or a combination of any of an evm-type virtual machine, a wasm-type virtual machine, and a jvm-type virtual machine.
  • This application also provides an electronic device, which may be a PC (Personal Computer, personal computer), or a terminal device such as a smart phone, a tablet computer, a palmtop computer, and a portable computer.
  • the electronic device may be a node forming a CDN network or a blockchain network.
  • FIG. 6 a structural diagram of an electronic device provided by an embodiment of the present application, as shown in FIG. 6, may include a memory 11, a processor 12 and a bus 13.
  • the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like.
  • the memory 11 may be an internal storage unit of an electronic device, such as a hard disk of the electronic device.
  • the memory 11 may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (SD) card equipped on the electronic device. Flash Card, etc.
  • the memory 11 may also include both an internal storage unit of an electronic device and an external storage device.
  • the memory 11 can be used not only to store application software and various data of the installed electronic device, such as the code of the smart contract development program 01, etc., but also to temporarily store data that has been output or will be output.
  • the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip, and is used to run the program code or processing stored in the memory 11
  • the data implements the smart contract development method provided in any of the above embodiments, for example, executes the smart contract development program 01.
  • the bus 13 may be a peripheral component interconnect standard (PCI) bus or an extended industry standard architecture (EISA) bus, etc.
  • PCI peripheral component interconnect standard
  • EISA extended industry standard architecture
  • the bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in FIG. 6, but it does not mean that there is only one bus or one type of bus.
  • the embodiment of the application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode.
  • smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that the unified blockchain platform provided by the embodiments of the present application can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines and realize virtual machines on the blockchain. Adaptable and plug-in.
  • the electronic device further includes:
  • the input interface 14 is used to obtain externally imported computer programs, parameters, and instructions, and store them in the memory 11 under the control of the processor 12.
  • the input interface 14 can be connected to an input device to receive parameters or instructions manually input by the user.
  • the input device can be a touch layer covered on a display screen, a button, a trackball, or a touchpad provided on a terminal shell, or a keyboard, a touchpad, or a mouse.
  • the display unit 15 is used for displaying the data processed by the processor 12 and for displaying a visualized user interface.
  • the display unit 15 may be an LED display, a liquid crystal display, a touch liquid crystal display, an OLED (Organic Light-Emitting Diode, organic light emitting diode) touch device, etc.
  • the network port 16 is used to communicate with external terminal devices.
  • the communication technology used in the communication connection can be wired communication technology or wireless communication technology, such as mobile high-definition link technology (MHL), universal serial bus (USB), high-definition multimedia interface (HDMI), wireless fidelity technology (WiFi), Bluetooth communication technology, low-power Bluetooth communication technology, communication technology based on IEEE802.11s, etc.
  • MHL mobile high-definition link technology
  • USB universal serial bus
  • HDMI high-definition multimedia interface
  • WiFi wireless fidelity technology
  • Bluetooth communication technology low-power Bluetooth communication technology
  • Figure 7 only shows the electronic device with components 11-16 and the smart contract development program 01. Those skilled in the art can understand that the structure shown in Figure 7 does not constitute a limitation on the electronic device, and may include Fewer or more components, or combinations of certain components, or different component arrangements.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.).
  • wired such as coaxial cable, optical fiber, digital subscriber line (DSL)
  • wireless such as infrared, wireless, microwave, etc.
  • the computer-readable storage medium may be any available medium that can be stored by a computer or a data storage device such as a server or a data center integrated with one or more available media.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).
  • the disclosed device, device, and method may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another device, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
  • the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present application essentially or the part that contributes to the existing technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , Including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical disks and other media that can store program codes. .
  • sequence numbers of the above-mentioned embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments.
  • the terms “include”, “include” or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements not only includes those elements, but also includes those elements that are not explicitly included.
  • the other elements listed may also include elements inherent to the process, device, article, or method. If there are no more restrictions, the element defined by the sentence "including a" does not exclude the existence of other identical elements in the process, device, article, or method that includes the element.

Abstract

A smart contract development method and device, an electronic apparatus, and a computer-readable storage medium. The method comprises: acquiring smart contract source code, and using a compiler to compile the smart contract source code into bytecode; determining a language type of the bytecode, and determining, according to the language type, a virtual machine executing the bytecode; and determining an execution environment corresponding to the virtual machine, and executing the bytecode on the basis of the execution environment. By using the smart contract development method provided by the present application, a unified blockchain platform supports a variety of virtual machines, and is compatible with bytecode in a variety of languages, such that a user is not limited to a specific virtual machine, and a virtual machine in the blockchain is adaptable and pluggable.

Description

一种智能合约开发方法、装置及电子设备和存储介质Smart contract development method, device, electronic equipment and storage medium 技术领域Technical field
本申请涉及区块链技术领域,更具体地说,涉及一种智能合约开发方法、装置及一种电子设备和一种计算机可读存储介质。This application relates to the field of blockchain technology, and more specifically, to a smart contract development method and device, an electronic device, and a computer-readable storage medium.
背景技术Background technique
区块链技术是利用块链式数据结构来验证与存储数据、利用分布式节点共识算法来生成和更新数据、利用密码学的方式保证数据传输和访问的安全、利用由自动化脚本代码组成的智能合约来编程和操作数据的一种全新的分布式基础架构与计算方式。Blockchain technology uses block chain data structures to verify and store data, uses distributed node consensus algorithms to generate and update data, uses cryptography to ensure the security of data transmission and access, and uses intelligence composed of automated script codes. A new distributed infrastructure and calculation method in which contracts are used to program and manipulate data.
区块链技术早期,如比特币只具有简单的记账功能,随后引入灵活可编程的智能合约,允许用户在区块链上部署具有公信力的智能协议,极大地挖掘了区块链技术的发展潜力。In the early days of blockchain technology, for example, Bitcoin only had simple accounting functions, and then introduced flexible and programmable smart contracts, allowing users to deploy credible smart protocols on the blockchain, which greatly explored the development of blockchain technology potential.
在相关技术中,可以通过不同种类的虚拟机利用不同的高级语言进行智能合约的开发。但是,由于不同种类的虚拟机的底层字节码无法互通,无法一套代码多平台运行或者单平台支持多种字节码格式,制约了智能合约应用程序的推广,极大的阻碍了区块链技术的发展。In related technologies, different types of virtual machines can be used to develop smart contracts using different high-level languages. However, because the underlying bytecodes of different types of virtual machines cannot be interoperable, one set of code cannot run on multiple platforms or a single platform supports multiple bytecode formats, which restricts the promotion of smart contract applications and greatly hinders the block The development of chain technology.
因此,如何提供统一的区块链平台,支持不同种类虚拟机上利用不同高级语言开发的智能合约是本领域技术人员需要解决的技术问题。Therefore, how to provide a unified blockchain platform to support smart contracts developed using different high-level languages on different types of virtual machines is a technical problem that needs to be solved by those skilled in the art.
发明内容Summary of the invention
本申请的目的在于提供一种智能合约开发方法、装置及一种电子设备和一种计算机可读存储介质,提供了统一的区块链平台,支持不同种类虚拟机上利用不同高级语言开发的智能合约。The purpose of this application is to provide a smart contract development method and device, an electronic device, and a computer-readable storage medium, providing a unified blockchain platform, and supporting smart contracts developed on different types of virtual machines using different high-level languages. contract.
为实现上述目的,本申请提供了一种智能合约开发方法,包括:In order to achieve the above objectives, this application provides a smart contract development method, including:
获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;Obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;Determining the language type of the bytecode, and determining a virtual machine that executes the bytecode according to the language type;
确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。The execution environment corresponding to the virtual machine is determined, and the bytecode is executed based on the execution environment.
其中,所述基于所述执行环境执行所述字节码,包括:Wherein, the execution of the bytecode based on the execution environment includes:
确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;Determine an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine;
当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;When a target operation exists in the bytecode, determining whether there is an API interface corresponding to the target operation in the API list;
若是,则基于所述执行环境执行所述目标操作。If yes, execute the target operation based on the execution environment.
其中,所述基于所述执行环境执行所述目标操作,包括:Wherein, the execution of the target operation based on the execution environment includes:
确定所述目标操作对应的目标区块链系统,并利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作;其中,所述API接口为符合预设标准的API接口。Determine the target blockchain system corresponding to the target operation, and use the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment; wherein the API interface is API interface conforming to preset standards.
其中,所述利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作之后,还包括:Wherein, after said using the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment, the method further includes:
接收所述目标区块链系统的操作结果。Receive the operation result of the target blockchain system.
其中,所述虚拟机包括evm类型的虚拟机、wasm类型的虚拟机和jvm类型的虚拟机中的任一项或任几项的组合。Wherein, the virtual machine includes any one or a combination of any of an evm type virtual machine, a wasm type virtual machine, and a jvm type virtual machine.
其中,所述利用编译器将所述智能合约源码编译为字节码,包括:Wherein, the use of a compiler to compile the smart contract source code into bytecode includes:
利用编译器将所述智能合约源码编译为字节码,并在所述字节码中添加所述字节码的语言类型对应的标识符;Using a compiler to compile the smart contract source code into bytecode, and add an identifier corresponding to the language type of the bytecode to the bytecode;
相应的,所述确定所述字节码的语言类型,包括:Correspondingly, the determining the language type of the bytecode includes:
在所述字节码中获取标识符,通过识别所述标识符确定所述字节码的语言类型。An identifier is obtained from the bytecode, and the language type of the bytecode is determined by identifying the identifier.
为实现上述目的,本申请提供了一种智能合约开发装置,包括:In order to achieve the above objective, this application provides a smart contract development device, including:
编译模块,用于获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;Compilation module, used to obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
确定模块,用于确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;A determining module, configured to determine the language type of the bytecode, and determine a virtual machine that executes the bytecode according to the language type;
执行模块,用于确定所述虚拟机对应的执行环境,并基于所述执行环 境执行所述字节码。The execution module is used to determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
为实现上述目的,本申请提供了一种电子设备,所述电子设备包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的智能合约开发程序,所述智能合约开发程序被所述处理器执行时实现:获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。To achieve the above objective, the present application provides an electronic device, the electronic device includes a memory and a processor, the memory stores a smart contract development program that can run on the processor, the smart contract development program When executed by the processor, it is realized: obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode; determine the language type of the bytecode, and determine to execute the Bytecode virtual machine; determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
其中,所述智能合约开发程序被所述处理器执行时还实现:确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;若是,则基于所述执行环境执行所述目标操作。Wherein, when the smart contract development program is executed by the processor, it also implements: determining an API list corresponding to the virtual machine; wherein the API list is a list that records the API interfaces supported by the virtual machine; when the When there is a target operation in the bytecode, it is determined whether there is an API interface corresponding to the target operation in the API list; if so, the target operation is executed based on the execution environment.
为实现上述目的,本申请提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有智能合约开发程序,所述智能合约开发程序被处理器执行时实现如上述智能合约开发方法的步骤。In order to achieve the above objective, this application provides a computer-readable storage medium with a smart contract development program stored on the computer-readable storage medium. The smart contract development program is executed by a processor to implement the smart contract development method as described above. A step of.
为实现上述目的,本申请提供了一种计算机程序产品,包括计算机指令,当其在计算机上运行时,使得计算机可以执行上述任一项所述智能合约开发方法。In order to achieve the above objective, this application provides a computer program product, including computer instructions, which when run on a computer, enable the computer to execute any one of the smart contract development methods described above.
通过以上方案可知,本申请提供的一种智能合约开发方法,包括:获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。It can be seen from the above solution that a smart contract development method provided by this application includes: obtaining the smart contract source code, and using a compiler to compile the smart contract source code into bytecode; determining the language type of the bytecode, and A virtual machine that executes the bytecode is determined according to the language type; an execution environment corresponding to the virtual machine is determined, and the bytecode is executed based on the execution environment.
本申请提供的智能合约开发方法,通过识别字节码的语言类型,将智能合约分化到不同种类的虚拟机上执行。通过多虚拟机技术,可以将不同语言类型的智能合约同时在一个区块链平台上运行,共同操作同一个区块链系统的状态数据库。由此可见,本申请提供的智能合约开发方法,统一的区块链平台可以支持多种虚拟机,兼容多种不同语言类型的字节码,使用户不局限于特定的虚拟机,实现区块链上虚拟机可适配、插件化。本申 请还公开了一种智能合约开发装置及一种电子设备和一种计算机可读存储介质,同样能实现上述技术效果。The smart contract development method provided in this application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode. Through multi-virtual machine technology, smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that, in the smart contract development method provided by this application, a unified blockchain platform can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines and realize blocks. The virtual machine on the chain can be adapted and plug-in. This application also discloses a smart contract development device, an electronic device and a computer-readable storage medium, which can also achieve the above technical effects.
附图说明Description of the drawings
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.
图1为相关技术中的一种系统架构图;Figure 1 is a system architecture diagram in related technologies;
图2为本申请实施例公开的一种智能合约开发方法的流程图;Figure 2 is a flowchart of a smart contract development method disclosed in an embodiment of the application;
图3为本申请实施例公开的另一种智能合约开发方法的流程图;Figure 3 is a flowchart of another smart contract development method disclosed in an embodiment of the application;
图4为本申请提供的一种应用实施例的系统架构图;FIG. 4 is a system architecture diagram of an application embodiment provided by this application;
图5为本申请实施例公开的一种智能合约开发装置的结构图;Figure 5 is a structural diagram of a smart contract development device disclosed in an embodiment of the application;
图6为本申请实施例公开的一种电子设备的结构图;FIG. 6 is a structural diagram of an electronic device disclosed in an embodiment of the application;
图7为本申请实施例公开的另一种电子设备的结构图。FIG. 7 is a structural diagram of another electronic device disclosed in an embodiment of the application.
具体实施方式Detailed ways
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions, and advantages of the present invention clearer, the following further describes the present invention in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention, but not used to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排 他的包含,例如,包含了一系列步骤或单元的过程、方法、装置、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects, without having to use To describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in a sequence other than the content illustrated or described herein. In addition, the terms "including" and "having" and any variations of them are intended to cover non-exclusive inclusions. For example, a process, method, device, product, or device that includes a series of steps or units is not necessarily limited to the clearly listed Those steps or units may include other steps or units that are not clearly listed or are inherent to these processes, methods, products, or equipment.
需要说明的是,在本发明中涉及“第一”、“第二”等的描述仅用于描述目的,而不能理解为指示或暗示其相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。另外,各个实施例之间的技术方案可以相互结合,但是必须是以本领域普通技术人员能够实现为基础,当技术方案的结合出现相互矛盾或无法实现时应当认为这种技术方案的结合不存在,也不在本发明要求的保护范围之内。It should be noted that the descriptions related to "first", "second", etc. in the present invention are only used for descriptive purposes, and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. . Therefore, the features defined with "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but it must be based on what can be achieved by a person of ordinary skill in the art. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered that such a combination of technical solutions does not exist. , Is not within the protection scope of the present invention.
在相关技术中,可以通过不同种类的虚拟机利用不同的高级语言进行智能合约的开发。例如,以太坊开发智能合约使用的evm(英文全称:environment virtual machine)虚拟机,其高级语言为solidity,以及EOS(英文全称:Enterprise Operation System,商用分布式应用设计的一款区块链操作系统)采用的wasm(英文全称:Web Assembly)虚拟机,其高级语言为C++。如图1所示,其中最关键的技术为用于开发智能合约的高级语言和编译后的字节码以及执行字节码的虚拟机。上述两种虚拟机都与其特定区块链系统紧密相连,都有其特殊的内存、存储等执行环境,特殊支持的字节码以及合约编译器。例如A用户编写solidity合约在Ethereum上注册,B用户编写C++合约在EOS上注册,两者之间数据无法互通,而且A用户solidity合约无法在EOS上注册。In related technologies, different types of virtual machines can be used to develop smart contracts using different high-level languages. For example, the evm (full English name: environment virtual machine) virtual machine used by Ethereum to develop smart contracts, its high-level language is solidity, and EOS (full English name: Enterprise Operation System, a blockchain operating system designed for commercial distributed applications ) Used wasm (full English name: Web Assembly) virtual machine, and its high-level language is C++. As shown in Figure 1, the most critical technology is the high-level language used to develop smart contracts, the compiled bytecode, and the virtual machine that executes the bytecode. The above two types of virtual machines are closely connected to their specific blockchain systems, and they have their own special execution environments such as memory and storage, special supported bytecodes, and contract compilers. For example, user A writes a solidity contract to register on Ethereum, and user B writes a C++ contract to register on EOS. There is no data exchange between the two, and user A’s solidity contract cannot be registered on EOS.
可见多种虚拟机的底层字节码无法互通,无法一套代码多平台运行或者单平台支持多种字节码格式,制约了智能合约应用程序的推广,极大的阻碍了区块链技术的发展。因此,则本申请中,通过识别字节码的语言类型,将智能合约分化到不同种类的虚拟机上执行。统一的区块链平台可以支持多种虚拟机,兼容多种不同语言类型的字节码,使用户不局限于特定的虚拟机,实现区块链上虚拟机可适配、插件化。It can be seen that the underlying bytecodes of multiple virtual machines cannot be interoperable, and a set of codes cannot be run on multiple platforms or a single platform supports multiple bytecode formats, which restricts the promotion of smart contract applications and greatly hinders the development of blockchain technology. development of. Therefore, in this application, the smart contract is divided into different types of virtual machines for execution by identifying the language type of the bytecode. A unified blockchain platform can support multiple virtual machines, compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines, and realize the adaptability and plug-inization of virtual machines on the blockchain.
本申请实施例公开了一种智能合约开发方法,提供了统一的区块链平 台,支持不同种类虚拟机上利用不同高级语言开发的智能合约。The embodiment of the application discloses a smart contract development method, provides a unified blockchain platform, and supports smart contracts developed on different types of virtual machines using different high-level languages.
参见图2,本申请实施例公开的一种智能合约开发方法的流程图,如图2所示,包括:Referring to Fig. 2, a flow chart of a smart contract development method disclosed in an embodiment of the present application, as shown in Fig. 2, includes:
S101:获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;S101: Obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
本实施例的执行主体为统一的区块链平台,目的为对不同种类虚拟机上利用不同高级语言开发的智能合约进行支持。在本步骤中,获取智能合约源码,该智能合约源码包括利用不同高级语言编写的源码,例如solidity语言、C++语言等。对于不同编写语言的源码,利用不同的编译器编译为字节码,该字节码可以在虚拟机上执行。The execution subject of this embodiment is a unified blockchain platform, and the purpose is to support smart contracts developed using different high-level languages on different types of virtual machines. In this step, the smart contract source code is obtained. The smart contract source code includes source code written in different high-level languages, such as solidity language, C++ language, and so on. The source code of different programming languages is compiled into bytecode with different compilers, and the bytecode can be executed on a virtual machine.
S102:确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;S102: Determine the language type of the bytecode, and determine a virtual machine that executes the bytecode according to the language type;
本步骤旨在通过字节码的语言类型选择合适的虚拟机执行该字节码。首先,确定字节码对应的语言类型,利用不同编写语言编写的智能合约源码,可以编译为不同语言类型的字节码,如wasm类型、evm类型等。此处不对具体的确定方法进行限定,优选的,所述利用编译器将所述智能合约源码编译为字节码,包括:利用编译器将所述智能合约源码编译为字节码,并在所述字节码中添加所述字节码的语言类型对应的标识符;相应的,所述确定所述字节码的语言类型,包括:在所述字节码中获取标识符,通过识别所述标识符确定所述字节码的语言类型。在具体实施中,编译器在字节码中添加标识符,例如,若智能合约源码为利用solidity语言编写,则在字节码中添加“.evm”,若智能合约源码为利用C++语言编写,则在字节码中中添加“.asm”。确定执行字节码执行的虚拟机时,可提取字节码中的标识符,并确定该标识符对应的虚拟机。例如,“.evm”对应的虚拟机为evm类型的虚拟机,“.asm”对应的虚拟机为wasm类型的虚拟机。The purpose of this step is to select a suitable virtual machine to execute the bytecode through the language type of the bytecode. First, determine the language type corresponding to the bytecode, and use the smart contract source code written in different programming languages to compile into bytecodes of different language types, such as wasm type, evm type, etc. The specific determination method is not limited here. Preferably, the use of a compiler to compile the smart contract source code into bytecode includes: using a compiler to compile the smart contract source code into bytecode, and download Adding the identifier corresponding to the language type of the bytecode to the bytecode; correspondingly, the determining the language type of the bytecode includes: obtaining the identifier from the bytecode, and identifying the The identifier determines the language type of the bytecode. In specific implementation, the compiler adds an identifier to the bytecode. For example, if the smart contract source code is written in solidity language, add ".evm" to the bytecode. If the smart contract source code is written in C++ language, Then add ".asm" to the bytecode. When determining the virtual machine that executes the bytecode execution, the identifier in the bytecode can be extracted, and the virtual machine corresponding to the identifier can be determined. For example, the virtual machine corresponding to ".evm" is an evm type virtual machine, and the virtual machine corresponding to ".asm" is a wasm type virtual machine.
S103:确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。S103: Determine an execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
在具体实施中,不同类型的虚拟机需要不同的执行环境来解析执行字节码。针对每种虚拟机在平台上的运行环境,可以按照实际需要进行单独 配置,例如,可以为某一类型的虚拟机分配较大的CPU或者较大的执行内存空间。In specific implementation, different types of virtual machines require different execution environments to parse and execute bytecodes. The operating environment of each type of virtual machine on the platform can be configured separately according to actual needs. For example, a larger CPU or larger execution memory space can be allocated to a certain type of virtual machine.
优选的,所述基于所述执行环境执行所述字节码的步骤包括:确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;若是,则基于所述执行环境执行所述目标操作。Preferably, the step of executing the bytecode based on the execution environment includes: determining an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine; When the bytecode has a target operation, it is determined whether there is an API interface corresponding to the target operation in the API list; if so, the target operation is executed based on the execution environment.
在具体实施中,不同类型的虚拟机使用各自的接口去访问区块链系统资源。对于不同的区块链系统的差异功能,使得不同的虚拟机可以支持不同的API接口,实现更加细度的虚拟机管理,即每个类型的虚拟机均存在对应的API列表。例如,可以指定某个类型的虚拟机不支持合约转账,限制区块链数据读取等功能,该类型的虚拟机对应的API列表中则不包含合约转账和数据读取的接口。又如,EOS支持超级节点,以太坊不支持超级节点等,则evm类型的虚拟机对应的API列表中则包含实现超级节点的接口,wasm类型的虚拟机对应的API列表中则不包含实现超级节点的接口。在执行字节码时,若字节码中包括一个目标操作,若API列表中存在该目标操作对应的API接口时,则执行该目标操作,否则拒绝该目标操作。In specific implementation, different types of virtual machines use their own interfaces to access blockchain system resources. For the different functions of different blockchain systems, different virtual machines can support different API interfaces, realizing more detailed virtual machine management, that is, each type of virtual machine has a corresponding API list. For example, you can specify that a certain type of virtual machine does not support contract transfers and restrict functions such as blockchain data reading. The API list corresponding to this type of virtual machine does not include contract transfer and data reading interfaces. For another example, EOS supports super nodes, Ethereum does not support super nodes, etc., the API list corresponding to the evm type virtual machine includes the interface to implement the super node, and the API list corresponding to the wasm type virtual machine does not include the implementation of the super node. The interface of the node. When executing the bytecode, if the bytecode includes a target operation, if the API interface corresponding to the target operation exists in the API list, the target operation is executed, otherwise the target operation is rejected.
更为优选的,所述基于所述执行环境执行所述目标操作的步骤包括:确定所述目标操作对应的目标区块链系统,并利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作;其中,所述API接口为符合预设标准的API接口。More preferably, the step of executing the target operation based on the execution environment includes: determining the target blockchain system corresponding to the target operation, and using the API interface corresponding to the target operation to perform the target operation based on the execution environment. The target operation is executed on the target blockchain system; wherein, the API interface is an API interface meeting a preset standard.
在具体实施中,在统一的区块链平台中提供虚拟机统一的API接口,屏蔽底层区块链平台底层实现细节。通常来讲,不同的区块链平台有各式各样的API,例如,在支持非中心化交易所上的平台上,会有用户挂单,交易的操作接口,EOS平台上面有买卖CPU和内存的接口等等。这些不同接口的调用方式、参数、返回值各不相同。此处通过统一的API接口,即符合预设标准的API接口,合约开发者可不用太过关心底层区块链平台的实现细节,只需要调用API即可。In the specific implementation, a unified API interface for virtual machines is provided in a unified blockchain platform to shield the underlying implementation details of the underlying blockchain platform. Generally speaking, different blockchain platforms have various APIs. For example, on platforms that support decentralized exchanges, there will be user orders and trading operation interfaces. EOS platform has trading CPU and memory. Interface and so on. The calling methods, parameters, and return values of these different interfaces are different. Here, through a unified API interface, that is, an API interface that meets the preset standards, contract developers do not need to care too much about the implementation details of the underlying blockchain platform, and only need to call the API.
可以理解的是,所述利用所述目标操作对应的API接口基于所述执行 环境对所述目标区块链系统上执行所述目标操作之后,还可以包括接收所述目标区块链系统的操作结果的步骤。It is understandable that after the use of the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment, it may also include the operation of receiving the target blockchain system Results of the steps.
本申请实施例提供的智能合约开发方法,通过识别字节码的语言类型,将智能合约分化到不同种类的虚拟机上执行。通过多虚拟机技术,可以将不同语言类型的智能合约同时在一个区块链平台上运行,共同操作同一个区块链系统的状态数据库。由此可见,本申请实施例提供的智能合约开发方法,统一的区块链平台可以支持多种虚拟机,兼容多种不同语言类型的字节码,使用户不局限于特定的虚拟机,实现区块链上虚拟机可适配、插件化。The smart contract development method provided by the embodiment of the application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode. Through multi-virtual machine technology, smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that, in the smart contract development method provided by the embodiments of this application, a unified blockchain platform can support multiple virtual machines and is compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines. The virtual machine on the blockchain can be adapted and plug-in.
本申请实施例公开了一种智能合约开发方法,相对于上一实施例,本实施例对技术方案作了进一步的说明和优化。具体的:The embodiment of the application discloses a smart contract development method. Compared with the previous embodiment, this embodiment further explains and optimizes the technical solution. specific:
参见图3,本申请实施例提供的另一种智能合约开发方法的流程图,如图3所示,包括:Referring to Fig. 3, a flowchart of another smart contract development method provided by an embodiment of the present application, as shown in Fig. 3, includes:
S201:获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码,并在所述字节码中添加所述字节码的语言类型对应的标识符;S201: Obtain smart contract source code, and use a compiler to compile the smart contract source code into bytecode, and add an identifier corresponding to the language type of the bytecode to the bytecode;
S202:在所述字节码中获取标识符,通过识别所述标识符确定所述字节码的语言类型;S202: Obtain an identifier from the bytecode, and determine the language type of the bytecode by identifying the identifier;
S203:根据所述语言类型确定所述字节码对应的虚拟机,并确定所述虚拟机对应的执行环境;S203: Determine the virtual machine corresponding to the bytecode according to the language type, and determine the execution environment corresponding to the virtual machine;
S204:确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;S204: Determine an API list corresponding to the virtual machine; where the API list is a list that records API interfaces supported by the virtual machine;
S205:当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;若是,则进入S206;若否,则进入S208;S205: When there is a target operation in the bytecode, determine whether there is an API interface corresponding to the target operation in the API list; if yes, go to S206; if not, go to S208;
S206:确定所述目标操作对应的目标区块链系统,并利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作;其中,所述API接口为符合预设标准的API接口;S206: Determine the target blockchain system corresponding to the target operation, and use the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment; wherein, the API The interface is an API interface that meets the preset standards;
S207:接收所述目标区块链系统的操作结果;S207: Receive the operation result of the target blockchain system;
S208:拒绝所述目标操作。S208: Reject the target operation.
由此可见,本实施例通过识别字节码,将智能合约分化到不同的虚拟机上执行,支持了多种类型的虚拟机。通过独立的虚拟机执行环境和API列表,实现了细粒度的虚拟机管理和插件适配。通过统一的API接口,屏蔽底层区块链平台底层实现细节,支持多种区块链系统接入。It can be seen that, by identifying bytecode, this embodiment divides the smart contract into different virtual machines for execution, and supports multiple types of virtual machines. Through independent virtual machine execution environment and API list, fine-grained virtual machine management and plug-in adaptation are realized. Through a unified API interface, shield the implementation details of the underlying blockchain platform and support the access of multiple blockchain systems.
下面介绍本申请提供的一种应用实施例,系统中包括wasm类型的虚拟机和jvm类型的虚拟机,如图4所示,可以包括以下步骤:The following describes an application embodiment provided by this application. The system includes a wasm type virtual machine and a jvm type virtual machine. As shown in FIG. 4, the following steps may be included:
步骤一:智能合约源码经过编译器编译为字节码;Step 1: The source code of the smart contract is compiled into bytecode by a compiler;
步骤二:经过识别层,将字节码传递给不同的虚拟机执行;Step 2: After the recognition layer, the bytecode is passed to different virtual machines for execution;
步骤三:虚拟机收到字节码,根据配置设定执行环境,执行合约字节码;Step 3: The virtual machine receives the bytecode, sets the execution environment according to the configuration, and executes the contract bytecode;
步骤四:执行字节码过程中,会访问虚拟机API列表,之后通过统一的API接口访问区块链系统资源;Step 4: During the execution of the bytecode, the virtual machine API list will be accessed, and then the blockchain system resources will be accessed through the unified API interface;
步骤五:通过API接口,甲、乙区块链系统上执行对应的操作,返回给虚拟机。Step 5: Through the API interface, the corresponding operation is executed on the blockchain system of A and B and returned to the virtual machine.
若A开发者使用solidity编写了一个权限名单的智能合约,而B开发者只会使用C++,但需要需要该权限名单。此时可以利用这套系统将A、B开发者的合约布置在同一区块链平台上,实现资源互通,数据共享,非常灵活高效。If developer A uses solidity to write a smart contract with a permission list, and developer B can only use C++, but the permission list is required. At this time, this system can be used to arrange the contracts of developers A and B on the same blockchain platform to realize resource interoperability and data sharing, which is very flexible and efficient.
下面对本申请实施例提供的一种智能合约开发装置进行介绍,下文描述的一种智能合约开发装置与上文描述的一种智能合约开发方法可以相互参照。The following describes a smart contract development device provided by an embodiment of the present application. The smart contract development device described below and the smart contract development method described above can be cross-referenced.
参见图5,本申请实施例提供的一种智能合约开发装置的结构图,如图5所示,包括:Referring to Fig. 5, a structural diagram of a smart contract development device provided by an embodiment of the present application, as shown in Fig. 5, includes:
编译模块501,用于获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;The compilation module 501 is used to obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
确定模块502,用于确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;The determining module 502 is configured to determine the language type of the bytecode, and determine the virtual machine that executes the bytecode according to the language type;
执行模块503,用于确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。The execution module 503 is configured to determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
本申请实施例提供的智能合约开发装置,通过识别字节码的语言类型,将智能合约分化到不同种类的虚拟机上执行。通过多虚拟机技术,可以将不同语言类型的智能合约同时在一个区块链平台上运行,共同操作同一个区块链系统的状态数据库。由此可见,本申请实施例提供的智能合约开发装置,统一的区块链平台可以支持多种虚拟机,兼容多种不同语言类型的字节码,使用户不局限于特定的虚拟机,实现区块链上虚拟机可适配、插件化。The smart contract development device provided by the embodiment of the present application differentiates the smart contract for execution on different types of virtual machines by identifying the language type of the bytecode. Through multi-virtual machine technology, smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that, in the smart contract development device provided by the embodiments of this application, the unified blockchain platform can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines. The virtual machine on the blockchain can be adapted and plug-in.
在上述实施例的基础上,作为一种优选实施方式,所述执行模块503包括:On the basis of the foregoing embodiment, as a preferred implementation manner, the execution module 503 includes:
第一确定单元,用于确定所述虚拟机对应的执行环境;The first determining unit is configured to determine the execution environment corresponding to the virtual machine;
第二确定单元,用于确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;The second determining unit is configured to determine an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine;
判断单元,用于当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;若是,则启动执行单元的工作流程;The judging unit is configured to judge whether the API interface corresponding to the target operation exists in the API list when the target operation exists in the bytecode; if so, start the work flow of the execution unit;
执行单元,用于基于所述执行环境执行所述目标操作。The execution unit is configured to execute the target operation based on the execution environment.
在上述实施例的基础上,作为一种优选实施方式,所述执行单元具体为确定所述目标操作对应的目标区块链系统,并利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作的单元;其中,所述API接口为符合预设标准的API接口。On the basis of the above-mentioned embodiment, as a preferred implementation, the execution unit specifically determines the target blockchain system corresponding to the target operation, and uses the API interface corresponding to the target operation to pair the target blockchain system based on the execution environment. The unit that executes the target operation on the target blockchain system; wherein, the API interface is an API interface that meets a preset standard.
在上述实施例的基础上,作为一种优选实施方式,还包括:On the basis of the foregoing embodiment, as a preferred implementation manner, it further includes:
接收模块,用于接收所述目标区块链系统的操作结果。The receiving module is used to receive the operation result of the target blockchain system.
在上述实施例的基础上,作为一种优选实施方式,所述确定模块502包括:On the basis of the foregoing embodiment, as a preferred implementation manner, the determining module 502 includes:
第三确定单元,用于在所述字节码中获取标识符,通过识别所述标识符确定所述字节码的语言类型;The third determining unit is configured to obtain an identifier from the bytecode, and determine the language type of the bytecode by identifying the identifier;
第四确定单元,用于根据所述语言类型确定执行所述字节码的虚拟机。The fourth determining unit is configured to determine a virtual machine that executes the bytecode according to the language type.
在上述实施例的基础上,作为一种优选实施方式,所述语言类型包括solidity语言和C++语言。On the basis of the foregoing embodiment, as a preferred implementation manner, the language types include solidity language and C++ language.
在上述实施例的基础上,作为一种优选实施方式,所述虚拟机包括evm类型的虚拟机、wasm类型的虚拟机和jvm类型的虚拟机中的任一项或任几项的组合。On the basis of the foregoing embodiment, as a preferred implementation manner, the virtual machine includes any one or a combination of any of an evm-type virtual machine, a wasm-type virtual machine, and a jvm-type virtual machine.
本申请还提供了一种电子设备,该电子设备可以是PC(Personal Computer,个人电脑),也可以是智能手机、平板电脑、掌上电脑、便携计算机等终端设备。该电子设备可以是组成CDN网络或者区块链网络的节点。This application also provides an electronic device, which may be a PC (Personal Computer, personal computer), or a terminal device such as a smart phone, a tablet computer, a palmtop computer, and a portable computer. The electronic device may be a node forming a CDN network or a blockchain network.
参见图6,本申请实施例提供的一种电子设备的结构图,如图6所示,可以包括存储器11、处理器12和总线13。Referring to FIG. 6, a structural diagram of an electronic device provided by an embodiment of the present application, as shown in FIG. 6, may include a memory 11, a processor 12 and a bus 13.
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是电子设备的内部存储单元,例如该电子设备的硬盘。存储器11在另一些实施例中也可以是电子设备的外部存储设备,例如电子设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括电子设备的内部存储单元也包括外部存储设备。存储器11不仅可以用于存储安装电子设备的应用软件及各类数据,例如智能合约开发程序01的代码等,还可以用于暂时地存储已经输出或者将要输出的数据。The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (SD) card equipped on the electronic device. Flash Card, etc. Further, the memory 11 may also include both an internal storage unit of an electronic device and an external storage device. The memory 11 can be used not only to store application software and various data of the installed electronic device, such as the code of the smart contract development program 01, etc., but also to temporarily store data that has been output or will be output.
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,实现上述任一实施例提供的智能合约开发方法,例如执行智能合约开发程序01等。In some embodiments, the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip, and is used to run the program code or processing stored in the memory 11 The data implements the smart contract development method provided in any of the above embodiments, for example, executes the smart contract development program 01.
该总线13可以是外设部件互连标准(peripheral component interconnect,简称PCI)总线或扩展工业标准结构(extended industry standard architecture, 简称EISA)总线等。该总线可以分为地址总线、数据总线、控制总线等。为便于表示,图6中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The bus 13 may be a peripheral component interconnect standard (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus and so on. For ease of representation, only one thick line is used in FIG. 6, but it does not mean that there is only one bus or one type of bus.
本申请实施例通过识别字节码的语言类型,将智能合约分化到不同种类的虚拟机上执行。通过多虚拟机技术,可以将不同语言类型的智能合约同时在一个区块链平台上运行,共同操作同一个区块链系统的状态数据库。由此可见,本申请实施例提供统一的区块链平台可以支持多种虚拟机,兼容多种不同语言类型的字节码,使用户不局限于特定的虚拟机,实现区块链上虚拟机可适配、插件化。The embodiment of the application divides the smart contract into different types of virtual machines for execution by identifying the language type of the bytecode. Through multi-virtual machine technology, smart contracts of different language types can be run on a blockchain platform at the same time to jointly operate the state database of the same blockchain system. It can be seen that the unified blockchain platform provided by the embodiments of the present application can support multiple virtual machines and be compatible with bytecodes of multiple different languages, so that users are not limited to specific virtual machines and realize virtual machines on the blockchain. Adaptable and plug-in.
在上述实施例的基础上,作为优选实施方式,参见图7,所述电子设备还包括:On the basis of the foregoing embodiment, as a preferred implementation manner, referring to FIG. 7, the electronic device further includes:
输入接口14,用于获取外部导入的计算机程序、参数和指令,经处理器12控制保存至存储器11中。该输入接口14可以与输入装置相连,接收用户手动输入的参数或指令。该输入装置可以是显示屏上覆盖的触摸层,也可以是终端外壳上设置的按键、轨迹球或触控板,也可以是键盘(Keyboard)、触控板或鼠标等。The input interface 14 is used to obtain externally imported computer programs, parameters, and instructions, and store them in the memory 11 under the control of the processor 12. The input interface 14 can be connected to an input device to receive parameters or instructions manually input by the user. The input device can be a touch layer covered on a display screen, a button, a trackball, or a touchpad provided on a terminal shell, or a keyboard, a touchpad, or a mouse.
显示单元15,用于显示处理器12处理的数据以及用于显示可视化的用户界面。该显示单元15可以为LED显示器、液晶显示器、触控式液晶显示器以及OLED(Organic Light-Emitting Diode,有机发光二极管)触摸器等。The display unit 15 is used for displaying the data processed by the processor 12 and for displaying a visualized user interface. The display unit 15 may be an LED display, a liquid crystal display, a touch liquid crystal display, an OLED (Organic Light-Emitting Diode, organic light emitting diode) touch device, etc.
网络端口16,用于与外部各终端设备进行通信连接。该通信连接所采用的通信技术可以为有线通信技术或无线通信技术,如移动高清链接技术(MHL)、通用串行总线(USB)、高清多媒体接口(HDMI)、无线保真技术(WiFi)、蓝牙通信技术、低功耗蓝牙通信技术、基于IEEE802.11s的通信技术等。The network port 16 is used to communicate with external terminal devices. The communication technology used in the communication connection can be wired communication technology or wireless communication technology, such as mobile high-definition link technology (MHL), universal serial bus (USB), high-definition multimedia interface (HDMI), wireless fidelity technology (WiFi), Bluetooth communication technology, low-power Bluetooth communication technology, communication technology based on IEEE802.11s, etc.
图7仅示出了具有组件11-16以及智能合约开发程序01的电子设备,本领域技术人员可以理解的是,图7示出的结构并不构成对电子设备的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同 的部件布置。Figure 7 only shows the electronic device with components 11-16 and the smart contract development program 01. Those skilled in the art can understand that the structure shown in Figure 7 does not constitute a limitation on the electronic device, and may include Fewer or more components, or combinations of certain components, or different component arrangements.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, it can be implemented in the form of a computer program product in whole or in part.
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk(SSD))等。The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions described in the embodiments of the present invention are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be stored by a computer or a data storage device such as a server or a data center integrated with one or more available media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的装置,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, the specific working process of the device, device and unit described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed device, device, and method may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another device, or some features can be ignored or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地 方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or software functional unit.
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solution of the present application essentially or the part that contributes to the existing technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , Including several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical disks and other media that can store program codes. .
需要说明的是,上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。并且本文中的术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。It should be noted that the sequence numbers of the above-mentioned embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments. And the terms "include", "include" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements not only includes those elements, but also includes those elements that are not explicitly included. The other elements listed may also include elements inherent to the process, device, article, or method. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, device, article, or method that includes the element.
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and do not limit the scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the description and drawings of the present invention, or directly or indirectly applied to other related technical fields , The same reason is included in the scope of patent protection of the present invention.

Claims (10)

  1. 一种智能合约开发方法,其特征在于,包括:A smart contract development method is characterized in that it includes:
    获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;Obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
    确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;Determining the language type of the bytecode, and determining a virtual machine that executes the bytecode according to the language type;
    确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。The execution environment corresponding to the virtual machine is determined, and the bytecode is executed based on the execution environment.
  2. 根据权利要求1所述智能合约开发方法,其特征在于,所述基于所述执行环境执行所述字节码,包括:The smart contract development method according to claim 1, wherein said executing said bytecode based on said execution environment comprises:
    确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;Determine an API list corresponding to the virtual machine; wherein the API list is a list that records API interfaces supported by the virtual machine;
    当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;When a target operation exists in the bytecode, determining whether there is an API interface corresponding to the target operation in the API list;
    若是,则基于所述执行环境执行所述目标操作。If yes, execute the target operation based on the execution environment.
  3. 根据权利要求2所述智能合约开发方法,其特征在于,所述基于所述执行环境执行所述目标操作,包括:The smart contract development method according to claim 2, wherein the executing the target operation based on the execution environment comprises:
    确定所述目标操作对应的目标区块链系统,并利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作;其中,所述API接口为符合预设标准的API接口。Determine the target blockchain system corresponding to the target operation, and use the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment; wherein the API interface is API interface conforming to preset standards.
  4. 根据权利要求3所述智能合约开发方法,其特征在于,所述利用所述目标操作对应的API接口基于所述执行环境对所述目标区块链系统上执行所述目标操作之后,还包括:The smart contract development method according to claim 3, wherein after said using the API interface corresponding to the target operation to execute the target operation on the target blockchain system based on the execution environment, the method further comprises:
    接收所述目标区块链系统的操作结果。Receive the operation result of the target blockchain system.
  5. 根据权利要求1所述智能合约开发方法,其特征在于,所述虚拟机包括evm类型的虚拟机、wasm类型的虚拟机和jvm类型的虚拟机中的任一项或任几项的组合。The smart contract development method according to claim 1, wherein the virtual machine includes any one or a combination of any one of an evm type virtual machine, a wasm type virtual machine, and a jvm type virtual machine.
  6. 根据权利要求1至5中任一项所述智能合约开发方法,其特征在于,所述利用编译器将所述智能合约源码编译为字节码,包括:The smart contract development method according to any one of claims 1 to 5, wherein said using a compiler to compile the smart contract source code into bytecode comprises:
    利用编译器将所述智能合约源码编译为字节码,并在所述字节码中添 加所述字节码的语言类型对应的标识符;Using a compiler to compile the smart contract source code into bytecode, and add an identifier corresponding to the language type of the bytecode to the bytecode;
    相应的,所述确定所述字节码的语言类型,包括:Correspondingly, the determining the language type of the bytecode includes:
    在所述字节码中获取标识符,通过识别所述标识符确定所述字节码的语言类型。An identifier is obtained from the bytecode, and the language type of the bytecode is determined by identifying the identifier.
  7. 一种智能合约开发装置,其特征在于,包括:A smart contract development device, which is characterized in that it includes:
    编译模块,用于获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;Compilation module, used to obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode;
    确定模块,用于确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;A determining module, configured to determine the language type of the bytecode, and determine a virtual machine that executes the bytecode according to the language type;
    执行模块,用于确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。The execution module is used to determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  8. 一种电子设备,其特征在于,所述电子设备包括存储器和处理器,所述存储器上存储有可在所述处理器上运行的智能合约开发程序,所述智能合约开发程序被所述处理器执行时实现:获取智能合约源码,并利用编译器将所述智能合约源码编译为字节码;确定所述字节码的语言类型,并根据所述语言类型确定执行所述字节码的虚拟机;确定所述虚拟机对应的执行环境,并基于所述执行环境执行所述字节码。An electronic device, characterized in that the electronic device includes a memory and a processor, the memory stores a smart contract development program that can run on the processor, and the smart contract development program is used by the processor. Implementation during execution: Obtain the smart contract source code, and use a compiler to compile the smart contract source code into bytecode; determine the language type of the bytecode, and determine the virtual execution of the bytecode according to the language type Machine; determine the execution environment corresponding to the virtual machine, and execute the bytecode based on the execution environment.
  9. 如权利要求8所述电子设备,其特征在于,所述智能合约开发程序被所述处理器执行时还实现:确定所述虚拟机对应的API列表;其中,所述API列表为记录所述虚拟机支持的API接口的列表;当所述字节码存在目标操作时,判断所述API列表中是否存在所述目标操作对应的API接口;若是,则基于所述执行环境执行所述目标操作。The electronic device according to claim 8, wherein when the smart contract development program is executed by the processor, it further implements: determining an API list corresponding to the virtual machine; wherein, the API list is a record of the virtual machine A list of API interfaces supported by the computer; when the bytecode has a target operation, it is determined whether there is an API interface corresponding to the target operation in the API list; if so, the target operation is executed based on the execution environment.
  10. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至6任一项所述智能合约开发方法的步骤。A computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the smart contract development method according to any one of claims 1 to 6 is realized A step of.
PCT/CN2019/120516 2019-11-25 2019-11-25 Smart contract development method and device, electronic apparatus, and storage medium WO2021102616A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/120516 WO2021102616A1 (en) 2019-11-25 2019-11-25 Smart contract development method and device, electronic apparatus, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/120516 WO2021102616A1 (en) 2019-11-25 2019-11-25 Smart contract development method and device, electronic apparatus, and storage medium

Publications (1)

Publication Number Publication Date
WO2021102616A1 true WO2021102616A1 (en) 2021-06-03

Family

ID=76128627

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/120516 WO2021102616A1 (en) 2019-11-25 2019-11-25 Smart contract development method and device, electronic apparatus, and storage medium

Country Status (1)

Country Link
WO (1) WO2021102616A1 (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110249307A (en) * 2018-12-29 2019-09-17 阿里巴巴集团控股有限公司 System and method for executing primary contract on block chain
US20190334920A1 (en) * 2018-04-30 2019-10-31 Dell Products L.P. Blockchain-based method and system for providing tenant security and compliance in a cloud computing environment

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190334920A1 (en) * 2018-04-30 2019-10-31 Dell Products L.P. Blockchain-based method and system for providing tenant security and compliance in a cloud computing environment
CN110249307A (en) * 2018-12-29 2019-09-17 阿里巴巴集团控股有限公司 System and method for executing primary contract on block chain

Similar Documents

Publication Publication Date Title
US10929149B2 (en) Method and system for updating firmware
WO2020015190A1 (en) Method for generating business rule, electronic device, and readable storage medium
WO2021031472A1 (en) Intelligent contract processing method and device, computer device and storage medium
CN111324396B (en) Block chain intelligent contract execution method, device and equipment
US11726799B2 (en) Preventing framework conflicts for multi-OS applications
WO2021217661A1 (en) Method and platform for implementing graphical code-free software development, computer device and storage medium
JP2012530972A (en) Managed system extension function
US10642587B2 (en) Technologies for indirectly calling vector functions
CN106796521B (en) API version control independent of product release
CN113590104A (en) Platform and method for realizing graphical code-free software development, computer equipment and storage medium
CN112905472A (en) Kernel debugging system and method
KR20220113372A (en) Unified reference and secondary object display
CN113032393A (en) Method and device for binding associated object
US20240126567A1 (en) Data processing system, method, and apparatus
EA001598B1 (en) Portable, secure transaction system for programmable, intelligent devices
CN111158777B (en) Component calling method, device and computer readable storage medium
US20120011490A1 (en) Development system
WO2021102616A1 (en) Smart contract development method and device, electronic apparatus, and storage medium
US9201936B2 (en) Rapid provisioning of information for business analytics
CN113625998B (en) Request processing method and device
CN110147328B (en) Database performance test method, system, electronic equipment and storage medium
CN113010115A (en) Data processing method in block chain node and related equipment
CN109669799A (en) Mistake method for controlling reporting, device and storage medium
CN113590085B (en) Processing method of multi-source heterogeneous data, computer equipment and storage medium
CN115827140B (en) Method, device, equipment and storage medium for generating visual large screen

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19953810

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19953810

Country of ref document: EP

Kind code of ref document: A1