Method and device for providing blockchain services
The blockchain data structure is obtained and parsed through off-chain devices and generated field tables, which solves the computing power bottleneck in blockchain development, and realizes the rapid construction of edge computing power service nodes, simplifying the development process.
Patent Information
- Application Number
- CN202210170751.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-23
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-02-23
AI Technical Summary
The development of blockchain has brought about a computing power bottleneck. The existing technology requires multiple encodings when building edge computing power service nodes, which is laborious and difficult to implement quickly.
The data structure of the on-chain data is obtained from the blockchain node through off-chain devices, parsing and generating a field table, including field identification and attribute information, providing data interaction services, and realizing automatic mapping of the data structure.
It has realized the rapid construction of service nodes that provide edge computing power, simplified the development process of blockchain services, and improved efficiency.
Smart Images

Figure CN114528353B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of blockchain technology, and more particularly to methods and devices for providing blockchain services. Background Art
[0002] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain system, data blocks are linked sequentially in chronological order to form a chain-like data structure, cryptographically guaranteeing an unalterable and unforgeable distributed ledger. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application.
[0003] With the rapid development of blockchain, more and more blockchains are being developed. This development has led to bottlenecks in blockchain computing power. However, the addition of edge computing power provides new room for growth. Therefore, how to quickly build service nodes that provide edge computing power has important practical significance and value. Summary of the Invention
[0004] The embodiments of this specification describe a method and apparatus for providing blockchain services. These methods, applied to off-chain devices, retrieve the data structure of on-chain data from blockchain nodes, parse the data structure, generate and store a field table for each field, and provide data interaction services for the blockchain based on the field table. Thus, by automatically mapping the data structure to the field table of the off-chain device, the off-chain device can provide edge computing power for the blockchain.
[0005] According to a first aspect, a method for providing blockchain services is provided, which is applied to off-chain devices, including: obtaining a data structure of on-chain data from a blockchain node, the data structure defining multiple fields in the on-chain data; parsing the obtained data structure, generating and storing a field table for each field, the field table including a field identifier of the corresponding field and attribute information of the field; and providing data interaction services for the blockchain according to the field table.
[0006] In one embodiment, the attribute information of the above-mentioned field includes an index identifier of the field data of the field, and the above-mentioned method also includes: receiving first data from a blockchain node, the above-mentioned first data including the field identifier of each field and the field data associated with the field identifier of each field; obtaining a field table of each field according to the field identifier of each field; storing the above-mentioned first data, and establishing an index relationship between each field identifier of the above-mentioned first data and each field data through the index identifier of each field data in each field table; the above-mentioned data interaction service provided to the above-mentioned blockchain according to the above-mentioned field table includes: querying the above-mentioned first data based on the above-mentioned index relationship.
[0007] In one embodiment, the first data also includes a data identifier, and the method also includes: generating and storing a data structure table of the data structure, the data structure table including the name of the data structure, the index identifier of the data structure and the data structure code; wherein the field table also includes the index identifier of the data structure; the storing of the first data and establishing an index relationship between each field identifier of the first data and each field data through the index identifier include: determining the data structure table corresponding to the first data, and determining the index identifier of the data structure from the data structure table; determining the index identifier of each field data from the field table according to the field identifier of each field and the index identifier of the data structure; generating and storing a data table of the first data, and the data table including: the data identifier, the index identifier of the data structure, each field data and the index identifier of each field data.
[0008] In one embodiment, the querying of the first data based on the index relationship includes: receiving an on-chain data query request from a user terminal, wherein the data query request includes the data identifier of the first data and the field identifier of the target field; obtaining the data table of the first data according to the data identifier of the first data; obtaining the field table of the target field according to the index identifier of the data structure in the data table of the first data and the field identifier of the target field; determining the index identifier corresponding to the target field according to the field table of the target field; searching for the field data corresponding to the target field from the data table of the first data according to the determined index identifier; and returning the field data to the user terminal.
[0009] In one embodiment, the above method also includes: generating a data query log based on the provided on-chain data query service; and uploading the above data query log to the chain.
[0010] In one embodiment, the data interaction service provided for the above-mentioned blockchain according to the above-mentioned field table includes: receiving an on-chain request from a user terminal, wherein the above-mentioned on-chain request includes field data of each field of the data to be on-chain; according to the field table of each field of the above-mentioned data to be on-chain, determining the field identifier corresponding to each field data from the field table of each field; and uploading data to the chain according to the above-mentioned each field data and the field identifier corresponding to each field data.
[0011] In one embodiment, the above-mentioned obtaining the data structure of the on-chain data from the blockchain node includes: sending a transaction to the blockchain node to call a contract, where the above-mentioned contract is used to limit the data structure of the on-chain data; and receiving the above-mentioned data structure from the blockchain node.
[0012] In one embodiment, the above-mentioned parsing of the obtained data structure to generate and store a field table of each field includes: verifying the obtained data structure; in response to determining that the data structure passes the verification, determining the programming language used by the data structure; parsing the data structure according to the programming language to generate a field table of each field.
[0013] According to the second aspect, a device for providing blockchain services is provided, which is arranged in an off-chain device and includes: an acquisition unit, configured to obtain a data structure of on-chain data from a blockchain node, wherein the data structure defines multiple fields in the on-chain data; a parsing unit, configured to parse the acquired data structure, generate and store a field table for each field, wherein the field table includes a field identifier of the corresponding field and attribute information of the field; and a service unit, configured to provide data interaction services for the blockchain according to the field table.
[0014] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in any implementation manner of the first aspect.
[0015] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, the method described in any implementation manner in the first aspect is implemented.
[0016] The method and apparatus for providing blockchain services, as provided in the embodiments of this specification, are applied to off-chain devices. First, the data structure of on-chain data is obtained from a blockchain node. This data structure defines multiple fields within the on-chain data. The obtained data structure is then parsed to generate and store a field table for each field. The field table includes a field identifier for the corresponding field and attribute information for the field. Finally, data interaction services for the blockchain are provided based on the field table. Thus, by automatically mapping the blockchain's data structure to the field table of the off-chain device, the off-chain device can provide edge computing power for the blockchain, enabling the rapid establishment of service nodes for providing edge computing power for the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0018] Figure 1A diagram showing a blockchain architecture in one embodiment is shown;
[0019] Figure 2 A schematic diagram showing an application scenario in which the embodiments of this specification can be applied;
[0020] Figure 3 A flowchart of a method for providing blockchain services according to one embodiment is shown;
[0021] Figure 4 A schematic diagram showing a data structure in one embodiment is shown;
[0022] Figure 5 A schematic diagram of a table stored in an off-chain device in an embodiment of this specification is shown;
[0023] Figure 6 Shown Figure 5 An example diagram of each table in;
[0024] Figure 7 A schematic block diagram of an apparatus for providing blockchain services according to one embodiment is shown. DETAILED DESCRIPTION
[0025] To help those skilled in the art better understand the technical solutions in this specification, the following will provide a clear and complete description of the technical solutions in the embodiments of this specification, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. All other embodiments derived by those skilled in the art based on the embodiments in this specification without creative effort shall fall within the scope of protection of this specification.
[0026] Figure 1 FIG. 1 shows a block chain architecture diagram in an embodiment. Figure 1 As shown, the blockchain 100 includes, for example, six nodes. The lines between the nodes schematically represent P2P (Peer to Peer) connections. These nodes can store the full ledger, that is, the state of all blocks and all accounts. Each node in the blockchain can generate the same state in the blockchain by executing the same transaction, and each node in the blockchain can store the same state database. It is understandable that Figure 1Although the blockchain is shown as including six nodes, the embodiments of this specification are not limited thereto and may include other numbers of nodes. Specifically, the nodes included in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements. This Byzantine Fault Tolerance requirement can be understood as allowing Byzantine nodes to exist within the blockchain without externally displaying Byzantine behavior. Generally, some Byzantine Fault Tolerance algorithms require the number of nodes to be greater than 3f+1, where f is the number of Byzantine nodes, such as the Practical Byzantine Fault Tolerance (PBFT) algorithm.
[0027] A transaction in the blockchain field can refer to a task unit executed and recorded in the blockchain. A transaction typically includes a send field (From), a receive field (To), and a data field (Data). In the case of a transfer transaction, the From field indicates the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field indicates the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount. In the case of a transaction calling a smart contract in the blockchain, the From field indicates the account address initiating the transaction, the To field indicates the account address of the contract called by the exchange, and the Data field includes data such as the function name in the called contract and the parameters passed to the function, which are used to retrieve the function code from the blockchain and execute the function code when the transaction is executed.
[0028] Blockchains offer smart contract functionality. Smart contracts on blockchains are contracts that can be triggered and executed by transactions within the blockchain system. Smart contracts can be defined in code. Invoking a smart contract in Ethereum involves initiating a transaction directed to the smart contract address, enabling each node in the Ethereum network to execute the smart contract code in a distributed manner. It should be noted that in addition to user-created smart contracts, smart contracts can also be set up by the system in the genesis block. This type of contract is generally referred to as a genesis contract. Generally, a genesis contract can set certain blockchain data structures, parameters, properties, and methods. Furthermore, accounts with system administrator privileges can create or modify system-level contracts (referred to as system contracts). These system contracts can be used to add data structures for different business operations to the blockchain.
[0029] In the scenario of deploying a contract, for example, Bob sends a transaction containing the information of creating a smart contract (ie deploying the contract) to Figure 1In the blockchain shown, the transaction's data field contains the code (such as bytecode or machine code) for the contract to be created. The transaction's to field is empty, indicating that the transaction is for deploying the contract. After the nodes reach consensus through the consensus mechanism, they determine the contract address "0x6f8ae93..." Each node adds a contract account corresponding to the smart contract's contract address to the state database, allocates state storage corresponding to the contract account, and saves the contract code in the contract's state storage, successfully creating the contract.
[0030] In the scenario of calling a contract, for example, Bob sends a transaction for calling a smart contract to Figure 1 In the blockchain shown, the transaction's "from" field is the account address of the initiator (Bob), the "to" field ("0x6f8ae93...") represents the address of the smart contract being called, and the transaction's "data" field contains the method and parameters for calling the smart contract. After consensus is reached on the transaction within the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract and updating the state database based on the contract's execution.
[0031] As mentioned earlier, the development of blockchain has created bottlenecks in blockchain computing power, while the addition of edge computing power provides new room for computing power growth. Edge computing refers to the use of an open platform integrating core network, computing, storage, and application capabilities close to the source of objects or data, providing local services. Initiated at the edge, it generates faster network service responses, meeting fundamental industry needs for real-time business, application intelligence, security, and privacy protection. Edge computing lies between physical entities and industrial connections, or even on top of them. Currently, some blockchain nodes rely on edge computing servers. The most commonly required services in edge computing include on-chain data query services and on-chain services. In some traditional approaches, developing blockchain edge computing requires multiple coding steps for different blockchains. For example, blockchain contracts need to be developed, including defining on-chain data structures and contract code, and generating serverless (serverless computing) on-chain interaction interfaces. Simultaneously, data structures on the edge computing server and service interfaces for processing capabilities need to be defined. This entire process is time-consuming and labor-intensive.
[0032] To this end, the embodiments of this specification provide a solution for providing blockchain services, which can be applied to off-chain devices and can provide blockchain services for blockchains in different industries. Taking multiple blockchains 201 such as logistics finance chain, ETC (Ethereum Classic) chain, legal chain, digital commodity chain, etc. as examples, Figure 2A schematic diagram showing an application scenario in which the embodiment of this specification can be applied is shown. Figure 2 In the application scenario shown, the off-chain device 202 is an edge computing server. Figure 2 As shown, for each blockchain 201 in the above-mentioned multiple blockchains, the off-chain device 202 can obtain the data structure of the on-chain data from any blockchain node of the blockchain, wherein the data structure is used to define multiple fields in the on-chain data. Afterwards, the obtained data structure can be parsed to generate and store a field table for each field. Here, the field table can include the field identifier of the corresponding field (for example, the field name) and the attribute information of the field. Then, the off-chain device can provide data interaction services for the blockchain based on the field table. In practice, the field tables corresponding to the above-mentioned multiple blockchains can be stored in the same table, thereby providing data interaction services for multiple blockchains based on the table.
[0033] Continue to see Figure 3 , Figure 3 The flowchart of the method for providing blockchain services according to one embodiment is shown. It can be understood that the method can be applied to Figure 2 The off-chain device 202 in the embodiment can be any device, equipment, platform, device cluster, etc. with computing and processing capabilities. Figure 3 As shown, the method for providing blockchain services may include the following steps:
[0034] Step 301: Obtain the data structure of the on-chain data from the blockchain node.
[0035] In this embodiment, off-chain devices can pull the on-chain data model from any blockchain node, thereby obtaining the data structure of the on-chain data. Data structures are used to define multiple fields within the on-chain data. Data stored in blockchains can include various types of data, such as transaction bodies, transaction receipts, block data, and account status data. Different types of data can have different data structures. Alternatively, a blockchain can have multiple business scenarios, such as financing, commission, and transaction scenarios. Different business scenarios can have different data structures. This scenario will be used as an example for the following description.
[0036] Figure 4 Schematic diagram of a data structure in one embodiment. This data structure is, for example, a data structure of a transaction receipt for a commission transaction in a commission scenario. Figure 4As shown, the data structure defines multiple fields with field identifiers (or field names) such as categoryID, commissionRuleAccountId, senderID, and receiverID. In addition, the data structure also defines other attributes of each field, such as field type (e.g., String, uint32, uint64, etc.), field code (code), and Figure 4 Some properties not shown in the figure, such as whether it is a unique key, whether it is an index, whether it is non-empty, whether it is a complex type, the index identifier of the associated data structure, etc.
[0037] As mentioned above, in the blockchain, the data structure of the data in the blockchain can be set through the genesis contract or system contract. The code of these contracts includes the data structure of the data and provides functions (or query interfaces) for obtaining the data structure. For example, in the commission payment business scenario, the blockchain can set up the following: Figure 4 The commission data structure shown (e.g., a Commission contract) includes a commission data structure and provides a query interface for the commission data structure. The commission data structure is used, for example, to define various fields in a commission business scenario. In addition, the commission contract can provide other functions (e.g., a payment function) for carrying out commission payment services. For example, a user terminal can pay a commission to another user or blockchain platform by sending a transaction to the blockchain that calls the payment function of the commission contract. After executing the transaction, the blockchain node generates a transaction receipt for the transaction and stores it in the blockchain. The transaction receipt includes field data for multiple fields defined in the commission data structure.
[0038] Off-chain device 202 can receive the data structure from any blockchain node by sending a call to the query interface. Specifically, for the aforementioned commission data structure, off-chain device 202 can send a query request (or transaction) to any blockchain node, invoking the query interface provided by the commission contract. Upon receiving the query request, the blockchain node executes the query interface, obtains the commission data structure included in the commission contract code, and returns the commission data structure to off-chain device 202.
[0039] Step 302: Parse the acquired data structure, generate and store a field table for each field.
[0040] In this embodiment, the data structure obtained in step 301 may be parsed to generate and store a field table for each field. Figure 5 Schematic diagram of a table stored in an off-chain device in an embodiment of this specification, including a field table 501. Figure 5 As shown, the field table 501 can be used to define the information of a single field in a data structure. In this example, the field table 501 may include the field identifier (e.g., field name) of the corresponding field and the attribute information of the field. The attribute information of the field may include various information related to the attributes of the field, including but not limited to the creation time, update time, index identifier of the data structure to which it belongs, index identifier of the field data corresponding to the field, field code (code), field type, whether it is a unique key, whether it is an index, whether it is non-empty, whether it is a complex type, index identifier of the associated data structure, etc. The index identifier of the field data is the name or number of the field data that uniquely identifies the target field among multiple fields of the data structure generated by the off-chain device 202. By generating the index identifier of the field data, the off-chain device 202 can store the index identifier of each field data in association with the corresponding field data when storing data having the data structure, so that the target field data in the stored data can be read through the index identifier.
[0041] Figure 6 for Figure 5 Schematic diagram of each table in the example. Figure 4 As an example, by analyzing the commission data structure, we can get Figure 6 For example, the field table corresponding to the field "categoryID" is shown in the second row of the field table 601, where the field data such as "field identifier categoryID", "field code categoryID", and "field type string" can be obtained from Figure 4 The data structure is parsed and obtained, "index identifier V0 of field data" is the index identifier corresponding to the field "categoryID" generated by the off-chain device 202, and "index identifier 01 of data structure" is the index identifier corresponding to the commission data structure generated by the off-chain device 202.
[0042] In some optional implementations, step 302 may be performed as follows:
[0043] First, the acquired data structure is verified. For example, the syntax between the data in the data structure can be verified to see whether it complies with the syntax rules or whether there are any syntax errors.
[0044] Then, after determining that the data structure has passed verification, the programming language used by the data structure is determined. As an example, the programming language that the data structure can use may include but is not limited to: Solidity programming language, Golang programming language, C++ programming language, etc.
[0045] Finally, the data structure is parsed according to the programming language to generate a field table for each field. For example, corresponding parsing methods can be pre-set for different programming languages, thereby enabling data structure parsing based on the programming language. Through this implementation method, data structures in different programming languages can be parsed.
[0046] Step 303: Provide data interaction services for the blockchain according to the field table.
[0047] In this embodiment, data interaction services for the blockchain can be provided based on the generated field table. Data interaction services for the blockchain can include on-chain data query services, on-chain services, and other service capabilities commonly required by edge computing. As an example, off-chain devices can include a SQL (Structured Query Language) conversion engine, a result conversion engine, a permission management engine, a log management engine, and so on. The SQL conversion engine can convert query parameters in the query interface into query SQL for the table, the result conversion engine can parse query results obtained based on the table into the results required by the query interface, the permission management engine can provide interface authentication control, and the log management engine can record query logs, on-chain logs, and so on.
[0048] In some optional implementations, the method for providing blockchain services may further include the following:
[0049] Step 1) Receive first data from a blockchain node in real time. The first data may include, but is not limited to, a data identifier, field identifiers for each field, and field data associated with the field identifiers for each field. The field identifiers included in the first data indicate the data structure to which the first data corresponds, or the first data may also include the name of the corresponding data structure. The first data may be, for example, a transaction receipt for a commission transaction. The transaction receipt may have the following format:
[0050] {Receipt1
[0051] CategoryID:02
[0052] …
[0053] SenderID:A
[0054] ReceiverID:B}
[0055] Among them, "Receipt1" is a data identifier, and the transaction receipt Receipt1 includes the field names (or field identifiers) and field values of multiple fields such as CategoryID, SenderID, and ReceiverID.
[0056] Step 2) Obtain the field table of each field according to the field identifier of each field.
[0057] Step 3) The first data is stored, and an index relationship is established between each field identifier of the first data and each field data using the index identifier of each field data in each field table. Specifically, a mapping relationship table can be established between the index identifier of each field data and the storage location (or storage address) of the corresponding field data. Thus, the index identifier of the field data corresponding to the field identifier can be determined based on the field table of the field, and the storage location of the field data can be determined based on the mapping relationship table, thereby reading the field data.
[0058] After the first data is stored as described above, the step 303 may be specifically performed as follows: querying the first data based on the index relationship.
[0059] Optionally, the above method for providing blockchain services may further include the following: generating and storing a data structure table of the data structure.
[0060] As an example, Figure 5 The schematic diagram of the table stored in the off-chain device shown also includes a data structure table 502. The data structure table 502 may include information such as the primary key ID (identifier), the name of the data structure, the index identifier of the data structure, the data structure code, the data structure version, and the blockchain ID (identifier) and blockchain name of the blockchain to which it belongs. Among them, the index identifier of the data structure is the name or number of the data structure generated by the off-chain device 202 that uniquely identifies the target data structure among multiple data structures. By generating the index identifier of the data structure, when storing data having the data structure, the off-chain device 202 can associate the index identifier of each data structure with the index identifier of the field data of multiple fields of the corresponding data structure, thereby enabling the field data of multiple fields of the target data structure in the stored data to be read through the index identifier.
[0061] For example, the data structure may be parsed according to a preset parsing method to obtain a data structure table of the data structure. Figure 6 As Figure 5 Schematic diagram of each table in the example. Figure 4 As an example, by analyzing the commission data structure, we can get Figure 6 The data structure table 602 is shown.
[0062] In this embodiment, the above step 3) stores the above first data and establishes an index relationship between each field identifier of the above first data and each field data through the index identifier of each field data in each field table, which can be specifically implemented as follows:
[0063] S1, determining a data structure table corresponding to first data, and determining an index identifier of the data structure from the data structure table.
[0064] Specifically, according to the multiple fields such as CategoryID, SenderID, ReceiverID, etc. included in the above transaction receipt Receipt1, it can be determined that the multiple fields included in the transaction receipt Receipt1 are related to Figure 4 The multiple fields defined in the data structure shown are consistent, thereby determining that the transaction receipt Receipt1 is consistent with Figure 6 Alternatively, if the transaction receipt Receipt1 includes the name of the data structure (Commission) or the corresponding contract name, the data structure table can be determined based on the data structure name. The off-chain device 202 can then read the index identifier "01" of the data structure of the transaction receipt Receipt1 from the data structure table 602.
[0065] S2, determining the index identifier of each field data from the field table according to the field identifier of each field and the index identifier of the data structure.
[0066] Specifically, Figure 6 As shown, taking a transaction receipt for a commission transaction as an example, the field table 601 for each field is first determined based on the index identifier 01 of the data structure and the field identifier of each field. Then, the index identifier of the field data for each field can be determined from the field table 601. For example, based on the field identifier CategoryID, the index identifier of the field data for the field CategoryID can be determined from the field table 601 as V0.
[0067] S3, generating and storing a data table of the first data, wherein the data table may include a data identifier, an index identifier of a data structure, each field data, and an index identifier of each field data. As an example, Figure 5 The schematic diagram of tables stored in the off-chain device also includes a data table 503. And Figure 6 As Figure 5 Schematic diagram of each table in the example. Figure 4 Taking the commission data structure in as an example, by pulling the on-chain data in real time, we can get Figure 6 The data table 603 is shown. VO data, V1 data, etc. are field data associated with the index identifier of the field data. By storing the field data of multiple fields of the data structure separately, it is easier to read the data by field. The index identifier of the data can be a name or number generated by the off-chain device 202 to identify the data. The off-chain device 202 can store the index identifier of the data in association with the storage address information of the data, so that the data can be read through the index identifier of the data.
[0068] In some optional implementations, the data interaction service may be an on-chain data query service, and the query of the first data based on the index relationship may be specifically performed as follows:
[0069] 1) Receive an on-chain data query request from a user terminal. The data query request may include a data identifier of the first data, a field identifier of a target field, and the like.
[0070] For example, the data query request is used to query the field data of the CategoryID field in the transaction receipt Receipt1. The data query request may include the data identifier "Receipt1" of the target data and the field identifier "CategoryID" of the target data.
[0071] When performing on-chain data queries, the on-chain data query request can be parsed and assembled into SQL according to the order of the fields, and the data in the data table can be found based on the assembled SQL.
[0072] 2) Obtaining a data table of the first data according to the data identifier of the first data.
[0073] Specifically, the off-chain device 202 can obtain the data table 603 of the first data according to the data identifier "Receipt1".
[0074] 3) Obtaining a field table of the target field according to the index identifier of the data structure in the data table of the first data and the field identifier of the target field.
[0075] Specifically, the off-chain device 202 may determine the field table 601 according to the index identifier 01 of the data structure in the data table of the first data, and determine the field table of the CategoryID field in the field table 601 according to the field identifier CategoryID.
[0076] 4) Determine the index identifier corresponding to the target field based on the field table of the target field.
[0077] Specifically, the off-chain device 202 can determine the index identifier ("V0") corresponding to the CategoryID field according to the field table of the CategoryID field.
[0078] 5) According to the determined index identifier, search for field data corresponding to the target field in the data table of the first data.
[0079] Specifically, the off-chain device 202 can search for field data corresponding to the CategoryID field from the data table of the first data according to the index identifier V0, and feed back the field data after further processing.
[0080] 6) Return the found field data to the user terminal.
[0081] It can be understood that the data query service provided by the embodiment of this specification is described above in the form of only one example, and the data query service provided by the embodiment of this specification is not limited to this. For example, in another example, the query request may include the field identifier and field data included in the data to be queried (for example, SenderID: Alice). The query request is used to query all transactions sent by Alice. After receiving the query request, the off-chain device 202 can locate the field table corresponding to the SenderID field in the Commission data structure according to the SenderID, obtain the index identifier of the SenderID field (for example, V5) from the field table, retrieve all data tables with V5=Alice according to the index identifier, and obtain the transactions sent by Alice from the retrieved data tables. The off-chain device 202 can also similarly retrieve transactions sent by Alice in other data structures.
[0082] Through this implementation method, an on-chain data query service based on edge computing power is realized.
[0083] In some optional implementations, the above-mentioned method for providing blockchain services may further include the following: generating a data query log based on the provided on-chain data query service; and uploading the data query log to the chain.
[0084] In addition, the services provided by off-chain devices, which provide edge computing power, can be encapsulated into interfaces. Off-chain devices can also have permission management capabilities to authenticate users who call the interfaces.
[0085] In some optional implementations, the data interaction service may also be an on-chain service, and step 303 may be specifically performed as follows:
[0086] First, a chain request is received from the user terminal. Here, the chain request may include field data of each field of the data to be chained. The chain request is used, for example, to chain the transaction that calls the commission contract (Commission contract). Similarly, the transaction also conforms to the Commission data structure. Among them, the chain request includes, for example, the field data of the SenderID field (corresponding to the From field of the transaction), the RecieverID field (corresponding to the To field of the transaction) and the Data field. For example, the data of the SenderID field is "Alice", the data of the receiverID field is the contract address of the Commission contract, and the data of the Data field includes the payment function name in the Commission contract to indicate that the transaction is initiated by the account Alice and calls the payment function in the Commission contract.
[0087] Then, according to the field table of each field of the data to be uploaded to the chain, the field identifier corresponding to each field data is determined from the field table of each field.
[0088] Specifically, the data structure table of the data to be uploaded can be determined based on the field data of each field, and the index identifier of the data structure of the data to be uploaded can be determined from the data structure table. For example, the off-chain device 202 can determine the data structure table of the data to be uploaded based on the contract address of the Commission contract in the field data of the To field in the uploaded data. Figure 6 The data structure table 602 is shown, so that the index identifier 01 of the data structure can be read from the data structure table 602. Then, the field table 601 of each field is obtained according to the index identifier 01 of the data structure, and the field identifier corresponding to each field data is determined from the field table of each field.
[0089] Finally, the data is uploaded to the chain based on the field data and the field identifiers corresponding to each field data.
[0090] Specifically, an on-chain transaction can be generated based on the field identifiers and field data corresponding to each field data. For example, the field data of the SenderID field is placed in the From field of the transaction, and the field data of the ReceiverID field is placed in the To field of the transaction, thereby generating an on-chain transaction that conforms to the preset transaction format. The on-chain transaction is then sent to the blockchain node to be stored in the blockchain. Through this implementation method, an on-chain service based on edge computing power can be realized.
[0091] Recalling the above process, in the embodiments of this specification, the data structure of the blockchain's on-chain data is automatically mapped to a table on the off-chain device. The off-chain device can then provide edge computing power based on the mapped table. This allows for the rapid establishment of service nodes that can provide edge computing power for the blockchain.
[0092] According to another embodiment, a device for providing blockchain services is provided. The device for providing blockchain services is provided on an off-chain device, which can be any device, platform, or device cluster with computing and processing capabilities.
[0093] Figure 7 FIG1 shows a schematic block diagram of an apparatus for providing blockchain services according to an embodiment. Figure 7 As shown, the device 700 for providing blockchain services includes: an acquisition unit 701, configured to obtain a data structure of on-chain data from a blockchain node, wherein the data structure defines multiple fields in the on-chain data; a parsing unit 702, configured to parse the acquired data structure, generate and store a field table for each field, wherein the field table includes a field identifier of a corresponding field and attribute information of the field; and a service unit 703, configured to provide data interaction services for the blockchain according to the field table.
[0094] In some optional implementations of this embodiment, the attribute information of the field includes an index identifier of the field data of the field, and the above-mentioned device 700 also includes: a receiving unit (not shown in the figure), configured to receive first data from a blockchain node, the above-mentioned first data including the field identifier of each field and the field data associated with the field identifier of each field; a field table acquisition unit (not shown in the figure), configured to obtain the field table of each field according to the field identifier of each field; a storage unit (not shown in the figure), configured to store the above-mentioned first data, and establish an index relationship between each field identifier and each field data of the above-mentioned first data through the index identifier of each field data in each field table; the above-mentioned service unit 703 includes a query module (not shown in the figure), and the above-mentioned query module is configured to: query the above-mentioned first data based on the above-mentioned index relationship.
[0095] In some optional implementations of this embodiment, the above-mentioned first data also includes a data identifier, and the above-mentioned device 700 also includes: a generation unit (not shown in the figure), configured to generate and store a data structure table of the above-mentioned data structure, the above-mentioned data structure table includes the name of the above-mentioned data structure, the index identifier of the data structure and the data structure code; wherein the above-mentioned field table also includes the index identifier of the above-mentioned data structure; the above-mentioned storage unit is further configured to: determine the above-mentioned data structure table corresponding to the above-mentioned first data, and determine the index identifier of the above-mentioned data structure from the above-mentioned data structure table; determine the index identifier of each field data from the above-mentioned field table according to the field identifier of each field and the index identifier of the above-mentioned data structure; generate and store a data table of the above-mentioned first data, and the above-mentioned data table includes: the above-mentioned data identifier, the index identifier of the above-mentioned data structure, each field data and the index identifier of each field data.
[0096] In some optional implementations of this embodiment, the above-mentioned query module is further configured to: receive an on-chain data query request from a user terminal, wherein the above-mentioned data query request includes the data identifier of the above-mentioned first data and the field identifier of the target field; obtain the data table of the above-mentioned first data according to the data identifier of the above-mentioned first data; obtain the field table of the target field according to the index identifier of the data structure in the data table of the first data and the field identifier of the above-mentioned target field; determine the index identifier corresponding to the above-mentioned target field according to the field table of the above-mentioned target field; according to the determined index identifier, search for the field data corresponding to the above-mentioned target field from the data table of the above-mentioned first data; and return the above-mentioned field data to the above-mentioned user terminal.
[0097] In some optional implementations of this embodiment, the above-mentioned device 700 also includes: a log generation unit (not shown in the figure), configured to generate a data query log based on the provided on-chain data query service; and an on-chain unit (not shown in the figure), configured to upload the above-mentioned data query log to the chain.
[0098] In some optional implementations of this embodiment, the above-mentioned service unit 703 is further configured to: receive an uplink request from a user terminal, wherein the above-mentioned uplink request includes field data of each field of the data to be uplinked; determine the field identifier corresponding to each field data from the field table of each field according to the field table of each field of the above-mentioned data to be uplinked; and uplink data according to the above-mentioned each field data and the field identifier corresponding to each field data.
[0099] In some optional implementations of this embodiment, the acquisition unit 701 is further configured to: send a transaction to call a contract to a blockchain node, where the contract is used to define the data structure of on-chain data; and receive the data structure from the blockchain node.
[0100] In some optional implementations of this embodiment, the parsing unit 702 is further configured to: verify the acquired data structure; in response to determining that the data structure passes the verification, determine the programming language used by the data structure; parse the data structure according to the programming language to generate a field table for each field.
[0101] According to another embodiment, there is also provided a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute Figure 3 The method described.
[0102] According to another embodiment, there is also provided a computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, Figure 3 The method described.
[0103] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD through their own programming, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
[0104] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.
[0105] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude that with the future development of computer technology, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, an in-vehicle human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0106] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any particular order.
[0107] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more of the present specifications, the functions of each module can be implemented in the same or multiple software and / or hardware, or the module that implements the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0108] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0109] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0110] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0111] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0112] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0113] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0114] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as a method, system, or computer program product. Thus, one or more embodiments of this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0115] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In distributed computing environments, program modules may be located in local and remote computer storage media, including storage devices.
[0116] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.
[0117] The foregoing is merely an example of one or more embodiments of this specification and is not intended to limit the one or more embodiments of this specification. It will be apparent to those skilled in the art that various modifications and variations may be made to one or more embodiments of this specification. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification shall be included within the scope of the claims.
Claims
1. A method for providing blockchain services, applied to off-chain devices, comprising: Obtaining a data structure of on-chain data from a blockchain node, wherein the data structure defines multiple fields in the on-chain data; Parsing the acquired data structure, generating and storing a field table for each field, wherein the field table includes a field identifier of the corresponding field and attribute information of the field, wherein the attribute information of the field includes an index identifier of the data structure to which it belongs; Provide data interaction services for the blockchain according to the field table.
2. The method according to claim 1, wherein The attribute information of the field includes an index identifier of the field data of the field, and the method further includes: Receiving first data from a blockchain node, the first data including a field identifier of each field and field data associated with the field identifier of each field; Get the field table of each field according to the field identifier of each field; storing the first data, and establishing an index relationship between each field identifier of the first data and each field data through the index identifier of each field data in each field table; Providing data interaction services for the blockchain according to the field table includes: The first data is queried based on the index relationship.
3. The method according to claim 2, wherein: The first data also includes a data identifier, and the method further includes: Generate and store a data structure table of the data structure, wherein the data structure table includes the name of the data structure, the index identifier of the data structure, and the data structure code; wherein the field table also includes the index identifier of the data structure; The storing of the first data and establishing an index relationship between each field identifier and each field data of the first data through the index identifier includes: Determine the data structure table corresponding to the first data, and determine the index identifier of the data structure from the data structure table; Determining the index identifier of each field data from the field table according to the field identifier of each field and the index identifier of the data structure; A data table of the first data is generated and stored, wherein the data table includes: the data identifier, the index identifier of the data structure, each field data and the index identifier of each field data.
4. The method according to claim 3, wherein: Querying the first data based on the index relationship includes: Receiving an on-chain data query request from a user terminal, wherein the data query request includes a data identifier of the first data and a field identifier of a target field; Acquire a data table of the first data according to the data identifier of the first data; Acquire a field table of the target field according to an index identifier of a data structure in a data table of the first data and a field identifier of the target field; Determine the index identifier corresponding to the target field according to the field table of the target field; Searching for field data corresponding to the target field from a data table of the first data according to the determined index identifier; The field data is returned to the user terminal.
5. The method according to claim 1, wherein The method further comprises: Generate data query logs based on the on-chain data query service provided; The data query log is uploaded to the chain.
6. The method according to claim 1, wherein Providing data interaction services for the blockchain according to the field table includes: Receive an uplink request from a user terminal, wherein the uplink request includes field data of each field of the data to be uplinked; According to the field table of each field of the data to be uploaded, determining the field identifier corresponding to each field data from the field table of each field; Data is uploaded to the chain according to the various field data and the field identifiers corresponding to the various field data.
7. The method according to claim 1, wherein The data structure of obtaining on-chain data from the blockchain node includes: Sending a transaction to a blockchain node to invoke a contract that defines the data structure of on-chain data; The data structure is received from a blockchain node.
8. The method according to claim 1, wherein The step of parsing the acquired data structure and generating and storing a field table of each field includes: Verifying the acquired data structure; In response to determining that the data structure passes verification, determining a programming language used by the data structure; The data structure is parsed according to a programming language to generate a field table for each field.
9. A device for providing blockchain services, provided on an off-chain device, comprising: an acquisition unit, configured to acquire a data structure of on-chain data from a blockchain node, wherein the data structure defines a plurality of fields in the on-chain data; a parsing unit configured to parse the acquired data structure, generate and store a field table for each field, wherein the field table includes a field identifier of the corresponding field and attribute information of the field, wherein the attribute information of the field includes an index identifier of the data structure to which it belongs; A service unit is configured to provide data interaction services for the blockchain according to the field table.
10. The device according to claim 9, wherein The attribute information of the field includes an index identifier of the field data of the field, and the device further includes: A receiving unit is configured to receive first data from a blockchain node, where the first data includes a field identifier of each field and field data associated with the field identifier of each field; A field table acquisition unit configured to acquire a field table of each field according to a field identifier of each field; a storage unit configured to store the first data, and establish an index relationship between each field identifier of the first data and each field data through the index identifier of each field data in each field table; The service unit includes a query module, and the query module is configured to: The first data is queried based on the index relationship.
11. The device according to claim 10, wherein The first data also includes a data identifier, and the device further includes: a generating unit configured to generate and store a data structure table of the data structure, wherein the data structure table includes a name of the data structure, an index identifier of the data structure, and a data structure code; wherein the field table also includes an index identifier of the data structure; The storage unit is further configured as: Determine the data structure table corresponding to the first data, and determine the index identifier of the data structure from the data structure table; Determining the index identifier of each field data from the field table according to the field identifier of each field and the index identifier of the data structure; A data table of the first data is generated and stored, wherein the data table includes: the data identifier, the index identifier of the data structure, each field data and the index identifier of each field data.
12. The device according to claim 11, wherein The query module is further configured to: Receiving an on-chain data query request from a user terminal, wherein the data query request includes a data identifier of the first data and a field identifier of a target field; Acquire a data table of the first data according to the data identifier of the first data; Acquire a field table of the target field according to an index identifier of a data structure in a data table of the first data and a field identifier of the target field; Determine the index identifier corresponding to the target field according to the field table of the target field; Searching for field data corresponding to the target field from a data table of the first data according to the determined index identifier; The field data is returned to the user terminal.
13. The device according to claim 9, wherein The device further comprises: a log generation unit, configured to generate a data query log according to the provided on-chain data query service; The chain-up unit is configured to chain-up the data query log.
14. The device according to claim 9, wherein The service unit is further configured as follows: Receive an uplink request from a user terminal, wherein the uplink request includes field data of each field of the data to be uplinked; According to the field table of each field of the data to be uploaded, determining the field identifier corresponding to each field data from the field table of each field; Data is uploaded to the chain according to the various field data and the field identifiers corresponding to the various field data.
15. The device according to claim 9, wherein The acquisition unit is further configured to: Sending a transaction to a blockchain node to invoke a contract that defines the data structure of on-chain data; The data structure is received from a blockchain node.
16. The device according to claim 9, wherein The parsing unit is further configured to: Verifying the acquired data structure; In response to determining that the data structure passes verification, determining a programming language used by the data structure; The data structure is parsed according to a programming language to generate a field table for each field.
17. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 8.
18. A computing device comprising a memory and a processor, characterized in that: The memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Data structure reading and updating method and device and electronic equipment
CN110032568A
Data query method, device and equipment based on block chain network, and storage medium
CN113722385A