CN108920523B - Method, device, equipment, system and medium for querying data on block chain - Google Patents

Method, device, equipment, system and medium for querying data on block chain Download PDF

Info

Publication number
CN108920523B
CN108920523B CN201810565553.XA CN201810565553A CN108920523B CN 108920523 B CN108920523 B CN 108920523B CN 201810565553 A CN201810565553 A CN 201810565553A CN 108920523 B CN108920523 B CN 108920523B
Authority
CN
China
Prior art keywords
block
block number
data
maximum
chain
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810565553.XA
Other languages
Chinese (zh)
Other versions
CN108920523A (en
Inventor
颜亮
王晓明
陈延
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Lexin Software Technology Co Ltd
Original Assignee
Shenzhen Lexin Software Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Lexin Software Technology Co Ltd filed Critical Shenzhen Lexin Software Technology Co Ltd
Priority to CN201810565553.XA priority Critical patent/CN108920523B/en
Publication of CN108920523A publication Critical patent/CN108920523A/en
Application granted granted Critical
Publication of CN108920523B publication Critical patent/CN108920523B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a method, a device, equipment, a system and a medium for inquiring data on a block chain. The method comprises the following steps: reading the maximum historical block number derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain; if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain; when the new block adding event is monitored, acquiring a new block number from the new block adding event; exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in the storage unit as a new maximum historical block number; and carrying out multi-dimensional data query through the storage middleware. The embodiment of the invention can accurately derive the block data in real time and realize multi-dimensional query.

Description

Method, device, equipment, system and medium for querying data on block chain
Technical Field
Embodiments of the present invention relate to a block chain technology, and in particular, to a method, an apparatus, a device, a system, and a medium for querying data on a block chain.
Background
The blockchain is a solution of a distributed consensus collaborative system, and is essentially a distributed ledger database. The blockchain may be used to store sensitive important data related to multi-party transaction records, transfer records, and the like. The data recorded in the block chain can be traced and can not be tampered through mechanisms such as a consensus algorithm and a cryptographic algorithm of the block chain, and all participants in the block chain necessarily achieve consensus on the written data to some extent.
In practical applications, it is often necessary to query data on the blockchain, for example, a blockchain-based billing system, where a bill for collection or payment is written into the blockchain, and it is necessary to perform a query and count the total amount of money received within a certain period of time or all bills of a certain class of users under such a service. However, the current blockchain platform does not provide a data query scheme for blockchains.
Disclosure of Invention
The embodiment of the invention provides a method, a device, equipment, a system and a medium for inquiring data on a block chain, which are used for realizing derivation and multi-dimensional inquiry of block data.
In a first aspect, an embodiment of the present invention provides a method for querying data on a block chain, including:
reading the maximum historical block number derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain;
if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain;
when the new block adding event is monitored, acquiring a new block number from the new block adding event;
exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in the storage unit as a new maximum historical block number;
and carrying out multi-dimensional data query through the storage middleware.
In a second aspect, an embodiment of the present invention further provides an apparatus for querying data on a block chain, where the apparatus includes:
the reading module is used for reading the maximum historical block number which is derived from the data from the storage unit and acquiring the block number on the maximum chain from the block chain;
a monitoring module, configured to monitor a new block join event on the block chain if the maximum history block number is the same as the block number on the maximum chain;
the acquisition module is used for acquiring a new block number from the new block adding event when the new block adding event is monitored;
the exporting and adding module is used for exporting the data in the block corresponding to the new block number to the storage middleware, and adding the new block number in the storage unit as a new maximum historical block number;
and the data query module is used for carrying out multi-dimensional data query through the storage middleware.
In a third aspect, an embodiment of the present invention further provides a data query device, where the data query device includes:
one or more processors;
a memory for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the block chaining data query method of any embodiment.
In a fourth aspect, an embodiment of the present invention further provides a system for querying data on a block chain, where the system includes a data querying device, a storage unit, and a storage middleware;
the data query equipment is respectively connected with the storage unit and the storage middleware;
the data query device is used for reading the maximum historical block number derived from the data from the storage unit and acquiring the block number on the maximum chain from the block chain; if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain; when the new block adding event is monitored, acquiring a new block number from the new block adding event; exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in the storage unit as a new maximum historical block number; performing multi-dimensional data query through the storage middleware;
the storage unit is used for storing the block number of the block subjected to data derivation;
the storage middleware is used for storing the data in the blocks and carrying out multi-dimensional data query.
In a fifth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for querying data on a blockchain according to any embodiment.
In the embodiment of the invention, the maximum historical block number derived from data is read from a storage unit, the block number on the maximum chain is obtained from a block chain, and if the maximum historical block number is the same as the block number on the maximum chain, a new block adding event on the block chain is monitored, so that the data of a newly added block is prevented from being not stored; when the new block adding event is monitored, acquiring a new block number from the new block adding event, exporting data in a block corresponding to the new block number to a storage middleware, and positioning the newly added block by taking the block number of the block as a reference; the new block number is added in the storage unit to be used as a new maximum historical block number, so that the exported block is recorded in real time, and the new maximum historical block number and the maximum on-chain block number are compared when the block is exported next time; and performing multi-dimensional data query through the storage middleware, so that the data in the block is exported to the storage middleware, and multi-dimensional query is realized in the storage middleware without depending on the query function of the block chain.
Further, since the blocks in the blockchain are connected in chronological order, the blockchain itself is traceable and not tampered. In this embodiment, the monitored data in the block corresponding to the new block adding event is exported to the storage middleware when the maximum historical block number is the same as the maximum on-chain block number, so that the export operation is performed according to the adding sequence of the blocks on the block chain, that is, the data sequence and the data content in the storage middleware are respectively the same as the sequence and the data content of the blocks on the block chain, and the accuracy of data export is ensured.
Drawings
Fig. 1 is a flowchart of a method for querying data on a block chain according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for querying data on a block chain according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a device for querying data on a block chain according to a third embodiment of the present invention;
FIG. 4 is a schematic structural diagram of a data query device according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of a data query system on a blockchain according to a fifth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
The present embodiment is applicable to the case of querying data in a block in a blockchain, and the method can be executed by a data querying device on the blockchain. The main idea of this embodiment is to export data from a block to storage middleware, and perform multidimensional query on the data in the storage middleware by using a multidimensional query function of the storage middleware.
Fig. 1 is a flowchart of a method for querying data on a block chain according to an embodiment of the present invention, which specifically includes the following steps:
s110, reading the maximum historical block number which is derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain.
The block number is the block number of the block itself and is the unique identifier of the block. For example, the block number of the created block is 0, the block number of the block connected to the created block is 1, the block number of the block connected to the next block is 2, and so on. In this embodiment, each time data of one block is derived, the block number of the block is stored in the storage unit, and based on this, the storage unit stores the block numbers of all blocks from which data has been derived. For convenience of description and distinction, a block number in a memory cell is referred to as a history block number, and a block number of a block on a block chain is referred to as an on-chain block number. Since the block chains are connected in a chain manner from small to large according to the block numbers, the data of the corresponding blocks are derived according to the sequence from small to large of the block numbers, and the block number of the largest historical block in the storage unit corresponds to the block which is newly subjected to data derivation. In one example, the storage unit stores block numbers 0, 1, 2, and 3, where 3 is the maximum history block number, and it is described that the block corresponding to block number 3 is the block from which data is most recently derived, and if the block number of the block next to the block corresponding to block number 3 is 4, data should be derived from the block corresponding to block number 4 next time.
The length of the block chain is not constant, and after a period of time, a new block is added at the end of the block chain. Sometimes, the data query device on the block chain exits the data query system on the block chain, and a new block may be added during the exit time of the data query device. Thus, when the data query device in the block chain accesses the system again, the newly added block cannot be monitored. In order to avoid data loss due to data not being stored in a newly added block, in this embodiment, preferably, after the data query device on the block chain accesses the data query system on the block chain, the maximum history block number derived from the data is read from the storage unit, and the maximum history block number on the block chain is obtained from the block chain. Of course, S110 may be performed each time before a new tile join event on the chain of listening tiles.
And S120, if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain.
S130, when a new block adding event is monitored, acquiring a new block number from the new block adding event.
If the maximum historical block number is the same as the block number on the maximum chain, the latest block on the block chain is described to have data exported, or no new block is added within the exit time of the data inquiry device, the monitoring of the new block addition event on the block chain is started.
Alternatively, on the Fabric blockchain platform, whenever a new block is added to a blockchain, the Fabric blockchain platform issues a block event, called a new block addition event, which includes the block number of the new block. The data query device on the block chain can monitor the new block join event in real time. And when a new block adding event is monitored, acquiring a new block number from the new block adding event.
S140, exporting the data in the block corresponding to the new block number to the storage middleware, and adding the new block number in the storage unit as a new maximum historical block number.
Optionally, exporting data in the block corresponding to the new block number to the storage middleware, includes: determining an access interface of a block corresponding to the new block number; exporting the data in the block from the access interface to the storage middleware. Specifically, the data in the tile is parsed from the access interface and the parsed content is copied into storage middleware.
After exporting the data in the block to the storage middleware, a new block number is added to the storage unit. Since the block number is the block number of the newly added block and the block number of the newly added block is larger than the block number of the already added block, the new block number is the new maximum history block number in the storage unit.
And S150, carrying out multi-dimensional data query through the storage middleware.
The storage middleware has a data storage function and a multi-dimensional data query function, and performs multi-dimensional statistics, summarization and extraction of a plurality of key fields on data in the storage middleware so as to provide service personnel for multi-dimensional data query.
Illustratively, a query condition is obtained, the query condition including a block query range and a query field. The method comprises the steps that a query request of a service worker can be received, and query conditions are obtained from the query request; alternatively, the query condition is set in advance. The block search range refers to which blocks are searched, and may be data of a certain block, or data of a plurality of continuous blocks or discontinuous blocks. The query field refers to the content to be queried, and in order to implement multi-dimensional query, the query field is a combination of at least one key field corresponding to the data in the storage middleware. And then, the block query range and the query field are transmitted to the storage middleware for the storage middleware to determine the data of the target block matched with the query range, and the data query is carried out according to the query field in the data of the target block.
In one example, the storage middleware stores data of 3 blocks with block numbers 1, 2 and 3. The data of the block number 1 comprises the expenses and incomes of the user A in 2017, the data of the block number 2 comprises the expenses and incomes of the user A in 2018, and the data of the block number 3 comprises the expenses and incomes of the user B in 2017 and 2018. The storage middleware performs statistics and summarization on the data of the 3 blocks, and extracts key fields: user a, user B, 2017, 2018, expenditure, income. Assuming that the query range is the block corresponding to the block number 3 and the query field is the user B, in 2017, the storage middleware queries the data of the block corresponding to the block number 3 to obtain the expense and income of the user B in 2017. Assuming that the query range is the block corresponding to the block numbers 1, 2 and 3, and the query field is the user a, the user B and the income, the storage middleware queries the data of the block corresponding to the block numbers 1, 2 and 3 to find the income of the user a and the user B in 2017 and 2018.
In some embodiments, the storage middleware has a query condition obtaining function, and the storage middleware obtains the query condition and further internally queries data matched with the query condition.
In this embodiment, the maximum historical block number derived from data is read from the storage unit, and the maximum block number on the block chain is obtained, and if the maximum historical block number is the same as the maximum block number on the chain, a new block adding event on the block chain is monitored, so that data of a newly added block is prevented from being not stored; when a new block adding event is monitored, acquiring a new block number from the new block adding event, exporting data in a block corresponding to the new block number to a storage middleware, and positioning the newly added block by taking the block number of the block as a reference; adding a new block number as a new maximum historical block number in the storage unit, thereby recording the derived block in real time so as to compare the new maximum historical block number with the maximum on-chain block number when deriving the block next time; and multi-dimensional data query is carried out through the storage middleware, so that the data in the block is exported to the storage middleware, and multi-dimensional query is realized in the storage middleware without depending on the query function of the block chain.
Further, since the blocks in the blockchain are connected in chronological order, the blockchain itself is traceable and not tampered. In this embodiment, the monitored data in the block corresponding to the new block adding event is exported to the storage middleware when the maximum historical block number is the same as the maximum on-chain block number, so that the export operation is performed according to the adding sequence of the blocks on the block chain, that is, the data sequence and the data content in the storage middleware are respectively the same as the sequence and the data content of the blocks on the block chain, and the accuracy of data export is ensured.
Example two
The embodiment further optimizes the above embodiment, and specifically adds a case that the maximum history block number is smaller than the maximum on-chain block number on the basis of the above embodiment. Fig. 2 is a flowchart of a method for querying data on a block chain according to a second embodiment of the present invention, including the following steps:
s210, reading the maximum historical block number derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain.
The block number on the maximum chain is the block number of the block which is added newly on the block chain at the current moment.
S220, judging whether the maximum historical block number is the same as the maximum on-chain block number, if so, continuing to execute S230. If the maximum history block number is less than the maximum on-chain block number, the process jumps to S270. If the maximum history block number is greater than the maximum on-chain block number, the process jumps to S290.
And S230, adding an event to a new block on the monitoring block chain.
When the maximum historical block number is the same as the block number on the maximum chain, the data in the blocks on the current block chain are all exported to the storage middleware, and then a new block adding event can be monitored.
The data query device on the block chain monitors a new block adding event in real time until the data query device on the block chain exits the data query system on the block chain.
S240, when a new block adding event is monitored, acquiring a new block number from the new block adding event.
And S250, exporting the data in the block corresponding to the new block number to the storage middleware, and adding the new block number in the storage unit to be used as a new maximum historical block number. Continuing to execute S260; meanwhile, it jumps to S240 to continue to store the data in the new block.
And S260, carrying out multi-dimensional data query through the storage middleware and finishing the operation.
In this embodiment, the storage middleware is a search server. The search server carries out multi-dimensional statistics and summarization on the data in the search server, and extracts a plurality of key fields so as to provide business personnel for carrying out multi-dimensional data query.
Illustratively, the search server is a Lucene-based search server, the Elasticsearch. The Elasticsearch is a distributed multi-user full-text search engine, is developed based on Java, is released as an open source code under Apache licensing terms, and is a currently popular enterprise-level search engine. The design is used in cloud computing, can achieve real-time search, and is stable, reliable, quick, and convenient to install and use.
The Elasticsearch is essentially a distributed database, allowing multiple servers to work together. For the data written in it, the elastic search indexes all the key fields, and writes them into an Inverted Index (inversed Index) after processing. When data query is carried out, the index is directly searched, all relevant key fields are indexed through the index, so that query fields obtained by any combination of the key fields are supported, and query conditions are enriched.
S270, exporting the data in the block corresponding to the maximum historical block number plus 1 to the storage middleware. Execution continues with S280.
If the maximum historical block number is smaller than the maximum on-chain block number, the data in the block corresponding to the maximum historical block number plus 1 to the maximum on-chain block number is not imported into the storage middleware. Then, the data in the blocks on the blockchain are exported to the storage middleware in sequence from the maximum historical block number plus 1.
S280, add the block number of the newly derived block in the storage unit as the new maximum history block number. Jumping to S210.
Every time data of one block is exported, the block number of the block is added to the storage unit, so that whether blocks which are not imported into the storage middleware exist or not is judged by comparing the maximum historical block number with the maximum on-chain block number.
Optionally, the storage unit is distributed application coordination service software, such as zookeeper, or a database.
S290, deleting the data of the block corresponding to the block number between the block number of the maximum on-chain block in the storage middleware plus 1 and the block number between the block number of the maximum on-chain block in the storage unit plus 1 and the block number of the maximum historical block. Jumping to S210.
And if the maximum history block number is larger than the maximum on-chain block number, which indicates that the data in the storage middleware is wrong, deleting the data of the block corresponding to the block number between the maximum on-chain block number plus 1 and the maximum history block number in the storage middleware, and deleting the block number between the maximum on-chain block number plus 1 and the maximum history block number in the storage unit. Then, execution returns to S210.
In this embodiment, if the maximum history block number is smaller than the maximum on-chain block number, the data in the block corresponding to the maximum history block number plus 1 is exported to the storage middleware; and adding a block number of a newly exported block in the storage unit as a new maximum historical block number until the new maximum historical block number is the same as the block number on the maximum chain, and adding an event into the new block on the monitoring block chain to ensure that data on the block chain is imported into the storage middleware, so that data loss is avoided, and the accuracy of data export is ensured.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a device for querying data on a block chain according to a third embodiment of the present invention, including: the device comprises a reading module 31, a monitoring module 32, an acquisition module 33, a exporting and adding module 34 and a data query module 35.
A reading module 31, configured to read a maximum history block number derived from data from a storage unit, and obtain a maximum on-chain block number from a block chain;
a monitoring module 32, configured to monitor a new block addition event on the block chain if the maximum history block number is the same as the block number on the maximum chain;
an obtaining module 33, configured to obtain a new block number from a new block adding event when the new block adding event is monitored;
a exporting and adding module 34, configured to export data in the block corresponding to the new block number to the storage middleware, and add the new block number to the storage unit as a new maximum history block number;
and the data query module 35 is configured to perform multidimensional data query through the storage middleware.
In this embodiment, the maximum historical block number derived from data is read from the storage unit, and the maximum block number on the block chain is obtained, and if the maximum historical block number is the same as the maximum block number on the chain, a new block adding event on the block chain is monitored, so that data of a newly added block is prevented from being not stored; when a new block adding event is monitored, acquiring a new block number from the new block adding event, exporting data in a block corresponding to the new block number to a storage middleware, and positioning the newly added block by taking the block number of the block as a reference; adding a new block number as a new maximum historical block number in the storage unit, thereby recording the derived block in real time so as to compare the new maximum historical block number with the maximum on-chain block number when deriving the block next time; and multi-dimensional data query is carried out through the storage middleware, so that the data in the block is exported to the storage middleware, and multi-dimensional query is realized in the storage middleware without depending on the query function of the block chain.
Further, since the blocks in the blockchain are connected in chronological order, the blockchain itself is traceable and not tampered. In this embodiment, the monitored data in the block corresponding to the new block adding event is exported to the storage middleware when the maximum historical block number is the same as the maximum on-chain block number, so that the export operation is performed according to the adding sequence of the blocks on the block chain, that is, the data sequence and the data content in the storage middleware are respectively the same as the sequence and the data content of the blocks on the block chain, and the accuracy of data export is ensured.
In an optional embodiment, the export and add module 34 is further configured to export, to the storage middleware, data in a block corresponding to the largest history block number plus 1 if the largest history block number is smaller than the largest on-chain block number; and adding the block number of the newly derived block in the storage unit as a new maximum historical block number, and returning to execute the reading operation of the maximum historical block number until the maximum historical block number is the same as the maximum on-chain block number.
In an optional embodiment, the export and add module 34 is specifically configured to determine an access interface of the block corresponding to the new block number when exporting data in the block corresponding to the new block number to the storage middleware; exporting the data in the block from the access interface to the storage middleware.
In an alternative embodiment, the storage middleware is a search server; the storage unit is distributed application coordination service software or a database.
In an optional embodiment, the data query module 35 is configured to, when performing multidimensional data query through the storage middleware, obtain a query condition, where the query condition includes a block query range and a query field, and the query field is a combination of at least one key field corresponding to data in the storage middleware; and transmitting the block query range and the query field to the storage middleware for the storage middleware to determine the data of the target block matched with the query range, and performing data query according to the query field in the data of the target block.
The device for querying data on a block chain provided by the embodiment of the invention can execute the method for querying data on the block chain provided by any embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of a data query device according to a fourth embodiment of the present invention, as shown in fig. 4, the data query device includes a processor 40, a memory 41; the number of processors 40 in the data query device may be one or more, and one processor 40 is taken as an example in fig. 4; the processor 40 and the memory 41 in the data query device may be connected by a bus or other means, and fig. 4 illustrates the connection by the bus as an example.
The memory 41 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the data query method on the block chain in the embodiment of the present invention (for example, the reading module 31, the listening module 32, the obtaining module 33, the exporting and adding module 34, and the data query module 35 in the data query device on the block chain). The processor 40 executes various functional applications of the data query device and data processing by running software programs, instructions and modules stored in the memory 41, that is, implements the above-described block chain data query method.
The memory 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal, and the like. Further, the memory 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 41 may further include memory located remotely from processor 40, which may be connected to a data querying device via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
EXAMPLE five
Fig. 5 is a schematic structural diagram of a data query system on a blockchain according to a fifth embodiment of the present invention, including a data query device 51, a storage unit 52, and a storage middleware 53, where fig. 5 further illustrates a blockchain 50 connected to the data query device 51. The data querying device 51 is connected with the storage unit 52 and the storage middleware 53, respectively. The storage middleware is a search server; the storage unit is distributed application coordination service software or a database.
A data query device 51, configured to read a maximum history block number derived from data from the storage unit 52, and obtain a maximum on-chain block number from the block chain 50; if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain; when a new block adding event is monitored, acquiring a new block number from the new block adding event; exporting the data in the block corresponding to the new block number to the storage middleware 53, and adding the new block number in the storage unit 52 as a new maximum historical block number; multidimensional data queries are performed through the storage middleware 53.
The storage unit 52 stores the block number of the block for which data derivation has been performed.
And the storage middleware 53 is used for storing the data in the blocks and performing multi-dimensional data query.
In an optional embodiment, the data query device 51 is further configured to, after reading the maximum history block number from the storage unit 52 and obtaining the maximum on-chain block number from the block chain 50, if the maximum history block number is smaller than the maximum on-chain block number, export the data in the block corresponding to the maximum history block number plus 1 to the storage middleware 53; the block number of the newly derived block is added in the storage unit 52 as a new maximum history block number, and the read operation of the maximum history block number is returned to be performed until the maximum history block number is the same as the maximum on-chain block number.
In an alternative embodiment, when exporting the data in the block corresponding to the new block number to the storage middleware, the data query device 51 is configured to: determining an access interface of a block corresponding to the new block number; exporting the data in the block from the access interface to the storage middleware.
In an optional embodiment, when the data query device 51 performs multidimensional data query through the storage middleware 53, it is specifically configured to: acquiring a query condition, wherein the query condition comprises a block query range and a query field, and the query field is a combination of at least one key field corresponding to data in the storage middleware; the block query range and the query field are transferred to the storage middleware 53, so that the storage middleware 53 determines the data of the target block matching the query range, and performs data query according to the query field in the data of the target block.
EXAMPLE six
An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, where the computer program is used for executing a method for querying data on a blockchain when executed by a computer processor, and the method includes:
reading the maximum historical block number derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain;
if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain;
when a new block adding event is monitored, acquiring a new block number from the new block adding event;
exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in a storage unit as a new maximum historical block number;
and carrying out multi-dimensional data query through the storage middleware.
Of course, the computer program of the computer-readable storage medium having the computer program stored thereon according to the embodiments of the present invention is not limited to the above method operations, and may also perform related operations in the method for querying data on a block chain according to any embodiment of the present invention.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods according to the embodiments of the present invention.
It should be noted that, in the embodiment of the data query apparatus on a block chain, each unit and each module included in the embodiment are only divided according to functional logic, but are not limited to the above division, as long as the corresponding function can be implemented; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (8)

1. A method for querying data on a block chain is characterized by comprising the following steps:
reading the maximum historical block number derived from the data from the storage unit, and acquiring the block number on the maximum chain from the block chain;
if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain;
when the new block adding event is monitored, acquiring a new block number from the new block adding event;
exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in the storage unit as a new maximum historical block number;
performing multi-dimensional data query through the storage middleware;
after the reading the maximum history block number derived from the data from the storage unit and obtaining the maximum on-chain block number from the block chain, the method further includes:
if the maximum historical block number is smaller than the maximum on-chain block number, exporting data in a block corresponding to the maximum historical block number plus 1 to the storage middleware;
and adding the block number of the newly derived block in the storage unit as a new maximum historical block number, and returning to execute the reading operation of the maximum historical block number until the maximum historical block number is the same as the maximum on-chain block number.
2. The method of claim 1, wherein exporting data in the block corresponding to the new block number to storage middleware comprises:
determining an access interface of a block corresponding to the new block number;
exporting the data in the block from the access interface to storage middleware.
3. The method of claim 1, wherein the storage middleware is a search server;
the storage unit is distributed application coordination service software or a database.
4. The method according to any one of claims 1-3, wherein the conducting, by the storage middleware, a multidimensional data query comprises:
acquiring a query condition, wherein the query condition comprises a block query range and a query field, and the query field is a combination of at least one key field corresponding to data in the storage middleware;
and transmitting the block query range and the query field to the storage middleware, so that the storage middleware determines the data of the target block matched with the query range, and performing data query according to the query field in the data of the target block.
5. An apparatus for querying data on a blockchain, comprising:
the reading module is used for reading the maximum historical block number which is derived from the data from the storage unit and acquiring the block number on the maximum chain from the block chain;
a monitoring module, configured to monitor a new block join event on the block chain if the maximum history block number is the same as the block number on the maximum chain;
the acquisition module is used for acquiring a new block number from the new block adding event when the new block adding event is monitored;
the exporting and adding module is used for exporting the data in the block corresponding to the new block number to the storage middleware, and adding the new block number in the storage unit as a new maximum historical block number;
the data query module is used for carrying out multi-dimensional data query through the storage middleware;
the export and addition module is further configured to export the data in the block corresponding to the largest history block number plus 1 to the storage middleware if the largest history block number is smaller than the largest on-chain block number;
and adding the block number of the newly derived block in the storage unit as a new maximum historical block number, and returning to execute the reading operation of the maximum historical block number until the maximum historical block number is the same as the maximum on-chain block number.
6. A data query device, the data query device comprising:
one or more processors;
a memory for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method for data query over blockchain as recited in any of claims 1-4.
7. A data query system on a block chain comprises data query equipment, a storage unit and storage middleware;
the data query equipment is respectively connected with the storage unit and the storage middleware;
the data query device is used for reading the maximum historical block number derived from the data from the storage unit and acquiring the block number on the maximum chain from the block chain; if the maximum historical block number is the same as the block number on the maximum chain, monitoring a new block adding event on the block chain; when the new block adding event is monitored, acquiring a new block number from the new block adding event; exporting data in the block corresponding to the new block number to a storage middleware, and adding the new block number in the storage unit as a new maximum historical block number; performing multi-dimensional data query through the storage middleware;
the storage unit is used for storing the block number of the block subjected to data derivation;
the storage middleware is used for storing the data in the blocks and carrying out multi-dimensional data query;
after the reading the maximum history block number derived from the data from the storage unit and obtaining the maximum on-chain block number from the block chain, the method further includes:
if the maximum historical block number is smaller than the maximum on-chain block number, exporting data in a block corresponding to the maximum historical block number plus 1 to the storage middleware;
and adding the block number of the newly derived block in the storage unit as a new maximum historical block number, and returning to execute the reading operation of the maximum historical block number until the maximum historical block number is the same as the maximum on-chain block number.
8. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out a method for data query on a block chain according to any one of claims 1 to 4.
CN201810565553.XA 2018-06-04 2018-06-04 Method, device, equipment, system and medium for querying data on block chain Active CN108920523B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810565553.XA CN108920523B (en) 2018-06-04 2018-06-04 Method, device, equipment, system and medium for querying data on block chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810565553.XA CN108920523B (en) 2018-06-04 2018-06-04 Method, device, equipment, system and medium for querying data on block chain

Publications (2)

Publication Number Publication Date
CN108920523A CN108920523A (en) 2018-11-30
CN108920523B true CN108920523B (en) 2020-09-29

Family

ID=64419634

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810565553.XA Active CN108920523B (en) 2018-06-04 2018-06-04 Method, device, equipment, system and medium for querying data on block chain

Country Status (1)

Country Link
CN (1) CN108920523B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110046914A (en) * 2019-03-14 2019-07-23 海南鑫镁科技有限公司 A kind of block chain retroactive method towards food and drug safety supervision
CN110069533B (en) * 2019-04-09 2023-06-09 深圳前海微众银行股份有限公司 Event subscription method and device based on blockchain
CN111177182B (en) * 2019-12-19 2023-06-30 达闼机器人股份有限公司 Data query method and device, storage medium and electronic equipment
CN111831744B (en) * 2020-06-05 2023-06-06 广东科学技术职业学院 System, method and medium for searching data on DAPP chain

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779127A (en) * 2011-05-11 2012-11-14 宏碁股份有限公司 Terminal device and file synchronization method
CN103605809B (en) * 2013-12-10 2016-09-14 厦门诚创网络有限公司 A kind of method of data syn-chronization
US20170091726A1 (en) * 2015-09-07 2017-03-30 NXT-ID, Inc. Low bandwidth crypto currency transaction execution and synchronization method and system
CN106777272A (en) * 2016-12-29 2017-05-31 成都康赛信息技术有限公司 A kind of comparing and synchronous method
CN107657059A (en) * 2017-10-20 2018-02-02 中国银行股份有限公司 Method of data synchronization, middleware and system based on block chain application system
CN107943951B (en) * 2017-11-24 2020-08-11 中钞信用卡产业发展有限公司杭州区块链技术研究院 Method and system for retrieving block chain service information

Also Published As

Publication number Publication date
CN108920523A (en) 2018-11-30

Similar Documents

Publication Publication Date Title
CN108920523B (en) Method, device, equipment, system and medium for querying data on block chain
US8635617B2 (en) Tracking requests that flow between subsystems using transaction identifiers for generating log data
US11256683B2 (en) Method and apparatus for integrating multi-data source user information
CN109189782A (en) A kind of indexing means in block chain commodity transaction inquiry
CN106155812A (en) Method, device, system and the electronic equipment of a kind of resource management to fictitious host computer
CN108228322B (en) Distributed link tracking and analyzing method, server and global scheduler
CN110245145A (en) Structure synchronization method and apparatus of the relevant database to Hadoop database
CN109903034B (en) Rule matching method and device, computer readable storage medium and computer equipment
CN113722276A (en) Log data processing method, system, storage medium and electronic equipment
CN108154024B (en) Data retrieval method and device and electronic equipment
CN111767320A (en) Data blood relationship determination method and device
CN114647698A (en) Data synchronization method and device and computer storage medium
CN107644382A (en) Policy information statistical method and device
CN103248511B (en) A kind of analysis methods, devices and systems of single-point service feature
CN105610881B9 (en) Distributed cache range query method, device and system
CN104503983A (en) Method and device for providing website certification data for search engine
CN107341047B (en) Route processing method and device of callback event, storage medium and computer equipment
CN109544207A (en) A kind of information processing method, storage medium and server
US20140214826A1 (en) Ranking method and system
US10572486B2 (en) Data communication in a distributed data grid
CN113052700B (en) Method and device for determining micro-service call chain
CN109377391A (en) A kind of tracking of information method, storage medium and server
Yadav et al. Big Data and cloud computing: An emerging perspective and future trends
CN106649352B (en) Data processing method and device
CN108763053A (en) Bury the generation method and terminal device of a title

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Data query methods, devices, devices, systems, and media on blockchain

Effective date of registration: 20230925

Granted publication date: 20200929

Pledgee: Luohu sub branch of Shenzhen Rural Commercial Bank Co.,Ltd.

Pledgor: SHENZHEN LEXIN SOFTWARE TECHNOLOGY Co.,Ltd.

Registration number: Y2023980058548