Method and apparatus for automatically executing a contract based on variable status

By defining target type variables in the blockchain contract state and registering a callback list, the contract is executed automatically, solving the problems of timely perception of variable state changes and preset operations in the blockchain. This achieves flexible and efficient operation execution and reduces energy consumption.

CN114968422BActive Publication Date: 2026-01-23ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210600436.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-30
Publication Date
2026-01-23
Estimated Expiration
2042-05-30

AI Technical Summary

Technical Problem

Existing technologies in blockchain applications struggle to promptly detect changes in variables within the world's state and efficiently execute pre-defined operations. This is especially true in privacy computing scenarios, where external parties are required to periodically query authorization status, resulting in a lack of real-time performance and high energy consumption.

Method used

By defining variables of the target type in the contract state and registering a callback list, the contract can be automatically executed using the callback parameters in the callback list, enabling timely perception of changes in variable state and preset operations.

Benefits of technology

It enables timely perception of changes in the state of variables in the world, flexibly executes preset operations, reduces the need for external queries, and saves energy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114968422B_ABST
    Figure CN114968422B_ABST
Patent Text Reader

Abstract

Embodiments of the present specification provide a method and device for automatically executing a contract based on a variable state. A specific embodiment of the method includes: determining that the state of a first variable of a target type has changed according to the execution result of a target transaction, wherein the target transaction calls a first contract; determining whether a callback list for the first variable is included in the contract state of the first contract, wherein a callback item in the callback list includes information of a callback contract and a callback parameter; and in response to determining that the callback list for the first variable is included, executing the callback contract based on the callback parameter of the callback item in the callback list.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present specification belong to the technical field of blockchains, and particularly relate to a method and device for automatically executing a contract based on a variable state. BACKGROUND

[0002] Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. In a blockchain system, data blocks are combined into a chain-type data structure in a time sequence, and are guaranteed to be non-tamperable and non-forgable by cryptography. Due to the characteristics of decentralization, information non-tamperability, and autonomy, blockchain has received more and more attention and application.

[0003] Blockchain can be understood as a distributed state machine: all nodes start from the same genesis state, and then run the transactions in the blocks that reach consensus one by one, driving the state of each node to change according to the same operation sequence (add, delete, modify), so that all nodes are consistent after executing the transactions in the same numbered block. We call this state the world state. The world state records various information, such as account balances, smart contract bytecodes, custom data of each smart contract, and chain configuration parameters. The world state represents the current state, i.e., the current values of the recorded state data. In some blockchain application scenarios, it is sometimes necessary to execute certain preset operations based on the values of certain variables in the world state. For example, in a privacy computing process based on blockchain, certain variables in the world state need to meet certain running conditions (such as collecting enough data authorization) before corresponding privacy computing can be started. For these scenarios, it is of great practical significance and value to timely perceive the changes of variables in the world state and efficiently execute preset operations based on the changes of variables in the world state. SUMMARY

[0004] One or more embodiments of the present specification describe a method and device for automatically executing a contract based on a variable state.

[0005] According to a first aspect, a method for automatically executing a contract based on a variable state is provided, the method comprising: determining that a state of a first variable of a target type changes according to an execution result of a target transaction, wherein the target transaction invokes a first contract; determining whether a callback list for the first variable is contained in a contract state of the first contract, wherein a callback item in the callback list comprises information of a callback contract and a callback parameter; and in response to determining that the callback list for the first variable is contained, executing the callback contract based on the callback parameter of the callback item in the callback list.

[0006] According to a second aspect, an apparatus for automatically executing a contract based on a variable state is provided, the apparatus comprising: a first determining unit configured to determine that a state of a first variable of a target type is changed according to an execution result of a target transaction, wherein the target transaction invokes a first contract; a second determining unit configured to determine whether a callback list for the first variable is contained in a contract state of the first contract, wherein a callback item in the callback list comprises information of a callback contract and a callback parameter; and an executing unit configured to, in response to determining that the callback list for the first variable is contained, execute the callback contract based on the callback parameter of the callback item in the callback list.

[0007] According to a third aspect, a computer readable storage medium is provided, which stores a computer program, when the computer program is executed in a computer, the computer is caused to execute the method according to any implementation manner of the first aspect.

[0008] According to a fourth aspect, a node of a blockchain is provided, comprising a memory and a processor, characterized in that the memory stores executable code, and the processor executes the executable code to implement the method according to any implementation manner of the first aspect.

[0009] The method and apparatus for automatically executing a contract based on a variable state provided by the embodiments of the present specification can declare the type of a variable that will affect the execution of a preset operation after a state change as a target type when a contract is used to define the variable, wherein a first variable of the target type can be defined by a first contract. The node of the blockchain can first determine that the state of the first variable of the target type is changed according to an execution result of a target transaction, and then determine whether a callback list for the first variable is contained in a contract state of the first contract, wherein a callback item in the callback list comprises information of a callback contract and a callback parameter. If it is determined that the callback list for the first variable is contained in the contract state of the first contract, the callback contract is executed based on the callback parameter of the callback item in the callback list, and the preset operation can be executed based on the callback contract, thereby realizing timely sensing of the state change of the variable of the target type in the world state and automatically executing the preset operation based on the state change of the variable of the target type. BRIEF DESCRIPTION OF DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present specification, the drawings needed in the embodiment description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments described in the present specification, and other drawings can also be obtained according to these drawings without creative labor.

[0011] Figure 1 A blockchain architecture diagram in an embodiment is shown;

[0012] Figure 2 A schematic diagram showing one application scenario in which the embodiments of the present specification can be applied is shown;

[0013] Figure 3 A flowchart showing a method of automatically executing a contract based on a variable state according to one embodiment is shown;

[0014] Figure 4 A flowchart showing one example of registering a callback item for a first variable is shown;

[0015] Figure 5 A flowchart showing one example of unregistering a callback item for a first variable is shown;

[0016] Figure 6 A schematic block diagram showing an apparatus of automatically executing a contract based on a variable state according to one embodiment is shown. DETAILED DESCRIPTION

[0017] In order to make the person skilled in the art better understand the technical solutions in the present specification, the technical solutions in the present specification will be described clearly and completely in the following with reference to the drawings in the embodiments of the present specification. Obviously, the described embodiments are only some of the embodiments of the present specification, not all. Based on the embodiments in the present specification, all other embodiments obtained by the person skilled in the art without creative labor should belong to the scope of protection of the present specification.

[0018] In order to further illustrate the blockchain technology, Figure 1 A blockchain architecture diagram in one embodiment is shown. In the blockchain architecture diagram shown, Figure 1 In the blockchain architecture diagram shown, the blockchain 100 contains, for example, 6 nodes. The connection between the nodes schematically represents a P2P (Peer to Peer) connection. The full amount of the ledger can be stored on these nodes, i.e. all blocks and the state of all accounts are stored. Among them, each node in the blockchain can produce the same state in the blockchain by executing the same transaction, and each node in the blockchain can store the same state database. It can be understood that, Figure 1Although the example shows a blockchain with 6 nodes, this specification's embodiments are not limited to this and may include other numbers of nodes. Specifically, the nodes in the blockchain can satisfy the Byzantine Fault Tolerance (BFT) requirement. The Byzantine Fault Tolerance requirement can be understood as the existence of Byzantine nodes within the blockchain, while the blockchain does not exhibit Byzantine behavior externally. Generally, some Byzantine Fault Tolerance algorithms require a number of nodes greater than 3f+1, where f is the number of Byzantine nodes, such as the Practical Byzantine Fault Tolerance (PBFT) algorithm.

[0019] In the blockchain field, a transaction refers to a unit of task executed and recorded within the blockchain. A transaction typically includes a From field, a To field, and a Data field. Specifically, in the case of a transfer transaction, the From field represents the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field represents the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount. In the case of a transaction calling a smart contract on the blockchain, the From field represents the account address initiating the transaction, the To field represents the account address of the contract called by the transaction, and the Data field includes the function name in the called contract and the parameters passed to that function, which is used to retrieve and execute the function's code from the blockchain during transaction execution.

[0020] Blockchain provides the functionality of smart contracts. A smart contract on the blockchain is a contract that can be triggered and executed by transactions within the blockchain system. Smart contracts can be defined in the form of code. In Ethereum, calling a smart contract involves initiating a transaction pointing to the smart contract address, causing each node in the Ethereum network to run the smart contract code in a distributed manner. It's worth noting that besides users creating smart contracts, the system can also set smart contracts in the genesis block. These contracts are generally called genesis contracts. Typically, genesis contracts can set some blockchain data structures, parameters, attributes, and methods. Furthermore, accounts with system administrator privileges can create or modify system-level contracts (referred to as system contracts). These system contracts can be used to add data structures for different business operations to the blockchain.

[0021] In a contract deployment scenario, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying the contract) to a server such as... Figure 1In the blockchain shown, the `data` field of the transaction includes the code (such as bytecode or machine code) of the contract to be created, and the `to` field of the transaction is empty, indicating that the transaction is used to deploy the contract. After the nodes reach an agreement through the consensus mechanism, the contract address "0x6f8ae93…" is determined. Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates state storage corresponding to the contract account, and saves the contract code in the contract's state storage, thus the contract is successfully created.

[0022] In scenarios where contracts are invoked, for example, Bob sends a transaction to invoke a smart contract, such as... Figure 1 In the blockchain shown, the `from` field of this transaction is the address of the account of the transaction initiator (i.e., Bob), the `to` field "0x6f8ae93…" represents the address of the smart contract being invoked, and the `data` field of the transaction includes the method and parameters for invoking the smart contract. After consensus is reached on this transaction in the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract separately, and updating the state database based on the execution of the contract.

[0023] As mentioned earlier, in some blockchain applications, it's sometimes necessary to execute predefined operations based on the values ​​of certain variables in the world state. For example, in blockchain-based privacy computing, sufficient data access authorization is required to initiate the corresponding workflow contract. To address this, one approach involves the workflow contract's data authorization addition function not only adding authorization but also checking whether the required data access authorization has been obtained after adding authorization based on the transaction. Once the authorization requirements are met, the workflow contract is proactively initiated as the workflow initiator during the execution of this transaction. This approach requires writing the logic for automatically initiating the workflow contract based on authorization additions into the contract body, which is inflexible and cannot handle unforeseen functional requirements during contract development. Furthermore, upgrading the contract to expand its capabilities involves review from various parties. Another approach involves the blockchain supporting querying the authorization status of the workflow contract through transactions. The workflow initiator periodically calls the query interface, and after confirming that the workflow contract has obtained sufficient authorization, sends a transaction to initiate the workflow. This approach requires external parties to periodically query the authorization status through transactions using a polling method, lacking real-time performance and resulting in high energy consumption.

[0024] Therefore, the embodiments of this specification provide a method for automatically executing contracts based on variable states, thereby enabling timely perception of changes in the state of variables in the world state and automatic execution of preset operations based on changes in variable states.

[0025] like Figure 2 As shown, Figure 2This diagram illustrates an application scenario to which the embodiments of this specification can be applied. This application scenario can be a scenario of privacy computing based on blockchain. In this scenario, after the amount of authorized data usage reaches a certain amount, the corresponding privacy computing can be initiated. That is, the value of the variable N1, which represents the amount of authorized data, will affect the execution of the corresponding privacy computing operation after a change. Therefore, when defining variable N1 through contract C1, the type of variable N1 is declared as the target type, and the information of variable N1 is stored in the contract state of contract C1. As an example, users can be allowed to query the state of the target type variable in the world state.

[0026] A blockchain node can receive a transaction Tx1 sent by caller B to register a callback item. Transaction Tx1 can invoke contract C1. Transaction Tx1 can include the variable name of variable N1, the callback parameters of the callback contract, and the information of the callback contract (e.g., the contract address of the callback contract). In this example, the callback contract can be used to determine whether variable N1 exceeds a preset threshold at the current moment. When variable N1 exceeds the preset threshold, a workflow contract for privacy computation is invoked to perform the relevant privacy computation operations. A blockchain node can execute transaction Tx1 to add a callback item to a pre-set callback list for variable N1. The callback item can include the information of the callback contract, the account of caller B, and the callback parameters of the callback contract. As an example, the callback list corresponding to variable N1 can be stored in the contract state of contract C1.

[0027] In this way, data owner A can send a target transaction to a blockchain node to upload authorization information to the chain. This target transaction can invoke contract C1. The blockchain node can receive and execute the target transaction sent by data owner A, and determine the state of variable N1 of the target type has changed based on the execution result of the target transaction. At this time, the blockchain node can determine whether the contract state of contract C1 contains a callback list for variable N1. The callback items in the callback list can include information about the callback contract and callback parameters. If the contract state of contract C1 includes a callback list for variable N1, the callback contract is executed based on the callback parameters of the callback items in the callback list. This callback contract can determine whether the value of variable N1 at the current moment exceeds a preset quantity threshold. If it does, the workflow contract for privacy computation is invoked to perform the relevant privacy computation operation. This achieves timely detection of changes in variable N1 and automatic invocation of the corresponding privacy computation workflow contract based on changes in the world state of variable N1 to perform privacy computation operations. This method does not require specifying the actions to be executed after the world state of variable N1 changes in the contract body of the workflow contract corresponding to privacy computation. Instead, it is customized by the caller B by registering callback items, which is flexible. Furthermore, this method does not require external sources to periodically query the value of variable N1 through transactions using a polling method, thus saving energy.

[0028] See also Figure 3 , Figure 3 A flowchart illustrating a method for automatically executing contracts based on variable states according to one embodiment is shown. It is understood that this method can be executed through nodes in a blockchain, which can be implemented by any device, equipment, or cluster of devices with computing and processing capabilities.

[0029] like Figure 3 As shown, this method for automatically executing contracts based on variable states may include the following steps:

[0030] Step 301: Based on the execution result of the target transaction, determine the change in the state of the first variable of the target type.

[0031] In this embodiment, blockchain nodes can receive and execute target transactions sent by users. After executing the target transaction, the blockchain nodes can determine that the state of the first variable of the target type has changed based on the execution result of the target transaction. That is, the execution result of the target transaction will change the state of the first variable of the target type in the world state. Here, the first variable of the target type can be predefined through a first contract. When defining the first variable through the first contract, the type of the first variable can be declared as the target type, and the information of the first variable (e.g., variable value, variable name, attributes, etc.) can be stored in the contract state of the first contract. The aforementioned target transaction can invoke the first contract to change the variable value of the first variable recorded in the contract state of the first contract.

[0032] To automatically execute a preset operation after the state of the first variable changes, users can register callback items for the first variable in a pre-defined callback list. This callback list can be stored in the contract state of the first contract. Here, the user can be the caller of the callback contract. In this way, blockchain nodes can automatically execute the callback contract based on the state of the first variable in the current world state. For example, when it is determined that the state of the first variable in the contract state of the first contract has changed after a transaction is executed, a callback item in the user-registered callback list for the first variable can be invoked.

[0033] In some alternative implementations, such as Figure 4 As shown, Figure 4 A flowchart illustrating an example of registering a callback item for the first variable is shown. Figure 4 In the example shown, a callback item can be registered for the first variable in the following way:

[0034] S401, the caller of the callback contract can send the first transaction to the blockchain to register the callback item.

[0035] In this implementation, the first transaction may include the variable name of the first variable, the information of the callback contract, and the callback parameters of the callback contract. Here, the callback contract information may include the code of the callback contract, the address of the callback contract, etc. The callback parameters may refer to the parameters used when calling the callback contract. In practice, the caller can set the callback parameters of the callback contract according to actual business needs, and define the corresponding business logic in the callback contract, that is, define the operations to be performed in response to changes in the state of the first variable. For example, in a privacy computing business scenario, assuming the first variable is the data access authorization amount in privacy computing, the callback contract can be used to determine whether the data access authorization amount at the current moment exceeds a preset threshold. When the data access authorization amount exceeds the threshold, a preset workflow contract is called, which can be used to perform related privacy computing operations. Specifically, the callback contract can define the contract address of the workflow contract corresponding to privacy computing, and the business logic for calling the corresponding workflow contract for privacy computing. For example, the business logic could be to call the corresponding workflow contract for privacy computing when the authorized data amount exceeds a preset value. For example, in a business scenario where emails are sent based on an account's balance, the business logic for sending emails can be defined in the callback contract. For instance, the business logic could be to automatically send an email with preset content to the email address corresponding to the account when the account balance is less than a preset value.

[0036] A node in the blockchain can receive a first transaction sent by the caller to register a callback item, which can then invoke the first contract.

[0037] S403, a node in the blockchain can execute the first transaction by adding a callback item to a pre-set callback list for the first variable.

[0038] In this implementation, a blockchain node can execute the first transaction, invoke the first contract, and add a callback item to a pre-defined callback list for the first variable. This callback item can include information about the callback contract, the caller's account, callback parameters, etc. The callback list for the first variable can be stored in the contract state of the first contract. It's understood that a callback list is only set for the first variable when a caller registers a callback item for it. If no caller registers a callback item for the first variable, or if a registered callback item is subsequently unregistered, a callback list is not required. This implementation allows the caller to set callback items for the first variable according to actual business needs and define the operations to be performed in response to state changes in the first variable within the callback contract included in the callback item. This approach customizes the operations to be performed when the state of the first variable changes by registering callback items, without requiring modification of other existing business-related contracts, thus offering flexibility.

[0039] In some alternative implementations, such as Figure 5 As shown, Figure 5 A flowchart illustrating an example of canceling a callback item for the first variable is shown. Figure 5 In the example shown, the caller can also unregister the callback item registered for the first variable in the following ways:

[0040] S501, the caller of the callback contract can send a second transaction to the blockchain to cancel the callback item.

[0041] In this implementation, the second transaction may include the caller's account and the variable name of the first variable.

[0042] A node in the blockchain can receive a second transaction sent by the caller to cancel the callback item, which can then invoke the first contract.

[0043] S503, a node in the blockchain can execute a second transaction by removing the callback item containing the caller's account from the callback list corresponding to the first variable.

[0044] In this implementation, blockchain nodes can execute a second transaction to invoke the first contract and delete callback entries containing the caller's account from the callback list corresponding to the first variable. Specifically, the blockchain nodes can search the callback list for the first variable in the contract state of the first contract based on the variable name of the first variable included in the second transaction, and then delete the callback entries containing the caller's account from the found callback list. This implementation allows the caller to delete previously set callback entries for the first variable according to actual business needs, thus enabling flexible configuration of callback entries.

[0045] Step 302: Determine whether the contract state of the first contract contains a callback list for the first variable.

[0046] In this embodiment, after the state of the first variable of the target type changes based on the execution result of the target transaction, the blockchain node can determine whether the contract state of the first contract contains a callback list for the first variable. The callback list can include callback items, which may include information about the callback contract, callback parameters, etc.

[0047] Step 303: In response to determining a callback list containing the first variable, execute the callback contract based on the callback parameters of the callback items in the callback list.

[0048] In this embodiment, if a blockchain node determines that the contract state of the first contract contains a callback list for the first variable, the blockchain node can execute the callback contract based on the callback parameters of the callback items in the callback list. In practice, the callback list for the first variable may include one or more callback items. For example, it may include one callback item registered by a caller, or it may include multiple callback items registered by multiple callers.

[0049] In some optional implementations, the execution of the callback contract based on the callback parameters of the callback items in the callback list in step 303 can be specifically performed as follows: After the target transaction is executed, the callback contract corresponding to the information of the callback contract included in the callback item is executed based on the callback parameters of the callback item in the callback list. With this implementation, the callback contracts corresponding to the callback items included in the callback list of the first variable can be executed immediately after the target transaction is executed.

[0050] In some alternative implementations, the target transaction can be a transaction within a target block, which can be a consensus-reached block and may include one or more transactions. Furthermore, step 303, which involves executing the callback contract based on the callback parameters of the callback items in the callback list, can be further implemented as follows:

[0051] First, blockchain nodes can determine whether the multiple transactions contained in the target block have been completed at the current moment.

[0052] Secondly, in response to the determination that the transactions contained in the target block at the current moment have not been completed, the variable name of the first variable can be added to the preset list of to be called.

[0053] Then, in response to determining that the transaction contained in the target block at the current moment has been completed, the variable name of the first variable is added to the call list. Based on the variable name contained in the call list, the corresponding callback contract and callback parameters are determined from the callback items in the callback list of the corresponding variable, and the corresponding callback contract is called through the determined callback parameters.

[0054] In this implementation, if the target block contains multiple transactions, the blockchain nodes can determine whether all transactions in the target block have been completed at the current moment. If not all transactions in the target block have been completed, the variable name of the first variable can be added to a pre-defined call list. In practice, the call list may include the variable names of one or more variables of the target type. If all transactions in the target block have been completed, after adding the variable name of the first variable to the call list, the corresponding callback contract can be executed based on the variable name of at least one variable included in the call list. Taking the first variable as an example, the blockchain nodes can query the callback list of the first variable from the contract state of the first contract based on the variable name of the first variable, then determine the corresponding callback contract and callback parameters from the callback items in the callback list of the first variable, and call the corresponding callback contract through the determined callback parameters. Through this implementation, the callback contract can be executed after all transactions in the target block have been completed, thereby increasing the flexibility of callback contract execution.

[0055] Optionally, blockchain nodes can also sort the callback items corresponding to the variable names in the call list. For example, a blockchain node can first obtain the callback items from the callback list of the variables corresponding to the variable names in the call list, and then sort the obtained call items in various ways, such as random sorting. After sorting the callback items corresponding to the variable names in the call list, the blockchain node can execute each callback item sequentially according to the sorting result. Specifically, for a certain callback item, the corresponding callback contract can be called based on the callback parameters of that callback item.

[0056] As an example, in addition to callback contract information and callback parameters, callback items in the callback list of the target type variable can also include callback priority. For example, callback priority can be set by the caller when registering the callback item. For instance, the caller can set the fee they are willing to pay to execute the callback contract when registering the callback item; the higher the fee, the higher the priority. That is, blockchain nodes can determine the priority of callback items based on the fee amount. Based on this, the sorting of callback items corresponding to variable names in the call list can be done as follows: sort the callback items corresponding to each variable name in the call list according to their callback priority. For example, they can be sorted in descending order of callback priority. Through this implementation, the execution order of callback items corresponding to variable names in the call list can be controlled based on their callback priority.

[0057] As another example, the sorting of callback items corresponding to variable names in the call list can also be done as follows:

[0058] First, the hash can be calculated based on the callback contract, callback party account, and block number of the target block where the target exchange is located, corresponding to each variable name in the to-be-called list. It's understandable that in practice, the information used to calculate the hash can be determined according to actual needs, and is not limited to using the callback contract, callback party account, and block number. For example, the hash can be calculated using the callback contract and callback party account. Or, the hash can be calculated using the callback contract, callback party account, and the registration time of the callback item, and so on.

[0059] Then, based on the hash calculation result, the callback items corresponding to the variable names in the to-be-called list are sorted. For example, they can be sorted in descending or ascending order of the hash calculation result. This implementation method allows the execution order of the callback items corresponding to the variable names in the to-be-called list to be determined based on hash calculation.

[0060] Reviewing the above process, in the embodiments of this specification, when using contract-defined variables, the type of a first variable that will affect the execution of a preset operation after its state changes can be declared as a target type. The first variable of the target type can be defined through a first contract. Blockchain nodes first determine that the state of the first variable of the target type has changed based on the execution result of the target transaction. Then, they determine whether the contract state of the first contract contains a callback list for the first variable. The callback items in the callback list include information about the callback contract and callback parameters. If it is determined that the contract state of the first contract contains a callback list for the first variable, the callback contract is executed based on the callback parameters of the callback items in the callback list. Based on the callback contract, a preset operation can be executed, thereby achieving timely perception of state changes of the target type variable in the world state and automatic execution of preset operations based on the change in the state of the target type variable.

[0061] According to another embodiment, an apparatus for automatically executing contracts based on variable states is provided. This apparatus can be deployed on nodes of a blockchain, and blockchain nodes can be implemented by any device, equipment, or cluster of devices with computing and processing capabilities.

[0062] Figure 6 A schematic block diagram of an apparatus for automatically executing contracts based on variable states, according to one embodiment, is shown. Figure 6As shown, the device 600 for automatically executing contracts based on variable states includes: a first determining unit 601, configured to determine, based on the execution result of a target transaction, that the state of a first variable of a target type has changed, wherein the target transaction invokes a first contract; a second determining unit 602, configured to determine, in the contract state of the first contract, whether a callback list for the first variable is included, wherein the callback items in the callback list include information of the callback contract and callback parameters; and an execution unit 603, configured to, in response to determining that a callback list for the first variable is included, execute the callback contract based on the callback parameters of the callback items in the callback list.

[0063] In some optional implementations of this embodiment, the apparatus 600 further includes: a first receiving unit (not shown in the figure), configured to receive a first transaction sent by the caller for registering a callback item, wherein the first transaction calls the first contract, and wherein the first transaction includes the variable name of the first variable, the callback parameters of the callback contract, and the information of the callback contract; and an adding unit (not shown in the figure), configured to execute the first transaction and add a callback item to a callback list pre-set for the first variable, wherein the callback item includes the information of the callback contract, the account of the caller, and the callback parameters.

[0064] In some optional implementations of this embodiment, the device 600 further includes: a second receiving unit (not shown in the figure), configured to receive a second transaction sent by the caller for canceling a callback item, wherein the second transaction calls the first contract, and the second transaction includes the variable name of the first variable; and a deletion unit (not shown in the figure), configured to execute the second transaction and delete the callback item containing the caller's account from the callback list corresponding to the first variable.

[0065] In some optional implementations of this embodiment, the execution unit 603 is further configured to: after the target transaction is executed, execute the callback contract based on the callback parameters of the callback items in the callback list.

[0066] In some optional implementations of this embodiment, the target transaction is a transaction in the target block, and the execution unit 603 includes: a variable name addition module (not shown in the figure), configured to add the variable name of the first variable to a preset call list in response to determining that the transaction contained in the target block at the current time has not been completed; and a contract invocation module (not shown in the figure), configured to, in response to determining that the transaction contained in the target block at the current time has been completed, add the variable name of the first variable to the call list, determine the corresponding callback contract and callback parameters from the callback items of the callback list of the corresponding variable based on the variable names contained in the call list, and invoke the corresponding callback contract through the determined callback parameters.

[0067] In some optional implementations of this embodiment, the device 600 further includes a sorting module (not shown in the figure), configured to sort the callback items corresponding to the variable names contained in the list to be called.

[0068] In some optional implementations of this embodiment, the callback item also includes a callback priority, and the sorting module is further configured to sort the callback items corresponding to each variable name in the list to be called according to the callback priority of the callback item corresponding to each variable name in the list to be called.

[0069] In some optional implementations of this embodiment, the sorting module is further configured to: calculate a hash based on the callback contract, the callback party account, and the block number of the target block where the target exchange is located for each callback item corresponding to the variable name in the call list; and sort the callback items corresponding to the variable names in the call list based on the hash calculation results.

[0070] In some optional implementations of this embodiment, the first variable is the data access authorization amount in privacy computing, and the callback contract is used to determine whether the data access authorization amount at the current moment exceeds a preset quantity threshold. When the data access authorization amount exceeds the preset quantity threshold, a preset workflow contract is invoked, wherein the workflow contract is used to perform related operations of privacy computing.

[0071] According to another embodiment, a computer-readable storage medium is also provided, on which a computer program is stored, which, when executed in a computer, causes the computer to perform... Figure 3 The method described.

[0072] According to another embodiment, a blockchain node is also provided, including a memory and a processor, characterized in that the memory stores executable code, and when the processor executes the executable code, it implements... Figure 3 The method described.

[0073] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages ​​and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.

[0074] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0075] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.

[0076] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.

[0077] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.

[0078] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0079] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0080] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0081] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0082] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0083] Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0084] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0085] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage devices.

[0086] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0087] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of this specification. Various modifications and variations can be made to the one or more embodiments of this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.

Claims

1. A method for automatically executing a contract based on variable state, the method comprising: The state of the first variable of the target type changes based on the execution result of the target transaction, wherein the target transaction calls the first contract, and the target type is the type of the first variable that affects the execution of the preset operation after the state change; Determine whether the contract state of the first contract contains a callback list for the first variable, wherein the callback items in the callback list include information about the callback contract and callback parameters; In response to determining a callback list containing the first variable, a callback contract is executed based on the callback parameters of the callback items in the callback list, and the preset operation is performed based on the callback contract.

2. The method according to claim 1, wherein, The method further includes: The caller sends a first transaction for registering a callback item. The first transaction calls the first contract. The first transaction includes the variable name of the first variable, the callback parameters of the callback contract, and the information of the callback contract. Execute the first transaction and add a callback item to the callback list pre-set for the first variable, wherein the callback item includes information about the callback contract, the caller's account, and the callback parameters.

3. The method according to claim 2, wherein, The method further includes: Receive a second transaction sent by the caller for canceling the callback item, the second transaction calling the first contract, wherein the second transaction includes the variable name of the first variable; Execute the second transaction and remove the callback item containing the caller's account from the callback list corresponding to the first variable.

4. The method according to claim 1, wherein, The execution of the callback contract based on the callback parameters of the callback items in the callback list includes: After the target transaction is completed, the callback contract is executed based on the callback parameters of the callback items in the callback list.

5. The method according to claim 1, wherein, The target transaction is the transaction in the target block, and The execution of the callback contract based on the callback parameters of the callback items in the callback list includes: In response to determining that the transactions contained in the target block at the current moment have not been completed, the variable name of the first variable is added to a preset list of to be invoked; In response to determining that the transaction contained in the target block at the current time has been completed, the variable name of the first variable is added to the call list. Based on the variable name contained in the call list, the corresponding callback contract and callback parameters are determined from the callback items in the callback list of the corresponding variable, and the corresponding callback contract is called through the determined callback parameters.

6. The method according to claim 5, wherein, The method further includes: Sort the callback items corresponding to the variable names contained in the list to be invoked.

7. The method according to claim 6, wherein, The callback items also include callback priority and sorting of callback items corresponding to variable names in the call list, including: The callback items corresponding to each variable name in the to-be-called list are sorted according to their callback priority.

8. The method according to claim 6, wherein, The step of sorting the callback items corresponding to the variable names contained in the list to be invoked includes: Calculate the hash based on the callback contract, callback party account, and block number of the target block where the target exchange is located, corresponding to each variable name in the call list; Based on the hash calculation results, the callback items corresponding to the variable names contained in the list to be called are sorted.

9. The method according to claim 1, wherein, The first variable is the data access authorization amount in privacy computing, and the callback contract is used to determine whether the data access authorization amount at the current moment exceeds a preset threshold. When the data access authorization amount exceeds the threshold, a preset workflow contract is invoked, wherein the workflow contract is used to perform privacy computing related operations.

10. An apparatus for automatically executing a contract based on variable state, the apparatus comprising: The first determining unit is configured to determine the state of a first variable of the target type changes based on the execution result of the target transaction, wherein the target transaction calls a first contract, and the target type is the type of the first variable that affects the execution of a preset operation after the state change; The second determining unit is configured to determine whether the contract state of the first contract contains a callback list for the first variable, wherein the callback items in the callback list include information about the callback contract and callback parameters. The execution unit is configured to, in response to determining a callback list containing callbacks for the first variable, execute a callback contract based on the callback parameters of the callback items in the callback list, and perform the preset operation based on the callback contract.

11. The apparatus according to claim 10, wherein, The device further includes: The first receiving unit is configured to receive a first transaction sent by the caller for registering a callback item. The first transaction calls the first contract, wherein the first transaction includes the variable name of the first variable, the callback parameters of the callback contract, and the information of the callback contract. Add a unit configured to execute the first transaction, and add a callback item to a callback list pre-set for the first variable, wherein the callback item includes information about the callback contract, the caller's account, and the callback parameters.

12. The apparatus according to claim 11, wherein, The device further includes: The second receiving unit is configured to receive a second transaction sent by the caller for canceling a callback item, wherein the second transaction calls the first contract, and the second transaction includes the variable name of the first variable; The deletion unit, configured to execute the second transaction, deletes the callback item containing the caller's account from the callback list corresponding to the first variable.

13. The apparatus according to claim 10, wherein, The execution unit is further configured as follows: After the target transaction is completed, the callback contract is executed based on the callback parameters of the callback items in the callback list.

14. The apparatus according to claim 10, wherein, The target transaction is the transaction in the target block, and The execution unit includes: The variable name addition module is configured to add the variable name of the first variable to a preset list of calls in response to determining that the transaction contained in the target block at the current time has not been completed. The contract invocation module is configured to, in response to determining that the transaction contained in the target block at the current time has been completed, add the variable name of the first variable to the list to be invoked, determine the corresponding callback contract and callback parameters from the callback items in the callback list of the corresponding variable based on the variable name contained in the list to be invoked, and invoke the corresponding callback contract through the determined callback parameters.

15. The apparatus according to claim 14, wherein, The device further includes: The sorting module is configured to sort the callback items corresponding to the variable names contained in the list to be called.

16. The apparatus according to claim 15, wherein, The callback item also includes callback priority, and the sorting module is further configured as follows: The callback items corresponding to each variable name in the to-be-called list are sorted according to their callback priority.

17. The apparatus according to claim 15, wherein, The sorting module is further configured as follows: Calculate the hash based on the callback contract, callback party account, and block number of the target block where the target exchange is located, corresponding to each variable name in the call list; Based on the hash calculation results, the callback items corresponding to the variable names contained in the list to be called are sorted.

18. The apparatus according to claim 10, wherein, The first variable is the data access authorization amount in privacy computing, and the callback contract is used to determine whether the data access authorization amount at the current moment exceeds a preset threshold. When the data access authorization amount exceeds the threshold, a preset workflow contract is invoked, wherein the workflow contract is used to perform privacy computing related operations.

19. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-9.

20. A blockchain node, comprising a memory and a processor, characterized in that, The memory stores executable code, and when the processor executes the executable code, it implements the method of any one of claims 1-9.

Citation Information

Patent Citations

  • Method, system and node for realizing privacy protection in block chain

    CN110032883A

  • Remote procedure call implementation method and device, equipment and medium

    CN110096381A