Data writing method and reading method based on smart contract virtual machine and related apparatuses

CN122653746APending Publication Date: 2026-08-28TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510239110.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2026-08-28

AI Technical Summary

Technical Problem

[0003]相关技术中,由于当前智能合约虚拟机为了能够支持对JSON对象中的数据读取,往往采用键值对Key-Value形式的状态数据库,在涉及JSON对象的存储时,如果直接存储JSON对象,则无法从JSON对象中进行数据读取,因此需要将JSON对象拆分为多个结构体、多个键值对再存储到预设的状态数据库中,但这样导致了存储的内容较多,使得数据存储成本高

Benefits of technology

[0018] According to one aspect of the present application, an electronic device is provided, including: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the method as described above.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122653746A_ABST
    Figure CN122653746A_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data writing method based on a smart contract virtual machine and a related device. In the method, a first preset instruction in the smart contract virtual machine enables the smart contract virtual machine to directly deserialize a serialized first JSON string to obtain a first JSON object, so that reading of any depth and any key can be implemented in the first JSON object. Then, a first target key name in the first JSON object is subjected to an assignment operation to obtain a second JSON object, and the second JSON object is serialized into a complete second JSON string and stored in a preset state database. In this way, data reading in the JSON object can be implemented, and a JSON object originally required to be split into multiple structures and key-value pairs can be stored as a single state, so that data storage cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and more specifically, to a data writing method and related apparatus based on a smart contract virtual machine. Background Technology

[0002] Currently, JSON (JavaScript Object Notation) is widely used in blockchains. It's a lightweight data exchange format that uses key-value pairs to represent data and supports nested structures, making it ideal for storing and transmitting complex data. Smart contracts are executable code stored on the blockchain that can automatically execute when predefined conditions are met. The virtual machine is an environment that provides computing resources and a runtime container for smart contracts; the data of smart contracts is stored in the contract database. The main role of the virtual machine is to process smart contracts, ensuring they run in an isolated and secure environment. A JSON object is a collection of key-value pairs. Blockchain systems can store and manage smart contract data in the form of JSON objects, making the data in smart contracts easy to understand and analyze, allowing for easy organization and access of data using key-value pairs, and enabling easy expansion to adapt to constantly changing data needs.

[0003] In related technologies, current smart contract virtual machines often use key-value pairs in the form of a state database to support reading data from JSON objects. When storing JSON objects, if the JSON object is stored directly, data cannot be read from the JSON object. Therefore, the JSON object needs to be split into multiple structures and multiple key-value pairs and then stored in a pre-defined state database. However, this results in a large amount of stored content, which leads to high data storage costs. Summary of the Invention

[0004] To address the aforementioned technical problems, embodiments of this application provide a data writing method and related apparatus based on a smart contract virtual machine, which enables the reading of data from JSON objects while reducing data storage costs in blockchain systems.

[0005] According to one aspect of the embodiments of this application, a data writing method based on a smart contract virtual machine is provided. The method includes: reading a first JSON string corresponding to an account in a first business request from a preset state database; wherein the first JSON string is a string obtained by serializing a JSON object containing a first target key name in the first business request; deserializing the first JSON string to obtain a first JSON object through a first preset instruction in the smart contract virtual machine, and assigning a value to the first target key name in the first JSON object to obtain a second JSON object; serializing the second JSON object to obtain a second JSON string, and writing the second JSON string into the account corresponding to the first business request.

[0006] In another exemplary embodiment, the step of deserializing the first JSON string to obtain a first JSON object using a first preset instruction in the smart contract virtual machine, and assigning a value to a first target key name in the first JSON object to obtain a second JSON object, includes: reading a first instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine; obtaining the first preset instruction from a preset instruction mapping table based on the first instruction identifier; reading and parsing elements from the data stack of the smart contract virtual machine according to the first preset instruction to obtain a tuple corresponding to the first JSON object; wherein the tuple corresponding to the first JSON object includes the first JSON string; deserializing the first JSON string to obtain the first JSON object; and assigning a value to the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object.

[0007] In another exemplary embodiment, the tuple corresponding to the first JSON object further includes the nesting depth of the first target key name, the key array corresponding to the first target key name, and the value to be written; the step of reading and parsing elements from the data stack according to the first preset instruction to obtain the tuple corresponding to the first JSON object includes: obtaining a preset parameter corresponding to the first preset instruction; wherein, the preset parameter is used to characterize the number of elements read from the data stack; according to the preset parameter corresponding to the first preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the first JSON object.

[0008] In another exemplary embodiment, the step of assigning values ​​to the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object includes: traversing the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object; if it does not exist, creating the first target key name at the corresponding position in the first JSON object according to the nesting depth of the first target key name, and assigning the value corresponding to the first target key name to the value to be written; and determining the first JSON object after the assignment operation as the second JSON object.

[0009] In another exemplary embodiment, the step of assigning values ​​to the first JSON object based on the tuple corresponding to the first JSON object to obtain a second JSON object includes: traversing the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object; if it exists, determining whether the value corresponding to the first target key name is a preset value or an empty string; if the value corresponding to the first target key name is neither the preset value nor the empty string, assigning the value corresponding to the first target key name to the value to be written; and determining the first JSON object after the assignment operation as the second JSON object.

[0010] In another exemplary embodiment, writing the second JSON string to the account corresponding to the first business request includes: loading the second JSON string onto the top of the data stack in the smart contract virtual machine; and writing the second JSON string from the top of the data stack to the account corresponding to the first business request in response to a preset write instruction in the smart contract virtual machine.

[0011] According to one aspect of the embodiments of this application, a data reading method based on a smart contract virtual machine is provided. The method includes: reading a third JSON string of an account corresponding to a second business request from a preset state database; wherein the third JSON string is a string obtained by serializing a JSON object to which a second target key name contained in the second business request belongs; and deserializing the third JSON string to obtain a third JSON object through a second preset instruction in the smart contract virtual machine, and performing a value retrieval operation on the second target key name in the third JSON object to obtain the value corresponding to the second target key name.

[0012] In another exemplary embodiment, the step of deserializing the third JSON string to obtain a third JSON object using a second preset instruction in the smart contract virtual machine, and performing a value retrieval operation on the second target key name in the third JSON object to obtain the value corresponding to the second target key name, includes: reading a second instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine; obtaining a second preset instruction from a preset instruction mapping table based on the second instruction identifier; reading and parsing elements from the data stack of the smart contract virtual machine according to the second preset instruction to obtain a tuple corresponding to the third JSON object; wherein the tuple corresponding to the third JSON object includes the third JSON string; deserializing the third JSON string to obtain the third JSON object; and performing a value retrieval operation on the third JSON object based on the tuple corresponding to the third JSON object to obtain the value corresponding to the second target key name.

[0013] In another exemplary embodiment, the tuple corresponding to the third JSON object further includes the nesting depth of the second target key name and the key array corresponding to the second target key name; the step of reading and parsing elements from the data stack according to the second preset instruction to obtain the tuple corresponding to the third JSON object includes: obtaining a preset parameter corresponding to the second preset instruction; the preset parameter is used to characterize the number of elements read from the data stack; according to the preset parameter corresponding to the second preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the third JSON object.

[0014] In another exemplary embodiment, the step of performing a value retrieval operation on the third JSON object based on the tuple corresponding to the third JSON object to obtain the value corresponding to the second target key name includes: traversing the key array corresponding to the second target key name according to the nesting depth of the second target key name to determine whether the second target key name exists in the third JSON object; if it exists, directly reading the value corresponding to the second target key name and loading the value corresponding to the second target key name into the top of the data stack of the smart contract virtual machine.

[0015] In another exemplary embodiment, the method further includes: if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is a first security level, then a preset value is used as the value corresponding to the second target key name and loaded onto the top of the data stack of the smart contract virtual machine; if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is a second security level, then the smart contract virtual machine is controlled to report an error; wherein the second security level is higher than the first security level.

[0016] According to one aspect of the embodiments of this application, a data writing device based on a smart contract virtual machine is provided, comprising: a first reading module configured to read a first JSON string corresponding to an account in a first business request from a preset state database; wherein the first JSON string is a string obtained by serializing a JSON object to which a first target key name in the first business request belongs; an assignment module configured to deserialize the first JSON string to obtain a first JSON object through a first preset instruction in the smart contract virtual machine, and assign a value to the first target key name in the first JSON object to obtain a second JSON object; and a writing module configured to serialize the second JSON object to obtain a second JSON string, and write the second JSON string into the account corresponding to the first business request.

[0017] According to one aspect of the embodiments of this application, a data reading device based on a smart contract virtual machine is provided, comprising: a second reading module configured to read a third JSON string of an account corresponding to a second business request from a preset state database; wherein the third JSON string is a string obtained by serializing a JSON object to which a second target key name contained in the second business request belongs; and a value retrieval module configured to deserialize the third JSON string to obtain a third JSON object through a second preset instruction in the smart contract virtual machine, and to retrieve the value corresponding to the second target key name in the third JSON object.

[0018] According to one aspect of the present application, an electronic device is provided, including: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the method as described above.

[0019] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided that stores computer-readable instructions thereon, which, when executed by a computer's processor, cause the computer to perform the method described above.

[0020] In the technical solution provided by the embodiments of this application, the first preset instruction in the smart contract virtual machine enables the smart contract virtual machine to directly deserialize the serialized first JSON string to obtain a first JSON object, thereby enabling the reading of arbitrary depth and arbitrary keys in the first JSON object; then, the first target key name in the first JSON object is assigned a value to obtain a second JSON object, and it is serialized into a complete second JSON string and stored in the preset state database. This not only enables the reading of data in the JSON object, but also stores the JSON object, which originally needed to be split into multiple structures and key-value pairs, as a single state, thereby reducing data storage costs.

[0021] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:

[0023] Figure 1 This is a schematic diagram of the structure of a blockchain system shown in an exemplary embodiment of this application;

[0024] Figure 2 This is a schematic diagram illustrating an implementation environment of the data writing method based on a smart contract virtual machine, as shown in an exemplary embodiment of this application;

[0025] Figure 3 This is a flowchart illustrating a data writing method based on a smart contract virtual machine, as shown in an exemplary embodiment of this application;

[0026] Figure 4 yes Figure 3 The flowchart of step S320 in the illustrated embodiment, which involves an assignment operation in an exemplary embodiment, is shown.

[0027] Figure 5 This is a schematic diagram illustrating the structure of the data stack of a smart contract virtual machine, as shown in an exemplary embodiment of this application.

[0028] Figure 6 yes Figure 4 The flowchart of step S440 in the illustrated embodiment, which involves an assignment operation in an exemplary embodiment, is shown.

[0029] Figure 7 yes Figure 4 A flowchart illustrating step S440 in the illustrated embodiment, which is an assignment operation in another exemplary embodiment;

[0030] Figure 8 This is an exemplary embodiment of the present application illustrating the application of data writing;

[0031] Figure 9 This is another exemplary embodiment of the present application illustrating the application of data writing;

[0032] Figure 10 This is a flowchart illustrating a data reading method based on a smart contract virtual machine, as shown in an exemplary embodiment of this application;

[0033] Figure 11 yes Figure 10 The flowchart of step S1020 in the illustrated embodiment, which involves a value retrieval operation in an exemplary embodiment, is shown.

[0034] Figure 12 This is a schematic diagram illustrating the structure of a data writing device based on a smart contract virtual machine, as shown in an exemplary embodiment of this application;

[0035] Figure 13 This is a schematic diagram illustrating the structure of a data reading device based on a smart contract virtual machine, as shown in an exemplary embodiment of this application;

[0036] Figure 14 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present application is shown. Detailed Implementation

[0037] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments identical to those described in this application. Rather, they are merely examples of apparatuses and methods identical to some aspects of this application as detailed in the appended claims.

[0038] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented as application programs, in one or more hardware modules or integrated circuits, or in different models and / or processor devices and / or microcontroller devices.

[0039] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0040] It should be noted that "multiple" as mentioned in this application refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0041] The technical solution provided in this application relates to a business scenario of data writing and data reading based on a smart contract virtual machine in a blockchain, wherein:

[0042] A smart contract is a computer program that runs on a blockchain system. Its key feature is the ability to automatically execute contract terms and verify the results, thereby achieving decentralized trust and execution. Smart contracts are typically used to write and execute a series of fully automated operations, such as currency transactions, digital identity verification, asset management, and voting. Based on blockchain technology, smart contracts can be jointly controlled by multiple participants without the need for a single governing body or intermediary. This decentralized nature makes smart contracts a powerful solution for transactions and business logic execution without the need to trust a third party. Multiple smart contracts can be deployed in a blockchain system, distinguished by contract identity (ID), identifier, or name. The appropriate smart contract is invoked to execute the business request by using the identifier contained within the request.

[0043] A smart contract virtual machine is a software or hardware entity that simulates the running of another complete operating system on a computer. It allows multiple virtual, independent operating system instances to be created and run on a single host operating system; each instance is called a virtual machine. In this embodiment, each time a node creates a smart contract, a corresponding virtual machine is created to store information related to that smart contract, such as its address, the storage address of the contract code, and other data. The smart contract virtual machine provides the execution environment for blockchain transactions.

[0044] To maintain consistency with all virtual machines in the network, the smart contract virtual machine organizes the account's state data into a state tree composed of key-value pairs (i.e., key names and their corresponding values). In this embodiment, the state tree is an MPT (Merkle Patricia Tree), whose tree structure includes three types of nodes: data nodes, extension nodes, and branch nodes. Data nodes are the leaf nodes of the tree structure, appearing only at the bottom of the MPT, and store the actual state data values. Extension nodes are parent nodes with only one child node, containing a string of arbitrary length representing part of the state data key name, and another tree node hash pointing to the child node. Branch nodes can have parent nodes with 1 to 16 child nodes and have a hash value array with a capacity of 16. These 16 positions correspond to hexadecimal 0-9-af, and each may potentially serve as a tree node hash pointing to a child node. The tree node hash is the hash value of the child node in the MPT, stored in the parent node. In some embodiments, the state data includes transaction information data, identity information data, logistics information data, etc.

[0045] Figure 1 A schematic diagram of the blockchain system in this embodiment is shown. The blockchain system 100 may include at least one terminal device 110 and a blockchain network 120. The blockchain network 120 includes at least one blockchain node 121. The terminal device 110 may be various electronic devices such as smartphones, tablets, laptops, desktop computers, smart wearable devices, smart in-vehicle devices, smart payment terminals, and facial recognition terminals. By installing corresponding applications, it can provide blockchain data services to users. The blockchain node 121 may be a terminal device or a server. For example, the blockchain node 121 may be an independent physical server, a server cluster composed of multiple physical servers, or a cloud server providing cloud computing services.

[0046] In blockchain network 120, each blockchain node 121 receives input information during normal operation and maintains shared data within the blockchain network based on the received input information. To ensure information interoperability, information connections can exist between the various blockchain nodes 121, allowing them to transmit information to each other. For example, when any blockchain node 121 in blockchain network 120 receives input information and broadcasts it within the blockchain network 120, other node devices in blockchain network 120 can obtain the input information according to a consensus algorithm and store it as shared data.

[0047] Each blockchain node 121 in the blockchain network 120 has a corresponding node identifier, and each blockchain node 121 in the blockchain network 120 can store the node identifiers of other blockchain nodes in the same blockchain network, so that the generated block can be broadcast to other nodes in the blockchain network 120 according to the node identifiers of other blockchain nodes.

[0048] As can be seen from the foregoing description of smart contract virtual machines, in order to support the reading of data from JSON objects, current smart contract virtual machines often use a pre-defined state database in the form of key-value pairs. However, when it comes to storing JSON objects, if the JSON objects are stored directly, data cannot be read from them. Therefore, it is necessary to split the JSON objects into multiple structures and multiple key-value pairs before storing them in the pre-defined state database. However, this results in a large amount of stored content, which leads to high data storage costs.

[0049] Based on this, this application provides a data writing method based on a smart contract virtual machine. This method uses a first preset instruction in the smart contract virtual machine to enable the smart contract virtual machine to directly deserialize the serialized first JSON string to obtain a first JSON object, thereby enabling the reading of arbitrary depth and arbitrary keys in the first JSON object. Then, the first target key name in the first JSON object is assigned a value to obtain a second JSON object, which is then serialized into a complete second JSON string and stored in a preset state database. This not only enables the reading of data from the JSON object, but also stores the JSON object, which originally needed to be split into multiple structures and key-value pairs, as a single state, thereby reducing data storage costs.

[0050] To facilitate understanding of the data writing method based on a smart contract virtual machine provided in the embodiments of this application, the following is combined with... Figure 2 The implementation environment shown illustrates the data writing and reading scenarios based on smart contract virtual machines in a blockchain system; specifically, this implementation environment is a blockchain network, such as... Figure 2As shown, the blockchain network includes a smart contract virtual machine 210 and a preset state database 220. The smart contract virtual machine 210 provides the runtime environment for smart contracts. Multiple smart contracts can be deployed in the blockchain network, distinguished by contract account (Identity, ID), identifier, or name. The corresponding smart contract is invoked to execute the business request by using the identifier contained in the obtained business request. Specifically, after a blockchain node receives a business request, it finds the corresponding smart contract virtual machine 210 in the virtual machine pool using the smart contract identifier included in the business request. Then, the corresponding smart contract virtual machine 210 executes the business request and, according to specific business requirements, writes or reads state data of the smart contract from the preset state database 220.

[0051] In some embodiments, current blockchain smart contract virtual machines often employ a key-value pair world state database. Therefore, the preset state database 220 can be a world state database, which is a persistent, global state storage system in the blockchain. The world state database stores account balances, smart contract code, and smart contract state data, including account balances, event logs, and custom contract data (logistics information, product invoices, game item information, etc.). In some embodiments, the state database 220 in this application can be a Merkel-Patricia tree, where accounts are organized using an MPT tree structure to form the world state. Each account is located at a leaf node of the tree, and the tree is organized by chaining hashes according to the order of arrangement, ultimately deriving the world state through layer-by-layer hashing. When a single account is changed, it triggers a change in the hash value of the upper-level branches it belongs to, until the hash value of the root node is affected. The hash value of the root node is called the StateRoot.

[0052] In this embodiment, the state data of the smart contract is stored in a preset state database as a JSON string. This JSON string is obtained by serializing a JSON object, which is constructed based on the smart contract's state data according to the JSON data format. Specifically, the JSON object includes at least one key-value pair, and each key-value pair includes a key name and a corresponding value. The JSON object is completely serialized into a string by the smart contract virtual machine. After adding native write instructions to the contract virtual machine instructions, it is serialized and stored in the state database. This reduces storage costs by storing the JSON object, which originally needed to be split into multiple structures and key-value pairs, as a single state. Furthermore, by adding data read instructions to the smart contract virtual machine, the smart contract virtual machine can directly deserialize the serialized JSON object and supports reading any key name and any depth, resulting in high readability and improved flexibility in reading and writing JSON data in the smart contract.

[0053] The data writing method based on a smart contract virtual machine provided in the embodiments of this application will be described in detail below.

[0054] Please see Figure 3 , Figure 3 This is a flowchart illustrating a data writing method based on a smart contract virtual machine, as shown in an exemplary embodiment of this application. This method can be applied to... Figure 2 The implementation environment shown is used, and the method is specifically executed by the smart contract virtual machine 210 in that implementation environment. It should be understood that this method can also be applied to other exemplary implementation environments and specifically executed by the smart contract virtual machine in other implementation environments. This embodiment does not limit the implementation environment to which this method is applicable.

[0055] like Figure 3 As shown, in an exemplary embodiment, the data writing method based on the smart contract virtual machine includes at least steps S310 to S330, which are described in detail below:

[0056] Step S310: Read the first JSON string of the account corresponding to the first business request from the preset status database.

[0057] The first JSON string is the string obtained by serializing the JSON object containing the first target key name in the first business request.

[0058] In this embodiment, the preset state database can be a world state database, which is a persistent, global state storage system in the blockchain. The world state database stores account balances, smart contract code, and smart contract state data. In some embodiments, the smart contract state data includes account balances, event logs, and custom contract data (logistics information, product invoices, game item information, etc.). The smart contract state data is stored in the preset state database as a JSON string, which is obtained by serializing a JSON object. This JSON object is constructed based on the smart contract state data according to the JSON data format. Therefore, it can be seen that the state database of this application stores the complete string obtained by processing the serialized string of a JSON object, rather than splitting it into multiple structures or key-value pairs for storage, thus avoiding wasted storage space.

[0059] Specifically, a JSON object includes at least one key-value pair. Each key-value pair includes a key and a corresponding value. The key and its corresponding value are determined based on the smart contract's state data; that is, the key is the attribute name of the smart contract's state data, and the corresponding value is the attribute value of the smart contract's state data. For example, the key in a key-value pair could be the account balance, and the corresponding value could be the amount of assets corresponding to that account balance.

[0060] The state data of a smart contract is generated when the smart contract executes a business request. For a given business request, a smart contract can initiate one or more data operation instructions. For example, when a smart contract transfers digital assets from account 1 to the address of account 2, the smart contract can initiate a first preset instruction for the account balance of account 1 and a first preset instruction for the account balance of account 2. In this case, the first target key indicated by the first preset instruction for the account balance of account 1 is the account balance of account 1, and the first target key indicated by the first preset instruction for the account balance of account 2 is the account balance of account 2.

[0061] In this embodiment, the JSON object is constructed by encapsulating the state data of the smart contract using a structured representation language. This structured representation language can be JSON (JavaScript Object Notation). JSON is a lightweight data exchange format that uses a text format completely independent of programming languages ​​to store and represent data. It is easy for humans to read and write, and also easy for machines to parse and generate. For example, the state data of the smart contract includes: in an account, the asset amount corresponding to the account balance of institution a is 100, and the asset amount corresponding to the account balance of user c in institution b is 200. The JSON object obtained by representing this state data using JSON is:

[0062]

[0063] As can be seen, this JSON object contains three key-value pairs: [a:100], [b:{c:200}], and [c:200]. In the key-value pair [a:100], the key is 'a', which represents 'a's' account balance, and the corresponding value is 100, which represents 'a's' account balance assets. In the key-value pair [b:{c:200}], the key is 'b', and the corresponding value is '{c:200}'. In the key-value pair [c:200], the key is 'c', and the corresponding value is '200'.

[0064] The state database stores JSON strings obtained by serializing JSON objects. In some embodiments, the JSON object can be serialized using the JSON serialization function JSON_DUMPS, resulting in a JSON string that can be directly stored in the state database: '{"a:100","b":{"c:200"}}'.

[0065] In some embodiments, when a blockchain node receives a business request, since the business request includes a first target key name to be written and a corresponding smart contract identifier, the corresponding smart contract virtual machine is invoked using the smart contract identifier to read a first JSON string containing the first target key name from a preset state database. For example, the JSON string is denoted as JsonString, and JsonString = State[AccountAddr][Key], where State is the world state of the smart contract, AccountAddr is the account address, Key is the corresponding key name, and JsonString is the value corresponding to the key name.

[0066] Step S320: The first JSON string is deserialized using the first preset instruction in the smart contract virtual machine to obtain the first JSON object, and the first target key name in the first JSON object is assigned a value to obtain the second JSON object.

[0067] It's important to understand that since the JSON string is a complete string obtained by serializing a JSON object, without being broken down into multiple structures or key-value pairs for storage, it's necessary to read and parse the complete string. Then, an assignment operation is performed using a first preset instruction added in the smart contract virtual machine to modify the value corresponding to the first target key in the JSON object. Specifically, the first preset instruction can be a JSON assignment instruction, which modifies the data in the first JSON object obtained after deserialization. In some embodiments, the JSON string can be deserialized using the preset deserialization function JSON_LOADS to obtain its corresponding JSON object.

[0068] In some embodiments, the first JSON string read from the state database is '{"a:100","b":{"c:200"}}', the first target key is "c", and the value is assigned to 300. Then, through a first preset instruction in the smart contract virtual machine, the first target key "c" is assigned a value to the first JSON object obtained by deserializing the first JSON string. The resulting second JSON object is:

[0069]

[0070] As can be seen, the first preset instruction can be used to assign values ​​to the keys in the JSON object obtained by deserialization, thereby enabling the writing of data with arbitrary depth and arbitrary keys in the JSON object.

[0071] Please see Figure 4 , Figure 4 yes Figure 3 The flowchart of step S320 in the illustrated embodiment, which involves an assignment operation in an exemplary embodiment, is shown below. It includes at least steps S410 to S440, which are described in detail below:

[0072] Step S410: Read the first instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine, and obtain the first preset instruction from the preset instruction mapping table according to the first instruction identifier.

[0073] In this embodiment, the instruction stack of the smart contract virtual machine stores instruction identifiers corresponding to the program counter, while the instruction mapping table stores the mapping relationship between instruction identifiers and preset instructions. This instruction stack setup makes instruction access fast and efficient; the program counter can accurately locate the instruction to be executed, thus quickly retrieving the corresponding instruction identifier from the instruction stack. Through the rapid lookup in the instruction mapping table, instruction identifiers can be quickly converted into preset commands, reducing instruction parsing events and improving execution efficiency. Furthermore, the instruction mapping table can easily map instruction identifiers to preset instructions. This method makes adding or modifying instructions in the smart contract virtual machine more flexible, without requiring extensive adjustments to the core of the smart contract virtual machine. When new instructions or functions need to be added, only the instruction mapping table needs to be updated, reducing the complexity and cost of code maintenance.

[0074] For example, if the instruction identifier corresponding to the program counter is read from the instruction stack as 0xFE, then the instruction identifier 0xFE is mapped to the corresponding preset instruction through the instruction mapping table, such as the JSON assignment instruction, which is the first preset instruction.

[0075] Step S420: Read and parse elements from the data stack of the smart contract virtual machine according to the first preset instruction to obtain the tuple corresponding to the first JSON object; wherein, the tuple corresponding to the first JSON object includes the first JSON string.

[0076] It is understandable that the data stack of the smart contract virtual machine serves as temporary memory during the execution of the smart contract. In this embodiment, after reading the first JSON string from the world state database, the first JSON string, the first target key name, and the value to be written are loaded into the data stack. The data stack is a last-in-first-out (LIFO) data structure, well-suited for storing and parsing temporary data. By loading the JSON string and corresponding state data into the data stack, the virtual machine can quickly access and manipulate this data, thereby improving operational efficiency.

[0077] In this embodiment of the application, elements in the data stack can be read and parsed through the following process:

[0078] Step S421: Obtain the preset parameters corresponding to the first preset instruction.

[0079] The preset parameters are used to characterize the number of elements read from the data stack.

[0080] Step S422: According to the preset parameters corresponding to the first preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the first JSON object.

[0081] Understandably, since a JSON object may contain multiple key-value pairs, and data reading and writing within a JSON object may only involve reading and writing one of the multiple state data in a single business operation, preset parameters can more accurately retrieve the data to be read and written from the data stack. In this embodiment, after reading the element from the data stack, it is parsed by the smart contract virtual machine to obtain the tuple corresponding to the first JSON object.

[0082] In some embodiments, the tuple corresponding to the first JSON object includes a first JSON string, the nesting depth of the first target key name, an array of keys corresponding to the first target key name, and the value to be written. The representation is [ <JsonString,KeyDepth,[Key i [Key], Value>]; where JsonString is the first JSON string, KeyDepth is the nesting depth of the first target key name, [Key i [] represents the key array and the value to be written corresponding to the first target key name. The length of the key array is determined by the nesting depth. Value is the value to be written, i = 0, 1, 2...

[0083] In some embodiments, combined with Figure 5 As shown, Figure 5 This is a schematic diagram of the data stack structure of a smart contract virtual machine, as illustrated in an exemplary embodiment of this application. The JSON string read from the state database is '{"a:100", "b":{"c:200"}}'. If the business request only needs to assign a value to the first target key name "c", since the state data "c" and "b" are nested, the key name "a" does not need to be loaded into the data stack. Only the key name "b" and the first target key name "c" need to be loaded into the data stack. Then, the JSON string '{"a:100", "b":{"c:200"}}', the corresponding state data key name "b" and the first target key name "c", and the value "300" to be written are written into the data stack. If the preset parameter corresponding to the first preset instruction is [STACK[1]+3], STACK[1] is used to characterize the nesting depth of the target key name "c", therefore [STACK[1]+3]=2+3=5. Therefore, the first 5 elements in the data stack need to be read and parsed to obtain the tuple corresponding to the first JSON object as [<'{"a:100","b":{"c:200"}}', 2, [Key0][Key1], 300>]. Furthermore, after being popped from the stack, these read elements are no longer in the data stack.

[0084] Step S430: Deserialize the first JSON string to obtain the first JSON object.

[0085] In this embodiment of the application, since the JSON string is stored as a complete data in the state database, the data in the JSON string cannot be directly modified. Therefore, the JSON string can be deserialized using the preset deserialization function JSON_LOADS to obtain its corresponding JSON object, which facilitates the assignment operation in the JSON object.

[0086] Step S440: Assign values ​​to the first JSON object based on the tuples corresponding to the first JSON object to obtain the second JSON object.

[0087] Understandably, since the tuple corresponding to the first JSON object includes not only the first JSON string, but also the embedding depth corresponding to the first target key, the key array corresponding to the first target key, and the value to be written, the assignment operation can be accurately performed on the first JSON object through this tuple, thereby obtaining the second JSON object.

[0088] In this embodiment, when assigning values ​​to a JSON object, depending on the different requirements of the business request, data writing includes two cases: data insertion and data update. Data insertion occurs when the corresponding first target key name does not exist in the status data corresponding to the business request. In this case, a new first target key name can be created and a value can be assigned to the new first target key name to achieve data insertion. Data modification occurs when the corresponding first target key name exists in the status data corresponding to the business request. In this case, the original value corresponding to the first target key name can be directly assigned to the value to be written to achieve data update.

[0089] In one exemplary embodiment, Figure 6 yes Figure 4 The flowchart of step S440 in the illustrated embodiment, which involves an assignment operation in an exemplary embodiment, includes at least steps S610 to S630, which are described in detail below:

[0090] Step S610: Traverse the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object.

[0091] In this embodiment, the Key array is traversed starting from i=0 according to the nesting depth of the first target key name to obtain the corresponding JSON pointer of the key name, and then the existence of the key name is determined based on the pointer. Specifically, if the key array is [Key0][Key1][Key2], then [Key0], [Key1] and [Key2] are traversed sequentially starting from i=0 to obtain the corresponding JSON pointers. The JSON pointers are parsed into a path array, and the existence of the first target key name in the first JSON object is checked layer by layer based on the path array.

[0092] Step S620: If it does not exist, create a new first target key name at the corresponding position in the first JSON object according to the nesting depth of the first target key name, and assign the value corresponding to the first target key name to the value to be written.

[0093] Step S630: Determine the first JSON object after the assignment operation as the second JSON object.

[0094] In this embodiment of the application, the existence of the first target key name in the first JSON object can be determined by the nesting depth of the first target key name in the tuple, so that data insertion can be realized when it does not exist, and the first target key name and its corresponding value can be created in the first JSON object.

[0095] In another exemplary embodiment, Figure 7 yes Figure 4 The flowchart illustrates step S440 in the illustrated embodiment, which involves an assignment operation in another exemplary embodiment. It includes at least steps S710 to S740, detailed below:

[0096] Step S710: Traverse the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object.

[0097] In this embodiment, the Key array is traversed starting from i=0 according to the nesting depth of the first target key name to obtain the corresponding JSON pointer of the key name, and then the existence of the key name is determined based on the pointer. Specifically, if the key array is [Key0][Key1][Key2], then [Key0], [Key1] and [Key2] are traversed sequentially starting from i=0 to obtain the corresponding JSON pointers. The JSON pointers are parsed into a path array, and the existence of the first target key name in the first JSON object is checked layer by layer based on the path array.

[0098] Step S720: If it exists, determine whether the value corresponding to the first target key name is a preset value or an empty string. The preset value is 0.

[0099] In step S730, if the value corresponding to the first target key name is not a preset value and is not an empty string, the value corresponding to the first target key name is assigned to the value to be written.

[0100] In some embodiments, if the value corresponding to the first target key is a preset value of 0, then the key is removed from the first JSON object. Specifically, this can be achieved using JSON_REMOVE(JsonObj[Key0][Key1]...). This way, values ​​of 0 or empty strings may be considered invalid data. Removing their corresponding keys reduces the amount of data stored during subsequent data writing, minimizing wasted storage space and further lowering data storage costs.

[0101] Step S740: Determine the first JSON object after the assignment operation as the second JSON object.

[0102] In this embodiment, the presence of a first target key name in the first JSON object can be determined by the nesting depth of the first target key name in the tuple, which facilitates updating the value corresponding to the first target key name when it exists.

[0103] For example, if the first JSON object is:

[0104]

[0105] The tuple corresponding to the first JSON object is [<'{"a:100","b":{"c:200"}}', 2, [Key0][Key1], 300>]. This shows that the nesting depth of the first target key "c" is 2, and the key array [Key0][Key1] corresponding to the first target key "c" is ["b"]["c"]. By traversing the key array corresponding to the first target key based on its nesting depth, we determine that the first target key "c" already exists in the first JSON object, so there's no need to create a new first target key. Furthermore, the value of the first target key in the first JSON object is 200, which is neither a preset value nor an empty string. Therefore, we can simply assign the value 300 to the first target key "c" in the first JSON object. The resulting second JSON object is:

[0106]

[0107] Step S330: Serialize the second JSON object to obtain the second JSON string, and write the second JSON string into the account corresponding to the first business request.

[0108] It is understandable that by serializing the second JSON object to obtain the second JSON string, it is possible to serialize the second JSON object into a complete JSON string and store it in the state database after writing data to any key name at any depth in the JSON object. This not only enables the reading of data in the JSON object, but also allows the storage of the JSON object, which originally needed to be split into multiple structures and key-value pairs, into a single state, thereby reducing data storage costs.

[0109] In some embodiments, a JSON object can be serialized using a preset serialization function JSON_DUMPS to obtain its corresponding JSON string.

[0110] In this embodiment of the application, the second JSON string can be written to the account corresponding to the first business request in the following manner: loading the second JSON string into the top of the data stack in the smart contract virtual machine; and writing the second JSON string at the top of the data stack into the account corresponding to the first business request in response to a preset write instruction in the smart contract virtual machine.

[0111] Understandably, by loading the second JSON string onto the top of the data stack in the smart contract virtual machine, it facilitates the smart contract virtual machine to directly perform the next assignment operation based on the business request. Furthermore, it allows the second JSON string at the top of the stack to be directly written to the state database via the SSTORE instruction in the smart contract. In some embodiments, if the value of the second JSON object, i.e., the second JSON string, exceeds the storage length of the state database, it is split and stored according to the default encoding method.

[0112] In some embodiments, the default write instruction is a native write instruction added to the smart contract virtual machine, used to store the serialized second JSON string into the state database.

[0113] Please see Figure 8 and Figure 9 , Figure 8 This is an exemplary embodiment of the present application illustrating the application of data writing. Figure 9 This is another exemplary embodiment of the present application illustrating the application of data writing. Figure 8This includes a smart contract virtual machine 210 and a preset state database 220. The state database 220 stores the state data of the smart contracts. This state data is stored in the preset state database as a JSON string. This JSON string is obtained by serializing a JSON object, which is constructed based on the smart contract's state data according to the JSON data format. Specifically, the JSON object includes at least one key-value pair, and each key-value pair includes a key name and its corresponding value. For example... Figure 8 As shown, the first JSON string is '{"a:100","b":{"c:200"}}'. After parsing the first JSON string using a JSON object parser, the first JSON object obtained is:

[0114]

[0115] In some embodiments, after receiving a first business request, the blockchain node uses the smart contract identifier included in the first business request to find the corresponding smart contract virtual machine 210 in the virtual machine pool and execute the first business request. Figure 8 and Figure 9 It can be seen that the data writing process of the smart contract virtual machine includes 7 steps:

[0116] 1. Read the first JSON string: The smart contract virtual machine 210 first reads the first JSON string '{"a:100","b":{"c:200"}}' corresponding to the account Account2 in the first business request from the state database.

[0117] 2. Loading the Data Stack: The first JSON string '{"a:100","b":{"c:200"}}' read is loaded into the data stack of the smart contract virtual machine 210. During loading, the first target key value included in the first business request can be loaded. State data that does not require data modification does not need to be loaded. In this data stack, from top to bottom, the following are stored in sequence: the first JSON string '{"a:100","b":{"c:200"}}', the embedding depth 2 corresponding to the first target key value, the key name "b" which has a nested relationship with the first target key name, the first target key name "c", and the value to be written 300.

[0118] 3. Reading the assignment instruction: The smart contract virtual machine 210 reads the instruction identifier of the corresponding program counter from the instruction stack, and then maps it to the preset instruction mapping table according to the instruction identifier to obtain the first preset instruction, namely the JSON assignment instruction.

[0119] 4. Parse the top of the stack: Read and parse elements from the data stack using the preset parameters of the JSON assignment instruction to obtain the tuple corresponding to the first JSON object, including the first JSON string, the embedding depth corresponding to the first target key, the key array corresponding to the first target key, and the value to be written, i.e., [<'{"a:100","b":{"c:200"}}', 2, [Key0][Key1], 300>].

[0120] 5. JSON Object Parsing: The first JSON string '{"a:100","b":{"c:200"}}' is parsed using a JSON object parser to obtain the first JSON object. The JSON object parser is used to serialize the JSON object and deserialize the JSON string.

[0121] 6. JSON Object Assignment: By traversing the key array based on the embedding depth of the first target key in the tuple corresponding to the first JSON object, it is determined whether the first target key exists in the first JSON object. If it does not exist, a new first target key is created at the corresponding position in the first JSON object according to the nesting depth of the first target key, and the value corresponding to the first target key is assigned the value to be written, 300. If it exists, it is determined whether the value corresponding to the first target key is 0 or an empty string. If the value corresponding to the first target key is not 0 and is not an empty string, the value 200 corresponding to the first target key is assigned the value to be written, 300.

[0122] 7. Loading into the data stack: Serialize the second JSON object to obtain the second JSON string, resulting in the second JSON string '{"a:100","b":{"c:300"}}'. Then, load the second JSON string onto the top of the data stack.

[0123] 8. Write the second JSON string: In response to the default write command, write the second JSON string '{"a:100","b":{"c:300"}}' to the account in the status database.

[0124] In this embodiment, a first preset instruction in the smart contract virtual machine enables the smart contract virtual machine to directly deserialize the serialized first JSON string to obtain a first JSON object, thereby enabling the reading of arbitrary depth and arbitrary keys in the first JSON object; then, the first target key name in the first JSON object is assigned a value to obtain a second JSON object, which is then serialized into a complete second JSON string and stored in a preset state database. This not only enables the reading of data from the JSON object, but also allows the storage of a single state in a JSON object that originally needed to be split into multiple structures and key-value pairs, thereby reducing data storage costs.

[0125] Please see Figure 10 , Figure 10 This is a flowchart illustrating a data reading method based on a smart contract virtual machine, as shown in an exemplary embodiment of this application. This method can be applied to... Figure 2 The implementation environment shown is used, and the method is specifically executed by the smart contract virtual machine 210 in that implementation environment. It should be understood that this method can also be applied to other exemplary implementation environments and specifically executed by the smart contract virtual machine in other implementation environments. This embodiment does not limit the implementation environment to which this method is applicable.

[0126] like Figure 10 As shown, in an exemplary embodiment, the data reading method based on the smart contract virtual machine includes at least steps S1010 to S1020, which are described in detail below:

[0127] Step S1010: Read the third JSON string of the account corresponding to the second business request from the preset status database.

[0128] The third JSON string is the string obtained by serializing the JSON object containing the second target key name contained in the second business request.

[0129] In this embodiment of the application, when the blockchain node receives a business request, since the business request includes a first target key name to be written and a corresponding smart contract identifier, the corresponding smart contract virtual machine is called through the smart contract identifier to directly read the third JSON string containing the second target key name from the preset state database.

[0130] For example, the JSON object containing the second target key "a" in the second business request is a third JSON object: The serialized third JSON string of this third JSON object is '{“a:100”,“b:50”}'. It can be seen that this third JSON object includes two key-value pairs: [a:100] and [b:50]. In the key-value pair [a:100], the key is 'a', representing the account balance of 'a', and the corresponding value is '100', meaning the asset amount in 'a's account balance is 100. In the key-value pair [b:50], the key is 'b', representing the account balance of 'b', and the corresponding value is '50', meaning the asset amount in 'b's account balance is 50.

[0131] Step S1020: The third JSON string is deserialized using the second preset instruction in the smart contract virtual machine to obtain a third JSON object, and the value of the second target key name in the third JSON object is retrieved to obtain the value corresponding to the second target key name.

[0132] It is understood that by adopting the data reading method improved in the embodiments of this application, by adding a second preset instruction in the smart contract virtual machine, the smart contract virtual machine can directly deserialize the serialized third JSON string to obtain a third JSON object, thereby enabling the reading of values ​​of any key at any depth in the third JSON object, improving the flexibility of reading and writing state data in the JSON object in the smart contract.

[0133] In this embodiment, since the JSON string is a complete string obtained by serializing a JSON object, and is not stored as multiple structures or key-value pairs, it is necessary to read and parse the complete string, and then perform a value retrieval operation using a second preset instruction added in the smart contract virtual machine. This allows the value corresponding to the second target key in the JSON object to be read. Specifically, the second preset instruction can be a JSON value retrieval instruction, which enables the reading of data from the deserialized third JSON object. In some embodiments, the JSON string can be deserialized using the preset deserialization function JSON_LOADS to obtain its corresponding JSON object.

[0134] In some embodiments, the third JSON string read from the state database is '{"a:100","b:50"}', the second target key is "a", and the third JSON object obtained by deserializing the third JSON string through the second preset instruction in the smart contract virtual machine is: Reading the value corresponding to the second target key "a" from the third JSON object, the value obtained is 50.

[0135] As can be seen, the second preset instruction can be used to retrieve the key names in the JSON object obtained by deserialization, thereby enabling data reading from the JSON object at any depth and with any key name.

[0136] It should be noted that the steps in this embodiment are consistent with the corresponding steps in the foregoing embodiments. Therefore, for a detailed description of these steps, please refer to the description in the foregoing embodiments. This embodiment will not repeat them here.

[0137] Please see Figure 11 , Figure 11 yes Figure 10 The flowchart of step S1020 in the illustrated embodiment, which involves a value retrieval operation in an exemplary embodiment, includes at least steps S1110 to S1140, which are described in detail below:

[0138] Step S1110: Read the second instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine, and obtain the second preset instruction from the preset instruction mapping table according to the second instruction identifier.

[0139] In this embodiment, the instruction stack of the smart contract virtual machine stores instruction identifiers corresponding to the program counter, while the instruction mapping table stores the mapping relationship between instruction identifiers and preset instructions. This instruction stack setup makes instruction access fast and efficient; the program counter can accurately locate the instruction to be executed, thus quickly retrieving the corresponding instruction identifier from the instruction stack. Through the rapid lookup in the instruction mapping table, instruction identifiers can be quickly converted into preset commands, reducing instruction parsing events and improving execution efficiency. Furthermore, the instruction mapping table can easily map instruction identifiers to preset instructions. This method makes adding or modifying instructions in the smart contract virtual machine more flexible, without requiring extensive adjustments to the core of the smart contract virtual machine. When new instructions or functions need to be added, only the instruction mapping table needs to be updated, reducing the complexity and cost of code maintenance.

[0140] For example, if the second instruction identifier corresponding to the program counter is read from the instruction stack as 0xFF, then the second instruction identifier 0xFF is mapped to the corresponding preset instruction through the instruction mapping table, such as the JSON value retrieval instruction, which is the second preset instruction.

[0141] Step S1120: Elements are read and parsed from the data stack of the smart contract virtual machine according to the second preset instruction to obtain the tuple corresponding to the third JSON object. The tuple corresponding to the third JSON object includes the third JSON string.

[0142] It is understandable that the data stack of the smart contract virtual machine serves as temporary memory during the execution of the smart contract. In this embodiment, after reading the third JSON string from the world state database, the third JSON string and the second target key name are loaded into the data stack. The data stack is a last-in-first-out (LIFO) data structure, well-suited for storing and parsing temporary data. By loading the JSON string and corresponding state data into the data stack, the virtual machine can quickly access and manipulate this data, thereby improving operational efficiency.

[0143] In this embodiment of the application, elements in the data stack can be read and parsed through the following process:

[0144] Step S1121: Obtain the preset parameters corresponding to the second preset command.

[0145] The preset parameters are used to characterize the number of elements read from the data stack.

[0146] Step S1122: According to the preset parameters corresponding to the second preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the third JSON object.

[0147] Understandably, since a JSON object may contain multiple key-value pairs, and data reading and writing within a JSON object may only involve reading and writing one of the multiple state data in a single business operation, preset parameters can more accurately retrieve the data to be read and written from the data stack. In this embodiment, after reading the element from the data stack, it is parsed by the smart contract virtual machine to obtain the tuple corresponding to the third JSON object.

[0148] In some embodiments, the tuple corresponding to the third JSON object includes the third JSON string, the nesting depth of the third target key name, and the array of keys corresponding to the second target key name. The representation is a triple [ <JsonString,KeyDepth,[Key i ]>]; where JsonString is the third JSON string, KeyDepth is the nesting depth of the second target key name, [Key i ] represents the key array corresponding to the second target key name. The length of the key array is determined by the nesting depth, i = 0, 1, 2...

[0149] In some embodiments, if the third JSON string read from the state database is '{"a:100", "b:50"}', and the business request only needs to retrieve the value of the second target key "a", then only the second target key "a" and the third JSON string need to be loaded into the data stack. If the preset parameter corresponding to the second preset instruction is [STACK[1]+1], STACK[1] is used to represent the nesting depth of the target key "a", so [STACK[1]+2]=1+2=3. Therefore, the first 3 elements in the data stack need to be read and parsed to obtain the tuple corresponding to the third JSON object as [<'{"a:100", "b:50"}',1,[Key0]>]. In addition, after popping from the stack, these read elements are no longer in the data stack.

[0150] Step S1130: Deserialize the third JSON string to obtain the third JSON object.

[0151] In this embodiment of the application, since the JSON string is stored as a complete data in the state database, the data in the JSON string cannot be read directly. Therefore, the JSON string can be deserialized using the preset deserialization function JSON_LOADS to obtain its corresponding JSON object, which facilitates value retrieval operations in the JSON object.

[0152] Step S1140: Perform a value retrieval operation on the third JSON object based on the tuple corresponding to the third JSON object to obtain the value corresponding to the second target key name.

[0153] It is understandable that, since the tuple corresponding to the third JSON object includes not only the third JSON string, but also the embedding depth and the key array corresponding to the second target key, the value can be accurately retrieved from the third JSON object through this tuple, thereby obtaining the value corresponding to the second target key.

[0154] In some embodiments, the value retrieval operation can be performed through the following procedure:

[0155] Step S1141: Traverse the key array corresponding to the second target key name according to the nesting depth of the second target key name to determine whether the second target key name exists in the third JSON object;

[0156] Step S1142: If it exists, directly read the value corresponding to the second target key name and load the value corresponding to the second target key name into the top of the data stack of the smart contract virtual machine.

[0157] In some embodiments, the key array corresponding to the second target key name can be traversed by the nesting depth of the second target key name to obtain the JSON pointer of the corresponding key name, and the JSON pointer can be parsed into a path array. Based on the path array, the existence of the second target key name in the third JSON object can be checked layer by layer.

[0158] In other embodiments, the value corresponding to the second target key can be obtained directly through a preset Try statement. The Try statement can be used to determine whether there is a key name anomaly. For example: if the value corresponding to the key name can be obtained directly through the Try statement (e.g., the value corresponding to the second target key name "a" is directly read as 100), then the key name is not anomaly; if a key name anomaly is determined to exist during the process of obtaining the value corresponding to the key name through the Try statement (e.g., the second target key name does not exist in the third JSON object), then the anomaly is handled through a Catch statement in the JSON object parser.

[0159] For example, if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the first security level, then the preset value is used as the value corresponding to the second target key name and loaded onto the top of the data stack of the smart contract virtual machine. The preset value is 0.

[0160] For example, if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the second security level, then the smart contract virtual machine is controlled to report an error; wherein, the second security level is higher than the first security level.

[0161] In this way, by applying different processing methods to address the different security requirements of the blockchain, the security requirements of the blockchain can be met during data reading and writing, thereby improving security.

[0162] It should be noted that the steps in this embodiment are consistent with the corresponding steps in the foregoing embodiments. Therefore, for a detailed description of these steps, please refer to the description in the foregoing embodiments. This embodiment will not repeat them here.

[0163] Combination Figure 12 As shown, Figure 12 This is a structural diagram illustrating a data writing device based on a smart contract virtual machine, as shown in an exemplary embodiment of this application. Figure 12As shown, this exemplary data writing device based on a smart contract virtual machine includes: a first reading module 1210, an assignment module 1220, and a writing module 1230. The first reading module 1210 is configured to read a first JSON string corresponding to the account in the first business request from a preset state database; wherein the first JSON string is a string obtained by serializing the JSON object containing the first target key name in the first business request. The assignment module 1220 is configured to deserialize the first JSON string using a first preset instruction in the smart contract virtual machine to obtain a first JSON object, and then assign a value to the first target key name in the first JSON object to obtain a second JSON object. The writing module 1230 is configured to serialize the second JSON object to obtain a second JSON string, and then write the second JSON string to the account corresponding to the first business request.

[0164] In an exemplary embodiment, the assignment module 1220 is configured to deserialize a first JSON string using a first preset instruction in the smart contract virtual machine to obtain a first JSON object, and then assign a value to a first target key name in the first JSON object to obtain a second JSON object. This includes: reading a first instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine; obtaining a first preset instruction from a preset instruction mapping table based on the first instruction identifier; reading and parsing elements from the data stack of the smart contract virtual machine according to the first preset instruction to obtain a tuple corresponding to the first JSON object; wherein the tuple corresponding to the first JSON object includes the first JSON string; deserializing the first JSON string to obtain the first JSON object; and assigning a value to the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object.

[0165] In an exemplary embodiment, the tuple corresponding to the first JSON object further includes the nesting depth of the first target key name, the key array corresponding to the first target key name, and the value to be written; the assignment module 1220 is configured to read and parse elements from the data stack according to the first preset instruction to obtain the tuple corresponding to the first JSON object in the following manner: obtaining the preset parameter corresponding to the first preset instruction; wherein, the preset parameter is used to characterize the number of elements read from the data stack; according to the preset parameter corresponding to the first preset instruction, reading elements sequentially from the top of the data stack downwards, and parsing the read elements to obtain the tuple corresponding to the first JSON object.

[0166] In an exemplary embodiment, the assignment module 1220 is configured to perform an assignment operation on the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object, including: traversing the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object; if it does not exist, creating a new first target key name at the corresponding position in the first JSON object according to the nesting depth of the first target key name, and assigning the value corresponding to the first target key name as the value to be written; and determining the first JSON object after the assignment operation as the second JSON object.

[0167] In an exemplary embodiment, the assignment module 1220 is configured to perform an assignment operation on the first JSON object based on the tuple corresponding to the first JSON object to obtain a second JSON object, including: traversing the key array corresponding to the first target key name according to the nesting depth of the first target key name to determine whether the first target key name exists in the first JSON object; if it exists, determining whether the value corresponding to the first target key name is a preset value or an empty string; if the value corresponding to the first target key name is neither a preset value nor an empty string, assigning the value corresponding to the first target key name to the value to be written; and determining the first JSON object after the assignment operation as the second JSON object.

[0168] In one exemplary embodiment, the writing module 1230 is configured to write a second JSON string to the account corresponding to the first business request by: loading the second JSON string onto the top of the data stack in the smart contract virtual machine; and writing the second JSON string at the top of the data stack to the account corresponding to the first business request in response to a preset write instruction in the smart contract virtual machine.

[0169] It should be noted that the data writing device based on a smart contract virtual machine provided in the above embodiments and the data writing method based on a smart contract virtual machine provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the data writing device based on a smart contract virtual machine provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. This is not a limitation.

[0170] Combination Figure 13 As shown, Figure 13 This is a structural diagram illustrating a data reading device based on a smart contract virtual machine, as shown in an exemplary embodiment of this application. Figure 13As shown, this exemplary data reading device based on a smart contract virtual machine includes a second reading module 1310 and a value retrieval module 1320. The second reading module 1310 is configured to read a third JSON string corresponding to the account in the second business request from a preset state database; wherein the third JSON string is a string obtained by serializing the JSON object containing the second target key name in the second business request; the value retrieval module 1320 is configured to deserialize the third JSON string using preset write instructions in the smart contract virtual machine to obtain a third JSON object, and then retrieve the value corresponding to the second target key name in the third JSON object.

[0171] In an exemplary embodiment, the value retrieval module 1320 is configured to deserialize a third JSON string using a second preset instruction in the smart contract virtual machine to obtain a third JSON object, and then retrieve the value corresponding to the second target key name in the third JSON object. This includes: reading a second instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine; obtaining a second preset instruction from a preset instruction mapping table based on the second instruction identifier; reading and parsing elements from the data stack of the smart contract virtual machine according to the second preset instruction to obtain a tuple corresponding to the third JSON object; wherein the tuple corresponding to the third JSON object includes the third JSON string; deserializing the third JSON string to obtain the third JSON object; and retrieving the value corresponding to the second target key name from the third JSON object based on the tuple corresponding to the third JSON object.

[0172] In an exemplary embodiment, the tuple corresponding to the third JSON object further includes the nesting depth of the second target key name and the key array corresponding to the second target key name; the value retrieval module 1320 is configured to read and parse elements from the data stack according to the second preset instruction to obtain the tuple corresponding to the third JSON object, including: obtaining the preset parameter corresponding to the second preset instruction; the preset parameter is used to characterize the number of elements read from the data stack; according to the preset parameter corresponding to the second preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the third JSON object.

[0173] In an exemplary embodiment, the value retrieval module 1320 is configured to perform a value retrieval operation on the third JSON object based on the tuple corresponding to the third JSON object in the following manner to obtain the value corresponding to the second target key name: traversing the key array corresponding to the second target key name according to the nesting depth of the second target key name to determine whether the second target key name exists in the third JSON object; if it exists, directly reading the value corresponding to the second target key name and loading the value corresponding to the second target key name into the top of the data stack of the smart contract virtual machine.

[0174] In an exemplary embodiment, the value retrieval module 1320 is further configured to: if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the first security level, then use the preset value as the value corresponding to the second target key name and load it onto the top of the data stack of the smart contract virtual machine; if the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the second security level, then control the smart contract virtual machine to report an error; wherein, the second security level is higher than the first security level.

[0175] It should be noted that the apparatus and method provided in the above embodiments belong to the same concept, and the specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the apparatus provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the apparatus can be divided into different functional modules to complete all or part of the functions described above, and this is not a limitation.

[0176] Embodiments of this application also provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device enables the data writing method or data reading method based on the smart contract virtual machine provided in the above embodiments.

[0177] Figure 14 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 14 The computer system 1400 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0178] like Figure 14As shown, the computer system 1400 includes a Central Processing Unit (CPU) 1401, which can perform various appropriate actions and processes based on programs stored in Read-Only Memory (ROM) 1402 or programs loaded from storage portion 1408 into Random Access Memory (RAM) 1403, such as performing the methods described in the above embodiments. Various programs and data required for system operation are also stored in RAM 1403. The CPU 1401, ROM 1402, and RAM 1403 are interconnected via bus 1404. An Input / Output (I / O) interface 1405 is also connected to bus 1404.

[0179] The following components are connected to I / O interface 1405: an input section 1406 including a keyboard, mouse, etc.; an output section 1407 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1408 including a hard disk, etc.; and a communication section 1409 including a model interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1409 performs communication processing via a model such as the Internet. A drive 1410 is also connected to I / O interface 1405 as needed. Removable media 1411, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1410 as needed so that computer programs read from them can be installed into storage section 1408 as needed.

[0180] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from the model via communication section 1409, and / or installed from removable medium 1411. When the computer program is executed by central processing unit (CPU) 1401, it performs various functions defined in the system of this application.

[0181] Another aspect of this application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the data writing method or data reading method based on a smart contract virtual machine as described above. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not assembled into the electronic device.

[0182] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the data writing or data reading method based on a smart contract virtual machine provided in the various embodiments above.

[0183] The above description is merely a preferred exemplary embodiment of this application and is not intended to limit the implementation of this application. Those skilled in the art can easily make corresponding modifications or alterations based on the main concept and spirit of this application. Therefore, the scope of protection of this application should be determined by the scope of protection claimed in the claims.

[0184] It should be noted that when the embodiments of this application are applied to specific products or technologies, such as when obtaining sample data, it is unavoidable to obtain status data related to business requests (such as product bills, transaction and logistics information). In this case, permission or consent from the object initiating the business request is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

Claims

1. A data writing method based on a smart contract virtual machine, characterized in that, include: The first JSON string corresponding to the first business request is read from the preset state database; wherein, the first JSON string is the string obtained by serializing the JSON object to which the first target key name in the first business request belongs; The first JSON string is deserialized using the first preset instruction in the smart contract virtual machine to obtain the first JSON object, and the first target key name in the first JSON object is assigned a value to obtain the second JSON object. The second JSON object is serialized to obtain a second JSON string, and the second JSON string is written to the account corresponding to the first business request.

2. The method according to claim 1, characterized in that, The step of deserializing the first JSON string to obtain a first JSON object using a first preset instruction in the smart contract virtual machine, and assigning a value to the first target key name in the first JSON object to obtain a second JSON object, includes: Read the first instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine, and obtain the first preset instruction from the preset instruction mapping table according to the first instruction identifier; According to the first preset instruction, elements are read and parsed from the data stack of the smart contract virtual machine to obtain the tuple corresponding to the first JSON object; wherein, the tuple corresponding to the first JSON object includes the first JSON string; The first JSON string is deserialized to obtain the first JSON object; The second JSON object is obtained by assigning values ​​to the tuples corresponding to the first JSON object.

3. The method according to claim 2, characterized in that, The tuple corresponding to the first JSON object also includes the nesting depth of the first target key, the key array corresponding to the first target key, and the value to be written; the step of reading and parsing elements from the data stack according to the first preset instruction to obtain the tuple corresponding to the first JSON object includes: Obtain the preset parameters corresponding to the first preset instruction; wherein, the preset parameters are used to characterize the number of elements read from the data stack; Based on the preset parameters corresponding to the first preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the first JSON object.

4. The method according to claim 3, characterized in that, The step of assigning values ​​to the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object includes: Based on the nesting depth of the first target key name, traverse the key array corresponding to the first target key name to determine whether the first target key name exists in the first JSON object; If it does not exist, the first target key name is created at the corresponding position in the first JSON object according to the nesting depth of the first target key name, and the value corresponding to the first target key name is assigned to the value to be written; The first JSON object after the assignment operation is determined as the second JSON object.

5. The method according to claim 3, characterized in that, The step of assigning values ​​to the first JSON object based on the tuple corresponding to the first JSON object to obtain the second JSON object includes: Based on the nesting depth of the first target key name, traverse the key array corresponding to the first target key name to determine whether the first target key name exists in the first JSON object; If it exists, determine whether the value corresponding to the first target key name is a preset numerical value or an empty string; If the value corresponding to the first target key is not the preset value and is not an empty string, the value corresponding to the first target key is assigned the value to be written. The first JSON object after the assignment operation is determined as the second JSON object.

6. The method according to claim 1, characterized in that, The step of writing the second JSON string into the account corresponding to the first business request includes: The second JSON string is loaded onto the top of the data stack in the smart contract virtual machine; In response to a preset write instruction in the smart contract virtual machine, the second JSON string at the top of the data stack is written to the account corresponding to the first business request.

7. A data reading method based on a smart contract virtual machine, characterized in that, include: The third JSON string corresponding to the account in the second business request is read from the preset state database; wherein, the third JSON string is the string obtained by serializing the JSON object to which the second target key name in the second business request belongs; The third JSON string is deserialized using the second preset instruction in the smart contract virtual machine to obtain a third JSON object, and the value of the second target key name in the third JSON object is retrieved to obtain the value corresponding to the second target key name.

8. The method according to claim 7, characterized in that, The step of deserializing the third JSON string using a second preset instruction in the smart contract virtual machine to obtain a third JSON object, and then retrieving the value corresponding to the second target key name in the third JSON object, includes: Read the second instruction identifier corresponding to the program counter from the instruction stack of the smart contract virtual machine, and obtain the second preset instruction from the preset instruction mapping table according to the second instruction identifier; According to the second preset instruction, elements are read and parsed from the data stack of the smart contract virtual machine to obtain the tuple corresponding to the third JSON object; wherein, the tuple corresponding to the third JSON object includes the third JSON string; The third JSON string is deserialized to obtain the third JSON object; The value corresponding to the second target key name is obtained by performing a value retrieval operation on the third JSON object based on the tuple corresponding to the third JSON object.

9. The method according to claim 8, characterized in that, The tuple corresponding to the third JSON object also includes the nesting depth of the second target key name and the key array corresponding to the second target key name; the step of reading and parsing elements from the data stack according to the second preset instruction to obtain the tuple corresponding to the third JSON object includes: Obtain the preset parameters corresponding to the second preset instruction; the preset parameters are used to characterize the number of elements read from the data stack; According to the preset parameters corresponding to the second preset instruction, elements are read sequentially from the top of the data stack downwards, and the read elements are parsed to obtain the tuple corresponding to the third JSON object.

10. The method according to claim 9, characterized in that, The step of retrieving values ​​from the third JSON object based on the tuple corresponding to the third JSON object to obtain the value corresponding to the second target key name includes: Based on the nesting depth of the second target key name, traverse the key array corresponding to the second target key name to determine whether the second target key name exists in the third JSON object; If it exists, the value corresponding to the second target key name is read directly, and the value corresponding to the second target key name is loaded into the top of the data stack of the smart contract virtual machine.

11. The method according to claim 10, characterized in that, The method further includes: If the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the first security level, then the preset value is used as the value corresponding to the second target key name and loaded onto the top of the data stack of the smart contract virtual machine. If the second target key name does not exist in the third JSON object, and the preset blockchain network security requirement is the second security level, then the smart contract virtual machine is controlled to report an error. The second security level is higher than the first security level.

12. A data writing device based on a smart contract virtual machine, characterized in that, include: The first reading module is configured to read the first JSON string of the account corresponding to the first business request from a preset status database; wherein, the first JSON string is the string obtained by serializing the JSON object to which the first target key name in the first business request belongs; The assignment module is configured to deserialize the first JSON string to obtain a first JSON object through a first preset instruction in the smart contract virtual machine, and then assign a value to the first target key name in the first JSON object to obtain a second JSON object. The writing module is configured to serialize the second JSON object to obtain a second JSON string, and then write the second JSON string to the account corresponding to the first business request.

13. A data reading device based on a smart contract virtual machine, characterized in that, include: The second reading module is configured to read a third JSON string of the account corresponding to the second business request from a preset status database; wherein, the third JSON string is a string obtained by serializing the JSON object to which the second target key name in the second business request belongs; The value retrieval module is configured to deserialize the third JSON string to obtain a third JSON object through a preset write instruction in the smart contract virtual machine, and then retrieve the value of the second target key name in the third JSON object to obtain the value corresponding to the second target key name.

14. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to perform the method as described in any one of claims 1 to 11.

15. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by the computer's processor, cause the computer to perform the method of any one of claims 1 to 11.