WO2021052338A1 - 智能合约客户端程序的生成方法、系统、设备和介质 - Google Patents

智能合约客户端程序的生成方法、系统、设备和介质 Download PDF

Info

Publication number
WO2021052338A1
WO2021052338A1 PCT/CN2020/115407 CN2020115407W WO2021052338A1 WO 2021052338 A1 WO2021052338 A1 WO 2021052338A1 CN 2020115407 W CN2020115407 W CN 2020115407W WO 2021052338 A1 WO2021052338 A1 WO 2021052338A1
Authority
WO
WIPO (PCT)
Prior art keywords
smart contract
interface
name
entity class
generating
Prior art date
Application number
PCT/CN2020/115407
Other languages
English (en)
French (fr)
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 JP2022511395A priority Critical patent/JP7315786B2/ja
Publication of WO2021052338A1 publication Critical patent/WO2021052338A1/zh
Priority to US17/676,840 priority patent/US20220179651A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/75Structural analysis for program understanding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/33Intelligent editors
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/433Dependency analysis; Data or control flow analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • G06F8/437Type checking
    • 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Definitions

  • This application relates to the field of smart contract technology, and in particular to a method, system, equipment and medium for generating a smart contract client program.
  • a smart contract is a computer program executable on the blockchain. After the smart contract is deployed on the blockchain, it can be called by a client program to obtain the services of the corresponding interface defined on the smart contract.
  • Java is an object-oriented programming language and one of the mainstream languages for background development.
  • the Java client program is the main choice for many developers to call the smart contract interface. Generally speaking, after a developer has finished writing a smart contract, he needs to write a client program that calls the smart contract accordingly. The process of developing a smart contract client program is relatively cumbersome and inefficient.
  • a method for automatically generating a Solidity smart contract Java client program includes the following steps:
  • parsing the interface of the smart contract in step (1) includes the following steps:
  • the corresponding ABI parsing object of the ABI is established, and the ABI text is converted into the ABI parsing object through JSON conversion, so as to obtain the information of all the interfaces of the smart contract;
  • the source code text of the smart contract is grammatically analyzed to establish a grammar tree, so as to obtain information about all the interfaces of the smart contract.
  • step (2) automatically generating the entity class corresponding to the input and return parameters of the smart contract interface includes the following steps:
  • the package name of the entity class is determined by the contract name, and the naming of the entity class is determined by the interface name and interface definition serial number; the field type of the entity class is transformed according to the type of the interface parameter; the field naming of the entity class is determined by the naming information of the interface parameter; the entity The constructor, Get, Set, ToString, Equals, and HashCode methods of the class are generated according to the POJO specification.
  • step (3) automatically generating the corresponding calling method of the smart contract interface includes the following steps:
  • the calling layer interface name is determined by the contract name, the method in the interface corresponds to the interface exposed in the smart contract, and the method name is determined by the interface name and interface definition serial number; the method input and return parameters are the corresponding entity classes.
  • generating the call layer program of the smart contract client in step (4) includes the following steps:
  • the beneficial effects of this application are as follows:
  • the method of this application provides a universal smart contract interface analysis, parameter conversion method, and supporting call layer framework design mode, which automatically generates smart contract client programs, and the caller follows the call of this application
  • the layer framework stipulates that it is convenient to call the interface of the smart contract without worrying about the analysis of the interface and the conversion of parameters, which simplifies the development process of the traditional smart contract and improves the development efficiency of the smart contract.
  • the method for generating includes the following steps:
  • the call layer program of the smart contract client is generated according to the matching call layer framework design mode, the entity class and the call method.
  • the interface for parsing the smart contract includes the following steps:
  • the ABI text is converted into an ABI parsing object through JSON conversion, so as to obtain the information of all the interfaces of the smart contract;
  • the source code text of the smart contract is grammatically analyzed to establish a syntax tree, so as to obtain information of all interfaces of the smart contract.
  • generating the entity class corresponding to the interface input parameters and return parameters of the smart contract according to the interface analysis result includes the following steps:
  • the constructor, Get, Set, ToString, Equals and HashCode methods of the entity class are generated.
  • generating the corresponding invocation method of the interface of the smart contract according to the interface analysis result includes the following steps:
  • the calling layer interface name is determined according to the contract name
  • the method in the calling layer interface corresponds to the interface exposed in the smart contract
  • the calling method name is determined according to the interface name and the interface definition serial number
  • the method of calling the method Input parameters and return parameters are corresponding entity classes
  • the return parameter of the smart contract is converted into the corresponding entity class, and the method returns the entity class.
  • the generating the call layer program of the smart contract client according to the supporting call layer framework design pattern, the entity class and the call method includes the following steps:
  • a system for generating a smart contract client program includes:
  • the interface analysis module is used to analyze the interface of the smart contract according to the ABI or source code of the smart contract;
  • the entity class generation module is used to generate the entity class corresponding to the interface input and return parameters of the smart contract according to the interface analysis result;
  • a calling method generating module configured to generate a calling method corresponding to the interface of the smart contract according to the interface analysis result
  • the program generation module is used to generate the call layer program of the smart contract client according to the matching call layer framework design mode, the entity class and the call method.
  • a device for generating a smart contract client program includes a memory and a processor, the memory stores a computer program, and the processor executes the computer program when the computer program is executed. The steps of the method for generating the above-mentioned smart contract client program are realized.
  • a readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for generating the smart contract client program described above are realized.
  • Fig. 1 is a flowchart of a method for automatically generating a Solidity smart contract Java client program according to an embodiment of the present application.
  • Figure 2 is a UML diagram based on the automatic generation of a Solidity smart contract Java client program according to an embodiment of the present application.
  • Fig. 3 is a schematic flowchart of a method for generating a smart contract client program according to an embodiment of the present application.
  • Fig. 4 is a schematic structural diagram of a system for generating a smart contract client program according to an embodiment of the present application.
  • Fig. 5 is an internal structure diagram of a device for generating a smart contract client program according to an embodiment of the present application.
  • first and second are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features.
  • the features defined with “first” and “second” may explicitly or implicitly include at least one of the features.
  • a plurality of means at least two, such as two, three, etc., unless specifically defined otherwise.
  • everal means at least one, such as one, two, etc., unless otherwise specifically defined.
  • a method for automatically generating a Solidity smart contract Java client program includes the following steps S1-S4:
  • S1 Analyze the interface of the smart contract according to the ABI or source code of the smart contract.
  • the ABI application binary interface
  • the corresponding ABI parsing object of the ABI is established, and the ABI text is converted into the ABI parsing object through JSON (JavaScript Object Notation) conversion, so as to obtain the information of all the interfaces of the smart contract.
  • JSON JavaScript Object Notation
  • the source code text of the smart contract is grammatically analyzed to establish a grammar tree, so as to obtain information about all the interfaces of the smart contract.
  • the package name of the entity class is determined by the contract name, and the name of the entity class is determined by the interface name and interface definition serial number.
  • the field type of the entity class is converted correspondingly according to the type of the interface input and return parameters.
  • Solidity is a computer high-level language for writing smart contracts, running on the Ethereum virtual machine EVM, because the basic unit of data in the Solidity smart contract is 256 bytes, in order to In the Java client side, the field types of Java entity classes are all corresponding to the string type.
  • the array type in Solidity it is represented as a string array type in the Java entity class.
  • the field naming of the entity class is determined by the naming information of the interface input and return parameters.
  • the constructor, Get, Set, ToString, Equals, and HashCode methods of the entity class are generated according to the POJO (Plain Ordinary Java Object, simple Java object) specification.
  • the calling layer interface name is determined by the contract name, and the method in the calling layer interface corresponds to the interface exposed in the smart contract.
  • the method name is determined by the interface name and interface definition serial number; the method input and return parameters are the corresponding entity classes.
  • S4 Generate the call layer program of the smart contract client according to the supporting call layer framework design mode.
  • (1) Define and implement tool classes that transform entity classes into smart contract parameters.
  • For the basic types in the smart contract one-to-one conversion is directly performed; for the array type and variable-length string type in the smart contract, the length of each fragment after the split is converted by splitting.
  • the Java entity class is converted into the Solidity smart contract to enter the parameters, it is essentially the conversion of the string to the corresponding data type in Solidity.
  • the call interface provided by the smart contract API application programming interface
  • the data of the API is finally passed in. Finally, it is sent in the form of a string.
  • the number of parameters of the Solidity smart contract can be reduced by integrating into an array of this type and the stack limit of the EVM can be avoided.
  • the number of parameters of the Solidity smart contract can be reduced by integrating into an array of this type and the stack limit of the EVM can be avoided.
  • the returned array type is an array type
  • it will be spliced into a string in the Java entity class according to the above splitting rules to ensure that the array elements conform to the split when splicing
  • the length of time is defined.
  • the Solidity smart contract Java client program is automatically generated.
  • the developer passes in the Java entity class as the input parameter of the smart contract interface by following the corresponding agreement of the calling layer program framework to obtain the return result of the Java entity class. Developers only need to care about the smart contract call layer, eliminating the need for smart contract interface analysis and parameter conversion steps, greatly reducing the workload of client program development.
  • the Solidity smart contract Java client program is automatically generated, and the finally generated client program is shown in the form of UML diagram as shown in Figure 2.
  • the Java structure specifically included in the client program is as follows:
  • Entity class package This package is used to manage the entity classes in all projects, especially the input parameter entity classes and return parameter entity classes related to invoking smart contracts.
  • a certain contract entity class package This package is used to manage the input entity classes and return parameter entity classes of all interfaces in a smart contract.
  • the package name is determined by the contract name.
  • An input parameter or return parameter entity class corresponds to the input parameter of an interface in a contract, and its field type is a string or a string array, and its field name is determined by the parameter name, and contains the default POJO class Constructor, Get, Set, ToString, Equals, HashCode methods, the entity class name is determined by the interface name and interface serial number.
  • a certain contract interface corresponds to all interfaces of a certain contract, that is, a method corresponds to a public function in the smart contract; the method name is determined by the interface name and the interface serial number, and the input parameters of the method are the corresponding input parameters of the method
  • the return parameter of the method is the corresponding return parameter entity class of the method; for the interface without input parameters, the input parameter of the method is empty; for the interface without return parameters, the return parameter of the method is void.
  • Interface entity class package This package is used to manage the interface implementation classes of all contracts.
  • a certain contract interface implementation class corresponds to the realization of a certain contract interface; the method declaration is consistent with the method declaration in the interface, and the realization logic of the method mainly goes through three steps: First, the entity class that the method is passed into Converted into the corresponding smart contract parameters; second, specify the corresponding smart contract interface and pass in the smart contract parameters, call the corresponding interface through the API provided by the smart contract to obtain the return parameters; third, convert the return parameters of the smart contract For the corresponding entity class, the method returns the entity class.
  • Framework tool layer This package is used to manage all contract call related interface analysis, parameter conversion and other tools.
  • Entity conversion tool category A tool category that converts the input parameter or return parameter entity class and the smart contract parameter to each other. The conversion rules are as described above.
  • API call tool class call the underlying method tool class of the smart contract interface. Its implementation depends on the specific blockchain protocol and the provided API interface, but it should meet the basic functions of calling the smart contract interface.
  • Solidity is a computer high-level language for writing smart contracts. If other programming languages are used, smart contracts can also be written. The solution in this application is also applicable; therefore, for smart contracts, as shown in Figure 3, you can use The following scheme realizes the generation of the smart contract client program:
  • S110 Analyze the interface of the smart contract according to the ABI or source code of the smart contract
  • S120 Generate entity classes corresponding to the interface input parameters and return parameters of the smart contract according to the interface analysis result;
  • S140 Generate a call layer program of the smart contract client according to the matching call layer framework design mode, the entity class, and the call method.
  • the parsing of the interface of the smart contract includes the following steps:
  • the ABI text is converted into an ABI parsing object through JSON conversion, so as to obtain the information of all the interfaces of the smart contract;
  • the source code text of the smart contract is grammatically analyzed to establish a syntax tree, so as to obtain information of all interfaces of the smart contract.
  • generating the entity class corresponding to the interface input parameters and return parameters of the smart contract according to the interface analysis result includes the following steps:
  • the constructor, Get, Set, ToString, Equals and HashCode methods of the entity class are generated.
  • the method for generating the corresponding invocation of the interface of the smart contract according to the interface analysis result includes the following steps:
  • the calling layer interface name is determined according to the contract name
  • the method in the calling layer interface corresponds to the interface exposed in the smart contract
  • the calling method name is determined according to the interface name and the interface definition serial number
  • the method of calling the method Input parameters and return parameters are corresponding entity classes
  • the return parameter of the smart contract is converted into the corresponding entity class, and the method returns the entity class.
  • the generating the call layer program of the smart contract client according to the supporting call layer framework design pattern, the entity class and the call method includes the following steps:
  • a smart contract client program generation system which includes: an interface analysis module 210, an entity class generation module 220, a calling method generation module 230, and a program generation module 240; wherein :
  • the interface analysis module 210 is configured to analyze the interface of the smart contract according to the ABI or source code of the smart contract;
  • the entity class generating module 220 is configured to generate an entity class corresponding to the interface input parameters and return parameters of the smart contract according to the interface analysis result;
  • the calling method generating module 230 is configured to generate a calling method corresponding to the interface of the smart contract according to the interface analysis result;
  • the program generation module 240 is used to generate the call layer program of the smart contract client according to the matching call layer framework design mode, the entity class, and the call method.
  • the interface parsing module 210 is also used to convert the ABI text into an ABI parsing object through JSON conversion when the ABI of the smart contract is provided, so as to obtain information about all the interfaces of the smart contract;
  • the source code of the smart contract is provided, the source code text of the smart contract is grammatically analyzed to establish a syntax tree, so as to obtain information of all interfaces of the smart contract.
  • the entity class generation module 220 is also used to determine the package name of the entity class according to the contract name, and determine the entity class naming based on the interface name and interface definition serial number; transform according to the types of interface input and return parameters to obtain the entity class The type of the field; determine the field naming of the entity class according to the naming information of the interface input and return parameters; generate the constructor, Get, Set, ToString, Equals, and HashCode methods of the entity class according to the POJO specification.
  • the calling method generation module 230 is also used to define a calling layer interface, wherein the calling layer interface name is determined according to the contract name, and the method in the calling layer interface corresponds to the interface exposed in the smart contract, and according to the interface name and The interface definition serial number determines the name of the calling method; the method input and return parameters of the calling method are corresponding entity classes;
  • the calling method generation module 230 is also used to implement the implementation class corresponding to the calling layer interface, wherein the implementation class name is determined according to the contract name, and the method in the implementation class includes the following steps:
  • the return parameter of the smart contract is converted into the corresponding entity class, and the method returns the entity class.
  • the program generation module 240 is also used to define and implement tool classes that convert the entity classes into smart contract parameters, and directly perform one-to-one conversion for the basic types in the smart contract;
  • the array and variable-length string types in the smart contract are split and converted into the length of each fragment after splitting; the API provided by the smart contract is encapsulated.
  • the various modules in the above-mentioned smart contract client program generation system can be implemented in whole or in part by software, hardware, and combinations thereof.
  • the above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
  • a device for generating a smart contract client program may be a terminal, and its internal structure diagram may be as shown in FIG. 5.
  • the device for generating the smart contract client program includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the generating device of the smart contract client program is used to provide calculation and control capabilities.
  • the memory of the device for generating the smart contract client program includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system and a computer program.
  • the internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the network interface of the generating device of the smart contract client program is used to communicate with an external terminal through a network connection.
  • a method for generating a smart contract client program is realized.
  • the display screen of the device for generating the smart contract client program can be a liquid crystal display or an electronic ink display screen
  • the input device of the device for generating the smart contract client program can be a touch layer covered on the display screen, or it can be a smart contract
  • the keys, trackball, or touchpad set on the shell of the generating device of the client program can also be an external keyboard, touchpad, or mouse.
  • FIG. 5 is only a block diagram of part of the structure related to the solution of the present application, and does not constitute a limitation on the generation device of the smart contract client program to which the solution of the present application is applied.
  • the specific smart contract client program generation device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
  • a device for generating a smart contract client program including a memory and a processor, and a computer program is stored in the memory.
  • the processor executes the computer program, the method for generating the smart contract client program is implemented. step.
  • a readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for generating the smart contract client program described above are realized.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

一种智能合约客户端程序的生成方法、系统、设备和介质。根据智能合约的ABI或者源代码,解析智能合约的接口(S110);根据接口解析结果生成智能合约接口入参和返回参数相应的实体类(S120);根据接口解析结果生成智能合约接口相应的调用方法(S130);根据配套的调用层框架设计模式、实体类和调用方法生成智能合约客户端的调用层程序(S140)。上述方法提供了一种通用的智能合约接口解析、参数转化方法以及配套的调用层框架设计模式,自动化地生成智能合约客户端程序,简化了传统的智能合约的开发流程,提高了智能合约的开发效率。

Description

智能合约客户端程序的生成方法、系统、设备和介质
相关申请
本申请要求2019年9月16日申请的,申请号为201910870035.3,发明名称为“一种自动生成Solidity智能合约Java客户端程序的方法”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及智能合约技术领域,特别是涉及一种智能合约客户端程序的生成方法、系统、设备和介质。
背景技术
智能合约是区块链上可执行的计算机程序,智能合约部署在区块链上之后,可以通过客户端程序进行调用,从而获得智能合约上定义的相应接口的服务。Java是一门面向对象编程的语言,是目前后台开发主流语言之一。Java客户端程序是众多开发者调用智能合约接口的主要选择。一般来说,开发者在编写完智能合约之后,还需要相应地编写调用该智能合约的客户端程序,开发智能合约客户端程序的流程较为繁琐,效率低。
发明内容
根据本申请的各种实施例,提供一种自动生成Solidity智能合约Java客户端程序的方法,所述方法包括以下步骤:
(1)根据智能合约的ABI或者源代码,解析智能合约的接口;
(2)根据接口解析结果,自动生成该智能合约接口入参和返回参数相应的实体类;
(3)根据接口解析结果,自动生成该智能合约接口相应的调用方法;
(4)根据配套的调用层框架设计模式,生成智能合约客户端的调用层程序。
在其中一个实施例中,步骤(1)中解析智能合约的接口包括以下步骤:
如果提供的是智能合约的ABI,则建立ABI相应的ABI解析对象,通过JSON转化把ABI文本转化为ABI解析对象,从而获得智能合约所有接口的信息;
如果提供的是智能合约的源代码,则把智能合约源代码文本进行语法分析,建立语法树,从而获得智能合约所有接口的信息。
在其中一个实施例中,步骤(2)中自动生成该智能合约接口入参和返回参数相应的实体类包括以下步骤:
实体类所在包名由合约名决定,实体类命名由接口名和接口定义序号决定;实体类的字段类型根据接口参数的类型进行相应的转化;实体类的字段命名由接口参数的命名信息决定;实体类的构造函数、Get、Set、ToString、Equals、HashCode方法按POJO规范相应生成。
在其中一个实施例中,步骤(3)中自动生成该智能合约接口相应的调用方法包括以下步骤:
(1)定义调用层接口。其中调用层接口名由合约名决定,接口中的方法对应智能合约中暴露的接口,方法名由接口名和接口定义序号决定;方法入参和返回参数为对应的实体类。
(2)实现调用层接口对应的实现类。其中实现类命名由合约名决定,实现类中的方法的实现经过三个步骤:第一,将方法参数传入的实体类转化为对应的智能合约参数;第二,指定对应的智能合约接口并传入智能合约参数,通过该智能合约提供的API调用相应的接口,获得返回参数;第三,将智能合约返回参数转化为对应的实体类,方法返回该实体类。
在其中一个实施例中,步骤(4)中生成智能合约客户端的调用层程序包括以下步骤:
(1)定义并实现将实体类转化为智能合约参数的工具类。对于智能合约中的基本类型,直接进行一对一转化;对于智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化。
(2)封装智能合约提供的API。
本申请的有益效果如下:本申请的方法提供了一种通用的智能合约接口解析、参数转化方法以及配套的调用层框架设计模式,自动化地生成智能合约客户端程序,调用者遵循本申请的调用层框架约定,可以方便地调用智能合约的接口,无需关心接口的解析和参数的转化,简化了传统的智能合约的开发流程,提高了智能合约的开发效率。
根据本申请的各种实施例,还提供一种智能合约客户端程序的生成方法,所述生成方法包括以下步骤:
根据智能合约的ABI或者源代码,解析所述智能合约的接口;
根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类;
根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序。
在其中一个实施例中,所述解析所述智能合约的接口包括以下步骤:
若提供的是所述智能合约的ABI,则通过JSON转化将ABI文本转化为ABI解析对象, 从而获得所述智能合约的所有接口的信息;
若提供的是所述智能合约的源代码,则对所述智能合约的源代码文本进行语法分析,建立语法树,从而获得所述智能合约的所有接口的信息。
在其中一个实施例中,所述根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类包括以下步骤:
根据合约名确定所述实体类所在包名,根据接口名和接口定义序号确定实体类命名;
根据所述接口入参和返回参数的类型进行转化,得到实体类的字段类型;
根据接口入参和返回参数的命名信息确定实体类的字段命名;
根据POJO规范生成所述实体类的构造函数、Get、Set、ToString、Equals和HashCode方法。
在其中一个实施例中,所述根据所述接口解析结果生成所述智能合约的接口相应的调用方法包括以下步骤:
定义调用层接口,其中根据合约名确定调用层接口名,所述调用层接口中的方法对应所述智能合约中暴露的接口,根据接口名和接口定义序号确定调用方法名;所述调用方法的方法入参和返回参数为对应的实体类;
实现所述调用层接口对应的实现类,其中根据合约名确定实现类命名,所述实现类中的方法包括以下步骤:
将方法入参传入的实体类转化为对应的智能合约参数;
指定对应的智能合约接口并传入所述智能合约参数,通过所述智能合约提供的API调用相应的接口,获得返回参数;
将所述智能合约的返回参数转化为对应的实体类,方法返回该实体类。
在其中一个实施例中,所述根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序包括以下步骤:
定义并实现将所述实体类转化为智能合约参数的工具类,对于所述智能合约中的基本类型,直接进行一对一转化;对于所述智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化;
封装所述智能合约提供的API。
根据本申请的各种实施例,还提供一种智能合约客户端程序的生成系统,所述生成系统包括:
接口解析模块,用于根据智能合约的ABI或者源代码,解析所述智能合约的接口;
实体类生成模块,用于根据接口解析结果生成所述智能合约的接口入参和返回参数相应 的实体类;
调用方法生成模块,用于根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
程序生成模块,用于根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序。
根据本申请的各种实施例,还提供一种智能合约客户端程序的生成设备,所述生成设备包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述智能合约客户端程序的生成方法的步骤。
根据本申请的各种实施例,还提供一种可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述智能合约客户端程序的生成方法的步骤。
附图说明
为了更好地描述和说明这里公开的那些发明的实施例和/或示例,可以参考一幅或多幅附图。用于描述附图的附加细节或示例不应当被认为是对所公开的发明、目前描述的实施例和/或示例以及目前理解的这些发明的最佳模式中的任何一者的范围的限制。
图1是本申请实施例的自动生成Solidity智能合约Java客户端程序的方法的流程图。
图2是本申请实施例的基于自动生成Solidity智能合约Java客户端程序的UML图。
图3是本申请实施例的智能合约客户端程序的生成方法的流程示意图。
图4是本申请实施例的智能合约客户端程序的生成系统的结构示意图。
图5是本申请实施例的智能合约客户端程序的生成设备的内部结构图。
具体实施方式
为了便于理解本申请,为使本申请的上述目的、特征和优点能够更加明显易懂,下面结合附图对本申请的具体实施方式做详细的说明。在下面的描述中阐述了很多具体细节以便于充分理解本申请,附图中给出了本申请的较佳实施方式。但是,本申请可以以许多不同的形式来实现,并不限于本文所描述的实施方式。相反地,提供这些实施方式的目的是使对本申请的公开内容理解的更加透彻全面。本申请能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本申请内涵的情况下做类似改进,因此本申请不受下面公开的具体实施例的限制。
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐 含地包括至少一个该特征。在本申请的描述中,“多个”的含义是至少两个,例如两个,三个等,除非另有明确具体的限定。在本申请的描述中,“若干”的含义是至少一个,例如一个,两个等,除非另有明确具体的限定。
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中所使用的术语只是为了描述具体的实施方式的目的,不是旨在于限制本申请。本文所使用的术语“及/或”包括一个或多个相关的所列项目的任意的和所有的组合。
如图1所示,一种自动生成Solidity智能合约Java客户端程序的方法,包括以下步骤S1-S4:
S1:根据所述智能合约的ABI或者源代码,解析所述智能合约的接口。
如果提供的是智能合约的ABI(应用程序二进制接口),则建立ABI相应的ABI解析对象,通过JSON(JavaScript对象简谱)转化将ABI文本转化为ABI解析对象,从而获得智能合约所有接口的信息。
如果提供的是智能合约的源代码,则把智能合约源代码文本进行语法分析,建立语法树,从而获得智能合约所有接口的信息。
根据语法树提取接口信息时,只需要提取public的函数即可。
S2:根据接口解析结果,自动生成该智能合约接口入参和返回参数相应的实体类。
实体类所在包名由合约名决定,实体类命名由接口名和接口定义序号决定。
实体类的字段类型根据接口入参和返回参数的类型进行相应的转化。应用在Solidity智能合约和Java客户端程序时,Solidity是一种编写智能合约的计算机高级语言,运行在以太坊虚拟机EVM之上,由于Solidity智能合约中数据的基本单元是256字节的,为了在Java客户端表示完全,Java实体类的字段类型全部采用字符串类型与之相对应。对于Solidity中的数组类型,在Java实体类中表示为字符串数组类型。
实体类的字段命名由接口入参和返回参数的命名信息决定。
实体类的构造函数、Get、Set、ToString、Equals、HashCode方法按POJO(Plain Ordinary Java Object,简单的Java对象)规范相应生成。
S3:根据接口解析结果,自动生成该智能合约接口相应的调用方法。
具体的:(1)定义调用层接口。其中调用层接口名由合约名决定,调用层接口中的方法对应智能合约中暴露的接口,方法名由接口名和接口定义序号决定;方法入参和返回参数为对应的实体类。
(2)实现调用层接口对应的实现类。其中实现类命名由合约名决定,实现类中的方 法的实现主要经过三个步骤:第一,将方法入参传入的实体类转化为对应的智能合约参数。第二,指定对应的智能合约接口并传入智能合约参数,通过该智能合约提供的API调用相应的接口,获得返回参数。第三,将智能合约的返回参数转化为对应的实体类,方法返回该实体类。
S4:根据配套的调用层框架设计模式,生成智能合约客户端的调用层程序。
具体的:(1)定义并实现将实体类转化为智能合约参数的工具类。对于智能合约中的基本类型,直接进行一对一转化;对于智能合约中的数组类型和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化。其中,将Java实体类转化为Solidity智能合约入参时,本质上是字符串转化为Solidity中相应的数据类型,根据智能合约API(应用程序编程接口)提供的调用接口,最终传入API的数据也最终以字符串的形式发送。对于一个Java实体类中存在多种对应于Solidity同一类型的字段时,通过整合为该类型的数组统一传入,可以减少Solidity智能合约的参数个数,避免超出EVM的堆栈限制。此时,如果Java实体类中存在该类型的数组类型,由于所占数组长度的不同,则需要记录每个字段在入参数组中所占的数组长度,在一个额外的正整数数组中进行记录。同样的,将Solidity智能合约返回参数转化为Java实体类时,如果返回的是数组类型,则按照上述拆分规则,相应的拼接成Java实体类中的字符串,确保数组元素拼接时符合拆分时的长度定义。
(2)封装智能合约提供的API。其可提供异常的捕捉、同步异步调用等特性的支持。该封装的实现和相关特性的支持依赖于具体的区块链协议和提供的API接口,但是应该满足的基本的调用智能合约接口的功能。
根据本申请的方法自动生成Solidity智能合约Java客户端程序,开发者通过遵循调用层程序框架的相应约定,传入Java实体类作为智能合约接口的入参,获取Java实体类的返回结果。开发者只需要关心智能合约调用层即可,省去了智能合约接口解析和参数转化的步骤,极大减少了客户端程序的开发工作量。
根据本申请的方法自动生成Solidity智能合约Java客户端程序,其最终生成的客户端程序以UML图的形式展示如图2。该客户端程序具体包含的Java结构如下:
(1)实体类包:该包用于管理所有项目中的实体类,尤其是调用智能合约相关的入参实体类和返回参数实体类。
(2)某合约实体类包:该包用于管理某一智能合约中所有接口的入参实体类和返回参数实体类,包名由合约名决定。
(3)某入参或返回参数实体类:该实体类对应某合约中某接口的入参,其字段类型为字符串或字符串数组,其字段名由参数名决定,并包含POJO类默认的构造函数、Get、Set、 ToString、Equals、HashCode方法,实体类名由接口名和接口序号决定。
(4)合约层包:该包用于管理所有智能合约的调用接口和接口实现类。
(5)某合约接口:该接口对应某一合约的所有接口,即某一方法对应智能合约中的一个公开函数;方法名由接口名和接口序号决定,方法的入参为该方法对应的入参实体类,方法的返回参数为该方法对应的返回参数实体类;对于没有入参的接口,则该方法的入参为空;对于没有返回参数的接口,则该方法的返回参数为void。
(6)接口实体类包:该包用于管理所有合约的接口实现类。
某合约接口实现类:该类对应某合约接口的实现;其中方法的声明同接口中方法声明保持一致,其中方法的实现逻辑主要经过三个步骤:第一,将方法入参传入的实体类转化为对应的智能合约参数;第二,指定对应的智能合约接口并传入智能合约参数,通过该智能合约提供的API调用相应的接口,获得返回参数;第三,将智能合约的返回参数转化为对应的实体类,方法返回该实体类。
(7)框架工具层:该包用于管理所有合约调用相关的接口解析、参数转化等工具类。
(8)实体类转化工具类:将入参或返回参数实体类与智能合约参数进行互相转化的工具类,其转化规则如上文所述。
(9)API调用工具类:调用智能合约接口的底层方法工具类,其实现依赖于具体的区块链协议和提供的API接口,但是应该满足基本的调用智能合约接口的功能。
进一步的,Solidity是一种编写智能合约的计算机高级语言,若采用其他的编程语言,也可以对智能合约进行编写,本申请的方案同样适用;因此针对智能合约,如图3所示,可以采用以下方案实现智能合约客户端程序的生成:
S110:根据智能合约的ABI或者源代码,解析所述智能合约的接口;
S120:根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类;
S130:根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
S140:根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序。
在一个实施例中,所述解析所述智能合约的接口包括以下步骤:
若提供的是所述智能合约的ABI,则通过JSON转化将ABI文本转化为ABI解析对象,从而获得所述智能合约的所有接口的信息;
若提供的是所述智能合约的源代码,则对所述智能合约的源代码文本进行语法分析,建立语法树,从而获得所述智能合约的所有接口的信息。
在一个实施例中,所述根据接口解析结果生成所述智能合约的接口入参和返回参数相 应的实体类包括以下步骤:
根据合约名确定所述实体类所在包名,根据接口名和接口定义序号确定实体类命名;
根据所述接口入参和返回参数的类型进行转化,得到实体类的字段类型;
根据接口入参和返回参数的命名信息确定实体类的字段命名;
根据POJO规范生成所述实体类的构造函数、Get、Set、ToString、Equals和HashCode方法。
在一个实施例中,所述根据所述接口解析结果生成所述智能合约的接口相应的调用方法包括以下步骤:
定义调用层接口,其中根据合约名确定调用层接口名,所述调用层接口中的方法对应所述智能合约中暴露的接口,根据接口名和接口定义序号确定调用方法名;所述调用方法的方法入参和返回参数为对应的实体类;
实现所述调用层接口对应的实现类,其中根据合约名确定实现类命名,所述实现类中的方法包括以下步骤:
将方法入参传入的实体类转化为对应的智能合约参数;
指定对应的智能合约接口并传入所述智能合约参数,通过所述智能合约提供的API调用相应的接口,获得返回参数;
将所述智能合约的返回参数转化为对应的实体类,方法返回该实体类。
在一个实施例中,所述根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序包括以下步骤:
定义并实现将所述实体类转化为智能合约参数的工具类,对于所述智能合约中的基本类型,直接进行一对一转化;对于所述智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化;
封装所述智能合约提供的API。
在一个实施例中,如图4所示,提供了一种智能合约客户端程序的生成系统,包括:接口解析模块210、实体类生成模块220、调用方法生成模块230和程序生成模块240;其中:
接口解析模块210用于根据所述智能合约的ABI或者源代码,解析所述智能合约的接口;
实体类生成模块220用于根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类;
调用方法生成模块230用于根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
程序生成模块240用于根据配套的调用层框架设计模式、所述实体类和所述调用方法生 成智能合约客户端的调用层程序。
在一个实施例中,接口解析模块210还用于在提供的是所述智能合约的ABI时,通过JSON转化将ABI文本转化为ABI解析对象,从而获得所述智能合约的所有接口的信息;在提供的是所述智能合约的源代码时,对所述智能合约的源代码文本进行语法分析,建立语法树,从而获得所述智能合约的所有接口的信息。
在一个实施例中,实体类生成模块220还用于根据合约名确定实体类所在包名,根据接口名和接口定义序号确定实体类命名;根据接口入参和返回参数的类型进行转化,得到实体类的字段类型;根据接口入参和返回参数的命名信息确定实体类的字段命名;根据POJO规范生成实体类的构造函数、Get、Set、ToString、Equals和HashCode方法。
在一个实施例中,调用方法生成模块230还用于定义调用层接口,其中根据合约名确定调用层接口名,所述调用层接口中的方法对应所述智能合约中暴露的接口,根据接口名和接口定义序号确定调用方法名;所述调用方法的方法入参和返回参数为对应的实体类;
调用方法生成模块230还用于实现所述调用层接口对应的实现类,其中根据合约名确定实现类命名,所述实现类中的方法包括以下步骤:
将方法入参传入的实体类转化为对应的智能合约参数;
指定对应的智能合约接口并传入所述智能合约参数,通过所述智能合约提供的API调用相应的接口,获得返回参数;
将所述智能合约的返回参数转化为对应的实体类,方法返回该实体类。
在一个实施例中,程序生成模块240还用于定义并实现将所述实体类转化为智能合约参数的工具类,对于所述智能合约中的基本类型,直接进行一对一转化;对于所述智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化;封装所述智能合约提供的API。
关于智能合约客户端程序的生成系统的具体限定可以参见上文中对于智能合约客户端程序的生成方法的限定,在此不再赘述。上述智能合约客户端程序的生成系统中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在一个实施例中,提供了一种智能合约客户端程序的生成设备,该智能合约客户端程序的生成设备可以是终端,其内部结构图可以如图5所示。该智能合约客户端程序的生成设备包括通过系统总线连接的处理器、存储器、网络接口、显示屏和输入装置。其中,该智能合约客户端程序的生成设备的处理器用于提供计算和控制能力。该智能合约客户端程序的生 成设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统和计算机程序。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该智能合约客户端程序的生成设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种智能合约客户端程序的生成方法。该智能合约客户端程序的生成设备的显示屏可以是液晶显示屏或者电子墨水显示屏,该智能合约客户端程序的生成设备的输入装置可以是显示屏上覆盖的触摸层,也可以是智能合约客户端程序的生成设备外壳上设置的按键、轨迹球或触控板,还可以是外接的键盘、触控板或鼠标等。
本领域技术人员可以理解,图5中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的智能合约客户端程序的生成设备的限定,具体的智能合约客户端程序的生成设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
在一个实施例中,提供了一种智能合约客户端程序的生成设备,包括存储器和处理器,存储器中存储有计算机程序,该处理器执行计算机程序时实现上述智能合约客户端程序的生成方法的步骤。
在一个实施例中,提供了一种可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现上述智能合约客户端程序的生成方法的步骤。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
以上所述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
以上所述实施例仅表达了本发明的几种实施方式,其描述较为具体和详细,但并不能 因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。因此,本发明专利的保护范围应以所附权利要求为准。

Claims (13)

  1. 一种自动生成Solidity智能合约Java客户端程序的方法,其特征在于,该方法具体包括如下步骤:
    (1)根据智能合约的ABI或者源代码,解析智能合约的接口;
    (2)根据接口解析结果,自动生成该智能合约接口入参和返回参数相应的实体类;
    (3)根据接口解析结果,自动生成该智能合约接口相应的调用方法;
    (4)根据配套的调用层框架设计模式,生成智能合约客户端的调用层程序。
  2. 根据权利要求1所述的方法,其特征在于,所述的步骤(1)中解析智能合约的接口的具体步骤如下:
    如果提供的是智能合约的ABI,则建立ABI相应的ABI解析对象,通过JSON转化把ABI文本转化为ABI解析对象,从而获得智能合约所有接口的信息;
    如果提供的是智能合约的源代码,则把智能合约源代码文本进行语法分析,建立语法树,从而获得智能合约所有接口的信息。
  3. 根据权利要求1所述的方法,其特征在于,所述的步骤(2)中自动生成该智能合约接口入参和返回参数相应的实体类的具体如下:
    实体类所在包名由合约名决定,实体类命名由接口名和接口定义序号决定;
    实体类的字段类型根据接口参数的类型进行相应的转化;
    实体类的字段命名由接口参数的命名信息决定;
    实体类的构造函数、Get、Set、ToString、Equals、HashCode方法按POJO规范相应生成。
  4. 根据权利要求1所述的方法,其特征在于,所述的步骤(3)中自动生成该智能合约接口相应的调用方法的具体步骤如下:
    (1)定义调用层接口,其中调用层接口名由合约名决定,接口中的方法对应智能合约中暴露的接口,方法名由接口名和接口定义序号决定;方法入参和返回参数为对应的实体类;
    (2)实现调用层接口对应的实现类,其中实现类命名由合约名决定,实现类中的方法的实现经过三个步骤:
    第一,将方法参数传入的实体类转化为对应的智能合约参数;
    第二,指定对应的智能合约接口并传入智能合约参数,通过该智能合约提供的API调用相应的接口,获得返回参数;
    第三,将智能合约返回参数转化为对应的实体类,方法返回该实体类。
  5. 根据权利要求1所述的方法,其特征在于,所述的步骤(4)中生成智能合约客户端的调用层程序的具体步骤如下:
    (1)定义并实现将实体类转化为智能合约参数的工具类:对于智能合约中的基本类型,直接进行一对一转化;对于智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化;
    (2)封装智能合约提供的API。
  6. 一种智能合约客户端程序的生成方法,其特征在于,所述生成方法包括以下步骤:
    根据智能合约的ABI或者源代码,解析所述智能合约的接口;
    根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类;
    根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
    根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序。
  7. 根据权利要求6所述的智能合约客户端程序的生成方法,其特征在于,所述解析所述智能合约的接口包括以下步骤:
    若提供的是所述智能合约的ABI,则通过JSON转化将ABI文本转化为ABI解析对象,从而获得所述智能合约的所有接口的信息;
    若提供的是所述智能合约的源代码,则对所述智能合约的源代码文本进行语法分析,建立语法树,从而获得所述智能合约的所有接口的信息。
  8. 根据权利要求6所述的智能合约客户端程序的生成方法,其特征在于,所述根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类包括以下步骤:
    根据合约名确定所述实体类所在包名,根据接口名和接口定义序号确定实体类命名;
    根据所述接口入参和返回参数的类型进行转化,得到所述实体类的字段类型;
    根据所述接口入参和返回参数的命名信息确定所述实体类的字段命名;
    根据POJO规范生成所述实体类的构造函数、Get、Set、ToString、Equals和HashCode方法。
  9. 根据权利要求6所述的智能合约客户端程序的生成方法,其特征在于,所述根据所述接口解析结果生成所述智能合约的接口相应的调用方法包括以下步骤:
    定义调用层接口,其中根据合约名确定调用层接口名,所述调用层接口中的方法对应所述智能合约中暴露的接口,根据接口名和接口定义序号确定调用方法名;所述调用方法的方法入参和返回参数为对应的实体类;
    实现所述调用层接口对应的实现类,其中根据合约名确定实现类命名,所述实现类中的方法包括以下步骤:
    将所述方法入参传入的实体类转化为对应的智能合约参数;
    指定对应的智能合约接口并传入所述智能合约参数,通过所述智能合约提供的API调用相应的接口,获得返回参数;
    将所述智能合约的返回参数转化为对应的实体类,所述调用方法返回该实体类。
  10. 根据权利要求6所述的智能合约客户端程序的生成方法,其特征在于,所述根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序包括以下步骤:
    定义并实现将所述实体类转化为智能合约参数的工具类,对于所述智能合约中的基本类型,直接进行一对一转化;对于所述智能合约中的数组和变长字符串类型,通过拆分并将拆分后每个片段的长度进行转化;
    封装所述智能合约提供的API。
  11. 一种智能合约客户端程序的生成系统,其特征在于,所述生成系统包括:
    接口解析模块,用于根据智能合约的ABI或者源代码,解析所述智能合约的接口;
    实体类生成模块,用于根据接口解析结果生成所述智能合约的接口入参和返回参数相应的实体类;
    调用方法生成模块,用于根据所述接口解析结果生成所述智能合约的接口相应的调用方法;
    程序生成模块,用于根据配套的调用层框架设计模式、所述实体类和所述调用方法生成智能合约客户端的调用层程序。
  12. 一种智能合约客户端程序的生成设备,其特征在于,所述生成设备包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现权利要求1至10中任一项所述方法的步骤。
  13. 一种可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现权利要求1至10中任一项所述方法的步骤。
PCT/CN2020/115407 2019-09-16 2020-09-15 智能合约客户端程序的生成方法、系统、设备和介质 WO2021052338A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
JP2022511395A JP7315786B2 (ja) 2019-09-16 2020-09-15 スマートコントラクトのクライアントプログラムの生成方法、システム、機器、及び媒体
US17/676,840 US20220179651A1 (en) 2019-09-16 2022-02-22 Smart contract client program generation method, system and device, and medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910870035.3A CN110633076B (zh) 2019-09-16 2019-09-16 一种自动生成Solidity智能合约Java客户端程序的方法
CN201910870035.3 2019-09-16

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/676,840 Continuation US20220179651A1 (en) 2019-09-16 2022-02-22 Smart contract client program generation method, system and device, and medium

Publications (1)

Publication Number Publication Date
WO2021052338A1 true WO2021052338A1 (zh) 2021-03-25

Family

ID=68972505

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/115407 WO2021052338A1 (zh) 2019-09-16 2020-09-15 智能合约客户端程序的生成方法、系统、设备和介质

Country Status (4)

Country Link
US (1) US20220179651A1 (zh)
JP (1) JP7315786B2 (zh)
CN (1) CN110633076B (zh)
WO (1) WO2021052338A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113885862A (zh) * 2021-09-29 2022-01-04 武汉斗鱼鱼乐网络科技有限公司 一种头像框复用方法、存储介质、电子设备

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110633076B (zh) * 2019-09-16 2021-05-04 杭州趣链科技有限公司 一种自动生成Solidity智能合约Java客户端程序的方法
CN111581047B (zh) * 2020-03-24 2023-03-24 博雅正链(北京)科技有限公司 一种针对智能合约行为的监管方法
US11650802B2 (en) * 2020-12-22 2023-05-16 Diffblue Ltd Idiomatic source code generation
US11675571B1 (en) * 2021-12-28 2023-06-13 Nb Ventures, Inc. Restructuring enterprise application

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120246614A1 (en) * 2011-03-23 2012-09-27 Microsoft Corporation Automated generation of client/driver communication interfaces
CN106919509A (zh) * 2017-03-09 2017-07-04 腾讯科技(深圳)有限公司 一种客户端生成方法、装置及电子设备
CN108304307A (zh) * 2018-01-24 2018-07-20 深圳圣马歌科技有限公司 一种区块链上智能合约的性能检测方法
CN109614102A (zh) * 2018-10-09 2019-04-12 平安科技(深圳)有限公司 代码自动生成方法、装置、电子设备及存储介质
CN110633076A (zh) * 2019-09-16 2019-12-31 杭州趣链科技有限公司 一种自动生成Solidity智能合约Java客户端程序的方法

Family Cites Families (42)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8624921B2 (en) * 2008-09-30 2014-01-07 Rockwell Automation Technologies, Inc. Industrial automation visualization schemes employing overlays
US9883008B2 (en) * 2010-01-15 2018-01-30 Endurance International Group, Inc. Virtualization of multiple distinct website hosting architectures
JP2013073400A (ja) * 2011-09-27 2013-04-22 Fujitsu Ltd サービスモジュール生成プログラム、該装置、及びサービス情報管理方法
US8972489B2 (en) * 2011-11-15 2015-03-03 Google Inc. Providing a client interface for a server-based web application programming interface
US8732720B2 (en) * 2011-12-22 2014-05-20 Hewlett-Packard Development Company, L.P. Job scheduling based on map stage and reduce stage duration
US10187452B2 (en) * 2012-08-23 2019-01-22 TidalScale, Inc. Hierarchical dynamic scheduling
US9774401B1 (en) * 2013-07-15 2017-09-26 Paul Borrill Entangled links, transactions and trees for distributed computing systems
US11030105B2 (en) * 2014-07-14 2021-06-08 Oracle International Corporation Variable handles
US10210606B2 (en) * 2014-10-14 2019-02-19 Kla-Tencor Corporation Signal response metrology for image based and scatterometry overlay measurements
US9916170B2 (en) * 2015-12-30 2018-03-13 Vmware, Inc. Cloud computing simulator
US10339246B2 (en) * 2016-05-26 2019-07-02 Synopsys, Inc. Schematic overlay for design and verification
US10579421B2 (en) * 2016-08-29 2020-03-03 TidalScale, Inc. Dynamic scheduling of virtual processors in a distributed system
CN108572986B (zh) * 2017-03-13 2022-05-17 华为技术有限公司 一种数据更新的方法及节点设备
CN107038242B (zh) * 2017-04-24 2020-02-07 杭州趣链科技有限公司 一种面向区块链全局智能合约业务数据解析方法
CN107274186A (zh) * 2017-05-11 2017-10-20 上海点融信息科技有限责任公司 在区块链中获得智能合约接口的方法和设备
US11488121B2 (en) * 2017-05-11 2022-11-01 Microsoft Technology Licensing, Llc Cryptlet smart contract
US10325116B2 (en) * 2017-06-30 2019-06-18 Vmware, Inc. Dynamic privilege management in a computer system
US10671377B2 (en) * 2017-07-13 2020-06-02 Vmware, Inc. Method to deploy new version of executable in node based environments
CN107463376A (zh) * 2017-07-21 2017-12-12 珠海牛角科技有限公司 基于Javadoc的自动生成后端接口文档的方法及装置
CN107844294B (zh) * 2017-11-17 2020-05-19 杭州溪塔科技有限公司 一种高可用的合约执行方法及系统
CN112119423A (zh) * 2017-11-28 2020-12-22 耶鲁大学 形式化验证的系统和方法
CN108156022B (zh) * 2017-12-04 2021-07-09 北京奇艺世纪科技有限公司 一种服务调用方法、装置及电子设备
US20190188063A1 (en) * 2017-12-18 2019-06-20 Sap Se Mapping computer programs to network protocol methods
US11256712B2 (en) * 2018-02-05 2022-02-22 Accenture Global Solutions Limited Rapid design, development, and reuse of blockchain environment and smart contracts
WO2020005328A2 (en) * 2018-02-09 2020-01-02 Orbs Ltd. Decentralized application platform for private key management
JP7157348B2 (ja) * 2018-04-06 2022-10-20 日本電信電話株式会社 ブロックチェーンシステム、承認端末、スマートコントラクト登録方法、および、スマートコントラクト登録プログラム
CN108769173B (zh) * 2018-05-21 2021-11-09 阿里体育有限公司 运行智能合约的区块链实现方法及设备
US10754952B2 (en) * 2018-07-23 2020-08-25 Vmware, Inc. Host software metadata verification during remote attestation
US10896195B2 (en) * 2018-07-29 2021-01-19 International Business Machines Corporation Automatic generation of smart contracts
US11188911B2 (en) * 2018-08-21 2021-11-30 Bcdb, Inc. Object oriented smart contracts for UTXO-based blockchains
CN109375899B (zh) * 2018-09-25 2021-08-03 杭州趣链科技有限公司 一种形式验证Solidity智能合约的方法
US10871989B2 (en) * 2018-10-18 2020-12-22 Oracle International Corporation Selecting threads for concurrent processing of data
CN109710235B (zh) * 2018-12-29 2022-04-01 杭州趣链科技有限公司 一种基于Java智能合约业务逻辑的事务实现系统及方法
US11194600B2 (en) * 2019-01-16 2021-12-07 Vmware, Inc. Secure digital workspace using machine learning and microsegmentation
CN110959282B (zh) * 2019-03-04 2022-05-31 蚂蚁双链科技(上海)有限公司 用于智能合约的软件接口
CN110175022B (zh) * 2019-04-25 2023-10-13 平安科技(深圳)有限公司 自动生成pojo类的方法、装置及存储介质、计算机设备
US11526610B2 (en) * 2019-05-21 2022-12-13 Veracode, Inc. Peer-to-peer network for blockchain security
CN110297721B (zh) * 2019-06-24 2021-08-03 杭州趣链科技有限公司 一种基于java的智能合约的跨合约调用方法
US11573951B2 (en) * 2019-10-03 2023-02-07 Curvegrid, Inc. Systems, methods, and storage media for interfacing a user device with a decentralized architecture
KR102247233B1 (ko) * 2019-10-28 2021-05-03 주식회사 린아레나 다중 레이어 기반 스마트 컨트랙트 감사 방법 및 그 장치
SG11202010736YA (en) * 2019-11-08 2020-11-27 Alipay Hangzhou Inf Tech Co Ltd System and method for blockchain-based decentralized application development
US11641354B2 (en) * 2020-03-09 2023-05-02 Nant Holdings Ip, Llc Enhanced access to media, systems and methods

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120246614A1 (en) * 2011-03-23 2012-09-27 Microsoft Corporation Automated generation of client/driver communication interfaces
CN106919509A (zh) * 2017-03-09 2017-07-04 腾讯科技(深圳)有限公司 一种客户端生成方法、装置及电子设备
CN108304307A (zh) * 2018-01-24 2018-07-20 深圳圣马歌科技有限公司 一种区块链上智能合约的性能检测方法
CN109614102A (zh) * 2018-10-09 2019-04-12 平安科技(深圳)有限公司 代码自动生成方法、装置、电子设备及存储介质
CN110633076A (zh) * 2019-09-16 2019-12-31 杭州趣链科技有限公司 一种自动生成Solidity智能合约Java客户端程序的方法

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113885862A (zh) * 2021-09-29 2022-01-04 武汉斗鱼鱼乐网络科技有限公司 一种头像框复用方法、存储介质、电子设备

Also Published As

Publication number Publication date
US20220179651A1 (en) 2022-06-09
JP7315786B2 (ja) 2023-07-26
CN110633076A (zh) 2019-12-31
CN110633076B (zh) 2021-05-04
JP2022545489A (ja) 2022-10-27

Similar Documents

Publication Publication Date Title
WO2021052338A1 (zh) 智能合约客户端程序的生成方法、系统、设备和介质
US9235380B2 (en) Software modeling framework
WO2019153472A1 (zh) 接口自动化测试方法、装置、设备及存储介质
CN112748908B (zh) 基于SSM框架的Restful服务开发方法与装置
KR101795844B1 (ko) 런타임 시스템
CN110187902B (zh) 基于spring boot的项目改造方法、装置、设备及存储介质
US20060230379A1 (en) System and method for generating a user interface based on metadata exposed by object classes
US20140245134A1 (en) Remotable contracts for the web
US7818719B2 (en) Extending expression-based syntax for creating object instances
JP2009512014A (ja) オブジェクト合成に対する拡張可能メカニズム
CN112104709A (zh) 智能合约的处理方法、装置、介质及电子设备
WO2022199283A1 (zh) 用于确定调用栈栈帧的对象的方法、装置、设备和介质
CN112506492B (zh) 一种支持动态场景配置的可视化埋点方法
CN112685020A (zh) 动态创建服务接口的方法、装置、电子设备及存储介质
CN114968192A (zh) 一种项目创建方法、装置、计算机设备及存储介质
US20080196018A1 (en) SimpleBinding Extension
CN111324395B (zh) 调用方法、装置和计算机可读存储介质
US8196152B2 (en) Container context information propagation in an aspect-oriented environment
CN115934537A (zh) 接口测试工具生成方法、装置、设备、介质及产品
CN113342399B (zh) 应用项目的结构配置方法、装置及可读存储介质
CN115658187A (zh) 基于面向切面编程的类实现方法、装置、设备及介质
CN113626001A (zh) 一种基于脚本的api动态编排方法及装置
CN114219643A (zh) 一种交易调用方法、装置、设备及存储介质
CN112380142A (zh) 接口文档管理方法、装置和测试设备
Srinivasmurthy et al. Web2exchange: A model-based service transformation and integration environment

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: 20864348

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2022511395

Country of ref document: JP

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20864348

Country of ref document: EP

Kind code of ref document: A1