A smart contract upgrading method, a deployment method and an apparatus

By storing business data as mapped type variables in data contracts within smart contracts, the complexity and difficulty of smart contract upgrades can be solved by simply editing and deploying the business contracts, thus simplifying the upgrade process.

CN115827776BActive Publication Date: 2026-07-14NETEASE (HANGZHOU) NETWORK CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NETEASE (HANGZHOU) NETWORK CO LTD
Filing Date
2022-11-07
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Upgrading existing smart contracts is complex and difficult, especially for data contracts, which require redeployment and data migration steps that cannot be reduced.

Method used

By storing business data in data contracts as mapped type variables, and editing logic in business contracts to call data contracts, only the business contracts need to be deployed without changing the data contract structure, thus reducing data migration steps.

Benefits of technology

It simplifies the smart contract upgrade process, reduces the difficulty of upgrades, and avoids the redeployment and migration of data contracts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115827776B_ABST
    Figure CN115827776B_ABST
Patent Text Reader

Abstract

The application discloses an upgrading method of a smart contract, comprising: in response to a data contract upgrading request sent by a client, providing a business contract for the client to edit business logic corresponding to to-be-upgraded content in the business contract; in response to a business contract deployment request sent by the client, deploying the edited business contract on a blockchain, and writing an address of a data contract into the edited business contract; according to the address of the data contract contained in the edited business contract, the edited business contract calls the data contract, and saves a mapping type variable corresponding to the business logic edited in the edited business contract into the data contract. The method sets business data in the data contract as a mapping type variable in a data service separation mode, so that the data contract has a fixed data structure. Therefore, when the smart contract is upgraded, the data contract does not need to be redeployed, and the data migration step is reduced.
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 in particular to a method for upgrading smart contracts. This application further provides a method for deploying smart contracts, a device for upgrading smart contracts, a device for deploying smart contracts, an electronic device, and a computer-readable storage medium. Background Technology

[0002] Smart contracts are computer programs that run on a blockchain. They automatically execute their content when triggering conditions written in their source code are met. They are characterized by data transparency, immutability, and permanent operation, thus enjoying high user trust. In current technologies, smart contracts cannot be modified after deployment to a blockchain. Modifying or upgrading a smart contract is equivalent to rewriting and deploying a new one. Furthermore, it requires migrating business data from the old smart contract to the new one, making the upgrade process complex and difficult.

[0003] To address the aforementioned technical challenges, one current approach is to design smart contracts using a business data separation model. This involves setting up a collection of smart contracts, including data contracts and business contracts, aiming to separate business data from business logic within the smart contract to reduce data migration steps during upgrades. However, for existing smart contracts using this business data separation model, while upgrading the business contract allows for the continued use of the data contract and reduces data migration steps, upgrading the data contract requires redeploying it and migrating the business data, as changes to the business data alter the data structure. Therefore, the data migration steps cannot be reduced. Consequently, existing smart contracts still suffer from complex upgrade processes and high upgrade difficulty. Summary of the Invention

[0004] This application provides a method for upgrading and deploying smart contracts, as well as a device for upgrading and deploying smart contracts, an electronic device, and a computer-readable storage medium, to solve the problems of complex upgrade processes and high difficulty in upgrading existing smart contracts.

[0005] This application provides a method for upgrading a smart contract. The smart contract is a collection of contracts, including at least a data contract and a business contract. The data contract stores business data, and the business contract stores business logic. The business data is stored in the data contract in the form of mapped type variables. The method is applied to a server and includes:

[0006] In response to a data contract upgrade request sent by a client, the business contract is provided to the client so that the client can edit the business logic corresponding to the content to be upgraded in the business contract;

[0007] In response to the business contract deployment request sent by the client, the edited business contract is deployed on the blockchain, and the address of the data contract is written into the edited business contract;

[0008] Based on the address of the data contract contained in the edited business contract, the edited business contract calls the data contract and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0009] This application embodiment also provides a method for upgrading a smart contract, wherein the smart contract is a contract set including at least a data contract and a business contract, the data contract is used to store business data, the business contract is used to store business logic, and the business data is stored in the data contract in the form of a mapped type variable. The method is applied to a client and includes:

[0010] Send a data contract upgrade request to the server;

[0011] Receive the business contract provided by the server;

[0012] Edit the business logic corresponding to the content to be upgraded in the business contract;

[0013] A business contract deployment request is sent to the server so that the server deploys the edited business contract on the blockchain and calls the data contract according to the address of the data contract contained in the edited business contract, and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0014] This application also provides a method for deploying a smart contract, the method comprising:

[0015] Obtain a set of contracts including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract.

[0016] Deploy the permission management contract on the blockchain and obtain the address of the permission management contract;

[0017] Deploy the data contract on the blockchain and obtain the address of the data contract;

[0018] Write the address of the permission management contract into the data contract so that when the data contract is invoked by the client, the permission management contract can be used to authenticate the client's access permission to the data contract based on the address of the permission management contract contained in the data contract.

[0019] Deploy the business contract on the blockchain;

[0020] Write the address of the permission management contract into the business contract so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract;

[0021] The address of the data contract is written into the business contract so that the business contract can invoke the data contract based on the address of the data contract contained in the business contract.

[0022] This application embodiment also provides a smart contract upgrade device, wherein the smart contract is a contract set including at least a data contract and a business contract, the data contract is used to store business data, the business contract is used to store business logic, the business data is stored in the data contract in the form of a mapping type variable, the device is applied to the server, and the device includes: a business logic editing unit, a business contract deployment unit, and a data contract upgrade unit;

[0023] The business logic editing unit is used to respond to a data contract upgrade request sent by the client, and provide the client with the business contract so that the client can edit the business logic corresponding to the content to be upgraded in the business contract;

[0024] The business contract deployment unit is used to respond to the business contract deployment request sent by the client, deploy the edited business contract on the blockchain, and write the address of the data contract into the edited business contract;

[0025] The data contract upgrade unit is used to call the data contract according to the address of the data contract contained in the edited business contract, and save the mapping type variable corresponding to the business logic edited in the edited business contract to the data contract.

[0026] This application embodiment also provides a smart contract upgrade device, wherein the smart contract is a contract set including at least a data contract and a business contract, the data contract is used to store business data, the business contract is used to store business logic, the business data is stored in the data contract in the form of a mapping type variable, the device is applied to a client, and the device includes: an upgrade request sending unit, a business contract receiving unit, a business logic editing unit, and a deployment request sending unit;

[0027] The upgrade request sending unit is used to send a data contract upgrade request to the server;

[0028] The business contract receiving unit is used to receive the business contract provided by the server;

[0029] The business logic editing unit is used to edit the business logic corresponding to the content to be upgraded in the business contract.

[0030] The deployment request sending unit is used to send a business contract deployment request to the server so that the server deploys the edited business contract on the blockchain and calls the data contract according to the address of the data contract contained in the edited business contract, and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0031] This application embodiment also provides a smart contract deployment device, the device comprising: a smart contract acquisition unit, a permission management contract deployment unit, a data contract deployment unit; a first address writing unit, a business contract deployment unit, a second address writing unit, and a third address writing unit;

[0032] The smart contract acquisition unit is used to acquire a set of contracts including data contracts, business contracts, and permission management contracts. The data contracts are used to store business data, the business contracts are used to store business logic, and the permission management contracts are used to provide call permission authentication for the data contracts and the business contracts.

[0033] The permission management contract deployment unit is used to deploy the permission management contract on the blockchain and obtain the address of the permission management contract;

[0034] The data contract deployment unit is used to deploy the data contract on the blockchain and obtain the address of the data contract;

[0035] The first address writing unit is used to write the address of the permission management contract into the data contract, so that when the data contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the data contract based on the address of the permission management contract contained in the data contract;

[0036] The business contract deployment unit is used to deploy the business contract on the blockchain;

[0037] The second address writing unit is used to write the address of the permission management contract into the business contract, so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract;

[0038] The third address writing unit is used to write the address of the data contract into the business contract, so that the business contract can call the data contract according to the address of the data contract contained in the business contract.

[0039] This application also provides an electronic device, including: a memory and a processor;

[0040] The memory is used to store one or more computer instructions;

[0041] The processor is configured to execute one or more computer instructions to implement the above method.

[0042] This application also provides a computer-readable storage medium storing one or more computer instructions that, when executed by a processor, perform the above-described method.

[0043] Compared to existing technologies, the smart contract upgrade method provided in this application, based on the existing data-business separation model, sets the business data stored in the data contract as mapping type variables, giving the data contract a fixed data structure. When upgrading the data contract, it is only necessary to edit the business logic corresponding to the content to be upgraded into the business contract, redeploy the edited business contract, and write the address of the data contract into the edited business contract. The edited business contract can then call the data contract based on the address of the data contract it contains, saving the mapping type variables corresponding to the edited business logic into the data contract. Since only the new mapping type variables are saved in the data contract without changing the data structure, there is no need to redeploy the data contract, thereby reducing data migration steps and simplifying the smart contract upgrade process. This solves the problems of complex upgrade processes and high upgrade difficulty in existing smart contracts. Attached Figure Description

[0044] Figure 1 This is an application scenario diagram of a smart contract provided in an embodiment of this application;

[0045] Figure 2 This is a schematic diagram of the smart contract framework provided in the first embodiment of this application;

[0046] Figure 3 This is a flowchart of the smart contract deployment method provided in the second embodiment of this application;

[0047] Figure 4 This is a schematic diagram of the smart contract deployment method provided in the second embodiment of this application;

[0048] Figure 5 This is a flowchart of the smart contract upgrade method provided in the third embodiment of this application;

[0049] Figure 6 This is a flowchart of the smart contract upgrade method provided in the fourth embodiment of this application;

[0050] Figure 7 This is a signaling flowchart of the upgrade data contract provided in the fifth embodiment of this application;

[0051] Figure 8 This is a signaling flowchart of the upgrade service contract provided in the fifth embodiment of this application;

[0052] Figure 9 This is a signaling flowchart of the upgrade permission management contract provided in the fifth embodiment of this application;

[0053] Figure 10 This is a schematic diagram of the structure of the smart contract upgrade device provided in the sixth embodiment of this application;

[0054] Figure 11 This is a schematic diagram of the structure of the smart contract upgrade device provided in the seventh embodiment of this application;

[0055] Figure 12 This is a schematic diagram of the structure of the smart contract deployment device provided in the eighth embodiment of this application;

[0056] Figure 13 This is a schematic diagram of the structure of the electronic device provided in the ninth embodiment of this application. Detailed Implementation

[0057] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.

[0058] The following explanations of the technical terms used in the embodiments of this application are provided for ease of understanding.

[0059] Ethereum is an open-source blockchain platform that allows anyone to build and use decentralized applications, and is maintained by supporters from all over the world.

[0060] The Ethereum Virtual Machine (EVM) is the runtime environment for smart contracts on Ethereum. It compiles the source code of smart contracts into computer programs that can be executed on Ethereum, allowing users to create smart contracts on the EVM.

[0061] A blockchain is a chain of blocks. Each block contains specific information, and these blocks are linked together in chronological order of their creation to form the blockchain. The blockchain is stored on servers, and as long as at least one server in the entire blockchain system is functioning correctly, the entire blockchain is secure. These servers are the nodes in the blockchain system, primarily providing storage and computation. Compared to traditional networks, blockchain features data that is difficult to tamper with and is decentralized, making the data recorded on the blockchain more authentic and reliable. Blockchain can be applied in numerous fields, including finance, the Internet of Things and logistics, public services, digital copyright, insurance, and philanthropy.

[0062] Smart contracts, a core technology of blockchain, are a set of digitally defined computer protocols designed to disseminate, verify, or execute contracts in an informational manner. They are contracts that use computer language instead of legal language to record terms, are automatically executed by computer systems, allow for trusted transactions without a third party, and are traceable and irreversible. If blockchain is a database, then smart contracts are the application layer that enables blockchain technology to be applied to real-world scenarios.

[0063] A data contract is a module in a smart contract that stores business data in a data business classification model. A data contract can be called by a business contract to read the stored business data or to store the generated business data in it.

[0064] A business contract is a module in a smart contract that stores business logic within a data business classification model. It is a computer program that can run on the blockchain, reading the business data stored in the data contract during its execution and executing business applications.

[0065] Solidity, a smart contract programming language, is a new language built on top of Ethereum. It's a high-level programming language used to implement smart contracts. Influenced by C++, Python, and JavaScript, Solidity runs on the Ethereum Virtual Machine. Solidity is a statically typed language that supports features such as inheritance and library references, allowing users to define complex structure types.

[0066] The delegatecall function is a type of delegate invocation function in smart contract programming languages. It is the invocation mechanism by which a calling contract invokes functions of a target contract. When the target contract executes its business logic, it uses the context of the calling contract.

[0067] With the rapid development of blockchain technology, smart contracts, as one of the core technologies of blockchain, have received widespread attention. A smart contract is a computer program developed using the Ethereum Virtual Machine (EVM) and the contract programming language Solidity, running on the blockchain. Its greatest advantage lies in using program algorithms to replace manual arbitration and contract execution. Therefore, a smart contract can be described as program code that uses computer language to record contract terms instead of legal language. It can be automatically executed by a computer system; that is, when the triggering conditions written in its source code are met, the computer system can automatically execute the contract content.

[0068] Smart contracts are characterized by data transparency, immutability, and permanent operation. Their immutability lends them high user trust. However, this same immutability also makes upgrading smart contracts challenging. Even if an existing smart contract has defects requiring fixing or its business logic needs changing, it cannot be directly modified and redeployed. After running on the blockchain for a period, smart contracts often require business upgrades. Each upgrade necessitates rewriting and redeploying the source code, and also involves migrating business data from the old smart contract to the new one, making the upgrade process complex and difficult.

[0069] To address the aforementioned issues, two common smart contract models are currently employed, aiming to separate business data from business logic within smart contracts, thereby reducing data migration steps when business logic changes. The following is a brief explanation of these two existing smart contract models.

[0070] Firstly, there's the delegate contract pattern. This uses the `delegatecall` function in Solidity to store the business data of the smart contract in a delegate contract, executing only the smart contract's code and avoiding data migration during smart contract upgrades. However, when using this method to upgrade smart contracts, developers need to ensure that the data structure in the new smart contract is consistent with the data structure in the old smart contract. Therefore, developers need a complete understanding of the memory design in smart contracts to ensure the correctness of the upgrade, increasing the development and learning difficulty.

[0071] Second, there's the business data separation model. This involves setting up a collection of smart contracts, including data contracts and business contracts. Data contracts store only business data, while business contracts store only business logic, and the business contracts contain the addresses of the data contracts. When the business logic in a smart contract needs upgrading, only the business contract's source code needs to be modified and redeployed; the data contract can still be used directly, avoiding data migration steps. However, this method still cannot upgrade the data contract. When the business data in the smart contract changes, the data structure of the data contract changes, requiring redeployment. This further involves migrating business data from the old data contract to the new one, and cannot reduce the data migration steps. Therefore, the business data separation model can only upgrade the business contract, not the data contract.

[0072] As shown above, existing smart contract models, while maintaining the data structure (i.e., keeping the data contract unchanged), can achieve business logic changes (i.e., business contract upgrades) without requiring business data migration. However, when the data structure of a smart contract changes, existing smart contracts still suffer from complex upgrade processes and high upgrade difficulty.

[0073] To address the aforementioned issues, this application provides a method for upgrading smart contracts. Building upon the existing business data separation model, it sets the business data stored in the data contract as mapped type variables, giving the data contract a fixed data structure. When upgrading the data contract, only the business logic corresponding to the content to be upgraded needs to be edited into the business contract. Then, the business contract calls the data contract to write the mapped type variables corresponding to the edited business logic into the data contract. There is no need to re-edit the data contract or change its data structure. Therefore, redeployment of the data contract is unnecessary, reducing data migration steps and simplifying the smart contract upgrade process.

[0074] The following detailed description, in conjunction with specific embodiments and accompanying drawings, illustrates the smart contract upgrade method, deployment method, upgrade device, deployment device, electronic device, and computer-readable storage medium described in this application.

[0075] Figure 1 This is a diagram illustrating an application scenario of a smart contract provided in an embodiment of this application. For example... Figure 1 As shown, smart contracts are applied in digital asset trading scenarios. Smart contracts provide protocol terms for the trading of digital assets on the blockchain, realizing decentralized and secure trading of digital assets. Figure 1 This paper provides a transaction process for digital assets on the blockchain, realizing the transfer of digital assets from holders to buyers. This involves information interaction between the holder, buyer, issuer, and blockchain server. All of these information interaction processes are implemented by smart contracts deployed on the blockchain.

[0076] Beyond digital asset trading, smart contracts are also applied in various fields such as digital identity, securities trading, trade finance, fiscal data recording, supply chain, clinical medicine, social insurance, and the Internet of Things. For different business applications, programmers write the corresponding smart contract source code, then deploy the smart contracts on the blockchain, converting the source code into a computer-readable language, thereby enabling the business application on the blockchain.

[0077] The following embodiments will provide a detailed description of the smart contract upgrade method and deployment method provided in this application from the aspects of smart contract design, deployment and upgrade.

[0078] The first embodiment of this application provides a smart contract framework.

[0079] Figure 2 This is a schematic diagram of the smart contract framework provided in this embodiment.

[0080] like Figure 2 As shown, the smart contract framework provided in this embodiment includes: a data contract 1401, a business contract 1402, and a permission management contract 1403;

[0081] The data contract 1401 includes business data. The data structure of the data contract is a mapping type, and the business data is stored in the data contract 1401 in the form of mapping type variables.

[0082] The business contract 1402 includes: business logic.

[0083] The permission management contract 1403 includes the address of the data contract 1401 and the address of the business contract 1402, and is used to provide access permission authentication for the business contract 1402 to call the data contract 1401.

[0084] The data contract 1401 provided in this embodiment may further include: the address of the permission management contract 1403, which is used to provide access permission authentication for clients to call the data contract 1401.

[0085] The business contract 1402 provided in this embodiment may further include: the address of the data contract 1401 and the address of the permission management contract 1403, which are used to provide call permission authentication for clients to call the business contract 1402.

[0086] In an optional implementation of this embodiment, the design method of the smart contract framework may include the following steps:

[0087] Step S201: Set the smart contract as a contract set including a data contract, a business contract, and a permission management contract, wherein the data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract.

[0088] This embodiment provides a smart contract framework, which mainly includes three smart contract modules: data contract, business contract, and permission management contract.

[0089] The data contract stores the business data of the smart contract, while the business contract stores the business logic of the smart contract. In other words, the business contract provides the execution methods for the business application, and the data contract provides the data required during the execution of the business application and saves any new data generated during the execution process.

[0090] For example, a digital identity verification contract includes the following business logic: First, if the holder applies for a verifiable claim from the issuer, the issuer verifies the legitimacy and validity of the holder's identity; second, if the legitimacy and validity of the holder's identity are verified, the issuer issues a verifiable claim to the holder; third, if the holder presents a verifiable claim to a service provider and requests services, the service provider verifies the holder's signature, the issuer's identity and signature, and the claim information through an identifier registry; fourth, if verification is successful, the service provider provides services to the holder. The digital identity verification contract also includes the following business data: First, the inventor's name / person, the issuer's distributed digital identity identifier, etc., in the issuer information; second, the holder's name / person, the holder's distributed digital identity identifier, etc., in the holder information; third, the verifiable claim's issuance date, expiration date, and claim type information, etc., in the verifiable claim. The above business logic is stored in a business contract, and the business data is stored in a data contract. When this digital identity verification contract is triggered by a business application, the business logic in the business contract is executed. The business contract calls the business data in the data contract based on the execution status and progress of the business logic, and stores the newly generated business data in the data contract.

[0091] The access control contract includes two access control categories:

[0092] First, regarding the scope of contract invocation, the access control contract ensures that only business contracts have permission to invoke the data contract; invocations by other contracts or users will fail. Therefore, the access control contract needs to include both the address of the data contract and the address of the business contract.

[0093] Second, the scope of interface calls: The permission management contract provides clients with permission authentication for calling data contracts and / or business contracts, that is, authenticating whether the client has permission to call business contract interfaces and data contract interfaces. Therefore, the address of the permission management contract needs to be written into both the data contract and the business contract.

[0094] The access control contract is similar to a security authentication plugin integrated into a smart contract, ensuring the security of data contract and business contract calls.

[0095] For example, if programmer A needs to upgrade a business contract that stores business logic in a digital identity verification contract, programmer A initiates a call request to the business contract interface. The business contract will call the permission management contract based on the address of the stored permission management contract to authenticate whether programmer A has the permission to call the business contract interface. For example, after the permission management contract is called, it sends a username and password authentication request to the terminal where programmer A is located. Programmer A enters the username and password on his terminal and sends the authentication information to the permission management contract. The permission management contract verifies whether the username and password are true. If both are true, it can be determined that programmer A has the permission to call the business contract interface, and only then can programmer A upgrade the business contract.

[0096] Therefore, setting a smart contract as a collection of contracts including data contracts, business contracts, and permission management contracts not only enables the business applications of smart contracts but also ensures the security of smart contract calls.

[0097] Step S202: Set the data structure of the data contract to a mapping type, and store the business data in the data contract in the form of mapping type variables. The variable name of the mapping type variable corresponds to the data name of the business data, and the variable value of the mapping type variable corresponds to the data value of the business data.

[0098] A data structure is a way of storing and organizing data in a computer. It is a collection of data elements that have one or more specific relationships with each other; that is, a collection of data elements with a "structure," where "structure" refers to the relationships between the data elements. There are many types of data structures, commonly used ones include arrays, queues, linked lists, and hash tables.

[0099] A map is a data structure that stores entries composed of keys and data (e.g., key-value pairs, where the key is a key object and the value is a data object; the key can be used to retrieve the corresponding value). Map structures require that the keys of different entries be distinct, and multiple entries are not allowed to have the same key. An element in a map can be a variable, with the variable name used as the key object and the variable value used as the data object, combined to form a map-type variable.

[0100] The mapping type variable is a variable stored using a mapping type. The variable is stored as a key-value pair structure, where the key corresponds to the variable name and the value corresponds to the variable value. The variable value can be found by its name. For example, mapping type variables in a dictionary are key-value pairs of words and their definitions; mapping type variables in a roster are key-value pairs of ID numbers and names; and mapping type variables in a database are key-value pairs of data identifier codes and data information.

[0101] This embodiment provides an optional general data structure type for data contracts, namely, a mapping type. Business data will be stored in the data contract in the form of mapping type variables. The variable name of the mapping type variable can be mapped to the data name of the business data, and the variable value of the mapping type variable can be mapped to the data value of the business data.

[0102] For example, if a business data item is "the holder's name is Zhang San", then the business data item "the holder's name is Zhang San" will be stored in the data contract as a mapping type variable. The variable name is "holder's name" and the variable value is "Zhang San". Therefore, the mapping type variable corresponding to this business data can be represented as "holder's name - Zhang San".

[0103] In the smart contract framework provided in this embodiment, all business data is stored in the data contract in the form of mapped type variables. In an optional implementation of this embodiment, the variable name of the mapped type variable can be defined as a string type, and the variable value of the mapped type variable can be defined as any data type in the smart contract programming language.

[0104] The String type is a sequence of characters and belongs to the reference type. Any variable can be represented as a reference type, and a variable using a reference type is called a reference variable, which references a String object. For example, in the code `String string = "Hello World!"`, `String` is a reference type, `string` is a reference variable, and it references a String object containing the text "Hello World!".

[0105] Solidity, a smart contract programming language, is a new language built on Ethereum. It is a high-level programming language used to implement smart contracts. Solidity has various data types, commonly used ones include: data types (int, uint), string type (string), boolean type (bool), byte type (bytes), address type (address), etc.

[0106] Therefore, although the data structure of a data contract is a mapping type, the diversity of data types in smart contract programming languages ​​results in various forms for the mapping type variables stored in the data contract. The following are some commonly used forms of mapping type variables:

[0107] map(string => bool) _bool;

[0108] map(string => uint) _uint;

[0109] map (string =>string) _string;

[0110] map(string => bytes) _bytes;

[0111] map (string =>address) _address;

[0112] map(string => bytes) _bytes;

[0113] map (string =>bytes32) _bytes32;

[0114] map (string =>bytes1) _bytes1;

[0115] map (string =>mapping(address =>uint)) map_addressToUint;

[0116] map (string =>mapping(address =>bool)) map_addressToBool;

[0117] map (string =>mapping(address =>string)) map_addressToStriAddress;

[0118] map (string =>mapping(address =>address)) map_addressToString;

[0119] map (string =>mapping(string=>uint)) map_stringToUint;

[0120] map (string =>mapping(string=>bool)) map_stringToBool;

[0121] map (string =>mapping(string=>string)) map_stringToString;

[0122] map (string =>mapping(string=>address)) map_stringToAddress;

[0123] map (string =>mapping(address =>uint)) map_stringToUintes;

[0124] map (string =>mapping(address =>string)) map_stringToStringes, etc.

[0125] Different types of business data can be stored in data contracts using different forms of mapping type variables.

[0126] For example, if we need to define a `uint` type mapping variable for business data A based on its type, we can use the form `map(string => uint) _uint` to store the corresponding mapping variable for business data A in the data contract. If the data name of business data A is `sum`, its value is 1, and its type is `unit`, then business data A will be stored in the data contract as the mapping variable `_uint["sum"] = 1`.

[0127] Based on the smart contract framework provided in this embodiment, adding or deleting business data in the data contract will not affect the existing business data stored in the data contract. The new business data is simply added to the data contract as a mapping type variable. Therefore, the data structure of the data contract remains unchanged, and there is no need for redeployment or data migration, simplifying the smart contract upgrade process and reducing the difficulty of upgrading smart contracts.

[0128] The second embodiment of this application provides a method for deploying smart contracts, which deploys the acquired smart contracts on a blockchain.

[0129] Figure 3 This is a flowchart of the smart contract deployment method provided in this embodiment. The following is in conjunction with... Figure 3The deployment method of smart contracts provided in this embodiment will be described in detail. The embodiments described below are used to explain the technical solutions of this application and are not intended to limit actual use.

[0130] like Figure 3 As shown, the smart contract deployment method provided in this embodiment includes the following steps:

[0131] Step S301: Obtain a contract set including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract.

[0132] Obtain a set of contracts including data contracts, business contracts, and access control contracts. Data contracts store business data, business contracts store business logic, and access control contracts provide access authentication for the data contracts and business contracts. The data contracts, business contracts, and access control contracts have been described in detail in the first embodiment and will not be repeated here.

[0133] Step S302: Deploy the permission management contract on the blockchain and obtain the address of the permission management contract.

[0134] When deploying the smart contract obtained in step S301, the permission management contract should be deployed first. The purpose of deploying the permission management contract on the blockchain is twofold: firstly, to ensure that only clients with the necessary permissions can call the data contract and business contract; and secondly, to ensure that only the corresponding business contract has the right to call the data contract, while calls from other contracts or users to the data contract will fail. Therefore, when deploying the smart contract, not only should the address of the permission management contract be written into the data contract and business contract, but the addresses of the data contract and business contract should also be written into the permission management contract.

[0135] Step S303: Deploy the data contract on the blockchain and obtain the address of the data contract.

[0136] Once the access control contract is deployed on the blockchain, the data contract will be deployed and its address will be obtained, so that the address of the data contract can be written into the business contract and the access control contract later.

[0137] Step S304: Write the address of the permission management contract into the data contract, so that when the data contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the data contract based on the address of the permission management contract contained in the data contract.

[0138] The client refers to the terminal where the client calling the smart contract is located. The client refers to a professional who can develop, maintain, and upgrade the smart contract, such as a smart contract development engineer or a smart contract maintenance engineer.

[0139] The purpose of a client calling a smart contract can be to upgrade the smart contract or to fix vulnerabilities in the smart contract.

[0140] The data contract is deployed on the blockchain, and the address of the permission management contract is written into the data contract. When a client calls the data contract to trigger an operation, the data contract will call the permission management contract based on the written address to authenticate whether the client has the permission to call the data contract. If the client passes the authentication, the client can be allowed to call the data contract.

[0141] Authentication can be performed in various ways. For example, in response to a client's call to a data contract, the server sends a username and password authentication request to the client according to the authentication procedure in the permission management contract. The client fills in the username and password through the client and sends the authentication information to the server. The server, according to the authentication procedure in the permission management contract, determines that the client has the right to call the data contract if the username and password are correct; otherwise, it determines that the client does not have the right to call the data contract.

[0142] Step S305: Deploy the business contract on the blockchain.

[0143] Once the permission management contract and data contract are deployed on the blockchain, the business contract will be deployed.

[0144] Step S306: Write the address of the permission management contract into the business contract, so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract.

[0145] Step S307: Write the address of the data contract into the business contract so that the business contract can call the data contract based on the address of the data contract contained in the business contract.

[0146] The business contract is deployed on the blockchain, and the address of the permission management contract is written into the business contract. When the client calls the business contract to trigger an operation, the business contract will call the permission management contract to authenticate whether the client has the permission to call the business contract based on the written address of the permission management contract. If the client passes the authentication, the client can be allowed to call the business contract.

[0147] By deploying the business contract on the blockchain and writing the address of the data contract into the business contract, when the client upgrades the data contract, since the business data is stored in the data contract in the form of a mapping type variable, the business logic corresponding to the content to be upgraded can be edited in the business contract, and then the mapping type variable corresponding to the business logic edited in the business contract can be written into the data contract through the call of the data contract by the business contract, thereby realizing the upgrade of the data contract.

[0148] The smart contract deployment method provided in this embodiment further includes: obtaining the address of the business contract; writing the address of the data contract and the address of the business contract into the permission management contract, so that when the business contract calls the data contract, the permission management contract can be used to authenticate the business contract's calling permission to the data contract.

[0149] When a business contract calls a data contract, an authorization authentication is required. Therefore, the addresses of the corresponding data contract and business contract are written into the authorization management contract. The authorization management contract can determine whether the business contract calling the data contract is the corresponding business contract.

[0150] For example, data contract M and business contract N are corresponding contract modules within the same smart contract. The addresses of data contract M and business contract N are written into the permission management contract L. When a business contract X calls data contract M, the permission management contract L verifies whether business contract X has the permission to call data contract M. If the address of business contract X matches the address of business contract N, then business contract X, which calls data contract M, is business contract N, and business contract X can call data contract M. If the address of business contract X does not match the address of business contract N, then business contract X, which calls data contract M, is not business contract N, and business contract X cannot call data contract M.

[0151] This embodiment provides an optional method for deploying smart contracts. Figure 4 This is a schematic diagram of the smart contract deployment method provided in this embodiment.

[0152] like Figure 4 As shown, the smart contract deployment method provided in this embodiment includes the following steps:

[0153] First, obtain the smart contract 41, which includes the data contract 411, the business contract 412, and the permission management contract 413.

[0154] Second, deploy the permission management contract 413 on the blockchain 42 and obtain the address 433 of the permission management contract.

[0155] Third, deploy data contract 411 on blockchain 42 and obtain the address 431 of the data contract.

[0156] Fourth, write the address 433 of the permission management contract into the data contract 411, and write the address 431 of the data contract into the permission management contract 413.

[0157] Fifth, deploy business contract 412 on blockchain 42 and obtain the address 432 of the business contract.

[0158] Sixth, write the address 433 of the permission management contract into the business contract 412, and write the address 432 of the business contract into the permission management contract 413.

[0159] Seventh, write the data contract address 431 into the business contract 412.

[0160] The second embodiment described above provides a specific implementation of the smart contract deployment method provided in this application, which includes, but is not limited to, the method described in the second embodiment above.

[0161] The third embodiment of this application provides a method for upgrading smart contracts. The smart contract provided in this embodiment is a collection of contracts, including at least a data contract and a business contract. The data contract is used to store business data, and the business contract is used to store business logic. The business data is stored in the data contract in the form of a mapped type variable. The data contract and the business contract have been described in detail in the first embodiment of this application, and will not be repeated here.

[0162] The smart contract upgrade method provided in this embodiment is applied to the server side, and mainly provides an upgrade method for data contracts.

[0163] The server refers to the terminal that drives smart contracts to run on the blockchain. It can be a physical terminal or a virtual terminal. It can be a standalone server, a terminal that runs smart contracts, or a terminal that deploys the blockchain. There are no restrictions here.

[0164] Figure 5 This is a flowchart of the smart contract upgrade method provided in this embodiment.

[0165] like Figure 5 As shown, the smart contract upgrade method provided in this embodiment includes the following steps:

[0166] Step S501: In response to the data contract upgrade request sent by the client, the business contract is provided to the client so that the client can edit the business logic corresponding to the content to be upgraded in the business contract.

[0167] The data contract upgrade request can be a request sent by the client to the server through the client, or it can be a request sent by the client to the server when the client triggers an upgrade operation on the data contract through the client.

[0168] Upon receiving a data contract upgrade request from the client, the server can provide the business contract to the client, giving the client the authority to edit the business logic within the contract.

[0169] The client, based on pre-defined upgrade content, edits the corresponding business logic in the business contract. For example, it encodes the variable names and values ​​of the mapping type variables corresponding to the business data to be added in the business contract. Another example is changing the value of the mapping type variable corresponding to the business data to be removed to zero in the business contract.

[0170] Step S502: In response to the business contract deployment request sent by the client, the edited business contract is deployed on the blockchain, and the address of the data contract is written into the edited business contract.

[0171] The business contract deployment request refers to the request information sent by the client to the server to deploy the edited business contract on the blockchain.

[0172] Upon receiving the request, the server can deploy the edited business contract on the blockchain and write the address of the data contract into the edited business contract.

[0173] Step S503: Based on the address of the data contract contained in the edited business contract, the edited business contract calls the data contract and saves the mapping type variable corresponding to the business logic edited in the edited business contract to the data contract.

[0174] Since the address of the data contract has been written into the edited business contract, the business contract can call the data contract based on the address of the data contract, and save the mapping type variables corresponding to the business logic edited in the edited business contract into the data contract, thereby realizing the upgrade of the data contract.

[0175] In an optional implementation of this embodiment, the smart contract further includes a permission management contract, which is used to provide call permission authentication for the data contract and the business contract. The permission management contract has been described in detail in the first embodiment of this application, and will not be repeated here.

[0176] In another optional implementation of this embodiment, before the step of providing the business contract to the client, the method further includes:

[0177] First, based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to authenticate whether the client has the permission to call the data contract and the business contract;

[0178] Second, based on the authentication result, determine whether to provide the business contract to the client, specifically as follows:

[0179] If the client has the authority to invoke the data contract and the business contract, then the business contract is provided to the client;

[0180] If the client does not have the permission to invoke the data contract and the business contract, then the business contract will not be provided to the client.

[0181] When the server receives a data contract upgrade request from the client, it can call the permission management contract to authenticate whether the client has the permission to call the data contract. If the client passes the authentication, the client can be allowed to call the data contract.

[0182] Since the business data stored in the data contract exists in the form of mapped type variables, these mapped type variables need to be coded and defined in the business contract. Therefore, it is also necessary to call the permission management contract to authenticate whether the client has the permission to call the business contract. If the client is authenticated, then the client can be allowed to call the business contract.

[0183] The client needs to have access to both the data contract and the business contract in order to upgrade the data contract. Upgrading the data contract is impossible if either contract access is missing. This access control authentication ensures the security of the smart contract.

[0184] In an optional implementation of this embodiment, after the steps of deploying the edited business contract on the blockchain and writing the address of the data contract into the edited business contract, the method further includes:

[0185] First, obtain the address of the edited business contract;

[0186] Second, the address of the edited business contract is written into the permission management contract;

[0187] Third, the address of the permission management contract is written into the edited business contract.

[0188] Through the above steps, the deployment of the new business contract (i.e., the edited business contract) on the blockchain is completed. The method for deploying the business contract on the blockchain has been described in detail in the second embodiment of this application, and will not be repeated here.

[0189] In another optional implementation of this embodiment, before the step of the edited business contract calling the data contract based on the address of the data contract contained in the edited business contract, the method further includes:

[0190] First, the permission management contract is invoked to verify whether the edited business contract has the permission to call the data contract.

[0191] After the edited business contract is deployed on the blockchain, the address of the edited business contract is written to the permission management contract, and the addresses of the data contract and the permission management contract are written to the edited business contract. Furthermore, as can be seen from the smart contract deployment method provided in the second embodiment of this application, the permission management contract stores the addresses of both the data contract and the business contract.

[0192] Once the server deploys the edited business contract on the blockchain, it invokes the permission management contract based on the address of the data contract written in the edited business contract and the address of the permission management contract. This verifies whether the edited business contract has the permission to access the data contract. If the address of the edited business contract matches the address of the business contract stored in the permission management contract, then the edited business contract has the permission to access the data contract.

[0193] Second, based on the authentication results, determine whether the edited business contract can call the data contract, specifically as follows:

[0194] If the edited business contract has the permission to call the data contract, then it can call the data contract;

[0195] If the edited business contract does not have permission to call the data contract, then the data contract cannot be called.

[0196] This embodiment primarily provides a method for upgrading a data contract in a smart contract. The business data stored in the data contract exists in the form of mapped type variables. The variable name of the mapped type variable corresponds to the data name of the business data and is of string type. The variable value of the mapped type variable corresponds to the data value of the business data and can be any data type in the smart contract programming language. This part has been described in detail in the first embodiment of this application and will not be repeated here.

[0197] Because business data is stored as mapped type variables, the data structure of the data contract is fixed as a mapped type. This means that when the data contract needs to be upgraded, only the business logic corresponding to the content to be upgraded needs to be edited in the business contract. Then, the business contract calls the data contract to write the mapped type variables corresponding to the edited business logic into the data contract. There is no need to re-edit the data contract or change its data structure. Therefore, there is no need to redeploy the data contract or migrate the business data.

[0198] The fourth embodiment of this application provides a method for upgrading smart contracts. The smart contract provided in this embodiment is a collection of contracts, including at least a data contract and a business contract. The data contract is used to store business data, and the business contract is used to store business logic. The business data is stored in the data contract in the form of a mapped type variable. The data contract and the business contract have been described in detail in the first embodiment of this application, and will not be repeated here.

[0199] The smart contract upgrade method provided in this embodiment is applied to the client side, and mainly provides an upgrade method for data contracts.

[0200] The client refers to the terminal where the client calling the smart contract is located. The client refers to a professional who can develop, maintain, and upgrade the smart contract, such as a smart contract development engineer or a smart contract maintenance engineer.

[0201] Figure 6 This is a flowchart of the smart contract upgrade method provided in this embodiment.

[0202] like Figure 6 As shown, the smart contract upgrade method provided in this embodiment includes the following steps:

[0203] Step S601: Send a data contract upgrade request to the server.

[0204] The data contract upgrade request can be a request sent by the client to the server through the client, or it can be a request sent by the client to the server when the client triggers an upgrade operation on the data contract through the client.

[0205] Step S602: Receive the business contract provided by the server.

[0206] After receiving a data contract upgrade request from the client, the server will call the permission management contract to verify whether the client has the permission to invoke the data contract and business contract. If it is determined that the client has the permission to invoke the data contract and business contract, the server will provide the business contract to the client.

[0207] Step S603: Edit the business logic corresponding to the content to be upgraded in the business contract.

[0208] The client edits the corresponding business logic in the business contract based on the pre-set content to be upgraded.

[0209] The upgrade content provided in this embodiment includes: adding first business data to the data contract. Correspondingly, editing the business logic corresponding to the upgrade content in the business contract includes: editing the variable name and variable value of the mapping type variable corresponding to the first business data in the business contract, so that the server can save the first business data as a mapping type variable into the data contract according to the variable name and variable value edited in the edited business contract.

[0210] The following example illustrates how to edit the business logic corresponding to the first business data in a business contract, and how to save the mapping type variable corresponding to the business logic in the data contract.

[0211] For example: The original data contract stores gender data (stored as a mapped type variable), and we need to add age data to the original data contract. The original business contract includes the business logic for gender data. Therefore, by simply editing the business logic for the variable name and value of the mapped type variable corresponding to the age data in the original business contract, subsequent steps (including the deployment of the new business contract and the new business contract calling the original data contract) will save the age data as a mapped type variable in the data contract. See Table 1 for details.

[0212]

[0213] As shown in Table 1, the original data contract only included the mapping type variable uint["gender"]=1 corresponding to gender data, and the original business contract only edited the business logic corresponding to gender data. When it is necessary to add age data to the data contract, it is only necessary to add the business logic corresponding to age data to the original business contract. That is, edit the variable name and variable value of the mapping type variable corresponding to age data in the business contract. Then, through subsequent steps (including: deployment of the new business contract, the new business contract calling the original data contract, etc.), the mapping type variable uint["age"]=30 corresponding to age data will be saved in the original data contract, forming a new data contract. The new data contract only adds the mapping type variable uint["age"]=30 corresponding to age data to the original mapping type variable uint["gender"]=1, without changing the data structure. Therefore, it is not necessary to redeploy the new data contract.

[0214] The upgrade content provided in this embodiment also includes: reducing the second business data in the data contract, and correspondingly editing the business logic corresponding to the upgrade content in the business contract, including: editing the variable value of the mapping type variable corresponding to the second business data to zero in the business contract, so that the server can delete the second business data from the data contract according to the variable value edited in the edited business contract.

[0215] The following example illustrates how to edit the business logic corresponding to the second business data in a business contract, and how to delete the mapping type variable corresponding to that business logic from the data contract.

[0216] For example, if the original data contract stores gender and age data (both stored as mapped type variables), and the gender data needs to be deleted from the original data contract, and the original business contract includes business logic for both gender and age data, then simply changing the value of the mapped type variable corresponding to the gender data to zero in the original business contract will automatically delete the gender data from the data contract through subsequent steps (including: deployment of the new business contract, the new business contract calling the original data contract, etc.). See Table 2 for details.

[0217]

[0218] As shown in Table 2, the original data contract includes a mapping type variable `uint["gender"]=1` for gender data and a mapping type variable `uint["age"]=30` for age data. The original business contract also edited the business logic corresponding to gender and age data. When gender data needs to be removed from the data contract, it is only necessary to set the value of the mapping type variable corresponding to gender data to zero in the original business contract. Then, through subsequent steps (including the deployment of the new business contract and the new business contract calling the original data contract), the mapping type variable `uint["gender"]=1` will be deleted from the original data contract, forming a new data contract. The new data contract only removes the mapping type variable `uint["gender"]=1` from the original data contract; it does not change the data structure. Therefore, redeployment of the new data contract is not required.

[0219] Step S604: Send a business contract deployment request to the server so that the server can deploy the edited business contract on the blockchain and call the data contract according to the address of the data contract contained in the edited business contract to save the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0220] The business contract deployment request refers to the request information sent by the client to the server to deploy the edited business contract on the blockchain.

[0221] After the client sends a business contract deployment request to the server, the server will deploy the edited business contract on the blockchain upon receiving the request. The server will also write the address of the data contract into the edited business contract, enabling the edited business contract to call the data contract based on the address of the data contract it contains. The server will then write the mapping type variables corresponding to the business logic edited in the edited business contract into the data contract, thus completing the upgrade of the data contract.

[0222] The fifth embodiment of this application provides a method for upgrading a smart contract. A smart contract is obtained using the smart contract design method provided in the first embodiment of this application, and then deployed on a blockchain using the smart contract deployment method provided in the second embodiment of this application. If the smart contract needs to be repaired or its business functions need to be improved during actual operation, the smart contract can be upgraded using the method provided in this embodiment.

[0223] Through the first and second embodiments of this application, the smart contract deployed on the blockchain is a collection of contracts including a data contract, a business contract, and a permission management contract. The data contract stores business data, the business contract stores business logic, and the permission management contract provides access authorization authentication for the data contract and the business contract. The data structure of the data contract is a mapping type, and the business data is stored in the data contract as mapping type variables. The data contract, business contract, permission management contract, and their deployment methods have been described in detail in the first and second embodiments of this application, and will not be repeated here.

[0224] The smart contract obtained through the smart contract design method provided in the first embodiment of this application can achieve full upgradeability of data contracts, business contracts, and permission management contracts. The upgrade methods for data contracts, business contracts, and permission management contracts are described below, involving information interaction between the client and the server.

[0225] The client refers to the terminal where the client calling the smart contract is located. The client refers to a professional who can develop, maintain, and upgrade the smart contract, such as a smart contract development engineer or a smart contract maintenance engineer.

[0226] The server refers to the terminal that drives the smart contract to run on the blockchain. It can be a physical terminal or a virtual terminal. It can be a standalone server, a terminal that runs the smart contract, or a terminal that deploys the blockchain. A preferred server is the terminal that runs the smart contract.

[0227] This embodiment provides an optional method for upgrading data contracts.

[0228] Figure 7 This is a signaling flowchart of the upgraded data contract provided in this embodiment.

[0229] like Figure 7 As shown, the method for upgrading a data contract provided in this embodiment includes the following steps:

[0230] Step S701: The client sends a data contract upgrade request to the server;

[0231] Step S702: After receiving the data contract upgrade request sent by the client, the server calls the permission management contract to verify whether the client has the permission to call the data contract and the business contract.

[0232] Step S703: If the client has the authority to call the data contract and the business contract, the server sends the business contract to the client.

[0233] Step S704: After receiving the business contract sent by the server, the client edits the business logic corresponding to the content to be upgraded in the business contract according to the content to be upgraded.

[0234] Step S705: The client sends a business contract deployment request to the server;

[0235] Step S706: The server receives the business contract deployment request sent by the client and deploys the modified business contract on the blockchain;

[0236] Step S707: The server writes the address of the modified business contract into the permission management contract, and writes the address of the data contract and the address of the permission management contract into the modified business contract.

[0237] Step S708: The server calls the permission management contract to verify whether the modified business contract has the permission to call the data contract;

[0238] Step S709: If the modified business contract has the right to call the data contract, the server calls the data contract.

[0239] In step S710, the server writes the mapping type variable corresponding to the business logic edited in the modified business contract into the data contract.

[0240] This embodiment also provides an optional method for upgrading business contracts.

[0241] Figure 8 This is a signaling flowchart of the upgrade service contract provided in this embodiment.

[0242] like Figure 8 As shown, the method for upgrading a business contract provided in this embodiment includes the following steps:

[0243] Step S801: The client sends a business contract upgrade request to the server.

[0244] Step S802: After receiving the business contract upgrade request sent by the client, the server calls the permission management contract to verify whether the client has the permission to call the business contract.

[0245] Step S803: If the client has the permission to call the business contract, the server sends the business contract to the client.

[0246] Step S804: After receiving the business contract sent by the server, the client modifies the business logic of the business contract according to the content to be upgraded.

[0247] Step S805: The client sends a business contract deployment request to the server;

[0248] Step S806: The server receives the business contract deployment request sent by the client and deploys the modified business contract on the blockchain;

[0249] In step S807, the server writes the address of the modified business contract into the permission management contract, and writes the address of the data contract and the address of the permission management contract into the modified business contract.

[0250] This embodiment also provides an optional method for upgrading permission management contracts.

[0251] Figure 9 This is the signaling flowchart of the upgrade permission management contract provided in this embodiment.

[0252] like Figure 9 As shown, the method for upgrading permission management contracts provided in this embodiment includes the following steps:

[0253] Step S901: The client sends a permission management contract upgrade request to the server;

[0254] Step S902: After receiving the permission management contract upgrade request sent by the client, the server calls the permission management contract to verify whether the client has the permission to call the permission management contract.

[0255] Step S903: If the client has the permission to call the permission management contract, the server sends the permission management contract to the client.

[0256] Step S904: After receiving the permission management contract sent by the server, the client modifies the source code of the permission management contract according to the content to be upgraded.

[0257] Step S905: The client sends a permission management contract deployment request to the server;

[0258] Step S906: The server receives the permission management contract deployment request sent by the client and deploys the modified permission management contract on the blockchain;

[0259] In step S907, the server writes the address of the modified permission management contract into the data contract and the business contract, and writes the address of the data contract and the address of the business contract into the modified permission management contract.

[0260] The sixth embodiment of this application provides a smart contract upgrade device. The smart contract is a collection of contracts, including at least a data contract and a business contract. The data contract stores business data, and the business contract stores business logic. The business data is stored in the data contract in the form of mapped type variables. The device is applied to a server. Figure 10 This is a schematic diagram of the structure of the smart contract upgrade device provided in this embodiment.

[0261] like Figure 10 As shown, the smart contract upgrade device provided in this embodiment includes: a business logic editing unit 1001, a business contract deployment unit 1002, and a data contract upgrade unit 1003.

[0262] The business logic editing unit 1001 is used to respond to a data contract upgrade request sent by the client and provide the client with the business contract so that the client can edit the business logic corresponding to the content to be upgraded in the business contract.

[0263] The business contract deployment unit 1002 is used to respond to the business contract deployment request sent by the client, deploy the edited business contract on the blockchain, and write the address of the data contract into the edited business contract.

[0264] The data contract upgrade unit 1003 is used to call the data contract according to the address of the data contract contained in the edited business contract, and save the mapping type variable corresponding to the business logic edited in the edited business contract to the data contract.

[0265] Optionally, the smart contract may further include a permission management contract, which is used to provide access permission authentication for the data contract and the business contract.

[0266] Optionally, prior to the step of providing the business contract to the client, the apparatus is further configured to:

[0267] Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to authenticate whether the client has the permission to call the data contract and the business contract;

[0268] Based on the authentication result, determine whether to provide the business contract to the client, specifically as follows:

[0269] If the client has the authority to invoke the data contract and the business contract, then the business contract is provided to the client;

[0270] If the client does not have the permission to invoke the data contract and the business contract, then the business contract will not be provided to the client.

[0271] Optionally, after the steps of deploying the edited business contract on the blockchain and writing the address of the data contract into the edited business contract, the apparatus is further configured to:

[0272] Obtain the address of the edited business contract;

[0273] Write the address of the edited business contract into the permission management contract;

[0274] Write the address of the permission management contract into the edited business contract.

[0275] Optionally, before the step of the edited business contract calling the data contract based on the address of the data contract included in the edited business contract, the apparatus is further configured to:

[0276] The permission management contract is invoked to verify whether the edited business contract has the permission to call the data contract;

[0277] Based on the authentication results, it is determined whether the edited business contract can call the data contract, specifically as follows:

[0278] If the edited business contract has the permission to call the data contract, then it can call the data contract;

[0279] If the edited business contract does not have permission to call the data contract, then the data contract cannot be called.

[0280] Optionally, the variable name of the mapping type variable corresponds to the data name of the business data, and the variable value of the mapping type variable corresponds to the data value of the business data.

[0281] Optionally, the variable name of the mapping type variable is of type string, and the variable value of the mapping type variable is any data type in the smart contract programming language.

[0282] The seventh embodiment of this application provides a smart contract upgrade device. The smart contract is a collection of contracts, including at least a data contract and a business contract. The data contract stores business data, and the business contract stores business logic. The business data is stored in the data contract in the form of mapped type variables. The device is applied to a client. Figure 11 This is a schematic diagram of the structure of the smart contract upgrade device provided in this embodiment.

[0283] like Figure 11 As shown, the smart contract upgrade device provided in this embodiment includes: an upgrade request sending unit 1101, a business contract receiving unit 1102, a business logic editing unit 1103, and a deployment request sending unit 1104.

[0284] The upgrade request sending unit 1101 is used to send a data contract upgrade request to the server.

[0285] The business contract receiving unit 1102 is used to receive the business contract provided by the server.

[0286] The business logic editing unit 1103 is used to edit the business logic corresponding to the content to be upgraded in the business contract. Optionally, the content to be upgraded includes: adding first business data to the data contract; editing the business logic corresponding to the content to be upgraded in the business contract includes:

[0287] Edit the variable name and variable value of the mapping type variable corresponding to the first business data in the business contract, so that the server can save the first business data as a mapping type variable into the data contract according to the variable name and variable value edited in the edited business contract.

[0288] Optionally, the content to be upgraded further includes: reducing the second business data in the data contract; the step of editing the business logic corresponding to the content to be upgraded in the business contract further includes:

[0289] In the business contract, the value of the mapping type variable corresponding to the second business data is edited to zero, so that the server can delete the second business data from the data contract according to the variable value edited in the edited business contract.

[0290] The deployment request sending unit 1104 is used to send a business contract deployment request to the server so that the server deploys the edited business contract on the blockchain and calls the data contract according to the address of the data contract contained in the edited business contract, and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0291] The eighth embodiment of this application provides a smart contract deployment apparatus. Figure 12 This is a schematic diagram of the smart contract deployment device provided in this embodiment.

[0292] like Figure 12 As shown, the smart contract deployment device provided in this embodiment includes: a smart contract acquisition unit 1201, a permission management contract deployment unit 1202, a data contract deployment unit 1203; a first address writing unit 1204, a business contract deployment unit 1205, a second address writing unit 1206, and a third address writing unit 1207.

[0293] The smart contract acquisition unit 1201 is used to acquire a set of contracts including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract.

[0294] The permission management contract deployment unit 1202 is used to deploy the permission management contract on the blockchain and obtain the address of the permission management contract.

[0295] The data contract deployment unit 1203 is used to deploy the data contract on the blockchain and obtain the address of the data contract.

[0296] The first address writing unit 1204 is used to write the address of the permission management contract into the data contract, so that when the data contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the data contract based on the address of the permission management contract contained in the data contract.

[0297] The business contract deployment unit 1205 is used to deploy the business contract on the blockchain;

[0298] The second address writing unit 1206 is used to write the address of the permission management contract into the business contract, so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract.

[0299] The third address writing unit 1207 is used to write the address of the data contract into the business contract, so that the business contract can call the data contract according to the address of the data contract contained in the business contract.

[0300] Optionally, the device is also used for:

[0301] Obtain the address of the business contract;

[0302] The address of the data contract and the address of the business contract are written into the permission management contract so that when the business contract calls the data contract, the permission management contract can be used to authenticate the business contract's calling permission to the data contract.

[0303] The ninth embodiment of this application provides an electronic device. Figure 13 This is a schematic diagram of the structure of the electronic device provided in this embodiment.

[0304] like Figure 13As shown, the electronic device provided in this embodiment includes a memory 1301 and a processor 1302.

[0305] The memory 1301 is used to store computer instructions for executing smart contract upgrade methods and / or smart contract deployment methods.

[0306] The processor 1302 is used to execute computer instructions stored in the memory 1301, and to perform the following operations:

[0307] In response to a data contract upgrade request sent by a client, the business contract is provided to the client so that the client can edit the business logic corresponding to the content to be upgraded in the business contract;

[0308] In response to the business contract deployment request sent by the client, the edited business contract is deployed on the blockchain, and the address of the data contract is written into the edited business contract;

[0309] Based on the address of the data contract contained in the edited business contract, the edited business contract calls the data contract and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0310] Optionally, the smart contract may further include a permission management contract, which is used to provide access permission authentication for the data contract and the business contract.

[0311] Optionally, before the step of providing the business contract to the client, the following operations are performed:

[0312] Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to authenticate whether the client has the permission to call the data contract and the business contract;

[0313] Based on the authentication result, determine whether to provide the business contract to the client, specifically as follows:

[0314] If the client has the authority to invoke the data contract and the business contract, then the business contract is provided to the client;

[0315] If the client does not have the permission to invoke the data contract and the business contract, then the business contract will not be provided to the client.

[0316] Optionally, after the steps of deploying the edited business contract on the blockchain and writing the address of the data contract into the edited business contract, the following operations are performed:

[0317] Obtain the address of the edited business contract;

[0318] Write the address of the edited business contract into the permission management contract;

[0319] Write the address of the permission management contract into the edited business contract.

[0320] Optionally, before the step of the edited business contract calling the data contract based on the address of the data contract contained in the edited business contract, the following operation is performed:

[0321] The permission management contract is invoked to verify whether the edited business contract has the permission to call the data contract;

[0322] Based on the authentication results, it is determined whether the edited business contract can call the data contract, specifically as follows:

[0323] If the edited business contract has the permission to call the data contract, then it can call the data contract;

[0324] If the edited business contract does not have permission to call the data contract, then the data contract cannot be called.

[0325] Optionally, the variable name of the mapping type variable corresponds to the data name of the business data, and the variable value of the mapping type variable corresponds to the data value of the business data.

[0326] Optionally, the variable name of the mapping type variable is of type string, and the variable value of the mapping type variable is any data type in the smart contract programming language.

[0327] Alternatively, perform the following operation:

[0328] Send a data contract upgrade request to the server;

[0329] Receive the business contract provided by the server;

[0330] Edit the business logic corresponding to the content to be upgraded in the business contract;

[0331] A business contract deployment request is sent to the server so that the server deploys the edited business contract on the blockchain and calls the data contract according to the address of the data contract contained in the edited business contract, and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract.

[0332] Optionally, the content to be upgraded includes: adding first business data to the data contract; and editing the business logic corresponding to the content to be upgraded in the business contract includes:

[0333] Edit the variable name and variable value of the mapping type variable corresponding to the first business data in the business contract, so that the server can save the first business data as a mapping type variable into the data contract according to the variable name and variable value edited in the edited business contract.

[0334] Optionally, the content to be upgraded further includes: reducing the second business data in the data contract; the step of editing the business logic corresponding to the content to be upgraded in the business contract further includes:

[0335] In the business contract, the value of the mapping type variable corresponding to the second business data is edited to zero, so that the server can delete the second business data from the data contract according to the variable value edited in the edited business contract.

[0336] Alternatively, perform the following operation:

[0337] Obtain a set of contracts including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract.

[0338] Deploy the permission management contract on the blockchain and obtain the address of the permission management contract;

[0339] Deploy the data contract on the blockchain and obtain the address of the data contract;

[0340] Write the address of the permission management contract into the data contract so that when the data contract is invoked by the client, the permission management contract can be used to authenticate the client's access permission to the data contract based on the address of the permission management contract contained in the data contract.

[0341] Deploy the business contract on the blockchain;

[0342] Write the address of the permission management contract into the business contract so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract;

[0343] The address of the data contract is written into the business contract so that the business contract can invoke the data contract based on the address of the data contract contained in the business contract.

[0344] Optionally, perform the following operations:

[0345] Obtain the address of the business contract;

[0346] The address of the data contract and the address of the business contract are written into the permission management contract so that when the business contract calls the data contract, the permission management contract can be used to authenticate the business contract's calling permission to the data contract.

[0347] The tenth embodiment of this application provides a computer-readable storage medium, which includes computer instructions that, when executed by a processor, are used to implement the methods described in the embodiments of this application.

[0348] It should be noted that the relational terms such as "first" and "second" used in this document are only used to distinguish one entity or operation from another, and do not require or imply any actual relationship or order between these entities or operations. Furthermore, "including," "having," "containing," and other similar terms are synonymous, and the conclusion of any one or more items following any of the foregoing words is open-ended; none of the foregoing terms indicates that the one or more items have been exhaustively listed, or are limited to only one or more of the listed items.

[0349] When used herein, unless otherwise expressly stated, the term "or" includes all possible combinations except those that are impractical. For example, if expressed as a database may include A or B, then unless otherwise specified or impractical, it may include database A, or B, or A and B. As a second example, if expressed as a database may include A, B, or C, then unless otherwise specified or impractical, the database may include database A, or B, or C, or A and B, or A and C, or B and C, or A and B and C.

[0350] It is worth noting that the above embodiments can be implemented by hardware or software (program code), or a combination of hardware and software. If implemented by software, it can be stored in the above-described computer-readable medium. When executed by a processor, the software can perform the methods disclosed above. The computing units and other functional units described in this disclosure can be implemented by hardware or software, or a combination of hardware and software. Those skilled in the art will also understand that the above-described multiple modules / units can be combined into one module / unit, and each of the above-described modules / units can be further divided into multiple sub-modules / sub-units.

[0351] In the foregoing detailed description, embodiments have been described with reference to numerous specific details, which may vary depending on the implementation. Certain adaptations and modifications can be made to the embodiments. Other implementations will be readily apparent to those skilled in the art from the specific embodiments disclosed herein. This specification and examples are for illustrative purposes only, and the true scope and essence of this application are defined by the claims. The sequence of steps shown in the figures is also for illustrative purposes only and is not intended to limit to any particular step or order. Therefore, those skilled in the art will recognize that these steps can be performed in different orders when implementing the same method.

[0352] Exemplary embodiments are disclosed in the figures and detailed description of this application. However, many variations and modifications can be made to these embodiments. Accordingly, although specific terms are used, they are only general and descriptive and not for limiting purposes.

Claims

1. A method for upgrading smart contracts, characterized in that, The smart contract is a collection of contracts, including at least a data contract and a business contract. The data contract stores business data, and the business contract stores business logic. The business data is stored in the data contract as a mapped type variable. The method is applied to the server side and includes: In response to a data contract upgrade request sent by a client, the business contract is provided to the client so that the client can edit the business logic corresponding to the content to be upgraded in the business contract; In response to the business contract deployment request sent by the client, the edited business contract is deployed on the blockchain, and the address of the data contract is written into the edited business contract; Based on the address of the data contract contained in the edited business contract, the edited business contract calls the data contract and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract; The smart contract further includes a permission management contract, which provides access permission authentication for the data contract and the business contract; prior to the step of providing the business contract to the client, the method further includes: Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to authenticate whether the client has the permission to call the data contract and the business contract; Based on the authentication result, determine whether to provide the business contract to the client.

2. The method according to claim 1, characterized in that, The step of determining whether to provide the business contract to the client based on the authentication result specifically involves: If the client has the authority to invoke the data contract and the business contract, then the business contract is provided to the client; If the client does not have the permission to invoke the data contract and the business contract, then the business contract will not be provided to the client.

3. The method according to claim 1, characterized in that, After the steps of deploying the edited business contract on the blockchain and writing the address of the data contract into the edited business contract, the method further includes: Obtain the address of the edited business contract; Write the address of the edited business contract into the permission management contract; Write the address of the permission management contract into the edited business contract.

4. The method according to claim 3, characterized in that, Before the step of invoking the data contract based on the address of the data contract contained in the edited business contract, the method further includes: The permission management contract is invoked to verify whether the edited business contract has the permission to call the data contract; Based on the authentication results, it is determined whether the edited business contract can call the data contract, specifically as follows: If the edited business contract has the permission to call the data contract, then it can call the data contract; If the edited business contract does not have permission to call the data contract, then the data contract cannot be called.

5. The method according to claim 1, characterized in that, The variable name of the mapping type variable corresponds to the data name of the business data, and the variable value of the mapping type variable corresponds to the data value of the business data.

6. The method according to claim 5, characterized in that, The variable name of the mapping type variable is of type string, and the variable value of the mapping type variable is any data type in the smart contract programming language.

7. A method for upgrading smart contracts, characterized in that, The smart contract is a collection of contracts, including at least a data contract and a business contract. The data contract stores business data, and the business contract stores business logic. The business data is stored in the data contract in the form of mapped type variables. The method is applied to the client and includes: Send a data contract upgrade request to the server; Receive the business contract provided by the server; Edit the business logic corresponding to the content to be upgraded in the business contract; A business contract deployment request is sent to the server so that the server deploys the edited business contract on the blockchain and calls the data contract according to the address of the data contract contained in the edited business contract, and saves the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract; The smart contract further includes a permission management contract, which provides access permission authentication for the data contract and the business contract; prior to the step of receiving the business contract provided by the server, the method further includes: Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to verify whether the client has the permission to call the data contract and the business contract; Based on the authentication result, the server determines whether to provide the business contract to the client.

8. The method according to claim 7, characterized in that, The content to be upgraded includes: adding first business data to the data contract; and editing the business logic corresponding to the content to be upgraded in the business contract, including: Edit the variable name and variable value of the mapping type variable corresponding to the first business data in the business contract, so that the server can save the first business data as a mapping type variable into the data contract according to the variable name and variable value edited in the edited business contract.

9. The method according to claim 7, characterized in that, The content to be upgraded also includes: reducing the second business data in the data contract; the step of editing the business logic corresponding to the content to be upgraded in the business contract also includes: In the business contract, the value of the mapping type variable corresponding to the second business data is edited to zero, so that the server can delete the second business data from the data contract according to the variable value edited in the edited business contract.

10. A method for deploying a smart contract, characterized in that, The method includes: Obtain a set of contracts including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract. The business data is stored in the data contract in the form of a mapping type variable. Deploy the permission management contract on the blockchain and obtain the address of the permission management contract; Deploy the data contract on the blockchain and obtain the address of the data contract; Write the address of the permission management contract into the data contract so that when the data contract is invoked by the client, the permission management contract can be used to authenticate the client's access permission to the data contract based on the address of the permission management contract contained in the data contract. Deploy the business contract on the blockchain; Write the address of the permission management contract into the business contract so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract; The address of the data contract is written into the business contract so that the business contract can invoke the data contract based on the address of the data contract contained in the business contract.

11. The method according to claim 10, characterized in that, The method further includes: Obtain the address of the business contract; The address of the data contract and the address of the business contract are written into the permission management contract so that when the business contract calls the data contract, the permission management contract can be used to authenticate the business contract's calling permission to the data contract.

12. A smart contract upgrade device, characterized in that, The smart contract is a collection of contracts that includes at least a data contract and a business contract. The data contract is used to store business data, and the business contract is used to store business logic. The business data is stored in the data contract in the form of a mapping type variable. The device is applied to the server side and includes: a business logic editing unit, a business contract deployment unit, and a data contract upgrade unit. The business logic editing unit is used to respond to a data contract upgrade request sent by the client, and provide the client with the business contract so that the client can edit the business logic corresponding to the content to be upgraded in the business contract; The business contract deployment unit is used to respond to the business contract deployment request sent by the client, deploy the edited business contract on the blockchain, and write the address of the data contract into the edited business contract; The data contract upgrade unit is used to call the data contract according to the address of the data contract contained in the edited business contract, and save the mapping type variable corresponding to the business logic edited in the edited business contract to the data contract; The smart contract further includes a permission management contract, which is used to provide call permission authentication for the data contract and the business contract; prior to the step of providing the business contract to the client, it is also used for: Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to authenticate whether the client has the permission to call the data contract and the business contract; Based on the authentication result, determine whether to provide the business contract to the client.

13. A smart contract upgrade device, characterized in that, The smart contract is a collection of contracts that includes at least a data contract and a business contract. The data contract is used to store business data, and the business contract is used to store business logic. The business data is stored in the data contract in the form of a mapped type variable. The device is applied to a client and includes: an upgrade request sending unit, a business contract receiving unit, a business logic editing unit, and a deployment request sending unit. The upgrade request sending unit is used to send a data contract upgrade request to the server; The business contract receiving unit is used to receive the business contract provided by the server; The business logic editing unit is used to edit the business logic corresponding to the content to be upgraded in the business contract. The deployment request sending unit is used to send a business contract deployment request to the server so that the server can deploy the edited business contract on the blockchain and call the data contract according to the address of the data contract contained in the edited business contract, and save the mapping type variable corresponding to the business logic edited in the edited business contract into the data contract; The smart contract further includes a permission management contract, which is used to provide call permission authentication for the data contract and the business contract; prior to the step of receiving the business contract provided by the server, it is also used for: Based on the address of the permission management contract contained in the data contract and the business contract, the data contract and the business contract call the permission management contract to verify whether the client has the permission to call the data contract and the business contract; Based on the authentication result, the server determines whether to provide the business contract to the client.

14. A smart contract deployment device, characterized in that, The device includes: a smart contract acquisition unit, a permission management contract deployment unit, a data contract deployment unit; a first address writing unit, a business contract deployment unit, a second address writing unit, and a third address writing unit; The smart contract acquisition unit is used to acquire a set of contracts including a data contract, a business contract, and a permission management contract. The data contract is used to store business data, the business contract is used to store business logic, and the permission management contract is used to provide call permission authentication for the data contract and the business contract. The business data is stored in the data contract in the form of a mapping type variable. The permission management contract deployment unit is used to deploy the permission management contract on the blockchain and obtain the address of the permission management contract; The data contract deployment unit is used to deploy the data contract on the blockchain and obtain the address of the data contract; The first address writing unit is used to write the address of the permission management contract into the data contract, so that when the data contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the data contract based on the address of the permission management contract contained in the data contract; The business contract deployment unit is used to deploy the business contract on the blockchain; The second address writing unit is used to write the address of the permission management contract into the business contract, so that when the business contract is called by the client, the permission management contract can be used to authenticate the client's calling permission to the business contract based on the address of the permission management contract contained in the business contract; The third address writing unit is used to write the address of the data contract into the business contract, so that the business contract can call the data contract according to the address of the data contract contained in the business contract.

15. An electronic device, characterized in that, include: Memory, processor; The memory is used to store one or more computer instructions; The processor is configured to execute one or more computer instructions to implement the method as described in any one of claims 1-6, 7-9, or 10-11.

16. A computer-readable storage medium storing one or more computer instructions thereon, characterized in that, When this instruction is executed by the processor, it performs the method as described in any one of claims 1-6, 7-9, or 10-11.