CN112400182A - Method and device for executing intelligent contracts in block chain and electronic equipment - Google Patents

Method and device for executing intelligent contracts in block chain and electronic equipment Download PDF

Info

Publication number
CN112400182A
CN112400182A CN202080002396.7A CN202080002396A CN112400182A CN 112400182 A CN112400182 A CN 112400182A CN 202080002396 A CN202080002396 A CN 202080002396A CN 112400182 A CN112400182 A CN 112400182A
Authority
CN
China
Prior art keywords
contract
data
logic
address
transaction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202080002396.7A
Other languages
Chinese (zh)
Inventor
刘海峰
郭三彬
陈复星
李腾
卓越
雷宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Helian Consensus Technology Co ltd
Original Assignee
Beijing Helian Consensus Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Helian Consensus Technology Co ltd filed Critical Beijing Helian Consensus Technology Co ltd
Publication of CN112400182A publication Critical patent/CN112400182A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3827Use of message hashing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Abstract

The embodiment of the specification provides an execution method and device of an intelligent contract in a block chain and an electronic device. The method comprises the following steps: receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution; responding to the first transaction, calling a logic contract corresponding to the first contract address, and acquiring service logic maintained in a contract account corresponding to the logic contract; determining a field name for executing state data lacking in the business logic; calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract; calling a data contract corresponding to the second contract address to acquire state data of the field name maintained in a contract account corresponding to the data contract; supplementing the state data to missing state data in the business logic to execute the business logic.

Description

Method and device for executing intelligent contracts in block chain and electronic equipment
Technical Field
One or more embodiments of the present disclosure relate to the field of blockchain technologies, and in particular, to a method and an apparatus for executing an intelligent contract in a blockchain, and an electronic device.
Background
The block chain technology, also called distributed ledger technology, is an emerging technology in which several computing devices participate in "accounting" together, and a complete distributed database is maintained together. The blockchain technology has been widely used in many fields due to its characteristics of decentralization, transparency, participation of each computing device in database records, and rapid data synchronization between computing devices.
Disclosure of Invention
The embodiment of the specification provides a method and a device for creating, upgrading and executing an intelligent contract in a block chain and an electronic device.
According to a first aspect of embodiments of the present specification, there is provided a method for executing an intelligent contract in a blockchain, the method including:
receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
responding to the first transaction, calling a logic contract corresponding to the first contract address, and acquiring service logic maintained in a contract account corresponding to the logic contract;
determining a field name for executing state data lacking in the business logic;
calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
calling a data contract corresponding to the second contract address to acquire state data of the field name maintained in a contract account corresponding to the data contract;
supplementing the state data to missing state data in the business logic to execute the business logic.
Optionally, the method further includes:
and after the business logic is executed to generate new state data of a target field, calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to modify the state data of the target field into new state data.
Optionally, the method further includes:
receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
in response to the second transaction, creating a logical contract, and writing the business logic in a contract account corresponding to the logical contract;
creating a data contract, and writing initial state data of each field in the business logic in a contract account corresponding to the data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to write a first contract address corresponding to the logic contract and a second contract address of the data contract into the mapping table.
Optionally, the method further includes:
receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
in response to the third transaction, creating a new logical contract, and writing the new business logic in a contract account corresponding to the new logical contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to modify the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
Optionally, the method further includes:
if the new business logic is added with a new field compared with the old business logic, a new data contract is created, and the initial state data of the new field is written in a contract account corresponding to the new data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to increase the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
Optionally, if the first transaction further carries status data related to a service, the invoking a logical contract corresponding to the first contract address in response to the first transaction to obtain a service logic maintained in a contract account corresponding to the logical contract specifically includes:
in response to the first transaction, invoking a routing contract of the blockchain, and querying a second contract address mapped to the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
further calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to record the state data carried by the first transaction;
and further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
Optionally, the state data maintained by the contract account corresponding to the data contract is located in an asset mapping table, and the asset mapping table stores the state data of the user account and the user asset;
the invoking a data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract, includes:
if the first transaction is an entry transaction of the user asset, calling a data contract corresponding to the second contract address, and recording the state data of the user account and the user asset in the asset mapping table;
if the first transaction is the expenditure presentation transaction of the user asset, calling a data contract corresponding to the second contract address, and checking whether a user account indicated by the first transaction is located in the asset mapping table;
the logic contract corresponding to the first contract address is called to obtain the service logic maintained in the contract account corresponding to the logic contract,
and when the user account is positioned in the asset mapping table, further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
According to a second aspect of embodiments herein, a method for creating an intelligent contract in a blockchain, the method comprising:
receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
in response to the second transaction, creating a logical contract, and writing the business logic in a contract account corresponding to the logical contract;
creating a data contract, and writing initial state data of each field in the business logic in a contract account corresponding to the data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to write a first contract address corresponding to the logic contract and a second contract address of the data contract into the mapping table.
According to a third aspect of embodiments herein, a method for upgrading an intelligent contract in a blockchain, the method includes:
receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
in response to the third transaction, creating a new logical contract, and writing the new business logic in a contract account corresponding to the new logical contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to modify the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
Optionally, the method further includes:
if the new business logic is added with a new field compared with the old business logic, a new data contract is created, and the initial state data of the new field is written in a contract account corresponding to the new data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to increase the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
According to a fourth aspect of embodiments herein, an apparatus for executing an intelligent contract in a blockchain, the apparatus comprising:
the receiving unit is used for receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
the response unit is used for responding to the first transaction, calling a logic contract corresponding to the first contract address and acquiring service logic maintained in a contract account corresponding to the logic contract;
a determining unit that determines a field name for executing state data lacking in the business logic;
the routing unit is used for calling the routing contract of the block chain and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
the acquisition unit is used for calling the data contract corresponding to the second contract address and acquiring the state data of the field name maintained in the contract account corresponding to the data contract;
and the execution unit supplements the state data to the missing state data in the service logic so as to execute the service logic.
Optionally, the apparatus further comprises:
and the updating unit is used for calling the data contract corresponding to the second contract address after the business logic is executed to generate new state data of the target field, updating the state data of the target field maintained in the contract account corresponding to the data contract and modifying the state data of the target field into the new state data.
Optionally, the apparatus further comprises:
the first receiving subunit receives a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
the first response subunit responds to the second transaction, creates a logic contract and writes the business logic into a contract account corresponding to the logic contract;
the first creating subunit is used for creating a data contract and writing initial state data of each field in the business logic into a contract account corresponding to the data contract;
and the first updating subunit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and writing the first contract address corresponding to the logic contract and the second contract address of the data contract into the mapping table.
Optionally, the apparatus further comprises:
the second receiving subunit receives a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
a second response subunit, configured to create a new logical contract in response to the third transaction, and write the new business logic in a contract account corresponding to the new logical contract;
and the second updating subunit is used for calling the routing contract in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contract, and modifying the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
Optionally, the apparatus further comprises:
a second creating subunit, configured to create a new data contract if the new service logic is added with a new field compared with the old service logic, and write initial state data of the new field into a contract account corresponding to the new data contract;
and the third updating subunit is used for calling the routing contract in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contract, and increasing the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
Optionally, the response unit includes:
if the first transaction also carries state data related to services, responding to the first transaction, calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract; further calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to record the state data carried by the first transaction; and further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
Optionally, the state data maintained by the contract account corresponding to the data contract is located in an asset mapping table, and the asset mapping table stores the state data of the user account and the user asset;
in the response unit, invoking a data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract, including:
if the first transaction is an entry transaction of the user asset, calling a data contract corresponding to the second contract address, and recording the state data of the user account and the user asset in the asset mapping table;
if the first transaction is the expenditure presentation transaction of the user asset, calling a data contract corresponding to the second contract address, and checking whether a user account indicated by the first transaction is located in the asset mapping table;
in the response unit, invoking a logical contract corresponding to the first contract address to obtain a service logic maintained in a contract account corresponding to the logical contract, including:
and when the user account is positioned in the asset mapping table, further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
According to a fifth aspect of embodiments herein, an apparatus for creating an intelligent contract in a blockchain, the apparatus comprising:
the receiving unit is used for receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
a response unit, which responds to the second transaction, creates a logic contract and writes the business logic in a contract account corresponding to the logic contract;
the creating unit is used for creating a data contract and writing initial state data of each field in the business logic into a contract account corresponding to the data contract;
and the updating unit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and writing the first contract address corresponding to the logic contract and the second contract address of the data contract into the mapping table.
According to a sixth aspect of embodiments herein, an apparatus for upgrading an intelligent contract in a blockchain, the apparatus comprising:
the receiving unit is used for receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
a response unit, which responds to the third transaction, creates a new logic contract and writes the new business logic in the contract account corresponding to the new logic contract;
and the upgrading unit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and modifying the first contract address of the old logic contract in the mapping table into the first contract address of the new logic contract.
Optionally, the apparatus further comprises:
a creating unit, if the new service logic is added with a new field compared with the old service logic, creating a new data contract, and writing the initial state data of the new field into a contract account corresponding to the new data contract;
and the updating unit is used for calling the routing contract in the block chain, updating a mapping table maintained in a contract account corresponding to the routing contract, and increasing the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
According to a seventh aspect of embodiments herein, an intelligent contract for a blockchain, the intelligent contract being comprised of a logical contract, a routing contract, and a data contract;
business logic is maintained in a contract account corresponding to the logic contract;
a mapping table is maintained in a contract account corresponding to the routing contract, and the mapping table stores the mapping relation between a first contract address of a logic contract and a second contract address of a data contract;
the contract account corresponding to the data contract is maintained with the state data generated by the execution of the logic contract.
According to an eighth aspect of embodiments herein, there is provided an electronic apparatus comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured as a method for executing, creating and upgrading the intelligent contracts in any one of the blockchains.
The embodiment of the specification provides a scheme for executing, creating and upgrading intelligent contracts in a block chain, wherein the intelligent contracts are divided into logic contracts, routing contracts and data contracts. The logic contract for maintaining business logic no longer maintains state data, so that the restrictions of asset security and data migration do not exist, and the business logic is scalable and pluggable. When the service logic is upgraded, the logic contract written in the new service logic is directly created, and the mapping relation between the data contract storing the state data and the old logic contract is modified into the new logic contract by updating the mapping table maintained by the routing contract.
Drawings
FIG. 1 is a schematic diagram of a smart contract for a blockchain provided by an exemplary embodiment;
FIG. 2 is a flow diagram of a method for creating intelligent contracts in blockchains, as provided by an exemplary embodiment;
FIG. 3 is a flowchart of a method for upgrading intelligent contracts in a blockchain, as provided by an exemplary embodiment;
FIG. 4 is a flowchart of a method for executing intelligent contracts in blockchains provided by an exemplary embodiment;
FIG. 5 is a schematic diagram of an electronic device provided by an exemplary embodiment;
fig. 6 is a block diagram of an apparatus for executing an intelligent contract in a blockchain according to an exemplary embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the exemplary embodiments below do not represent all implementations consistent with one or more embodiments of the present specification. Rather, they are merely examples of apparatus and methods consistent with certain aspects of one or more embodiments of the specification, as detailed in the claims which follow.
It should be noted that: in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described herein. In some other embodiments, the method may include more or fewer steps than those described herein. Moreover, a single step described in this specification may be broken down into multiple steps for description in other embodiments; multiple steps described in this specification may be combined into a single step in other embodiments. The first, second, third and the like in this specification are for distinguishing between different ones, and do not limit the order of the steps.
For ease of understanding, some technical concepts in the blockchain are first introduced below.
Blockchains are generally divided into three types: public chain (Public Blockchain), Private chain (Private Blockchain) and alliance chain (Consortium Blockchain). Furthermore, there may be a combination of the above types, such as private chain + federation chain, federation chain + public chain, and so on.
Among them, the most decentralized is the public chain. The public chain is represented by bitcoin and ether house, and participants (also called nodes in the block chain) joining the public chain can read data records on the chain, participate in transactions, compete for accounting rights of new blocks, and the like. Moreover, each node can freely join or leave the network and perform related operations.
Private chains are the opposite, with the network's write rights controlled by an organization or organization and the data read rights specified by the organization. Briefly, a private chain may be a weakly centralized system with strict restrictions on nodes and a small number of nodes. This type of blockchain is more suitable for use within a particular establishment.
A federation chain is a block chain between a public chain and a private chain, and "partial decentralization" can be achieved. Each node in a federation chain typically has a physical organization or organization corresponding to it; the nodes are authorized to join the network and form a benefit-related alliance, and block chain operation is maintained together.
Based on the basic characteristics of a blockchain, a blockchain is usually composed of several blocks. The time stamps corresponding to the creation time of the block are recorded in the blocks respectively, and all the blocks form a time-ordered data chain according to the time stamps recorded in the blocks strictly.
The real data generated by the physical world can be constructed into a standard transaction (transaction) format supported by a block chain, then is issued to the block chain, the node equipment in the block chain performs consensus processing on the received transaction, and after the consensus is achieved, the node equipment serving as an accounting node in the block chain packs the transaction into a block and performs persistent evidence storage in the block chain.
In the field of blockchain, an important concept is Account (Account); taking an ether house as an example, the ether house generally divides an account into an external account and a contract account; the external account is an account directly controlled by the user and is also called as a user account; and the contract account is created by the user through an external account, the account containing the contract code (i.e. the smart contract).
For accounts in a blockchain, the account status of the account is usually maintained through a structure. When a transaction in a block is executed, the status of the account associated with the transaction in the block chain is also typically changed.
Taking etherhouses as an example, the structure of an account usually includes fields such as Balance, Nonce, Code and Storage. Wherein:
a Balance field for maintaining the current account Balance of the account;
a Nonce field for maintaining a number of transactions for the account; the counter is used for guaranteeing that each transaction can be processed only once, and replay attack is effectively avoided;
a Code field for maintaining a contract Code for the account; in practical applications, only the hash value of the contract Code is typically maintained in the Code field; thus, the Code field is also commonly referred to as the Codhash field.
A Storage field to maintain status data for the account (default field value is null); for a contract account, a separate storage space is usually allocated to store the status data of the contract account; this separate storage space is often referred to as the account storage of the contract account. The state data of the contract account is usually constructed into a data structure of an MPT (Merkle Patricia Trie) tree and stored in the independent storage space; the MPT tree is constructed based on the state data of the contract account, and is also commonly called a Storage tree. Whereas the Storage field typically maintains only the root node of the Storage tree; thus, the Storage field is also commonly referred to as the Storage root field.
Wherein, for the external account, the field values of the Code field and the Storage field shown above are both null values.
In practical applications, whether public, private, or alliance, it is possible to provide the functionality of a Smart contract (Smart contract). An intelligent contract on a blockchain is a contract on a blockchain that can be executed triggered by a transaction. An intelligent contract may be defined in the form of code.
Taking an Etherhouse as an example, a user is supported to create and call some complex logic in the Etherhouse network. The ethernet workshop is used as a programmable block chain, and the core of the ethernet workshop is an ethernet workshop virtual machine (EVM), and each ethernet workshop node can run the EVM. The EVM is a well-behaved virtual machine through which various complex logic can be implemented. The user issuing and invoking smart contracts in the etherhouse is running on the EVM. In fact, the EVM directly runs virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"), so the intelligent contract deployed on the blockchain may be bytecode.
For reasons of security of blockchains, the intelligent contracts in existing blockchains are designed to be non-modifiable, non-upgradeable. Taking etherhouses as an example, once an intelligent contract is created in a blockchain, the contract code of the business logic declared in this intelligent contract cannot be modified. However, any business logic needs to be changed to adapt to different requirements, that is, in practice, the intelligent contracts need to be modified or upgraded. For this reason, the business parties need to continually issue intelligent contracts for new business logic. However, there are the following problems with doing so:
the contract account corresponding to the intelligent contract not only maintains the contract Code (Code field) of the business logic, but also maintains the state data (Storage field). The newly created intelligent contract, although able to write contract code for the new business logic, cannot directly create state data in the old intelligent contract. This requires additional operations to acquire and the operation of synchronizing the state data is complicated. In addition, since the old intelligent contracts can no longer be used, the maintained state data is not updated, but the state data is always recorded, thereby additionally occupying the resources of the blockchain. With the continuous iteration and upgrading of the intelligent contract, more and more block chain resources are occupied by state data maintained in the old intelligent contract, and therefore available resources of the existing block chain are continuously squeezed.
To this end, the present specification is primarily directed to improvements in traditional intelligent contracts. Referring to the intelligent contracts of the block chain provided in the exemplary embodiment of fig. 1, the intelligent contracts may be divided into logical contracts, routing contracts, and data contracts; wherein:
business logic is maintained in a contract account corresponding to the logic contract;
a mapping table is maintained in a contract account corresponding to the routing contract, and the mapping table stores the mapping relation between a first contract address of a logic contract and a second contract address of a data contract;
the contract account corresponding to the data contract is maintained with the state data generated by the execution of the logic contract.
As shown in FIG. 1, a logical contract may be upgraded (an embodiment of which will be described in detail later) and a data contract may be extended (an embodiment of which will be described in detail later). A user may initiate a transaction to a logical contract or a data contract. A logical contract may read and write data to a data contract. Routing contracts are used to provide routing services to logical contracts or data contracts.
By separating intelligent contracts into logical contracts, routing contracts, and data contracts. The logic contract for maintaining business logic no longer maintains state data, so that the restrictions of asset security and data migration do not exist, and the business logic is scalable and pluggable. When the service logic is upgraded, the logic contract written in the new service logic is directly created, and the mapping relation between the data contract storing the state data and the old logic contract is modified into the new logic contract by updating the mapping table maintained by the routing contract.
The following introduced embodiments of creating, upgrading, executing and the like of the intelligent contract in the blockchain are all performed on the basis of the improved intelligent contract architecture.
An embodiment of a method of creating an intelligent contract as shown in FIG. 2 is further described below. The method comprises the following steps:
step 110: receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
step 120: in response to the second transaction, creating a logical contract, and writing the business logic in a contract account corresponding to the logical contract;
step 130: creating a data contract, and writing initial state data of each field in the business logic in a contract account corresponding to the data contract;
step 140: and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to write a first contract address corresponding to the logic contract and a second contract address of the data contract into the mapping table.
In this embodiment, a user may send a transaction to the blockchain that includes creating an intelligent contract, the transaction carrying contract code for the business logic. When agreement is reached between nodes in the blockchain through a consensus mechanism, the creation of the intelligent contract can be started.
Unlike prior art implementations of an intelligent contract, this embodiment creates a data contract for storing state data in addition to a logical contract for storing contract code for business logic.
After the logical contract is created, a contract account corresponding to the logical contract appears on the blockchain, and the contract account has a unique contract address (called a first contract address). The contract Code of the business logic carried in the transaction will be stored in the Code of the contract account corresponding to the logic contract (in some cases, the Code stores the hash pointer of the contract Code, and the contract Code is addressed by the hash pointer). And (4) the Storage of the contract account corresponding to the logic contract is empty, namely the logic contract only maintains the service logic and does not store the state data.
After the data contract is created, a contract account corresponding to the data contract appears on the blockchain, and the data account has a unique contract address (called a second contract address). The initial state data (generally 0) of each service field is written in the Storage of the contract account corresponding to the data contract. And when the Code of the contract account corresponding to the data contract is empty, namely the data contract only maintains state data and does not store business logic.
After the logical contract and the data contract are both created, the routing contract needs to update a mapping table maintained in a contract account corresponding to the routing contract so as to write a mapping relation between a first contract address corresponding to the logical contract and a second contract address of the data contract into the mapping table.
An embodiment of a method for upgrading the intelligent contract shown in fig. 3 is further described below. The method comprises the following steps:
step 210: receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
step 220: in response to the third transaction, creating a new logical contract, and writing the new business logic in a contract account corresponding to the new logical contract;
step 230: and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to modify the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
In this embodiment, the user may send a transaction containing an upgrade smart contract to the blockchain, the transaction carrying the first contract address of the old logical contract and the contract code of the new business logic to be upgraded. When the nodes in the block chain reach the agreement through the consensus mechanism, the intelligent contract can be upgraded.
Unlike existing upgrade intelligent contracts, there is no need to synchronize state data maintained by old contracts because the logical contracts in this embodiment no longer maintain state data.
After the new logical contract is created, a contract account corresponding to the new logical contract appears on the blockchain, and the contract account has a unique contract address (referred to as the first contract address of the new logical contract). The contract Code of the new business logic carried in the transaction will be stored in the Code of the contract account corresponding to the new logic contract (in some cases, the Code stores the hash pointer of the contract Code, and the contract Code is addressed by the hash pointer). And the Storage of the contract account corresponding to the new logical contract is also empty, namely, the new logical contract only maintains the business logic and does not store the state data.
Since the state data is stored in the contract data, there is no need to synchronize the state to a new logical contract. In order for a new logical contract to obtain the required state data, the mapping table maintained by the routing contract needs to be updated. That is, the first contract address of the old logical contract in the mapping table is modified to the first contract address of the new logical contract to invalidate and establish the association between the old logical contract and the data contract.
Although the logic contract in the specification can be modified and upgraded, the data contract inherits the concept of the traditional intelligent contract, and is not modifiable and upgradable. This data contract, once deployed on the chain, is not modifiable and the data structure (the current traffic field) will lock into this data contract. However, in practical applications, if the business logic is iteratively upgraded, the corresponding data structure is often iterated. For example, service logic has added some service fields. But the data contract is not upgradeable. Therefore, the intelligent contracts in the block chain also have the problem of data expansion.
In order to solve this problem, the present specification further proposes a scheme for data expansion, and on the basis of fig. 3, the scheme may further include:
if the new business logic is added with a new field compared with the old business logic, a new data contract is created, and the initial state data of the new field is written in a contract account corresponding to the new data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to increase the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
In this embodiment, if the business logically needs to add new fields, these fields are stored in a completely new data contract. At the same time, the second contract address and the included field name of the new data contract are updated to the mapping table of the routing contract, and the logic contract obtains the second contract address of the data contract corresponding to the new field by inquiring the mapping table, so that the routing is read and written.
It should be noted that, for the case that a logical contract maps multiple data contracts, in order to improve the query efficiency, the form of the mapping table maintained in the routing contract may further include:
a first mapping of a first contract address of a logical contract with the respective field and a second mapping of the respective field with a second contract address of the associated data contract.
Thus, through the two-layer mapping relationship, the state data corresponding to each field required by the execution of the logic contract can be finally determined.
An embodiment of a method of executing the intelligent contract shown in FIG. 4 is further described below. The intelligent contracts are divided into logic contracts, routing contracts and data contracts; business logic is maintained in a contract account corresponding to the logic contract; a mapping table is maintained in a contract account corresponding to the routing contract, and the mapping table stores the mapping relation between a first contract address of a logic contract and a second contract address of a data contract; state data generated by the execution of the logic contract is maintained in a contract account corresponding to the data contract; the method comprises the following steps:
step 310: receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
step 320: responding to the first transaction, calling a logic contract corresponding to the first contract address, and acquiring service logic maintained in a contract account corresponding to the logic contract;
step 330: determining a field name for executing state data lacking in the business logic;
step 340: calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
step 350: calling a data contract corresponding to the second contract address to acquire state data of the field name maintained in a contract account corresponding to the data contract;
step 360: supplementing the state data to missing state data in the business logic to execute the business logic.
In this embodiment, the user sends a transaction containing a call To the blockchain, the From field of the transaction is used To record the address of the user who initiated the call To the logical contract (i.e., the address of the user's account on the blockchain), the To field is used To record the contract address of the called logical contract (i.e., the first contract address of the logical contract on the blockchain), and the Data field of the transaction is used To record the method and parameters for calling the logical contract.
And executing the transaction in a local EVM by the node equipment in the blockchain, calling a logic contract corresponding to the first contract address, and acquiring a contract code of the service logic maintained in a contract account corresponding to the logic contract.
Because the logic contract does not store state data, after the field name of the state data lacking in the business logic is determined, a routing contract of the block chain is called, and a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract is inquired.
And further calling the data contract corresponding to the second contract address to acquire the state data of the field name maintained in the contract account corresponding to the data contract.
At this time, the node device acquires the contract code of the service logic and the missing state data in the service logic, supplements the state data to the missing state data in the service logic in the EVM, and runs the contract code of the service logic in the EVM.
As can be seen from the above process, in the execution of the intelligent contract provided in this embodiment, through the cooperation among the logic contract, the routing contract and the data contract, the contract code of the service logic is obtained from the logic contract, the data contract corresponding to the service logic is obtained from the routing contract, the relevant state data is obtained from the data contract, and finally, the contract code and the state data are assembled into a complete executable code to be run in the EVM.
In practical applications, after the intelligent contract is called, the corresponding state data changes, so that the state data needs to be updated. Therefore, on the basis of fig. 4, the method may further include:
and after the execution service logic generates new state data of a target field, calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to modify the state data of the target field into new state data.
In this embodiment, after the logic contract is executed and new state data is generated, since the second contract address of the corresponding data contract has been acquired before, the data contract corresponding to the second contract address is directly invoked, and the state data of the target field maintained in the contract account corresponding to the data contract is modified into the new state data.
The calling mode of the intelligent contract shown in fig. 4 is that the logic contract can be directly called for the state data which is not related to the service in the first transaction.
If the first transaction also carries service-related state data; step 320 specifically includes:
step 321, in response to the first transaction, invoking a routing contract of the block chain, and querying a second contract address mapped to the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
step 322, further invoking a data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract, so as to record the state data carried in the first transaction;
step 323, further invoking a logic contract corresponding to the first contract address to obtain a service logic maintained in a contract account corresponding to the logic contract.
In the embodiment, aiming at the transaction of the state data directly by the user, the transaction is directly sent to the data contract, and after the state data is recorded by the data contract, the logic contract is called to process and record the business logic. Since the original state data (state data specified in the transaction) is not transferred in the logical contract but is directly recorded by the data contract, but the data contract is not modifiable and upgradeable, the original state data directly recorded by the data contract is trusted, so that the data security is guaranteed to the greatest extent possible.
For purposes of this specification, if the logical contracts are scalable and the data contracts are extensible, then issues of data ownership and asset security for the user follow.
With traditional intelligent contracts, all assets of a user are locked into the contract. The intelligent contract's ability to extract assets or modify the balance of assets is also guaranteed to the user in the form of code disclosure, and no one or program other than the user himself can obtain the assets locked by the user in the contract. Further, the non-modifiable nature of conventional smart contracts allows contracts to be deployed without code changes, thereby ensuring that the user assets maintained in the smart contracts are absolutely secure.
However, the present specification separates traditional intelligent contracts into two separate contracts, a logical contract and a data contract, in a role-separated manner. The user assets in the data contract are the users determined to belong by the mapping relation maintained by the routing contract, but the mapping relation can be modified, namely the user assets do not directly correspond to the users, and the problem of user asset safety exists. For example, user A's assets are mapped to user B.
For this purpose, the contract account corresponding to the data contract may also maintain an asset mapping table of the mapping relationship between the user account and the user asset. The mapping table is in the data contract, only provides two interfaces of the entry and the exit of the user asset, and any other interface has no right to write and update the asset mapping table.
In the above step 322, invoking the data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract, includes:
if the first transaction is an entry transaction of the user asset, calling a data contract corresponding to the second contract address, and recording the state data of the user account and the user asset in the asset mapping table;
if the first transaction is the expenditure presentation transaction of the user asset, calling a data contract corresponding to the second contract address, and checking whether a user account indicated by the first transaction is located in the asset mapping table;
in the above step 323, a logic contract corresponding to the first contract address is called to obtain a service logic maintained in a contract account corresponding to the logic contract;
and when the user account is positioned in the asset mapping table, further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
The user assets may refer to virtual tokens or virtual assets.
The virtual token may be a virtual token that converts real world currency into currency that can be circulated on a chain. For example bitcoins are typical virtual tokens.
The virtual assets may refer to physical assets of some non-monetary attributes in the real world, which are converted into virtual assets capable of circulating on a blockchain.
Here, the conversion of an entity asset having a non-monetary attribute in the real world into a virtual asset on a blockchain generally refers to a process of "anchoring" the entity asset and a virtual asset on the blockchain to serve as a value support for the virtual assets, and generating a virtual asset (hereinafter referred to as a user asset) on the blockchain that matches the value of the entity asset and can be distributed between blockchain accounts on the blockchain.
In implementation, status data for user assets may be maintained in contract accounts corresponding to data contracts, so that physical assets of non-monetary attributes in the real world may be used as value supports.
Specifically, the value of the contract field, the Nonce of the contract account of the data contract, may be null (or not null); and the field value of the Storage field may no longer be a null value; the Storage field may be used to maintain an asset status of a user asset corresponding to a user account. The specific manner of maintaining the asset state of the user asset in the Storage field can be flexibly designed based on requirements, for example, an asset mapping table of a mapping relationship between the user account and the asset state of the user asset.
The specific form of the user assets can be entity assets with non-currency attributes such as real estate, stocks, loan contracts, bills, accounts receivable and the like, and the user assets which are converted into value matching are circulated on the block chain.
Returning to this embodiment, the user, when placing an asset, is to directly invoke an posting interface on the data contract. And after the user assets are locked into the data contract, recording the corresponding relation between the address of the user account and the user assets in the asset mapping table.
The user, when retrieving the asset, still calls the checkout interface on the data contract directly. The data contract checks whether the address of the user account exists in the asset mapping table, calls a logic contract to execute subsequent steps when the address exists, and finally directly transfers the user asset to the request address of the user.
Any user account that is not in the asset mapping table will not respond to its operation request for the user asset by the checkout interface. Therefore, any user asset which is paid out belongs to the address of the original user account which is paid in at first time, the binding of the user to the asset ownership is ensured, and the safety of the user asset is improved.
In summary, the technical solution provided by the present specification divides the intelligent contract into a logic contract, a routing contract and a data contract. The logic contract for maintaining the business logic can not maintain the state data any more, so that the limitation of asset safety and data migration does not exist, and the intelligent contract can be upgraded. On the other hand, the data contract is set to be not scalable but expandable, thereby meeting the requirement of business logic upgrading. On the other hand, the user account to which each user asset belongs is managed through an asset mapping table maintained in the data contract, and the account and account of the user assets are managed based on the asset mapping table, so that the user assets are completely protected, and asset safety risks are not generated due to contract upgrading.
Corresponding to the above method embodiments, the present specification also provides embodiments of an apparatus for executing, creating, and upgrading an intelligent contract in a blockchain.
The embodiments of the apparatus for executing, creating and upgrading intelligent contracts in a blockchain of the present specification can be applied to electronic devices. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. Taking a software implementation as an example, as a logical device, the device is formed by reading, by a processor of the electronic device where the device is located, a corresponding computer program instruction in the nonvolatile memory into the memory for operation.
From a hardware aspect, as shown in fig. 5, the block chain is a hardware structure diagram of an electronic device in which an execution apparatus of an intelligent contract in a block chain (a creating and upgrading apparatus of the intelligent contract in the block chain is not shown) in this specification, except for the processor, the memory, the network interface, and the nonvolatile memory shown in fig. 5, the electronic device in which the apparatus is located in the embodiment may also include other hardware generally according to an actual function of the electronic device, which is not described again.
Fig. 6 is a block diagram illustrating an apparatus for executing an intelligent contract in a blockchain according to an exemplary embodiment of the present disclosure. The apparatus can be applied to the electronic device shown in fig. 5, and the apparatus includes:
a receiving unit 410, which receives a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
a response unit 420, configured to, in response to the first transaction, invoke a logical contract corresponding to the first contract address, and obtain service logic maintained in a contract account corresponding to the logical contract;
a determining unit 430 for determining field names for executing the state data lacking in the business logic;
the routing unit 440 is configured to invoke a routing contract of the block chain, and query a second contract address mapped to the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
the obtaining unit 450 is configured to invoke the data contract corresponding to the second contract address, and obtain the state data of the field name maintained in the contract account corresponding to the data contract;
the execution unit 460 supplements the state data to the missing state data in the service logic to execute the service logic.
Optionally, the apparatus further comprises:
and the updating unit is used for calling the data contract corresponding to the second contract address after the business logic is executed to generate new state data of the target field, updating the state data of the target field maintained in the contract account corresponding to the data contract and modifying the state data of the target field into the new state data.
Optionally, the apparatus further comprises:
the first receiving subunit receives a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
the first response subunit responds to the second transaction, creates a logic contract and writes the business logic into a contract account corresponding to the logic contract;
the first creating subunit is used for creating a data contract and writing initial state data of each field in the business logic into a contract account corresponding to the data contract;
and the first updating subunit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and writing the first contract address corresponding to the logic contract and the second contract address of the data contract into the mapping table.
Optionally, the apparatus further comprises:
the second receiving subunit receives a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
a second response subunit, configured to create a new logical contract in response to the third transaction, and write the new business logic in a contract account corresponding to the new logical contract;
and the second updating subunit is used for calling the routing contract in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contract, and modifying the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
Optionally, the apparatus further comprises:
a second creating subunit, configured to create a new data contract if the new service logic is added with a new field compared with the old service logic, and write initial state data of the new field into a contract account corresponding to the new data contract;
and the third updating subunit is used for calling the routing contract in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contract, and increasing the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
Optionally, the response unit 420 includes:
if the first transaction also carries state data related to services, responding to the first transaction, calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract; further calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to record the state data carried by the first transaction; and further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
Optionally, the state data maintained by the contract account corresponding to the data contract is located in an asset mapping table, and the asset mapping table stores the state data of the user account and the user asset;
in the response unit 420, invoking a data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract includes:
if the first transaction is an entry transaction of the user asset, calling a data contract corresponding to the second contract address, and recording the state data of the user account and the user asset in the asset mapping table;
if the first transaction is the expenditure presentation transaction of the user asset, calling a data contract corresponding to the second contract address, and checking whether a user account indicated by the first transaction is located in the asset mapping table;
in the response unit 420, invoking a logical contract corresponding to the first contract address to obtain service logic maintained in a contract account corresponding to the logical contract, including:
and when the user account is positioned in the asset mapping table, further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
An apparatus for creating an intelligent contract in a blockchain according to an exemplary embodiment of the present specification is described below. The apparatus can also be applied to the electronic device shown in fig. 5, and the apparatus includes:
the receiving unit is used for receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
a response unit, which responds to the second transaction, creates a logic contract and writes the business logic in a contract account corresponding to the logic contract;
the creating unit is used for creating a data contract and writing initial state data of each field in the business logic into a contract account corresponding to the data contract;
and the updating unit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and writing the first contract address corresponding to the logic contract and the second contract address of the data contract into the mapping table.
An apparatus for upgrading an intelligent contract in a blockchain according to an exemplary embodiment of the present disclosure is described below. The apparatus can also be applied to the electronic device shown in fig. 5, and the apparatus includes:
the receiving unit is used for receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
a response unit, which responds to the third transaction, creates a new logic contract and writes the new business logic in the contract account corresponding to the new logic contract;
and the upgrading unit is used for calling the routing contracts in the block chain, updating the mapping table maintained in the contract account corresponding to the routing contracts, and modifying the first contract address of the old logic contract in the mapping table into the first contract address of the new logic contract.
Optionally, the apparatus further comprises:
a creating unit, if the new service logic is added with a new field compared with the old service logic, creating a new data contract, and writing the initial state data of the new field into a contract account corresponding to the new data contract;
and the updating unit is used for calling the routing contract in the block chain, updating a mapping table maintained in a contract account corresponding to the routing contract, and increasing the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some implementations, multitasking and parallel processing may also be possible or may be advantageous.
The terminology used in the description of the one or more embodiments is for the purpose of describing the particular embodiments only and is not intended to be limiting of the description of the one or more embodiments. As used in one or more embodiments of the present specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used in one or more embodiments of the present description to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of one or more embodiments herein. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
The above description is only for the purpose of illustrating the preferred embodiments of the one or more embodiments of the present disclosure, and is not intended to limit the scope of the one or more embodiments of the present disclosure, and any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the one or more embodiments of the present disclosure should be included in the scope of the one or more embodiments of the present disclosure.

Claims (10)

1. A method for executing intelligent contracts in a blockchain, the method comprising:
receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
responding to the first transaction, calling a logic contract corresponding to the first contract address, and acquiring service logic maintained in a contract account corresponding to the logic contract;
determining a field name for executing state data lacking in the business logic;
calling a routing contract of the block chain, and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
calling a data contract corresponding to the second contract address to acquire state data of the field name maintained in a contract account corresponding to the data contract;
supplementing the state data to missing state data in the business logic to execute the business logic.
2. The method of claim 1, further comprising:
and after the business logic is executed to generate new state data of a target field, calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to modify the state data of the target field into new state data.
3. The method of claim 1, further comprising:
receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
in response to the second transaction, creating a logical contract, and writing the business logic in a contract account corresponding to the logical contract;
creating a data contract, and writing initial state data of each field in the business logic in a contract account corresponding to the data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to write a first contract address corresponding to the logic contract and a second contract address of the data contract into the mapping table.
4. The method of claim 1, further comprising:
receiving a third transaction submitted by the user; the third transaction carries a first contract address of an old logic contract to be upgraded and new service logic to be upgraded;
in response to the third transaction, creating a new logical contract, and writing the new business logic in a contract account corresponding to the new logical contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to modify the first contract address of the old logical contract in the mapping table into the first contract address of the new logical contract.
5. The method of claim 4, further comprising:
if the new business logic is added with a new field compared with the old business logic, a new data contract is created, and the initial state data of the new field is written in a contract account corresponding to the new data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to increase the mapping relation between the first contract address and the second contract address of the new data contract in the mapping table.
6. The method according to claim 1, wherein if the first transaction further carries status data related to a service, the invoking a logical contract corresponding to the first contract address in response to the first transaction to obtain a service logic maintained in a contract account corresponding to the logical contract specifically includes:
in response to the first transaction, invoking a routing contract of the blockchain, and querying a second contract address mapped to the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
further calling a data contract corresponding to the second contract address, and updating the state data of the target field maintained in a contract account corresponding to the data contract so as to record the state data carried by the first transaction;
and further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
7. The method of claim 6, wherein the status data maintained by the contract account corresponding to the data contract is located in an asset mapping table, the asset mapping table storing status data of the user account and the user asset;
the invoking a data contract corresponding to the second contract address, and updating the state data of the target field maintained in the contract account corresponding to the data contract, includes:
if the first transaction is an entry transaction of the user asset, calling a data contract corresponding to the second contract address, and recording the state data of the user account and the user asset in the asset mapping table;
if the first transaction is the expenditure presentation transaction of the user asset, calling a data contract corresponding to the second contract address, and checking whether a user account indicated by the first transaction is located in the asset mapping table;
the logic contract corresponding to the first contract address is called to obtain the service logic maintained in the contract account corresponding to the logic contract,
and when the user account is positioned in the asset mapping table, further calling a logic contract corresponding to the first contract address to acquire service logic maintained in a contract account corresponding to the logic contract.
8. A method for creating an intelligent contract in a blockchain, the method comprising:
receiving a second transaction submitted by the user; the second transaction carries service logic of the intelligent contract to be created;
in response to the second transaction, creating a logical contract, and writing the business logic in a contract account corresponding to the logical contract;
creating a data contract, and writing initial state data of each field in the business logic in a contract account corresponding to the data contract;
and calling the routing contract in the block chain, and updating a mapping table maintained in a contract account corresponding to the routing contract so as to write a first contract address corresponding to the logic contract and a second contract address of the data contract into the mapping table.
9. An apparatus for executing intelligent contracts in a blockchain, the apparatus comprising:
the receiving unit is used for receiving a first transaction submitted by a user; the first transaction carries a first contract address of a logic contract required to be called by service execution;
the response unit is used for responding to the first transaction, calling a logic contract corresponding to the first contract address and acquiring service logic maintained in a contract account corresponding to the logic contract;
a determining unit that determines a field name for executing state data lacking in the business logic;
the routing unit is used for calling the routing contract of the block chain and inquiring a second contract address mapped by the first contract address in a mapping table maintained in a contract account corresponding to the routing contract;
the acquisition unit is used for calling the data contract corresponding to the second contract address and acquiring the state data of the field name maintained in the contract account corresponding to the data contract;
and the execution unit supplements the state data to the missing state data in the service logic so as to execute the service logic.
10. An electronic device, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor implements the method of any one of claims 1-8 by executing the executable instructions.
CN202080002396.7A 2020-10-12 2020-10-12 Method and device for executing intelligent contracts in block chain and electronic equipment Pending CN112400182A (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/120487 WO2022077186A1 (en) 2020-10-12 2020-10-12 Execution method and apparatus for smart contract in blockchain, and electronic device

Publications (1)

Publication Number Publication Date
CN112400182A true CN112400182A (en) 2021-02-23

Family

ID=74624922

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202080002396.7A Pending CN112400182A (en) 2020-10-12 2020-10-12 Method and device for executing intelligent contracts in block chain and electronic equipment

Country Status (2)

Country Link
CN (1) CN112400182A (en)
WO (1) WO2022077186A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112819634A (en) * 2021-02-25 2021-05-18 成都质数斯达克科技有限公司 Transaction processing method and device, electronic equipment and readable storage medium
CN113220701A (en) * 2021-05-25 2021-08-06 成都佰纳瑞信息技术有限公司 Block chain-based data structure adaptive change upgrading method, device, equipment and product
CN113486114A (en) * 2021-06-30 2021-10-08 电子科技大学 Block chain intelligent contract calling management method
WO2024021417A1 (en) * 2022-07-29 2024-02-01 蚂蚁区块链科技(上海)有限公司 Data account creation method and apparatus

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117726343A (en) * 2024-02-06 2024-03-19 中国信息通信研究院 Method, device, equipment and medium for supervising execution of intelligent contracts in block chain

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107145521A (en) * 2017-04-10 2017-09-08 杭州趣链科技有限公司 A kind of data migration method towards block chain multistage intelligent contract
CN109151031A (en) * 2018-08-28 2019-01-04 北京奇虎科技有限公司 Contract processing method and processing device based on block chain
US20200169385A1 (en) * 2018-10-26 2020-05-28 Alibaba Group Holding Limited Data processing method and apparatus

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109559229A (en) * 2018-11-30 2019-04-02 众安信息技术服务有限公司 The method of the intelligent contract group of update based on block chain
US20200202355A1 (en) * 2019-04-19 2020-06-25 Alibaba Group Holding Limited Storage and execution of smart contracts in blockchains
CN110933163B (en) * 2019-11-27 2021-08-24 腾讯科技(深圳)有限公司 Block chain contract deployment method, device, equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107145521A (en) * 2017-04-10 2017-09-08 杭州趣链科技有限公司 A kind of data migration method towards block chain multistage intelligent contract
CN109151031A (en) * 2018-08-28 2019-01-04 北京奇虎科技有限公司 Contract processing method and processing device based on block chain
US20200169385A1 (en) * 2018-10-26 2020-05-28 Alibaba Group Holding Limited Data processing method and apparatus

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
原力小小鱼: ""ForTube技术文章系列一|技术架构规划"", pages 1 - 5, Retrieved from the Internet <URL:《https://weibo.com/ttarticle/p/show?id=2309404509250859696285》> *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112819634A (en) * 2021-02-25 2021-05-18 成都质数斯达克科技有限公司 Transaction processing method and device, electronic equipment and readable storage medium
CN112819634B (en) * 2021-02-25 2023-06-02 成都质数斯达克科技有限公司 Transaction processing method, device, electronic equipment and readable storage medium
CN113220701A (en) * 2021-05-25 2021-08-06 成都佰纳瑞信息技术有限公司 Block chain-based data structure adaptive change upgrading method, device, equipment and product
CN113486114A (en) * 2021-06-30 2021-10-08 电子科技大学 Block chain intelligent contract calling management method
CN113486114B (en) * 2021-06-30 2023-03-28 电子科技大学 Block chain intelligent contract calling management method
WO2024021417A1 (en) * 2022-07-29 2024-02-01 蚂蚁区块链科技(上海)有限公司 Data account creation method and apparatus

Also Published As

Publication number Publication date
WO2022077186A1 (en) 2022-04-21

Similar Documents

Publication Publication Date Title
CN110471984B (en) Service processing method and device based on block chain and electronic equipment
US11336589B2 (en) Allocating virtual resource based on blockchain
CN112400182A (en) Method and device for executing intelligent contracts in block chain and electronic equipment
CN110706114B (en) Block chain-based default asset processing method and device and electronic equipment
CN110020542B (en) Data reading and writing method and device and electronic equipment
CN110032599B (en) Data structure reading and updating method and device, and electronic equipment
CN110458631B (en) Bill number distribution method and device based on block chain and electronic equipment
CN110765200B (en) Asset procurement method and device based on block chain and electronic equipment
US20200175487A1 (en) Obtaining a blockchain-based, real-name, electronic bill
US11429983B2 (en) Blockchain-based bill write-off method, apparatus, electronic device, and storage medium
CN110032598B (en) Method and device for updating field and electronic equipment
US11361054B2 (en) Blockchain-based infringement detection method, apparatus, and electronic device
WO2021017437A1 (en) Blockchain-based note verification method and apparatus, electronic device, and storage medium
WO2021017439A1 (en) Block chain-based electronic bill number application method and apparatus, and electronic device
US10963854B2 (en) Blockchain-based electronic bill reimbursement method, apparatus, and electronic device
US10846765B2 (en) Blockchain-based e-bill number application method, apparatus, and electronic device
CN110032568B (en) Data structure reading and updating method and device, and electronic equipment
US11256551B2 (en) Blockchain-based virtual resource allocation
US10789628B2 (en) Blockchain-based bill number allocation method, apparatus and electronic device
CN112258189A (en) Block chain-based subscription management method and device and electronic equipment
US20200279309A1 (en) Blockchain-based electronic bill cancellation method, apparatus, and electronic device
CN111831678A (en) Privacy protection method and device based on block chain and electronic equipment
CN111523052A (en) Block chain-based user recommendation method and device and electronic equipment
CN111898139B (en) Data reading and writing method and device and electronic equipment
CN113836227B (en) Asset purchasing method and device based on blockchain and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination