Deployment Method and Device of Smart Contract, Electronic Device, Storage Medium

By introducing a data migration interface into smart contracts, the problem of contract data migration during smart contract upgrades is solved, efficient contract upgrades and data migration are achieved, and changes in business logic and data structures are supported.

CN113986300BActive Publication Date: 2025-06-13NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111319763.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-09
Publication Date
2025-06-13
Estimated Expiration
2041-11-09

AI Technical Summary

Technical Problem

Existing smart contracts cannot effectively migrate contract data during upgrade, resulting in the inability to directly modify or upgrade the contract, affecting changes in business logic and modification of data structure.

Method used

By introducing a data migration interface into a smart contract, receiving contract deployment instructions, analyzing the contract address, and using the data migration interface in the blockchain, the contract data of the basic contract is migrated to a specified contract, realizing the upgrade and migration of contract data.

Benefits of technology

There is no need to use external data migration tools, which avoids the drawbacks of using tools, realizes efficient upgrades and data migration of smart contracts, and supports business needs to change the data structure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113986300B_ABST
    Figure CN113986300B_ABST
Patent Text Reader

Abstract

The present application provides a method and apparatus for deploying a smart contract, an electronic device, and a computer-readable storage medium. The method includes: receiving a contract deployment instruction for a basic contract; wherein the basic contract includes a data migration interface, and the contract deployment instruction is used to upgrade the basic contract and migrate the contract data of the basic contract; parsing the contract address of the basic contract from the contract deployment instruction; and migrating the contract data of the basic contract to a specified contract in a blockchain according to the contract address and the data migration interface. The solution of the present application does not require the aid of an external data migration tool, avoiding the drawbacks of using a data migration tool; in addition, the specified contract can change the data structure based on business requirements when being upgraded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and particularly to a method and device for deploying smart contracts, an electronic device, and a computer-readable storage medium. Background Art

[0002] The EVM (Ethereum Virtual Machine) is the most widely used virtual machine in the current blockchain field. The smart contract language it supports is Turing complete and can be used to implement smart contracts. Once a smart contract is published on the blockchain, it cannot be tampered with. Even if there are vulnerabilities in the smart contract that need to be modified or the business logic changes, it is impossible to directly modify and republish the original contract. Therefore, a reasonable upgrade mechanism needs to be considered in combination with the business scenario at the beginning of contract design. Summary of the Invention

[0003] The purpose of the embodiments of this application is to provide a method and device for deploying smart contracts, an electronic device, and a computer-readable storage medium, which are used to migrate contract data during the process of deploying a new contract to upgrade an old contract.

[0004] On the one hand, this application provides a method for deploying a smart contract, including:

[0005] Receiving a contract deployment instruction for a base contract; wherein, the base contract includes a data migration interface, and the contract deployment instruction is used to upgrade the base contract and migrate the contract data of the base contract;

[0006] Parsing out the contract address of the base contract from the contract deployment instruction;

[0007] According to the contract address and the data migration interface, migrating the contract data of the base contract to a specified contract in the blockchain.

[0008] In an embodiment, the data migration interface includes an index query interface and a data acquisition interface;

[0009] The step of migrating the contract data of the base contract to a specified contract in the blockchain according to the contract address and the data migration interface includes:

[0010] Using the contract address as an input parameter of the constructor of the specified contract, and calling the index query interface through the constructor to obtain the full amount of index information of the contract data;

[0011] Based on the index information in the full amount of index information, calling the data acquisition interface through the constructor to read the contract data corresponding to the index information and write it into the specified contract;

[0012] After the constructor is executed, a function processing event is generated; wherein, the function processing event indicates whether the contract data of the basic contract has been migrated.

[0013] In one embodiment, after the function processing event is generated, the method further includes:

[0014] If the function processing event indicates that the contract data has not been migrated, the index query interface is called through the upgrade function of the specified contract to obtain the full amount of index information;

[0015] Determine the index information of the migrated contract data as the completed index information;

[0016] Through the upgrade function, according to the full amount of index information and the completed index information, write the un-migrated contract data in the basic contract into the specified contract.

[0017] In one embodiment, the step of writing the un-migrated contract data in the basic contract into the specified contract through the upgrade function includes:

[0018] Determine the difference in the number of indexes between the full amount of index information and the completed index information, and determine whether the difference in the number of indexes is greater than the difference threshold;

[0019] If the difference in the number of indexes is greater than the difference threshold, call the data acquisition interface through the upgrade function to read the contract data between the completed index information and the difference threshold, and write it into the specified contract;

[0020] Update the completed index information based on the difference threshold, and return to the step of determining the difference in the number of indexes.

[0021] In one embodiment, after determining whether the difference in the number of indexes is greater than the difference threshold, the method further includes:

[0022] If the difference in the number of indexes is not greater than the difference threshold, call the data acquisition interface through the upgrade function to read the contract data between the completed index information and the full amount of index information, and write it into the specified contract.

[0023] In one embodiment, the step of writing into the specified contract includes:

[0024] According to the field mapping relationship between the first data structure of the basic contract and the second data structure of the specified contract, write each field data in the contract data into the specified contract.

[0025] In one embodiment, the designated contract includes a plurality of designated sub-contracts, each designated sub-contract has a corresponding data screening strategy, and the method further includes:

[0026] For each designated sub-contract, the full index information is screened according to the data screening strategy corresponding to the designated sub-contract to obtain the target index information corresponding to the designated sub-contract;

[0027] The full index information is replaced with the target index information corresponding to each specified sub-contract, and the contract data migration step is performed.

[0028] On the other hand, the present application also provides a smart contract deployment device, including:

[0029] A receiving module, configured to receive a contract deployment instruction for a base contract; wherein the base contract includes a data migration interface, and the contract deployment instruction is used to upgrade the base contract and migrate the contract data of the base contract;

[0030] A parsing module, used to parse the contract address of the basic contract from the contract deployment instruction;

[0031] An upgrade module is used to migrate the contract data of the basic contract to the specified contract in the blockchain according to the contract address and the data migration interface.

[0032] Furthermore, the present application also provides an electronic device, the electronic device comprising:

[0033] processor;

[0034] a memory for storing processor-executable instructions;

[0035] Wherein, the processor is configured to execute the above-mentioned smart contract deployment method.

[0036] In addition, the present application also provides a computer-readable storage medium, which stores a computer program, and the computer program can be executed by a processor to complete the above-mentioned smart contract deployment method.

[0037] After receiving the contract deployment instruction for the base contract, the present application solution parses the contract address of the base contract from the contract deployment instruction, and can migrate the contract data of the base contract to the specified contract based on the contract address and the data migration interface of the base contract. Since the base contract presets the data migration interface, during the deployment process of the specified contract, the contract data is migrated based on the contract address and data migration interface of the base contract, without the need for external data migration tools, thus avoiding the drawbacks of using data migration tools; in addition, the specified contract can change the data structure based on business needs when upgrading. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required to be used in the embodiments of the present application.

[0039] Figure 1 Schematic diagram of the application scenario of the intelligent contract deployment method provided by an embodiment of the present application;

[0040] Figure 2 Schematic diagram of the structure of the electronic device provided by an embodiment of the present application;

[0041] Figure 3 Schematic flowchart of the intelligent contract deployment method provided by an embodiment of the present application;

[0042] Figure 4 Schematic flowchart of the data migration method provided by an embodiment of the present application;

[0043] Figure 5 Schematic flowchart of the data migration method provided by another embodiment of the present application;

[0044] Figure 6 For Figure 5 detailed flowchart of step 430 in;

[0045] Figure 7 Schematic diagram of the data migration scenario provided by an embodiment of the present application;

[0046] Figure 8 Schematic diagram of the data migration scenario provided by another embodiment of the present application;

[0047] Figure 9 Schematic diagram of the data migration scenario provided by yet another embodiment of the present application;

[0048] Figure 10 Block diagram of the intelligent contract deployment device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] The following will describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application.

[0050] Similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.

[0051] The related technology upgrades contracts through the CD (Controller-Data) mode. In the CD mode, smart contracts are divided into two categories: the controller contract and the data contract. Among them, the controller contract obtains data by accessing the data contract, performs logical processing on the data, and then writes the processing result into the data contract. Generally, the controller contract does not need to store any data and completely depends on external inputs to determine the access to the data contract. In special cases, the controller contract can store the address or namespace of a certain fixed data contract (obtain the address of the data contract through the namespace at runtime). The data contract can provide the read and write interfaces for its stored data to the controller contract.

[0052] In one case, since the data contract is separated from the controller contract, during the upgrade, only the controller contract can be upgraded without upgrading the data contract. In another case, if the data contract needs to be upgraded, an external migration tool can be used to copy the data of the data contract outside the blockchain, and then write the data from outside the blockchain into the new version of the data contract.

[0053] For the first upgrade solution, when the business logic of the controller contract changes significantly and the data structure needs to be modified, this solution cannot support the modification of the data structure. For the second upgrade solution, the data migration tool needs to adapt to different data contracts, resulting in a high development cost; during the data migration process, the data contract needs to stop service, otherwise it is easy to appear dirty data; it requires the operation and maintenance personnel to apply for various data rights, and there are data security risks in manual operations.

[0054] Figure 1 It is a schematic diagram of the application scenario of the smart contract deployment method provided by the embodiment of the present application. As Figure 1 shown, the application scenario includes a user terminal 20 and a blockchain node 30; the user terminal 20 can be a device such as a host, a mobile phone, or a tablet computer, and is used to send a contract deployment instruction to the blockchain node 30 to upgrade the smart contract of the blockchain network; the blockchain node 30 can be a server, a server cluster, or a cloud computing center, and can respond to the contract deployment instruction to deploy a new smart contract.

[0055] As Figure 2 shown, this embodiment provides an electronic device 1, including: at least one processor 11 and a memory 12, Figure 2Take a processor 11 as an example. The processor 11 and the memory 12 are connected through a bus 10. The memory 12 stores instructions executable by the processor 11. The instructions are executed by the processor 11 so that the electronic device 1 can execute all or part of the processes of the methods in the following embodiments. In one embodiment, the electronic device 1 may be the above-mentioned blockchain node 30 for executing the method for deploying a smart contract.

[0056] The memory 12 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic memory, flash memory, a magnetic disk, or an optical disc.

[0057] This application also provides a computer-readable storage medium storing a computer program executable by the processor 11 to complete the method for deploying a smart contract provided by this application.

[0058] See Figure 3 , which is a schematic flowchart of the method for deploying a smart contract provided by an embodiment of this application. As Figure 3 shown, the method may include the following steps 310-step 350.

[0059] Step 310: Receive a contract deployment instruction for a base contract; wherein, the base contract includes a data migration interface, and the contract deployment instruction is used to upgrade the base contract and migrate the contract data of the base contract.

[0060] Here, the base contract is an old version of the smart contract, which contains data and business logic. The data migration interface provides the contract data in the base contract by providing a full-volume index query service for the contract data and a service for reading the contract data based on the index information.

[0061] The contract deployment instruction is used to deploy a new version of the smart contract, and the combined deployment instruction may include the smart contract code of the new version contract.

[0062] When there are vulnerabilities in the business logic of the basic contract or the business logic needs to be changed, developers can initiate a contract deployment instruction to the blockchain network through the user terminal. Any blockchain node in the blockchain network can receive the contract deployment instruction. The contract deployment instruction may carry the contract address of the basic contract, and this contract address is used to indicate the basic contract.

[0063] Step 320: Parse the contract address of the basic contract from the contract deployment instruction.

[0064] After obtaining the contract deployment instruction, the blockchain node can parse the contract deployment instruction to obtain the contract address of the basic contract.

[0065] Step 330: According to the contract address and the data migration interface, migrate the contract data of the basic contract to the specified contract in the blockchain.

[0066] Among them, the specified contract is the new version of the smart contract.

[0067] The blockchain node can parse the smart contract code from the contract deployment instruction and deploy the specified contract according to the smart contract code. During the process of deploying the specified contract, the blockchain node can access the basic contract based on the contract address and read the contract data through the data migration address of the basic contract, so as to write the contract data into the specified contract. After the specified contract is deployed, the contract data of the basic contract can be migrated to the specified contract.

[0068] Through the above measures, the specified contract integrating the data contract and the controller contract can complete the upgrade of the basic contract during the deployment process without relying on external data migration tools, avoiding the disadvantages of using data migration tools; in addition, the specified contract can change the data structure based on business requirements during the upgrade.

[0069] In addition, the specified contract deployed according to the smart contract code can provide a data migration interface, so that when subsequent contracts are updated, data can continue to be directly migrated through the data migration interface.

[0070] In one embodiment, the data migration interface may include an index query interface and a data acquisition interface. The index query interface is used to provide an index query service for the contract data; the data acquisition interface is used to provide a reading service for the contract data.

[0071] See Figure 4 For the flowchart of the data migration method provided by an embodiment of this application, as Figure 4 shown, when the blockchain node executes step 330, it can execute the following steps 331-step 333.

[0072] Step 331: Use the contract address as the input parameter of the constructor of the specified contract, and call the index query interface through the constructor to obtain the full-index information of the contract data.

[0073] Among them, the constructor is used to initialize the specified contract when creating the specified contract. In the solution of this application, the contract data is migrated through the constructor.

[0074] The full-index information is the index information of all contract data, and the index information is used to indicate the contract data. Exemplarily, the index information can be the number of each contract data. Generally, the number of contract data starts from zero and is continuous. At this time, the full-index information can be the maximum data number. Exemplarily, the index information can be the unique identifier of each contract data, which is used to indicate the contract data.

[0075] During the process of deploying the specified contract, the blockchain node can use the parsed contract address as the input parameter of the constructor and call the index query interface through the constructor parameter to obtain the full-index information.

[0076] Step 332: Based on the index information in the full-index information through the constructor, call the data acquisition interface, read the contract data corresponding to the index information, and write it into the specified contract.

[0077] After obtaining the full-index information, the blockchain node can call the data acquisition interface based on the constructor for each index information, so as to read the contract data corresponding to the index information and write the read contract data into the specified contract. The content of the contract data is determined by the business of the basic contract. Exemplarily, each contract data can include the user age, account balance, and user account address of a user.

[0078] The blockchain node can write the contract data read one by one into the specified contract through the constructor.

[0079] Step 333: When the constructor finishes execution, generate a function processing event; among them, the function processing event indicates whether the contract data migration of the basic contract is completed.

[0080] The constructor is executed only once and the amount of data it can process is limited. Exemplarily, the upper limit of the amount of data processed by the constructor is 1MByte.

[0081] When the total amount of contract data in the basic data does not exceed the processing capacity upper limit of the constructor, after the constructor finishes execution, data migration can be realized. When the total amount of contract data in the basic data is greater than the processing capacity upper limit of the constructor, after the constructor finishes execution, there is still contract data that has not been migrated.

[0082] In this case, an event generation mechanism can be set for the constructor in advance, so that after the constructor is executed, function handling events can be generated. After the blockchain node migrates the contract data through the constructor, it can determine whether all the contract data has been migrated based on the function handling events returned by the constructor.

[0083] In one embodiment, refer to Figure 5 , which is a schematic flowchart of the data migration method provided by another embodiment of the present application. As Figure 5 shown, the method may include the following steps 410-step 430.

[0084] Step 410: If the function handling event indicates that the contract data has not been migrated completely, obtain the full amount of index information by querying the interface of the upgrade function call index of the specified contract.

[0085] When the function handling event indicates that the contract data has not been migrated completely, the blockchain node can continue to execute the data migration work through the upgrade function. Here, the upgrade function is a pre-compiled function for migrating contract data. The upgrade function can obtain the contract address of the base contract from the constructor, thereby accessing the base contract through the contract address, and obtaining the full amount of index information through the index query interface of the base contract.

[0086] Step 420: Determine the index information of the migrated contract data as the completion index information.

[0087] The blockchain node can determine the index information of all the migrated contract data within the specified contract and use the above index information as the completion index information. Exemplarily, the index information is the number of each contract data, and the numbers of the contract data are consecutive and start from zero. At this time, the completion index information can be the maximum data number of the migrated contract data.

[0088] Step 430: Through the upgrade function, write the un-migrated contract data in the base contract into the specified contract according to the full amount of index information and the completion index information.

[0089] After determining the full amount of index information and the completion index information, the index information of the un-migrated contract data can be determined. The blockchain node can read the un-migrated contract data through the data acquisition interface through the upgrade function and write it into the specified contract item by item. Compared with the constructor, the upgrade function can be called repeatedly until all the contract data has been migrated.

[0090] Through the above measures, when the data volume of the contract data in the base contract exceeds the processing capacity of the constructor, the data migration work is continued through the upgrade function to ensure that all the contract data in the base contract is migrated to the specified contract.

[0091] In one embodiment, refer to Figure 6, for Figure 5 is a detailed process schematic diagram of step 430 in Figure 6 As shown, this process may include the following steps 431 - step 433.

[0092] Step 431: Determine the index quantity difference between the full - volume index information and the completed index information, and judge whether the index quantity difference is greater than the difference threshold.

[0093] Among them, the index data difference represents the quantity difference between the full - volume index information and the completed index information. The difference threshold can be pre - configured based on experience and is used to indicate the amount of data migrated by the upgrade function in batches.

[0094] Exemplarily, the full - volume index information is represented by the maximum number dataNumMax of all contract data, and the completed index information is represented by the maximum number dataNumFinished of the migrated contract data. Subtract dataNumFinished from dataNumMax to obtain the index quantity difference.

[0095] After obtaining the index data difference, judge whether the index data difference is greater than the difference threshold through the upgrade function.

[0096] Step 432: If the index quantity difference is greater than the difference threshold, call the data acquisition interface through the upgrade function, read the contract data between the completed index information and the difference threshold, and write it into the specified contract.

[0097] If the index data difference is greater than the difference threshold, it means that all contract data cannot be migrated by calling the upgrade function once. In this case, the blockchain node can call the data acquisition interface with a small number of upgrades to read the contract data between the completed index information and the difference threshold one by one, and write it into the specified contract.

[0098] Exemplarily, the index data difference is 1000, the completed index information dataNumFinished is 350, and the difference threshold is 200. The contract data with index information from 351 to 550 is written into the specified contract through the upgrade function.

[0099] Step 433: Update the completed index information based on the difference threshold, and return to the step of determining the index quantity difference.

[0100] After calling the upgrade function once, the completed index information can be updated based on the difference threshold, so that the completed index information can indicate all the contract data that has been migrated currently. After the update, return to step 431 and continue to execute the data migration work through the upgrade function.

[0101] The upgrade function can be preset with a feedback mechanism. After being called, it compares whether the updated completion index information is equal to the full-index information and returns the comparison result. If the comparison result is "yes", it means that all contract data has been migrated; if the comparison result is "no", it means that the contract data has not been migrated yet, and the upgrade function can be called again to continue the data migration work.

[0102] Through the above measures, the blockchain node can repeatedly call the upgrade function to perform batch data migration work until all data is migrated.

[0103] In one embodiment, after step 431 is executed, if the difference in the number of indexes is not greater than the difference threshold, the blockchain node can call the data acquisition interface through the upgrade function to read the contract data between the completion index information and the full-index information and write it into the specified contract.

[0104] When the difference in the number of indexes is not greater than the difference threshold, it means that the remaining contract data can be migrated in one batch process of the upgrade function. In this case, the blockchain node, through the upgrade function, calls the data acquisition interface to read the remaining contract data based on all the remaining index information and writes the contract data read one by one into the specified contract.

[0105] After the call is completed, the completion index information can be updated to be consistent with the full-index information, and the comparison result "yes" is returned. At this time, all contract data migration is completed.

[0106] In one embodiment, there are differences in the data structures of the basic contract and the specified contract. In this case, the smart contract code of the specified contract can include the mapping relationship between the fields of the data structure of the basic contract and the data structure of the specified contract.

[0107] When the blockchain node calls the constructor or the upgrade function to write the contract data into the specified contract, it can write the data of each field in the contract data into the specified contract according to the field mapping relationship between the first data structure of the basic contract and the second data structure of the specified contract.

[0108] Among them, the first data structure is the data structure of the basic contract; the second data structure is the data structure of the specified contract. The field mapping relationship is the mapping relationship between the fields in the second data structure and the fields in the first data structure.

[0109] Exemplarily, the first data structure of the base contract includes fields "Age", "Account Balance", "Address"; the second data structure of the specified contract includes fields "Age", "Account Balance", "Address", "Transaction Count". The field mapping relationship can indicate that "Age", "Account Balance", "Address" in the first data structure respectively correspond to "Age", "Account Balance", "Address" in the second data structure. The blockchain node can use the upgrade function to write the data of the "Age" field in the contract data to the "Age" field in the specified contract, write the data of the "Account Balance" field in the contract data to the "Account Balance" field in the specified contract, and write the data of the "Address" field in the contract data to the "Address" field in the specified contract.

[0110] See Figure 7 , which is a schematic diagram of the data migration scenario provided by an embodiment of the present application. As Figure 7 shown, one base contract corresponds to one specified contract. The contract deployment instruction can include the contract address of the unique base contract. By executing the solution of the present application, the contract data in the base contract is migrated to the uniquely corresponding specified contract.

[0111] See Figure 8 , which is a schematic diagram of the data migration scenario provided by another embodiment of the present application. As Figure 8 shown, multiple base contracts correspond to one specified contract. At this time, the contract deployment instruction can include the contract addresses of multiple base contracts. By executing the solution of the present application, the contract data of multiple base contracts can be integrated into one specified contract.

[0112] In this scenario, the contract data of multiple base contracts may be spliced into one contract data in the specified contract. To avoid migration errors, when the blockchain node calls the constructor or upgrade function for data migration, it can migrate the contract data of each base contract in sequence. As Figure 8 shown, the blockchain node can write Data A in the base contract 1 to the specified contract, then write Data B in the base contract 2 to the specified contract, and then write Data C in the base contract 3 to the specified contract.

[0113] In this scenario, the smart contract code of the specified contract can include multiple sets of field mapping relationships, so as to select the required data from each base contract for migration.

[0114] Figure 9 which is a schematic diagram of the data migration scenario provided by yet another embodiment of the present application. As Figure 9 shown, one base contract corresponds to multiple specified contracts. At this time, the contract deployment instruction can include the contract address of one base contract and the smart contract codes of multiple specified contracts. By executing the solution of the present application, the contract data of the base contract is split and written into multiple specified contracts.Figure 9 As shown, the blockchain node can write Data A in the base contract into the specified contract 1, write Data B in the base contract into the specified contract 2, and write Data C in the base contract into the specified contract 3.

[0115] In this scenario, the smart contract code corresponding to each specified contract respectively includes its corresponding field mapping relationship, so as to select the required data from the base contract for migration.

[0116] In one embodiment, the specified contract includes several specified sub - contracts, and each specified sub - contract has a corresponding data screening strategy. Here, the specified sub - contract is Figure 9 the specified contract in the scenario of multiple specified contracts. The data screening strategy is used to screen the contract data required by the specified sub - contract.

[0117] When the blockchain node deploys the specified sub - contract, for each specified sub - contract, it can screen the full - volume index information according to the data screening strategy corresponding to the specified sub - contract, so as to obtain the target index information corresponding to the specified sub - contract. Among them, the target index information is the index information of the data required by the specified sub - contract.

[0118] The blockchain node can replace the full - volume index information with the target index information corresponding to each specified sub - contract, and execute the contract data migration step, so as to migrate the contract data corresponding to the data screening strategy to each specified sub - contract.

[0119] Figure 10 is a block diagram of a deployment device for a smart contract according to an embodiment of the present invention. As Figure 10 shown, the device may include:

[0120] A receiving module 1010, configured to receive a contract deployment instruction for the base contract; wherein, the base contract includes a data migration interface, and the contract deployment instruction is used to upgrade the base contract and migrate the contract data of the base contract;

[0121] A parsing module 1020, configured to parse the contract address of the base contract from the contract deployment instruction;

[0122] An upgrading module 1030, configured to migrate the contract data of the base contract to the specified contract in the blockchain according to the contract address and the data migration interface.

[0123] The implementation processes of the functions and roles of each module in the above - mentioned device are specifically described in the implementation processes of the corresponding steps in the above - mentioned smart contract deployment method, and will not be elaborated here.

[0124] In several embodiments provided in this application, the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of this application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and a module, a program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0125] In addition, the functional modules in each embodiment of this application can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.

[0126] If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of this application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

Claims

1. A method for deploying a smart contract, characterized in that, it includes: Receiving a contract deployment instruction for a basic contract; wherein, the basic contract includes a data migration interface, and the contract deployment instruction is used to upgrade the basic contract and migrate the contract data of the basic contract; Parsing the contract address of the basic contract from the contract deployment instruction; According to the contract address and the data migration interface, migrating the contract data of the basic contract to a specified contract in the blockchain; wherein, the data migration interface includes an index query interface and a data acquisition interface; The step of migrating the contract data of the basic contract to a specified contract in the blockchain according to the contract address and the data migration interface includes: Using the contract address as an input parameter of the constructor of the specified contract, and calling the index query interface through the constructor to obtain the full amount of index information of the contract data; Based on the index information in the full amount of index information through the constructor, calling the data acquisition interface to read the contract data corresponding to the index information and write it into the specified contract; When the constructor is executed, generating a function processing event; wherein, the function processing event indicates whether the contract data of the basic contract has been migrated; If the function processing event indicates that the contract data has not been migrated, calling the index query interface through the upgrade function of the specified contract to obtain the full amount of index information; Determining the index information of the migrated contract data as the completed index information; Through the upgrade function, according to the full amount of index information and the completed index information, writing the un-migrated contract data in the basic contract into the specified contract.

2. The method according to claim 1, characterized in that, The step of writing the un-migrated contract data in the basic contract into the specified contract according to the full amount of index information and the completed index information through the upgrade function includes: Determining the difference in the number of indexes between the full amount of index information and the completed index information, and judging whether the difference in the number of indexes is greater than a difference threshold; If the difference in the number of indexes is greater than the difference threshold, calling the data acquisition interface through the upgrade function to read the contract data between the completed index information and the difference threshold and write it into the specified contract; Updating the completed index information based on the difference threshold and returning to the step of determining the difference in the number of indexes.

3. The method according to claim 2, characterized in that, After judging whether the difference in the number of indexes is greater than the difference threshold, the method further includes: If the difference in the number of indexes is not greater than the difference threshold, calling the data acquisition interface through the upgrade function to read the contract data between the completed index information and the full amount of index information and write it into the specified contract.

4. The method according to any one of claims 1-3, characterized in that, The step of writing into the specified contract includes: Write each field data in the contract data into the specified contract according to the field mapping relationship between the first data structure of the basic contract and the second data structure of the specified contract.

5. The method according to any one of claims 1-3, wherein, the specified contract includes a number of specified sub-contracts, and each specified sub-contract has a corresponding data screening strategy. The method further includes: For each specified sub-contract, screen the full amount of index information according to the data screening strategy corresponding to the specified sub-contract to obtain the target index information corresponding to the specified sub-contract; Replace the full amount of index information with the target index information corresponding to each specified sub-contract, and execute the migration step of the contract data.

6. A deployment device for a smart contract, wherein, comprising: a receiving module, configured to receive a contract deployment instruction for a basic contract; wherein, the basic contract includes a data migration interface, and the contract deployment instruction is used to upgrade the basic contract and migrate the contract data of the basic contract; a parsing module, configured to parse the contract address of the basic contract from the contract deployment instruction; an upgrade module, configured to migrate the contract data of the basic contract to a specified contract in the blockchain according to the contract address and the data migration interface; wherein, the data migration interface includes an index query interface and a data acquisition interface; The upgrade module is specifically configured to: Use the contract address as an input parameter of the constructor of the specified contract, and call the index query interface through the constructor to obtain the full amount of index information of the contract data; Based on the index information in the full amount of index information through the constructor, call the data acquisition interface to read the contract data corresponding to the index information and write it into the specified contract; After the constructor is executed, generate a function processing event; wherein, the function processing event indicates whether the contract data of the basic contract has been migrated; If the function processing event indicates that the contract data has not been migrated, call the index query interface through the upgrade function of the specified contract to obtain the full amount of index information; Determine the index information of the migrated contract data as the completed index information; Through the upgrade function, write the un-migrated contract data in the basic contract into the specified contract according to the full amount of index information and the completed index information.

7. An electronic device, wherein, the electronic device includes: a processor; a memory for storing instructions executable by the processor; wherein, the processor is configured to execute the deployment method of the smart contract according to any one of claims 1-5.

8. A computer-readable storage medium, wherein, the storage medium stores a computer program, and the computer program can be executed by a processor to complete the deployment method of the smart contract according to any one of claims 1-5.

Citation Information

Patent Citations

  • Intelligent contract data migration method and system

    CN112527781A

  • Data migration method and device, computer equipment and storage medium

    CN113515364A