Disclosure of Invention
In order to solve the problems, the data creating method, the data creating device, the data creating equipment and the data creating storage medium based on the intelligent contracts solve the problems that when project development is carried out on the basis of a block chain, developers need to repeatedly develop parts with similar or identical functions in data, and accordingly workload is large and efficiency is low.
In a first aspect of the present application, a method for creating data based on an intelligent contract is provided, the method including:
receiving a command to create data;
calling a corresponding proxy contract according to the command; wherein the agent contract is a contract to manage the operation interface;
indexing a corresponding behavior contract according to the mapping relation in the agent contract;
analyzing the service logic relationship in the behavior contract, and generating a corresponding data contract by using a factory contract in the behavior contract according to the service logic relationship; wherein the data contract is for storing data.
Optionally, the method further includes:
pre-storing a common interface and a field in the intelligent contract in a base class form; wherein the intelligent contracts include agent contracts, behavioral contracts, and data contracts.
Optionally, the method further includes:
and adopting an inheritance mechanism to complete the creation of the intelligent contract through derivation of the class.
Optionally, the invoking a corresponding proxy contract according to the command includes:
judging whether the command is an object operation, if so, calling an object proxy contract; the object proxy contract is a functional interface for adding an operation object, deleting the operation object and modifying the operation object.
Optionally, the invoking a corresponding proxy contract according to the command includes:
judging whether the command is an account operation or not, and if so, calling an account agent contract; and the account proxy contract calls a function interface for creating an account, modifying the account and adding an external account.
Optionally, the generating a corresponding data contract by using the factory contract in the behavior contract includes:
generating a corresponding data contract by selecting a keyword contract in a construction function in the factory contract; wherein the constructor is pre-packaged in the plant contract.
Optionally, the method further includes:
the data contract is modified.
In a second aspect of the present application, there is provided an apparatus for creating data based on an intelligent contract, the apparatus comprising:
the device comprises a receiving unit, a calling unit, an indexing unit and an analyzing unit;
the receiving unit is used for receiving a command for creating data;
the calling unit is used for calling the corresponding proxy contract according to the command; wherein the agent contract is a contract to manage the operation interface;
the index unit is used for indexing a corresponding behavior contract according to the mapping relation in the agent contract;
the analysis unit is used for analyzing the business logic relationship in the behavior contract and generating a corresponding data contract by using a factory contract in the behavior contract according to the business logic relationship; wherein the data contract is for storing data.
In a third aspect of the present application, there is provided a data creation device based on an intelligent contract, the device comprising a processor and a memory:
the memory is used for storing program codes and transmitting the program codes to the processor;
the processor is used for executing the data creation method based on the intelligent contract according to the instructions in the program codes.
In a fourth aspect of the present application, a computer-readable storage medium is provided for storing program code for executing the above-mentioned intelligent contract-based data creation method.
Compared with the prior art, the technical scheme of the application has the advantages that:
in the technical scheme of the application, firstly, a command for creating data is received, and a corresponding proxy contract is called according to the command; the agent contract is a contract of a management operation interface, then indexes a corresponding behavior contract according to a mapping relation in the agent contract, finally analyzes a business logic relation in the behavior contract, and generates a corresponding data contract by utilizing a factory contract in the behavior contract according to the business logic relation; wherein the data contract is for storing data. According to the technical scheme provided by the embodiment of the application, the intelligent contract is designed in a layered mode according to the flow and the function of the project, and the data is created by adopting three intelligent contracts, namely the agent contract, the behavior contract and the design contract, so that the workload can be reduced, the efficiency can be improved, and the interference of malicious behaviors on the normal execution of the contract can be avoided. Specifically, by switching proxy contracts to other contracts, the business layer can index corresponding behavior contracts only by storing a small amount of proxy contracts, so that the redundancy of codes is greatly reduced; and the data creation can be completed by analyzing the service logic relationship in the behavior contract and generating a corresponding contract through a factory contract. The data contract generated by the factory contract can enable the contract instance to be generated more simply and conveniently. Data is stored through the data contract, so that other contracts can conveniently access the data and set fields. Meanwhile, the intelligent contract based on the block chain technology not only can exert the advantages of the intelligent contract in the aspect of cost efficiency, but also can avoid the interference of malicious behaviors on the normal execution of the contract. The intelligent contract is a block chain execution program, can be accurately and automatically executed, is written into a block chain in a reduced and coded form, and ensures that the whole processes of storage, reading and execution are transparent, traceable and uncontrollable by the characteristics of the block chain technology.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, fig. 1 is a flowchart of a data creation method based on intelligent contracts provided in the present application, which may include the following steps 101-104.
Step 101: a command to create data is received.
The command for receiving the creation data can be receiving data of an account opening data of a creation bank and the like.
It will be appreciated that the entity on the blockchain of the data may be an off-line bank, a bank branch or an entity of a ticket, etc.
Step 102: calling a corresponding proxy contract according to the command; wherein the agent contract is a contract to manage the operation interface.
And calling a corresponding proxy contract according to the received command, wherein the proxy contract is a contract used for managing an operation interface, does not realize the interface, only indexes and maps the available interface and is mainly used for switching to other contracts. For example, a proxy contract may define fields and a mount interface, and an incoming contract that will need to be mounted will be mounted in the contract interface abi by the eth.
It should be noted that a proxy contract may include an account proxy contract and an object proxy contract. For example, a functional operation in a project may be invoked via the two proxy contracts described above. The form of the account proxy contract may be accounting management. sol, and may call the relevant operation interfaces of all accounts, for example, function interfaces such as creating an account, modifying an account, adding an external account number, and the like; the object proxy contract may be in the form of object operator, and may call all object-related operation functions, for example, add an operation object, delete an operation object, modify an operation object, and other service-related function interfaces.
In a possible implementation manner, whether the command is an object operation may be determined first, and if so, an object proxy contract is invoked; the object proxy contract is a functional interface for adding an operation object, deleting the operation object and modifying the operation object.
In a possible implementation manner, whether the command is an account operation or not can be judged, and if the command is the account operation, an account proxy contract is called; and the account proxy contract calls a function interface for creating an account, modifying the account and adding an external account number.
Step 103: and indexing the corresponding behavior contract according to the mapping relation in the agent contract.
As shown in fig. 2, each operation interface is a separate behavior contract in the example of object contract, and the service layer only needs to know the contract address of object operator. The corresponding behavior contract is indexed through the agent contract, so that the design of a service layer is greatly facilitated, and the service layer can call any mounted behavior contract through the agent contract only by storing a small number of agent contract addresses.
Redundancy of data code may also be reduced by employing proxy contracts to index into corresponding behavioral contracts. It can be understood that, assuming that there are 100 contracts of bank branch organizations on the block chain, when the branch organization contract interface needs to be called externally due to the mechanism of the contract, the interface in the contract must be obtained through the address, if the agent mode is not used, each data contract needs to store its own abi (contract interface called by ethernet, JSON representation of intelligent contract interface, including variables, events and methods that can be called, abi is a binary representation of the intelligent contract interface), which will store the same abi in 100 branch organization contracts, greatly increasing the repetition rate of the contract codes, and using the agent mode, only store the same 100 abi in the agent contract, which greatly reduces the redundancy of the codes through the agent contract.
Step 104: analyzing the service logic relationship in the behavior contract, and generating a corresponding data contract by using a factory contract in the behavior contract according to the service logic relationship; wherein the data contract is for storing data.
Business logic relations in the behavior contract should be analyzed first so as to generate a data contract corresponding to each business logic. The operation interface is defined and realized in the behavior contract and is managed by the proxy contract. The behavior contract mainly takes responsibility on the aspect of business logic, and functions similar to java are packaged into a special function class. Behavior contracts do not hold data.
It should be noted that the behavior contract includes a special contract, i.e. a factory contract, and its operation interface is to generate and deploy a data contract. Each factory contract can generate a corresponding data contract, belongs to the contract generation contract in the intelligent contract grammar of the block chain, and is different from the traditional external call generation contract which generates a new contract through a construction function inside the contract. For example, a ticketing factory contract produces a ticketing contract, and a president factory contract produces a president contract. The data contract generated by the factory contract can enable the contract instance to be generated more simply and conveniently.
It should be noted that the data contract is mainly used to store various types of data, and the interface provided by the data contract is mainly used to obtain data and also can support modification of data. For example, a data contract may encapsulate a type of related data into individual data contracts, and a data contract contains various attribute fields that the data body should have, and a method for obtaining and setting each field to facilitate access and setting fields for other contracts.
For example, the command for receiving the creation data is to upgrade an account, a behavior contract of the account can be indexed through an account agent contract, and then the business logic relationship for upgrading the account is analyzed to find the account, upgrade the account and finally generate a new upgraded account. Then, the above three service logic relations are searched by using a search account behavior service logic contract, upgraded by using an account upgrade service logic behavior contract, and generated new account factory contract to generate new account data, and then data storage is performed by using a data contract.
In one possible implementation, the corresponding data contract may be generated by selecting a key contract of a constructor in the plant contract; wherein the constructor is pre-packaged in the plant contract. The design method comprises the following steps: each factory contract has a create function, and a new contract is generated by constructing a function through a new contract inside the function.
In one possible implementation mode, the common interfaces and fields in the intelligent contract are stored in advance in the form of a base class; wherein the intelligent contracts include agent contracts, behavioral contracts, and data contracts.
In the embodiment of the application, the intelligent contracts are designed in a layered mode and are designed into data contracts, agent contracts and behavior contracts according to different functions of corresponding contracts. When an intelligent contract is created, the common interface and the field saved in the base class form can be directly called, the same interface does not need to be repeatedly coded, and the working efficiency is greatly improved.
In one possible embodiment, the creation of the intelligent contract is accomplished by derivation of classes using an inheritance mechanism.
When the intelligent contract is created, more common interfaces and fields can be realized by derivation of the classes by adopting an inheritance mechanism. For example, a log event on which all contracts depend is to inherit a defined logable.
As shown in fig. 3, bank account factory is mainly a factory contract of a bank headquarter contract, bank branch office factory is a factory contract of a bank branch contract, account factory is mainly a common base class of an account class factory contract, factory is mainly a common base class of a factory class contract, meta. Specifically, the common base class of the factory contract of the banking institute contract and the factory contract of the banking branch institution contract is a common base class of the account class factory contract, and redundancy of the amount of the code can be avoided when the factory contract of the banking institute contract and the banking branch institution contract are created using the common base class of the account class factory contract.
In the embodiment of the application, when the intelligent contract is created, most common interfaces and fields can be written into the base class independently, so that the contract is convenient to update, and the readability of the contract code is higher.
In the technical scheme of the application, firstly, a command for creating data is received, and a corresponding proxy contract is called according to the command; the agent contract is a contract of a management operation interface, then indexes a corresponding behavior contract according to a mapping relation in the agent contract, finally analyzes a business logic relation in the behavior contract, and generates a corresponding data contract by utilizing a factory contract in the behavior contract according to the business logic relation; wherein the data contract is for storing data. According to the technical scheme provided by the embodiment of the application, the intelligent contract is designed in a layered mode according to the flow and the function of the project, and the data is created by adopting three intelligent contracts, namely the agent contract, the behavior contract and the design contract, so that the workload can be reduced, the efficiency can be improved, and the interference of malicious behaviors on the normal execution of the contract can be avoided. Specifically, by switching proxy contracts to other contracts, the business layer can index corresponding behavior contracts only by storing a small amount of proxy contracts, so that the redundancy of codes is greatly reduced; and the data creation can be completed by analyzing the service logic relationship in the behavior contract and generating a corresponding contract through a factory contract. The data contract generated by the factory contract can enable the contract instance to be generated more simply and conveniently. Data is stored through the data contract, so that other contracts can conveniently access the data and set fields. Meanwhile, the intelligent contract based on the block chain technology not only can exert the advantages of the intelligent contract in the aspect of cost efficiency, but also can avoid the interference of malicious behaviors on the normal execution of the contract. The intelligent contract is a block chain execution program, can be accurately and automatically executed, is written into a block chain in a reduced and coded form, and ensures that the whole processes of storage, reading and execution are transparent, traceable and uncontrollable by the characteristics of the block chain technology.
The embodiment of the present invention provides a data creating apparatus based on an intelligent contract in addition to the data creating method based on an intelligent contract, as shown in fig. 4, including:
a receiving unit 410, a calling unit 420, an indexing unit 430 and an analyzing unit 440, wherein:
the receiving unit 410 may be used to receive a command to create data;
the invoking unit 420 may be configured to invoke the corresponding proxy contract according to the command; wherein the agent contract is a contract to manage the operation interface;
the indexing unit 430 may be configured to index the corresponding behavior contract according to the mapping relationship in the proxy contract;
the analysis unit 440 may be configured to analyze a business logic relationship in the behavioral contract, and generate a corresponding data contract according to the business logic relationship by using a factory contract in the behavioral contract; wherein the data contract is for storing data.
The intelligent contract-based data creation apparatus in the embodiments disclosed in the present application may be implemented by various computer systems, which are described below with reference to fig. 5 and 6.
Fig. 5 is a block diagram of some embodiments of a smart contract-based data creation apparatus as disclosed herein. As shown in fig. 5, the apparatus of this embodiment includes: a memory 510 and a processor 520 coupled to the memory 510, the processor 520 being configured to execute the intelligent contract-based data creation method in any of the embodiments of the present application based on instructions stored in the memory 510.
Memory 510 may include, for example, system memory, fixed non-volatile storage media, and the like. The system memory stores, for example, an operating system, application programs, a boot loader, a database, and other programs.
Fig. 6 is a block diagram of still further embodiments of the intelligent contract-based data creation apparatus disclosed herein. As shown in fig. 6, the apparatus of this embodiment includes: memory 610 and processor 620 are similar to memory 510 and processor 520, respectively. An input output interface 630, a network interface 640, a storage interface 650, and the like may also be included. These interfaces 630, 640, 650 and the connections between the memory 610 and the processor 620 may be through a bus 660, for example. The input/output interface 630 provides a connection interface for input/output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 640 provides a connection interface for various networking devices, such as a database server or a cloud storage server. The storage interface 650 may provide a connection interface for external storage devices such as an SD card, a usb disk, and the like.
The present application further provides a computer-readable storage medium, described below in conjunction with fig. 7.
FIG. 7 is a block diagram of some embodiments of a computer-readable storage medium disclosed herein. As shown in fig. 7, the computer-readable storage medium of this embodiment includes: data creating means based on the intelligent contract in any one of the foregoing embodiments; and a host 710. Host 710 may include a host corresponding to an online environment and a host corresponding to a test environment. The host 710 is configured to receive a task issued by the intelligent contract-based data creation apparatus to perform intelligent contract-based data creation of corresponding content.
The data creating device based on the intelligent contract can be arranged in a management host, and the management host can be a continuous integration server. To further ensure the accuracy of the deployment update, the persistent integration server may be further divided into a persistent integration server in an online environment and a persistent integration server in a test environment. The related files (for example, RPM files) for automatic detection of abnormal data may be stored in the management host, or may be separately stored in the storage server, and the storage server may be further divided into a test environment storage server and an online environment storage server, so as to facilitate searching for the related files in different environments.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to some descriptions of the method embodiment for relevant points. The above-described apparatus embodiments are merely illustrative, and the units and modules described as separate components may or may not be physically separate. In addition, some or all of the units and modules may be selected according to actual needs to achieve the purpose of the solution of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is directed to embodiments of the present invention, and it is understood that various modifications and improvements can be made by those skilled in the art without departing from the spirit of the invention.