Smart contract calling method and device based on block chain, equipment and storage medium
By creating a contract container on the accounting node and executing external contracts through gRPC communication, the data leakage risks and security problems in running external contracts in the container are solved, and higher data transmission security and contract call efficiency are achieved.
Patent Information
- Application Number
- CN202311696382.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-12
- Publication Date
- 2025-06-13
AI Technical Summary
When executing external contracts through container calls, there are problems with data breach risks and low security.
By receiving the user's business request on the accounting node, determining the contract type and contract ID, and pulling an external contract image from the local area based on the contract ID to create a contract container, establishing communication with the contract container through gRPC, executing external contracts and returning the result to local storage.
The logic of running external contracts in the container is realized, the execution results are stored locally on the nodes, the security of data transmission is improved, and the problem of low security of external contract logic and storage in the container in the prior art is solved.
Smart Images

Figure CN120144266A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of smart contracts, and particularly to a method, device, equipment and storage medium for calling smart contracts based on a blockchain. Background Art
[0002] A smart contract is a computer protocol designed to spread, verify or execute a contract in an informatized manner. Smart contracts allow for trusted transactions without a third party, and these transactions are traceable and irreversible. A blockchain network completes corresponding business logics by calling functions of smart contracts. In the process of developing and using smart contracts, there may be a situation of calling external contracts.
[0003] At present, when calling an external smart contract in a blockchain network, the contract call can be performed by constructing a virtual machine, but the virtualization overhead caused by using the constructed virtual machine for external contract calls is relatively large. Therefore, the existing calls for external contracts adopt the method of creating a container to start and run the external contract. However, currently, when the external contract is called and executed through the container, both the logic layer and the storage layer of the external contract are deployed in the container, and for important services in the blockchain network, there is a certain risk of data leakage. Therefore, further improvement is needed. Summary of the Invention
[0004] The purpose of the embodiments of the present invention is to provide a method, device, equipment and storage medium for calling smart contracts based on a blockchain, so as to solve the problem of low security when an external contract is called and executed through a container at present.
[0005] The specific technical solution of the present invention is as follows: In the first aspect of the embodiments of the present invention, a method for calling a smart contract based on a blockchain is provided, which is applied to a bookkeeping node. The method includes: Receiving a service request sent by a user, and determining the contract type and contract ID to be called according to the service request; the contract type includes an internal contract and an external contract; If the contract type to be called is an internal contract, using the SEVM engine to call and execute the internal contract corresponding to the contract ID to respond to the service request; If the contract type to be called is an external contract, calling an external contract engine, pulling an external contract image from the local according to the contract ID to create a contract container, and establishing communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; Starting the contract container, executing the external contract to respond to the service request, and returning the execution result of the external contract to local storage.
[0006] Further, receiving the service request sent by the user and determining the contract type and contract ID to be invoked according to the service request includes: The accounting node receives the service request sent by the user, parses the service request, and obtains the contract ID of the smart contract to be invoked by the user; Match and query in the local smart contract library according to the contract ID to determine the contract type corresponding to the contract ID.
[0007] Further, invoking the external contract engine and pulling the external contract image from the local to create a contract container according to the contract ID includes: Match the corresponding external contract engine according to the contract ID, start the external contract engine, and read the mirror file of the external contract image from the local external contract mirror library according to the contract ID; Instantiate the read external contract mirror file to obtain the contract container corresponding to the external contract.
[0008] Further, starting the contract container, executing the external contract to respond to the service request, and returning the execution result of the external contract to the local storage includes: Send the request parameters in the service request to the contract container and start the contract container to run the external contract service; The external contract service automatically executes the external contract according to the request parameters in the service request and outputs the execution result of the external contract; Encrypt the execution result of the external contract according to the preset encryption algorithm to obtain an encrypted execution file; Transmit the encrypted execution file to the local through gRPC communication and store it in the database.
[0009] Further, the construction process of the external contract image includes: Build an external contract project locally and write a corresponding external contract file based on a preset development language; the preset development languages include Java, GO, and NODEJS; Configure the dependency packages or libraries corresponding to the preset development language in the external contract file, and package the external contract project to form an external contract package; According to the external contract package and external contract information, use the Dockerfile tool to create a corresponding external contract image, obtain the corresponding mirror file, and store the mirror file of the external contract image in the local external contract mirror library; the external contract information includes contract ID, contract type, contract version, contract partition, development language type, constructor method, and initialization parameters.
[0010] Further, the method further includes: The current accounting node splits the local contract file into multiple contract file blocks, and encrypts each contract file block according to a preset grouping encryption algorithm to obtain a file signature corresponding to each contract file block; Obtain the contract permissions of other online accounting nodes in the partition to which the current accounting node belongs, and determine the contract synchronization nodes; Send multiple contract file blocks and their corresponding file signatures to the contract synchronization nodes through gRPC communication.
[0011] Further, the method further includes: After the offline accounting node goes online, the offline accounting node sends a contract synchronization request to other accounting nodes in its partition according to the contract file information of its own node; Other accounting nodes in the partition receive the contract synchronization request, compare the contract file information in the contract synchronization request with the local contract file information, and determine the contract files to be synchronized according to the comparison result; Other accounting nodes in the partition send or do not send the contract files to be synchronized to the offline accounting node according to the contract permissions configured by themselves.
[0012] In a second aspect, the present application provides a blockchain-based intelligent contract calling device, including: A request parsing module, configured to receive a service request sent by a user, and determine the contract type and contract ID to be called according to the service request; the contract type includes an internal contract and an external contract; An internal contract calling module, configured to, when the contract type to be called is an internal contract, use the SEVM engine to call and execute the internal contract corresponding to the contract ID to respond to the service request; An external contract calling module, configured to, when the contract type to be called is an external contract, call an external contract engine, pull an external contract image from the local according to the contract ID to create a contract container, and establish communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; An external contract service module, configured to start the contract container, execute the external contract to respond to the service request, and return the execution result of the external contract to local storage.
[0013] In a third aspect of the embodiments of the present invention, an electronic device is provided, including: One or more processors; A storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, enable the one or more processors to implement the blockchain-based intelligent contract calling method provided in any embodiment of the present invention.
[0014] In the fourth aspect of the embodiments of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, it implements the blockchain-based intelligent contract calling method provided by any embodiment of the present invention.
[0015] In the present invention, first, the type of contract to be called is determined according to the service request, and the intelligent contract of the corresponding contract type is called according to the corresponding contract ID to respond to the user's service request, realizing the classified execution of the intelligent contract and improving the calling efficiency of the intelligent contract. At the same time, when calling an external contract, an external contract image is pulled from the node local according to the contract ID to create a contract container, and the contract container is started to execute the external contract to respond to the service request. Finally, the execution result of the external contract is returned to the local storage, realizing the logic of running the external contract in the container and storing the execution result locally at the node, solving the problem of low data security caused by the existing technology that both the logic operation and storage of the external contract are deployed in the container. At the same time, the accounting node of the present invention establishes communication with the contract container through gRPC, further improving the security of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0017] Figure 1 is a flowchart of a blockchain-based intelligent contract calling method proposed in an embodiment of the present invention; Figure 2 is an architecture diagram of an intelligent contract proposed in an embodiment of the present invention; Figure 3 is a schematic diagram of a blockchain-based intelligent contract calling device proposed in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts belong to the scope of protection of the present invention.
[0019] Embodiment 1: Refer to Figure 1 and Figure 2 as shown, Figure 1It is a flowchart of a method for invoking a smart contract based on a blockchain proposed in an embodiment of the present invention. Figure 2 It is an architecture diagram of a smart contract proposed in an embodiment of the present invention. Figure 1 The shown method for invoking a smart contract is mainly applied to the accounting nodes (i.e., Figure 2 the AN nodes in) in the blockchain network. The accounting nodes are used to record the corresponding data generated by blockchain transactions and provide data query and simulation execution externally.
[0020] As Figure 1 shown, a method for invoking a smart contract based on a blockchain, which is applied to an accounting node, the method includes: S1: Receive a service request sent by a user, and determine the contract type and contract ID to be invoked according to the service request; the contract type includes internal contracts and external contracts; S2: If the contract type to be invoked is an internal contract, use the SEVM engine to invoke and execute the internal contract corresponding to the contract ID to respond to the service request; S3: If the contract type to be invoked is an external contract, call the external contract engine to pull the external contract image from the local to create a contract container according to the contract ID, and establish communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; S4: Start the contract container, execute the external contract to respond to the service request, and return the execution result of the external contract to local storage.
[0021] Further, in the embodiment of the present invention, receiving the service request sent by the user in step S1 and determining the contract type and contract ID to be invoked according to the service request includes, but is not limited to, the following sub-steps: S11: The accounting node receives the service request sent by the user, and parses the service request to obtain the contract ID of the smart contract to be invoked by the user; S12: According to the contract ID, perform a matching query in the local smart contract library through the smart contract routing to determine the contract type corresponding to the contract ID.
[0022] Specifically, when the accounting node receives a business request submitted by a user, it first parses the business request to obtain the contract ID to be called by the user and the request parameters of the relevant business. Among them, the request parameters of the business can be data query fields, transaction data, electronic contracts and other data. After obtaining the contract ID, the accounting node needs to perform type matching in the local smart contract according to the contract ID to determine the contract type called by the business request, so that the smart contract of the subsequent node can call the corresponding type of smart contract to respond to the business request. For example, when the contract type called by the user is an internal contract, the accounting node calls and executes the internal contract corresponding to the contract ID through the internal SEVM engine. Among them, the SEVM engine refers to the blockchain EVM virtual machine developed based on the solidity language.
[0023] Referring to Figure 2 The shown smart contract architecture exemplarily gives a schematic diagram of the call processes of two external contract images and one internal contract. Among them, the two external contract images are the Java external contract image and the GO external contract image respectively. After the smart contract routing sends an external contract startup instruction to start the external contract service, it is necessary to read the dependencies of the mirror file from the accounting node to execute the corresponding smart contract.
[0024] Furthermore, in the embodiment of the present invention, the step of using the SEVM engine to call and execute the internal contract corresponding to the contract ID to respond to the business request in step S2 specifically includes: the accounting node matches the corresponding internal contract file locally according to the contract ID, starts the EVM virtual machine of the solidity language to run the internal contract, and finally returns the execution result of the internal contract to the user and stores the execution result locally.
[0025] In a specific practice process, an internal contract for implementing data query is set inside the accounting node. When receiving a data query business request submitted by a user, the accounting node determines that the contract type to be called is an internal contract according to the contract ID in the data query business request, searches and matches the contract file for data query locally according to the contract ID, executes the internal contract through the EVM virtual machine, performs data query according to the query fields in the data query business request, returns the data query result to the user, and stores the execution record and execution result of the internal contract locally for subsequent traceability.
[0026] Furthermore, in the embodiment of the present invention, the step of pulling the external contract image from the local according to the contract ID to create a contract container in step S3 includes, but is not limited to, the following sub-steps: S31: Match the corresponding external contract engine according to the contract ID, start the external contract engine, and read the mirror file of the external contract image from the local external contract image library according to the contract ID. In the embodiment of the present invention, after determining the contract type, it is necessary to further match the corresponding external contract engine at the node according to the contract ID. For example, if the contract ID corresponds to the Java language engine, then match the corresponding Java language engine to obtain the external contract image.
[0027] S32: Instantiate the read external contract image file to obtain a contract container corresponding to the external contract.
[0028] Specifically, in the present invention, when instantiating the read external contract image file, first decompress the external contract image file to obtain the configuration file and jar package of the external contract image. The configuration file includes the top-level configuration of the image, the name and tag of the image, and the global configuration of the image. Among them, the global configuration of the image includes information such as the completion time of building the image, the build history, the docker version of building the image, and the root file system. When instantiating the external contract image file, use the docker run command to organize the operation and configuration information of each layer in the external contract image file to jointly start a new container, that is, the contract container corresponding to the external contract.
[0029] Specifically, when building and pulling up a contract container, the accounting node needs to establish communication with the contract container for data transmission. The embodiment of the present invention uses gRPC to establish communication. gRPC is a high-performance, open-source, and general RPC framework. It can directly call the objects or methods of the application on the server of another different machine just like calling local objects, making it easier to create distributed applications. gRPC is independent of the development language during invocation, supports the invocation of multiple development languages, and gRPC uses protocol buffer as the Interface Definition Language (IDL) to describe the service interface and the structure of the payload message. It can also generate data structures, server interfaces, and client stubs in the specified language through the proto3 tool, and has features such as supporting bidirectional streaming, message header compression, multiplexing of a single TCP, and server-side push. Therefore, by establishing gRPC communication with the contract container in the present invention, after the contract container executes the contract, the execution result can be pushed to the accounting node, realizing efficient inter-process communication.
[0030] Furthermore, in the embodiment of the present invention, starting the contract container in step S4, executing the external contract in response to the service request, and returning the execution result of the external contract to the local storage includes, but is not limited to, the following sub-steps: S41: Send the request parameters in the service request to the contract container and start the contract container to run the external contract service; S42: The external contract service automatically executes the external contract according to the request parameters in the service request and outputs the execution result of the external contract; S43: Encrypt the execution result of the external contract according to a preset encryption algorithm to obtain an encrypted execution file; S44: Transmit the encrypted execution file to the local through gRPC communication and store it in the database.
[0031] Specifically, the preset encryption algorithm in the embodiments of the present invention can adopt national encryption algorithms, namely SM1, SM2, SM3, and SM4 algorithms. Which specific algorithm is used to encrypt the execution result can be determined according to the file size of the execution result and the security of data transmission. For example, when the file is large and needs to be transmitted in slices, the SM4 algorithm can be used for grouped encryption transmission. When the file is small, the SM3 algorithm can also be used to calculate the message digest of the execution result. When receiving, the message digest is recalculated based on the received file for comparison, and the integrity of the file is determined according to the comparison result. The embodiments of the present invention adopt national encryption algorithms for gRPC communication, which can realize national encryption communication based on gRPC and improve the security of data transmission.
[0032] In addition, other types of encryption algorithms can also be used to encrypt and transmit the execution result of the external contract, which is specifically selected according to the actual situation, and will not be elaborated in the embodiments of the present invention.
[0033] Furthermore, in one embodiment, the construction process of the external contract image of the present invention includes: First, build an external contract project locally and write the corresponding external contract file based on a preset development language. The preset development languages include Java, GO, and NODEJS.
[0034] Then, configure the dependency packages or dependency libraries corresponding to the preset development language in the external contract file, and package the external contract project to form an external contract package. After the code of the external contract file is completed and packaged, the external contract information can be pre-configured.
[0035] Finally, based on the external contract package and the external contract information, use the Dockerfile tool to create the corresponding external contract image, obtain the corresponding image file, and store the image file of the external contract image in the local external contract image library. The external contract information includes contract ID, contract type, contract version, contract partition, development language type, constructor method, and initialization parameters.
[0036] Specifically, the external contract image is created based on Docker containers. After the external contract image is created, information such as the Docker version for building the image, the completion time of building the image, and the build history record needs to be added to the corresponding contract file.
[0037] Further, in one embodiment, the smart contract invocation method of the present invention further includes: The current accounting node splits the local contract file into multiple contract file blocks, and encrypts each contract file block according to a preset block encryption algorithm to obtain a file signature corresponding to each contract file block. Obtain the contract permissions of other online accounting nodes in the partition to which the current accounting node belongs, and determine the contract synchronization nodes. Send the multiple contract file blocks and their corresponding file signatures to the contract synchronization nodes through gRPC communication.
[0038] Specifically, the method in the embodiment of the present invention has a file active sending function, that is, the accounting node actively sends its own contract file to other accounting nodes in the partition for contract file synchronization. Since the contract file is usually large, it is necessary to split the contract file for transmission during transmission to ensure the transmission efficiency of the file.
[0039] Among them, the preset block encryption algorithm used by the present invention for splitting the contract file includes the SM4 algorithm and the DES algorithm to complete. Which algorithm is specifically used for block encryption transmission can be selected according to the actual situation.
[0040] Further, in one embodiment, the smart contract invocation method of the present invention further includes: After the offline accounting node goes online, the offline accounting node sends a contract synchronization request to other accounting nodes in the partition according to the contract file information of its own node. Other accounting nodes in the partition receive the contract synchronization request, compare the contract file information in the contract synchronization request with the local contract file information, and determine the contract files to be synchronized according to the comparison result. Other accounting nodes in the partition send / do not send the contract files to be synchronized to the offline accounting node according to the contract permissions configured by themselves.
[0041] Specifically, nodes in the partition may go offline. When they go online again, it is necessary to synchronize the contract files to ensure that user service requests can be responded to in a timely manner. Therefore, the method in the embodiment of the present invention is also configured with a file active pulling function, that is, after the offline accounting node goes online, it actively pulls the contract files from other online accounting nodes in the partition. By actively pulling the contract files, it can ensure that the node can respond to requests in a timely manner and improve the invocation efficiency of the smart contract.
[0042] In an embodiment of the present invention, the contract type to be invoked is first determined according to a service request, and the smart contract of the corresponding contract type is invoked according to the corresponding contract ID to respond to the user's service request, realizing the classified execution of smart contracts and improving the invocation efficiency of smart contracts. At the same time, when invoking an external contract, an external contract image is pulled from the node local according to the contract ID to create a contract container, and the contract container is started to execute the external contract to respond to the service request. Finally, the execution result of the external contract is returned to the local storage, realizing the logic of running the external contract in the container and storing the execution result locally at the node, and solving the problem of low data security caused by the existing technology that both the logic running and storage of the external contract are deployed in the container. At the same time, the accounting node of the present invention establishes communication with the contract container through gRPC, further improving the security of data transmission.
[0043] Embodiment 2: Refer to Figure 2 As shown, the present application provides a blockchain-based smart contract invocation device, including: A request parsing module, configured to receive a service request sent by a user, and determine the contract type and contract ID to be invoked according to the service request; the contract type includes an internal contract and an external contract; An internal contract invocation module, configured to, when the contract type to be invoked is an internal contract, use the SEVM engine to invoke and execute the internal contract corresponding to the contract ID to respond to the service request; An external contract invocation module, configured to, when the contract type to be invoked is an external contract, invoke an external contract engine, pull an external contract image from the local according to the contract ID to create a contract container, and establish communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; An external contract service module, configured to start the contract container, execute the external contract to respond to the service request, and return the execution result of the external contract to the local storage.
[0044] In the embodiment of the present invention, the service request is first parsed by the request parsing module to determine the type of contract to be called, and the contract calling module corresponding to the contract type is called according to the corresponding contract ID to execute the corresponding contract to respond to the user's service request, realizing the classified execution of smart contracts and improving the calling efficiency of smart contracts. At the same time, when the external contract calling module calls an external contract, it calls the corresponding external contract engine, pulls the external contract image from the node local according to the contract ID to create a contract container, and starts the contract container through the external contract service module to execute the external contract to respond to the service request, and finally returns the execution result of the external contract to the local storage, realizing the logic of running the external contract in the container and storing the execution result locally at the node, solving the problem of low data security caused by deploying both the logic running and storage of the external contract in the container in the prior art. At the same time, the accounting node of the present invention establishes communication with the contract container through gRPC, further improving the security of data transmission.
[0045] In the embodiment of the present invention, an electronic device is further provided, including: one or more processors. Among them, The storage device is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method flow of the smart contract calling method based on the blockchain provided in the above embodiment of the present invention.
[0046] In the embodiment of the present invention, a computer-readable storage medium is further provided, on which a computer program is stored, and when the program is executed by a processor, the method flow of the smart contract calling method based on the blockchain provided in the above embodiment of the present invention is implemented.
[0047] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present invention are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)), etc.
[0048] It should be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including", or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article, or device that includes a series of elements includes not only those elements but also other elements not expressly listed, or elements that are inherent to such process, method, article, or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article, or device that includes the element.
[0049] Each embodiment in this specification is described in a related manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and reference can be made to the corresponding part of the method embodiment for the relevant content.
[0050] The above are only the preferred embodiments of the present invention and are not intended to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention are all included within the protection scope of the present invention.
Claims
1. A method for invoking smart contracts based on blockchain, characterized in that, applied to the accounting node, the method includes: Receiving a service request sent by a user, and determining the contract type and contract ID to be invoked according to the service request; the contract type includes internal contracts and external contracts; If the contract type to be invoked is an internal contract, use the SEVM engine to invoke and execute the internal contract corresponding to the contract ID to respond to the service request; If the contract type to be invoked is an external contract, call the external contract engine, pull the external contract image from the local according to the contract ID to create a contract container, and establish communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; Start the contract container, execute the external contract to respond to the service request, and return the execution result of the external contract to local storage.
2. The method for invoking smart contracts based on blockchain according to claim 1, characterized in that, The receiving the service request sent by the user, and determining the contract type and contract ID to be invoked according to the service request includes: The accounting node receives the service request sent by the user, and parses the service request to obtain the contract ID of the smart contract to be invoked by the user; Match and query in the local smart contract library according to the contract ID to determine the contract type corresponding to the contract ID.
3. The method for invoking smart contracts based on blockchain according to claim 1, characterized in that, The calling the external contract engine, pulling the external contract image from the local according to the contract ID to create a contract container includes: Match the corresponding external contract engine according to the contract ID, start the external contract engine, and read the mirror file of the external contract image from the local external contract mirror library according to the contract ID; Instantiate the read external contract mirror file to obtain the contract container corresponding to the external contract.
4. The method for invoking smart contracts based on blockchain according to claim 1, characterized in that, The starting the contract container, executing the external contract to respond to the service request, and returning the execution result of the external contract to local storage includes: Send the request parameters in the service request to the contract container, and start the contract container to run the external contract service; The external contract service automatically executes the external contract according to the request parameters in the service request, and outputs the execution result of the external contract; Encrypt the execution result of the external contract according to a preset encryption algorithm to obtain an encrypted execution file; Transmit the encrypted execution file to the local through gRPC communication and store it in the database.
5. The method for invoking smart contracts based on blockchain according to claim 1, characterized in that, The construction process of the external contract image includes: Build an external contract project locally, and write a corresponding external contract file based on a preset development language; the preset development languages include Java language, GO language, and NODEJS language; Configure the dependency packages or dependency libraries corresponding to the preset development language in the external contract file, and package the external contract project to form an external contract package; According to the external contract package and external contract information, use the Dockerfile tool to create a corresponding external contract image, obtain the corresponding image file, and store the image file of the external contract image in the local external contract image library; the external contract information includes contract ID, contract type, contract version, contract belonging partition, development language type, constructor method, and initialization parameters.
6. The method for invoking an intelligent contract based on a blockchain according to claim 1, wherein, it further includes: The current accounting node splits the local contract file into multiple contract file blocks, and encrypts each contract file block according to a preset grouping encryption algorithm to obtain a file signature corresponding to each contract file block; Obtain the contract permissions of other online accounting nodes in the partition to which the current accounting node belongs, and determine the contract synchronization nodes; Send multiple contract file blocks and their corresponding file signatures to the contract synchronization nodes through gRPC communication.
7. The method for invoking an intelligent contract based on a blockchain according to claim 6, wherein, it further includes: After the offline accounting node goes online, the offline accounting node sends a contract synchronization request to other accounting nodes in its partition according to the contract file information of its own node; Other accounting nodes in the partition receive the contract synchronization request, compare the contract file information in the contract synchronization request with the local contract file information, and determine the contract files to be synchronized according to the comparison result; Other accounting nodes in the partition send / do not send the contract files to be synchronized to the offline accounting node according to the contract permissions configured by themselves.
8. An apparatus for invoking an intelligent contract based on a blockchain, wherein, it includes: A request parsing module, configured to receive a service request sent by a user, and determine the contract type and contract ID to be invoked according to the service request; the contract type includes internal contracts and external contracts; An internal contract invocation module, configured to, when the contract type to be invoked is an internal contract, use the SEVM engine to invoke and execute the internal contract corresponding to the contract ID to respond to the service request; An external contract invocation module, configured to, when the contract type to be invoked is an external contract, invoke an external contract engine, pull an external contract image from the local according to the contract ID to create a contract container, and establish communication with the contract container through gRPC; the external contract engine includes a Java language engine and a GO language engine; An external contract service module, configured to start the contract container, execute the external contract to respond to the service request, and return the execution result of the external contract to local storage.
9. An electronic device, wherein, it includes: One or more processors; A storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, enable the one or more processors to implement the method for invoking an intelligent contract based on a blockchain according to any one of claims 1 to 7.
10. A computer-readable medium, on which a computer program is stored, wherein, When the computer program is executed by a processor, it implements the blockchain-based intelligent contract invocation method according to any one of claims 1 to 7.