CN110264361A - A kind of data analysis method and device of block chain - Google Patents
A kind of data analysis method and device of block chain Download PDFInfo
- Publication number
- CN110264361A CN110264361A CN201910550186.0A CN201910550186A CN110264361A CN 110264361 A CN110264361 A CN 110264361A CN 201910550186 A CN201910550186 A CN 201910550186A CN 110264361 A CN110264361 A CN 110264361A
- Authority
- CN
- China
- Prior art keywords
- transaction
- code
- data
- event
- module
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 237
- 238000007405 data analysis Methods 0.000 title claims abstract description 167
- 238000010276 construction Methods 0.000 claims description 49
- 238000004458 analytical method Methods 0.000 claims description 28
- 230000006870 function Effects 0.000 claims description 18
- 230000015654 memory Effects 0.000 claims description 17
- 238000012545 processing Methods 0.000 claims description 15
- 238000013507 mapping Methods 0.000 claims description 11
- 238000010586 diagram Methods 0.000 description 13
- 238000004590 computer program Methods 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 5
- 238000012986 modification Methods 0.000 description 4
- 230000004048 modification Effects 0.000 description 4
- 238000004891 communication Methods 0.000 description 2
- 230000008676 import Effects 0.000 description 2
- 239000007787 solid Substances 0.000 description 2
- 235000006719 Cassia obtusifolia Nutrition 0.000 description 1
- 235000014552 Cassia tora Nutrition 0.000 description 1
- 244000201986 Cassia tora Species 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000002427 irreversible effect Effects 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 238000011022 operating instruction Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000001902 propagating effect Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Business, Economics & Management (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Finance (AREA)
- Accounting & Taxation (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- General Health & Medical Sciences (AREA)
- Bioethics (AREA)
- Health & Medical Sciences (AREA)
- Development Economics (AREA)
- Economics (AREA)
- Marketing (AREA)
- Strategic Management (AREA)
- Technology Law (AREA)
- General Business, Economics & Management (AREA)
- Stored Programmes (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses the data analysis methods and device of a kind of block chain, to reduce the cost of the data in parsing block chain and improve the performance of data parsing.In the method, the intelligent contract of customer service is obtained first, includes for creating the building method for realizing the customer service, event methods and non-constant method in the intelligence contract;And according at least one method in the building method, event methods and non-constant method, it generates data and parses code, the data parsing code includes that the event data parsing code parsed for the event data to the customer service and the transaction data parsed for the transaction data to the customer service parse code;Then, the data in each of block chain block are parsed using data parsing code, obtains the event data and the transaction data.
Description
Technical Field
The invention relates to the field of science and technology finance (Fintech), in particular to a data analysis method and device of a block chain.
Background
The combination of blockchain (Block chain) technology and the financial field has made the traditional financial industry gradually move to science and technology finance (finth). In scientific finance combined with the blockchain technology, it is important to process data (e.g., contract account data, transaction data, and event data) in the blockchain, such as parsing the data or synchronizing the data.
For parsing data, two solutions are currently proposed:
the first solution is: a set of special interfaces is designed at the level of an intelligent contract (Smart contract), and when the service is needed, the data in the block chain is analyzed through the special interfaces in the intelligent contract.
The second solution is: the data is acquired by pre-storing the address of the data to be analyzed on the block chain and then calling the relevant interface according to the address.
However, with the first solution, since the code of the dedicated interface needs to occupy a certain storage space, especially when the number of the dedicated interfaces is large, the dedicated interface will cause a large overhead of the storage space, resulting in a high cost. Moreover, when the dedicated interface is complex, it may need to call different interfaces many times to obtain data, resulting in poor performance. For the second solution, since the addresses are specific to the intelligent contracts, when a new service or an intelligent contract is changed and cannot be reused, a technician is required to modify the codes again, and when the second solution acquires data, the data addresses are calculated according to the addressing rules in the data structure definition, so that the calculation amount is increased.
Therefore, the technical problems of high cost and poor performance exist in analyzing data in a block chain in the prior art.
Disclosure of Invention
The invention provides a data analysis method and device of a block chain, which are used for reducing the cost of analyzing data in the block chain and improving the performance of data analysis.
The invention provides a data analysis method of a block chain in a first aspect, which comprises the following steps:
acquiring an intelligent contract of a user service, wherein the intelligent contract comprises a construction method, an event method and an extraordinary method for creating and realizing the user service;
generating a data parsing code according to at least one of the construction method, the event method, and the non-trivial method, the data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service;
and analyzing the data in each block in the block chain by using the data analysis code to acquire the event data and the transaction data.
In the embodiment of the application, the process of generating the event data analysis code and the transaction data analysis code has different generation modes according to different methods.
In one possible embodiment, generating the event data parsing code according to at least one of the construction method, the event method, and the non-trivial method includes:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises an acquisition method for acquiring an event object in the event method, an event class corresponding to the event method and a binary code of the intelligent contract, and the binary code of the intelligent contract at least comprises a field type of the block chain accessed by each method in the construction method, the event method and the non-constant method;
loading the JAVA contract file, and acquiring the event class through reflection;
converting a field with the same type as the first field in the event class into a JAVA object through a first mapping relation between the JAVA object and the first field type, so as to obtain a first POJO object corresponding to the event class, wherein the first field type is a field type used for accessing the block chain in the event method;
the method comprises the steps of filling a preset event data analysis template with the first POJO object to generate an event data analysis code, wherein the preset event data analysis function template at least comprises a calling module, a first analysis module, a first instantiation module and a first storage module, the calling module is used for calling the obtaining method, the first analysis module is used for analyzing the event object and obtaining analyzed event data, the first instantiation module is used for converting the analyzed event data into a first POJO object instance, the first storage module is used for inserting the first POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
Accordingly, parsing the data in each tile in the chain of tiles using the event data parsing code to obtain the event data, including:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
running the event data analysis code, and acquiring an event object list in the block through a calling module in the event data analysis code, wherein the event object list comprises at least one value of the event object;
analyzing at least one value of the event object through an analysis module in the event data analysis code to obtain at least one analyzed event data;
respectively converting the at least one analyzed event data into at least one first POJO object instance through an instantiation module in the event data analysis code, wherein the at least one POJO first object instance is in one-to-one correspondence with the at least one analyzed event data;
inserting the at least one POJO object instance into the database table through a storage module in the event data parsing code.
In one possible embodiment, generating the transaction data parsing code according to at least one of the construction method, the event method, and the non-trivial method comprises:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises a binary code and a binary character string of the intelligent contract, the binary code of the intelligent contract at least comprises the field type of the block chain accessed by each method in the construction method and the non-constant method, and the binary character string is recursive length prefix coding of the intelligent contract;
loading the JAVA contract file, analyzing the binary code, and acquiring a transaction method, wherein the transaction method comprises the construction method and the non-constant method;
converting a field with the same type as a second field in the transaction method into a JAVA object through a second mapping relation between the JAVA object and the second field type, so as to obtain a second POJO object corresponding to the transaction method, wherein the second field type is a field type used for accessing the block chain in the transaction method;
filling a preset transaction data analysis template in the second POJO object to generate the transaction data analysis code, wherein the preset transaction data analysis template at least comprises a matching module, a second analysis module, a second instantiation module and a second storage module, the matching module is used for determining that the transaction method is the construction method or the non-normal method, the second analysis module is used for analyzing the transaction method and obtaining transaction data, the second instantiation module is used for converting the transaction data into a second POJO object instance, the second storage module is used for inserting the second POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
In the embodiment of the present application, the transaction data is obtained according to the transaction data parsing code, which may include, but is not limited to, the following two cases:
in a first case, parsing data in each tile in a chain of tiles using the transaction data parsing code to obtain the transaction data, including:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
acquiring a first transaction in the block through a preset transaction acquisition interface;
running the transaction data analysis code, acquiring a target field in the first transaction through a matching module in the transaction data analysis code, and determining a transaction type of the first transaction according to the target field, wherein the transaction type comprises a first transaction type and a second transaction type, the first transaction type is a transaction type corresponding to the construction method, the second transaction type is a transaction type corresponding to the non-volatile method, and the target field is used for indicating a transaction object of the first transaction;
when the transaction type of the first transaction is determined to be the first transaction type, acquiring the recursive-length prefix code of the first transaction through the matching module, and determining whether the recursive-length prefix code of the first transaction comprises the binary character string;
if so, analyzing a first remaining character string through a second analysis module in the transaction data analysis code to obtain first transaction data of the first transaction, wherein the first remaining character string is a character string obtained after the symbols identical to the binary character string are removed from the recursive length prefix code of the first transaction;
converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
In a second case, after the transaction data parsing code is run, the target field in the first transaction is obtained through a matching module in the transaction data parsing code, and the transaction type of the first transaction is determined according to the target field, the method further includes:
when the transaction type of the first transaction is the second transaction type, acquiring the recursive length prefix code of the first transaction through the matching module, and determining whether the recursive length prefix code of the first transaction comprises a signature of an extraordinary method corresponding to the transaction data analysis code;
if so, analyzing a second residual code through a second analysis module in the transaction data analysis code to obtain second transaction data of the first transaction, wherein the second residual code is a character string obtained by removing a symbol which is the same as the signature from the code of the first transaction;
converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
A second aspect of the present invention provides a data analysis apparatus for a block chain, including:
the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring an intelligent contract of a user service, and the intelligent contract comprises a construction method, an event method and an extraordinary method for creating and realizing the user service;
a generating unit for generating a data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service according to at least one of the constructing method, the event method, and the non-exception method;
and the analysis unit is used for analyzing the data in each block in the block chain by using the data analysis code to acquire the event data and the transaction data.
In a possible implementation, the generating unit is specifically configured to:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises an acquisition method for acquiring an event object in the event method, an event class corresponding to the event method and a binary code of the intelligent contract, and the binary code of the intelligent contract at least comprises a field type of the block chain accessed by each method in the construction method, the event method and the non-constant method;
loading the JAVA contract file, and acquiring the event class through reflection;
converting a field with the same type as the first field in the event class into a JAVA object through a first mapping relation between the JAVA object and the first field type, so as to obtain a first POJO object corresponding to the event class, wherein the first field type is a field type used for accessing the block chain in the event method;
the method comprises the steps of filling a preset event data analysis template with the first POJO object to generate an event data analysis code, wherein the preset event data analysis function template at least comprises a calling module, a first analysis module, a first instantiation module and a first storage module, the calling module is used for calling the obtaining method, the first analysis module is used for analyzing the event object and obtaining analyzed event data, the first instantiation module is used for converting the analyzed event data into a first POJO object instance, the first storage module is used for inserting the first POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
In a possible implementation manner, the parsing unit is specifically configured to:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
running the event data analysis code, and acquiring an event object list in the block through a calling module in the event data analysis code, wherein the event object list comprises at least one value of the event object;
analyzing at least one value of the event object through an analysis module in the event data analysis code to obtain at least one analyzed event data;
respectively converting the at least one analyzed event data into at least one first POJO object instance through an instantiation module in the event data analysis code, wherein the at least one POJO first object instance is in one-to-one correspondence with the at least one analyzed event data;
inserting the at least one POJO object instance into the database table through a storage module in the event data parsing code.
In a possible implementation, the generating unit is specifically configured to:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises a binary code and a binary character string of the intelligent contract, the binary code at least comprises the field types of the block chain accessed by each method in the construction method and the non-constant method, and the binary character string is the recursive length prefix code of the intelligent contract;
loading the JAVA contract file, analyzing the binary code, and acquiring a transaction method, wherein the transaction method comprises the construction method and the non-constant method;
converting a field with the same type as a second field in the transaction method into a JAVA object through a second mapping relation between the JAVA object and the second field type, so as to obtain a second POJO object corresponding to the transaction method, wherein the second field type is a field type used for accessing the block chain in the transaction method;
filling the second POJO object into a preset transaction data analysis template to generate the transaction data analysis code, wherein the preset transaction data analysis template at least comprises a matching module, a second analysis module, a second instantiation module and a second storage module, the matching module is used for determining that the transaction method is the construction method or the non-normal method, the second analysis module is used for analyzing the transaction method and obtaining transaction data, the second instantiation module is used for converting the transaction data into a second POJO object instance, the second storage module is used for inserting the second POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
In a possible implementation manner, the parsing unit is specifically configured to:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
acquiring a first transaction in the block through a preset transaction acquisition interface;
running the transaction data analysis code, acquiring a target field in the first transaction through a matching module in the transaction data analysis code, and determining a transaction type of the first transaction according to the target field, wherein the transaction type comprises a first transaction type and a second transaction type, the first transaction type is a transaction type corresponding to the construction method, the second transaction type is a transaction type corresponding to the non-volatile method, and the target field is used for indicating a transaction object of the first transaction;
when the transaction type of the first transaction is determined to be the first transaction type, acquiring the recursive-length prefix code of the first transaction through the matching module, and determining whether the recursive-length prefix code of the first transaction comprises the binary character string;
if so, analyzing a first remaining character string through a second analysis module in the transaction data analysis code to obtain first transaction data of the first transaction, wherein the first remaining character string is a character string obtained after the symbols identical to the binary character string are removed from the recursive length prefix code of the first transaction;
converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
In a possible implementation, the parsing unit is further configured to:
when the transaction type of the first transaction is the second transaction type, acquiring the recursive length prefix code of the first transaction through the matching module, and determining whether the recursive length prefix code of the first transaction comprises a signature of an extraordinary method corresponding to the transaction data analysis code;
if so, analyzing a second residual code through a second analysis module in the transaction data analysis code to obtain at least one second transaction data of the first transaction, wherein the second residual code is a character string obtained by removing a symbol which is the same as the signature from the code of the first transaction;
converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
A third aspect of the present invention provides an electronic device comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a data parsing method of the blockchain.
A third aspect of the invention provides a non-transitory computer readable storage medium storing computer instructions for causing the computer to perform a data parsing method of the blockchain.
In the embodiment of the invention, the code for analyzing the data can be automatically generated according to the intelligent contract of the user service, that is, aiming at different user services, only the user needs to import the intelligent contract corresponding to each user service, and no interface needs to be newly added or the code for data analysis needs not to be stored in advance, so that the storage space occupied by the code for data analysis can be reduced, and the cost for analyzing the data in the block chain can be reduced. And the codes generated according to the intelligent contract are in one-to-one correspondence with the interfaces in the intelligent contract, so that when data analysis is carried out, a plurality of interfaces do not need to be called or the address of data to be analyzed does not need to be calculated, and the performance of data analysis can be improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a block diagram of a system architecture to which a data parsing method is applied according to an embodiment of the present invention;
fig. 2 is a flowchart of a data parsing method for a block chain according to an embodiment of the present invention;
FIG. 3 is a flow chart of generating event data parsing codes in an embodiment of the invention;
FIG. 4 is a flow chart of generating transaction data parsing codes in an embodiment of the invention;
FIG. 5 is a flowchart illustrating an exemplary method for analyzing event data in a block according to an embodiment of the present invention;
FIG. 6 is a flowchart illustrating a process of parsing transaction data for a first transaction in a block according to an embodiment of the invention;
fig. 7 is a structural diagram of an example of data resolution of a block chain provided in the embodiment of the present invention;
fig. 8 is a structural diagram of another example of data resolution of a block chain provided in the embodiment of the present invention.
Detailed Description
The invention provides a data analysis method and device of a block chain, which are used for reducing the cost of analyzing data in the block chain and improving the performance of data analysis.
For convenience of understanding, terms that may be referred to in the embodiments of the present invention are defined and explained below.
Block chains: is a chain of blocks, each block having recorded thereon in addition to the data of the block a Hash value of the block, in such a way as to form a chain. The block chain has two core ideas, one is a cryptography technology, the other is a decentralization idea, and based on the two ideas, historical information on the block chain cannot be tampered. A block consists of a block header and a block body, wherein the block header definition comprises the height h of the block, important fields such as the Hash value prevHash of the previous block, and the block body mainly stores transaction data.
Intelligent contract: is a computer protocol aimed at propagating, verifying or executing contracts in an informative manner, the execution of smart contracts being identified, confirmed on a blockchain in the form of transactions that allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible.
web3 jsdk: the JAVA language accesses the bridge layer of the blockchain and provides an Application Programming Interface (API) to access the blockchain.
Solid: an intelligent contract high-level language is operated on an Ethernet Virtual Machine (EVM) and is mainly used for writing intelligent contracts.
JAVA: an object-oriented programming language for writing desktop applications, Web applications, distributed system and embedded system applications, and the like.
opcode: and operating instructions after the intelligent contract is compiled.
Event: one type of method for intelligent contracts is to store parameters in a log of transactions to facilitate tracking of intelligent contract execution.
Simple Java Object (Plain Ordinary Java Object, POJO): which is in fact a generic JavaBeans, can be understood as being interfaces, classes and objects in JAVA.
Recursive Length Prefix (RLP): is a coding rule and can be used for coding any nested binary array data. The result of RLP coding is also a binary sequence, which is used primarily to serialize/deserialize data.
Application Binary Interface (ABI): a low-level interface between an application program and an operating system, between an application and its libraries, or between components of an application is described.
It should be noted that the first and second embodiments of the present invention are only used for distinguishing different objects, and do not indicate the importance or priority of each object.
Next, an application scenario in the embodiment of the present invention is described.
Fig. 1 schematically shows a system architecture to which an embodiment of the present invention provides a data parsing method, and the system architecture may include a data parsing apparatus 100 and a blockchain 200. It should be noted that, in fig. 1, the data analysis device 100 and the block chain 200 are two independent modules, and in other examples, the data analysis device 100 may be disposed in the block chain 200, which is not limited herein.
For example, in the system architecture shown in fig. 1, the block chain 200 includes 2 blocks, namely block a and block B. A plurality of intelligent contracts can be set in each block according to user services, for example, an intelligent contract 1 is set in the block a, and an intelligent contract 2 is set in the block B.
The data analysis apparatus 100 may obtain and analyze any data in each tile in the tile chain 200 through different interfaces, for example, contract account data may be obtained through a contract interface, and tile data may be obtained through a tile interface, where the two data are not analyzed. However, since the event data and the transaction data in the blockchain depend on the smart contract and are relatively complex, the data analysis apparatus 100 needs to analyze the two data.
In the prior art, when analyzing event data or transaction data, a dedicated interface corresponding to each intelligent contract is set in advance, or an address of data to be analyzed is saved in advance, which specifically refers to a first solution and a second solution described in the background art, and is not described herein again. However, the method in the prior art for analyzing the event data or the transaction data has the technical problems of high cost and poor performance.
In order to solve the above technical problem, the present invention provides a data analysis method for a block chain, which is applied to the data analysis apparatus 100 shown in fig. 1. Please refer to fig. 2, which is a flowchart of the method, and the flowchart is described as follows:
s21, obtaining an intelligent contract of the user service, wherein the intelligent contract comprises a construction method, an event method and a non-trivial method for creating and realizing the user service.
In a specific implementation process, the data analysis device 100 may obtain the intelligent contract provided by the user through a preset interface, or may also obtain the intelligent contract in another manner, which is not limited in the embodiment of the present invention. The intelligent contracts can be written by different programming languages, and for convenience of description, the intelligent contracts are taken as an example of intelligent contracts written by using a solid programming language.
As an example, assuming that the user service is user information (UserInfo), the UserInfo intelligent contract obtained by the data parsing apparatus 100 may be as follows:
Contract UserInfo{
bytes32_userName;
uint8_sex;
function UserInfo(bytes32 userName,uint8 sex)public{
_userName=userName;
_sex=sex;
}
event modifyUserNameEvent(bytes32 userName,uint8 sex,address con);
function modifyUserName(bytes32 userName)public returns(bytes32){
_userName=userName;
modifyUserNameEvent(_userName,_sex,address(this));
return_userName;
}
}
in the UserInfo intelligent contract, a construction method for creating the UserInfo intelligent contract instance is included, namely:
function UserInfo(bytes32 userName,uint8 sex)public{
_userName=userName;
_sex=sex;
}
and, an event method for recording information of the user after each modification of the user name, namely: eventmodifyUserNameEvent (bytes32userName, uint8 sex, address con). And, a constant method for modifying the name of a user, namely:
function modifyUserName(bytes32 userName)public returns(bytes32){
_userName=userName;
modifyUserNameEvent(_userName,_sex,address(this));
return_userName;
}
in the above-mentioned UserInfo intelligent contract, the intelligent contract only includes one construction method, one event method and one non-constant method, which should be understood as an example of the intelligent contract, and not as a limitation that the intelligent contract only includes one construction method, one event method and one non-constant method, and in the actual use process, an intelligent contract may also include a plurality of construction methods or a plurality of event methods or a plurality of non-constant methods, and will not be described herein again.
And S22, generating a data analysis code according to at least one of the construction method, the event method and the non-constant method.
In the embodiment of the present invention, the data analysis code is mainly used for analyzing the transaction data and the event data in the block, and therefore, the generated data analysis code includes an event data analysis code for analyzing the event data of the user service and a transaction data analysis code for analyzing the transaction data of the user service.
Next, a process of generating an event data analysis code and a process of generating a transaction data analysis code will be described separately.
Referring to fig. 3, a flowchart for generating event data analysis codes is described as follows:
and S31, compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract.
Before generating event data analysis codes according to the intelligent contract, the intelligent contract is compiled through a compiler to obtain a compiled contract file.
As an example, the smart contract may be compiled into a JAVA code file by a compiler. Continuing with the example of the UserInfo intelligent contract as the intelligent contract, the code for compiling the UserInfo intelligent contract may be as follows:
pragma solidity^0.4.7;
Contract UserInfo{
bytes32_userName;
uint8_sex;
function UserInfo(bytes32 userName,uint8 sex)public{
_userName=userName;
_sex=sex;
}
event modifyUserNameEvent(bytes32 userName,uint8 sex,address con);
function modifyUserName(bytes32 userName)public returns(bytes32){
_userName=userName;
modifyUserNameEvent(_userName,_sex,address(this));
return_userName;
}
}
after the UserInfo intelligent contract is compiled by using the codes, a corresponding JAVA file is obtained, and the JAVA file is a JAVA contract file. Of course, the contract file may be another type of file according to a programming language used for compiling, for example, if the PHP programming language is adopted for compiling, a compiled PHP file is obtained, and the type of the contract file is not limited herein. For convenience of explanation, the contract file is hereinafter referred to as a JAVA file as an example.
In an embodiment of the present invention, the JAVA contract file includes at least an acquisition method for acquiring an event object in the event method, an event class corresponding to the event method, and a binary code of the smart contract, and the binary code in the smart contract includes at least a field type of the block chain accessed by each method in the construction method, the event method, and the non-trivial method.
Specifically, when the UserInfo smart contract is compiled using a JAVA compiler, JAVA files including, but not limited to, the following are obtained:
in the JAVA file, getModifyUserNameEventEvents is an obtaining method for obtaining an event object in an event method, public static class modifyusernameeventerresponse { } is an event class corresponding to the event method, and a String ABI is a binary code of the intelligent contract, where the ABI includes types of all methods in the intelligent contract, input parameters, output parameters, and field types and field names used by each method for accessing a block chain, and the like, and a binary (binary) character String is an RLP code of the intelligent contract and is used for signing a contract instance. Of course, the JAVA file may also include other content, which is not limited herein.
And S32, loading the JAVA contract file and acquiring the event class through reflection.
In the JAVA file, the event class is a modifyUserNameEvent class.
S33, converting the field in the event class, which is the same as the first field type, into a JAVA object through a first mapping relation between the JAVA object and the first field type, so as to obtain a first POJO object corresponding to the event class.
In this embodiment of the present invention, the first field type is a field type used for accessing the block chain in the event method. As an example, the first field type may be a web3jsdk type.
Following the above example, after obtaining the modifyUserNameEvent class in the JAVA file, a field with a field type of web3jsdk type in the modifyUserNameEvent class is first located, for example, the field of the web3jsdk type may include Bytes32, Uint8, and Address. And then, converting the field into the JAVA object according to the first mapping relation. The first mapping relationship may be: bytes32 corresponds to String, Uint8 corresponds to int, and Address corresponds to String, and the first mapping relationship may be stored in the data analysis device 100 in advance. After converting the field of the web3jsdk type in the JAVA file into a JAVA object, a first POJO object corresponding to the modifyUserNameEvent class may be generated. For example, the code for the POJO object associated with the modifyUserNameEvent class is as follows:
and S34, filling the first POJO object into a preset event data analysis template to generate the event data analysis code.
The applicant learns that: for all event data, the processing flow is basically the same, and the method can be divided into the following steps: calling a get function to obtain an event object, analyzing the event object, obtaining event data of the event object, converting the analyzed event data into a JAVA object instance, and inserting the JAVA object instance into a database table. Therefore, in the embodiment of the present invention, the processing flow may be preset as a plurality of modules to form a preset event data parsing template, and the preset event data parsing template is stored in the data parsing device 100, so that, after an event object in an intelligent contract to be parsed is obtained, the event object is directly filled into the preset event data parsing template according to the field type, and thus an event data parsing code for parsing event data in the intelligent contract is obtained. Therefore, when event data in different intelligent contracts are analyzed, only the corresponding intelligent contracts are needed to be obtained, no new interface is needed to be added or codes are not needed to be modified again, the implementation mode is simple, and secondary development is supported.
As an example, the preset event data parsing function template at least includes a calling module, a first parsing module, a first instantiation module, and a first storage module. The calling module is used for calling the obtaining method, the first analyzing module is used for analyzing the event object and obtaining analyzed event data, the first instantiation module is used for converting the analyzed event data into a first POJO object instance, the first storage module is used for inserting the first POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
Referring to fig. 4, a flowchart for generating transaction data analysis codes is described as follows:
and S41, compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract.
In an embodiment of the present invention, the JAVA contract file includes at least a binary code of the smart contract and a binary string, the binary code includes at least the field type of the block chain accessed by each of the construction method and the non-trivial method, and the binary string is recursive length prefix coding of the smart contract.
Step S41 is the same as step S31, and is not repeated here.
And S42, loading the JAVA contract file, analyzing the binary code, and acquiring the transaction method.
And after the JAVA file is loaded, obtaining the ABI character string in the JAVA file, analyzing the ABI character string and obtaining the transaction method in the JAVA file. For example, the name of the transaction method, and the parameter field, etc. may be acquired. The transaction method includes the construction method and the non-trivial method in step S21, which are not described herein again.
As another example, the transaction method may also be obtained from an operation instruction (opcode), for example, after the opcode in the JAVA file is obtained, the opcode is parsed, so that the transaction method in the opcode is obtained.
In order to ensure the accuracy of the acquired transaction method, after the transaction method is acquired, whether the transaction method is a construction method or an extraordinary method can be determined according to the acquired name and/or parameter field of the transaction method, if not, the process is exited, and if so, the subsequent process is continued.
And S43, converting the field with the same type as the second field in the transaction method into a JAVA object through a second mapping relation between the JAVA object and the second field type, so as to obtain a second POJO object corresponding to the transaction method, wherein the second field type is the field type used for accessing the block chain in the transaction method.
In an embodiment of the present invention, the second field type is a field type used for accessing the block chain in the transaction method. As an example, the second field type may be the same as the first field type, for example, a web3jsdk type, or the second field type may be another type different from the first field type, which is not limited herein.
Step S43 is similar to step S33 and will not be described herein.
And S44, filling a preset transaction data analysis template with the second POJO object to generate the transaction data analysis code.
Based on the principle similar to that in step S34, the applicant, by studying the transaction data analysis process, obtains a processing procedure for the transaction data, and the processing procedure includes the following steps: because the transaction data analysis is complex, there is no way to directly locate the transaction data (for example, different data are directly obtained through a get function), and the transaction matching can only be performed through a matching mode, so as to determine whether the transaction method is a construction method or an extraordinary method, then an encoded character string (for example, an RLP encoded character string) of the transaction method is analyzed, the transaction data of the transaction method is obtained, and thus the analyzed transaction data is converted into a POJO object instance, and the POJO object instance is inserted into a database table according to the field type. Therefore, in the embodiment of the present invention, the processing flow may be preset as a plurality of modules to form a preset transaction data analysis template, and the preset transaction data analysis template is stored in the data analysis device 100, so that, after the transaction method in the intelligent contract to be analyzed is obtained, the preset transaction data analysis template is directly filled with the POJO object corresponding to the transaction method, and thus, a transaction data analysis code for analyzing the transaction data in the intelligent contract is obtained.
As an example, the preset transaction data parsing template includes at least a matching module, a second parsing module, a second instantiation module, and a second storage module. The matching module is used for determining that the transaction method is the construction method or the extraordinary quantity method, the second analyzing module is used for analyzing the transaction method and obtaining transaction data, the second instantiation module is used for converting the transaction data into a second POJO object instance, and the second storage module is used for inserting the second POJO object instance into a database table.
It should be noted that, when the intelligent contract includes both the event method and the transaction method, the data analysis device 100 may generate the event data analysis code first, and then generate the transaction data analysis code; or the transaction data analysis code may be generated first, and then the event data analysis code is generated, or the transaction data analysis code and the event data analysis code may be generated in parallel, where the execution sequence is not limited.
And S23, analyzing the data in each block in the block chain by using the data analysis code to acquire the data.
After the transaction data analysis code and the event data analysis code corresponding to the intelligent contract are obtained, the transaction data analysis code and the event data analysis code can be operated to obtain the transaction data and the event data corresponding to the contract only in each block.
The following describes a method for acquiring event data and a method for acquiring transaction data, respectively.
Referring to fig. 5, a flowchart for acquiring event data by using an event data parsing code is described as follows:
s51, acquiring one block in the block chain, wherein the one block is any block in the block chain.
The data analysis apparatus 100 may sequentially acquire each block in the block chain, for example, taking the block chain shown in fig. 1 as an example, first acquire the block a, and after the event data in the block a is analyzed, acquire the block B. Alternatively, the data analysis device 100 may randomly acquire one of the blocks, which is not limited herein. It should be noted that, for each block, the manner of acquiring the event data in the block is the same, and hereinafter, one of the blocks in the block chain is taken as an example for description.
And S52, operating the event data analysis code, and acquiring an event object list in the block through a calling module in the event data analysis code.
After the data analysis device 100 acquires a block, the generated event data analysis code is called, and the calling module determines whether event data corresponding to the intelligent contract exists in the block, which can be understood as that if a corresponding event object list can be acquired by the calling module, the event data corresponding to the intelligent contract exists in the block, otherwise, the event data corresponding to the intelligent contract is not included.
For the aforementioned UserInfo intelligent contract, the calling module obtains a corresponding event data List, for example, List < modifyunnameeeventerresponse >, through a get function, for example, getmodifyunnameeeventevents >, if the List < modifyunnameeeventerresponse > can be obtained, it indicates that there is event data in the block, otherwise, there is no event data in the block.
In the embodiment of the present invention, the event object list includes at least one value of the event object. For example, for the userName in the usernanfo intelligent contract, at a first time, the user sets the userName as a first value, and at a second time, the user sets the userName as a second value, and the event object list corresponding to the userName includes the first value and the second value.
It should be noted that, in the embodiment of the present invention, the UserInfo intelligent contract includes only one event method, so that the data analysis device 100 generates only one event data analysis code, but in the actual use process, one intelligent contract may include a plurality of event methods, so that the data analysis device 100 generates a plurality of event data analysis codes for one intelligent contract. In this case, when the data analysis apparatus 100 analyzes event data in a block, it is necessary to traverse a plurality of event data analysis codes corresponding to the intelligent contract, and if all event data analysis codes are operated and an event data list cannot be obtained, it indicates that there is no event data in the block, otherwise there is event data in the block.
And S53, analyzing at least one value of the event object through an analysis module in the event data analysis code to obtain at least one analyzed event data.
And after at least one value of the event object is obtained, analyzing the at least one value through an analysis module so as to obtain corresponding event data.
S54, converting the at least one analyzed event data into at least one first POJO object instance respectively through an instantiation module in the event data analysis code.
Specifically, the at least one POJO first object instance corresponds one-to-one to the at least one parsed event data. For example, if the event object includes 2 values, the 2 values are analyzed to obtain 2 event data, and then each event data is converted into a POJO object instance, so as to obtain 2 first POJO object instances.
S55, inserting the at least one POJO object instance into the database table through a storage module in the event data analysis code.
And after the first POJO object instance corresponding to each event data is obtained, inserting the obtained first POJO object instance into a database table to finish the process of analyzing and synchronizing the event data.
Referring to fig. 6, a flowchart for obtaining transaction data by using a transaction data parsing code is shown, where the flowchart is described as follows:
s601, obtaining one block in the block chain, wherein the one block is any block in the block chain.
Step S601 is the same as step S51, and is not described herein again.
S602, acquiring a first transaction in the block through a preset transaction acquisition interface.
The transaction acquisition interface is similar to the prior art and will not be described in detail herein.
S603, operating the transaction data analysis code, acquiring a target field in the first transaction through a matching module in the transaction data analysis code, and determining the transaction type of the first transaction according to the target field.
In an embodiment of the present invention, the transaction types include a first transaction type and a second transaction type, the first transaction type is a transaction type corresponding to the construction method, and the second transaction type is a transaction type corresponding to the non-volatile method. The target field is used To indicate a transaction object of the first transaction, and the target field is a To field, as an example. And after the first transaction is obtained, operating the transaction data analysis code, obtaining the To field in the transaction, determining whether the To field is null (null), if so, determining that the first transaction is a first transaction type, otherwise, determining that the first transaction is a second transaction type.
In the embodiment of the present application, after determining that the transaction type of the first transaction is the first transaction type, step S604 to step S606 and step S610 are executed, and after determining that the transaction type of the first transaction is the second transaction type, step S607 to step S610 are executed.
In addition, similar to the event data analysis process, if the data analysis device 100 generates a plurality of transaction data analysis codes for one intelligent contract, the data analysis device 100 needs to traverse the plurality of transaction data analysis codes corresponding to the intelligent contract, and in the embodiment of the present invention, the description will be given by taking the example of operating one transaction data analysis code.
S604, when the transaction type of the first transaction is the first transaction type, acquiring the recursive-length prefix code of the first transaction through the matching module, and determining whether the recursive-length prefix code of the first transaction includes the binary character string.
In the embodiment of the present invention, the storage format of the transaction data corresponding to the construction method is: and (data), wherein, bind is RLP coding character string of the intelligent contract, and encode is coding function of the transaction data. Therefore, when the transaction type of the first transaction is determined to be the transaction type corresponding to the construction method, all the binding character strings of the intelligent contracts need to be compared, so as to determine which transaction corresponds to the construction method of the intelligent contract.
Specifically, the construction method in the aforementioned UserInfo smart contract is UserInfo (bytes32 userinname, agent 8 sex). And when the first transaction is determined to be the transaction corresponding to the construction method, acquiring a binary (with the length of M) in the JAVA file of the UserInfo intelligent contract, then acquiring an RLP code (with the length of N) of the first transaction, and if the first M character strings of the RLP code of the first transaction are the same as the binary in the JAVA file, acquiring the first transaction by executing the construction method of the UserInfo intelligent contract.
And S605, if so, analyzing a first residual character string through a second analysis module in the transaction data analysis code to obtain first transaction data of the first transaction, wherein the first residual character string is a character string obtained after the symbols identical to the binary character string are removed from the recursive length prefix code of the first transaction.
After the first M character strings of the RLP coding of the first transaction are determined to be the same as the bank in the JAVA file, the first M characters of the RLP coding of the first transaction are removed, namely the bank head of the first transaction is removed, a first residual character string with the length of (N-M) is obtained, then the decode (data) operation is carried out on the first residual character string, the decode () operation is calculated according to the type offset of each field, so that the value of each field in the first transaction is obtained, and the value of each field is at least one first transaction data.
Specifically, the first transaction is obtained by executing a construction method of a UserInfo intelligent contract, values of a field userinname and a field sex can be obtained through analysis, and then the values of the two fields are analyzed to obtain at least one first transaction data in the first transaction.
S606, converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code.
Step S606 is similar to step S54 and will not be described herein.
S607, when the transaction type of the first transaction is the second transaction type, the recursive length prefix code of the first transaction is obtained through the matching module, and whether the recursive length prefix code of the first transaction includes the signature of the non-constant method corresponding to the transaction data analysis code is determined.
In the embodiment of the present invention, the storage format of the transaction data corresponding to the non-constant method is: functionSignature + encode (data), where functionSignature is the signature of this non-trivial method. Therefore, when the transaction type of the first transaction is determined to be the transaction type corresponding to the non-constant method, the signatures of all the non-constant methods of the smart contract need to be compared, so as to determine which transaction corresponds to the non-constant method.
Specifically, the non-trivial method in the aforementioned UserInfo smart contract is modifyUserName (bytes32 userinname). When the first transaction is determined to be a transaction corresponding to a non-constant method, acquiring a signature (with the length of L) of a modifyUserName (bytes32userName) method in a JAVA file of a UserInfo intelligent contract, then acquiring an RLP code (with the length of N) of the first transaction, and if the first L character strings of the RLP code of the first transaction are the same as the signature of the modifUserName (bytes32userName) method, acquiring the first transaction by executing an extraordinary method of the UserInfo intelligent contract.
And S608, if so, analyzing a second residual code through a second analysis module in the transaction data analysis code to obtain second transaction data of the first transaction, wherein the second residual code is a character string of the code of the first transaction after a symbol identical to the signature is removed.
After the first L character strings of the RLP code of the first transaction are determined to be the same as the signature of the modifyUserName (bytes32userName) method, the first L characters of the RLP code of the first transaction are removed, namely the signature head of the first transaction is removed, a second remaining character string with the length of (N-L) is obtained, then decoding (data) operation is carried out on the second remaining character string, and therefore the value of each field in the first transaction is obtained, and the value of each field is at least one piece of first transaction data.
Specifically, the first transaction is obtained by executing an extraordinary method of the UserInfo intelligent contract, values of the field userinname, the field sex, and the field address can be obtained by analyzing, and then at least one first transaction data in the first transaction is obtained by analyzing the values of the three fields.
And S609, converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code.
S610, inserting the second POJO object instance into the database table through a second storage module in the transaction data analysis code.
Step S609 to step S610 are similar to step S54 to step S55, and are not described herein again.
In the above technical solution, the code for analyzing the data is generated automatically according to the intelligent contract of the user service, that is, for different user services, only the user needs to import the intelligent contract corresponding to each user service, and no interface needs to be added or no code for data analysis needs to be stored in advance, so that the storage space occupied by the code for data analysis can be reduced, and the cost for analyzing the data in the block chain can be reduced. And the codes generated according to the intelligent contract are in one-to-one correspondence with the interfaces in the intelligent contract, so that when data analysis is carried out, a plurality of interfaces do not need to be called or the address of data to be analyzed does not need to be calculated, and the performance of data analysis can be improved.
A second aspect of the present invention provides a data analysis apparatus for a block chain, referring to fig. 7, which is a schematic structural diagram of the data analysis apparatus, the data analysis apparatus including:
an obtaining unit 701, configured to obtain an intelligent contract for a user service, where the intelligent contract includes a construction method, an event method, and an extraordinary quantity method for creating and implementing the user service;
a generating unit 702 configured to generate a data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service according to at least one of the construction method, the event method, and the non-trivial method;
the analyzing unit 703 is configured to analyze data in each block in the block chain using the data analysis code, and obtain the event data and the transaction data.
Since the data analysis device is proposed under the same concept as the data analysis method of the block chain provided by the present invention, various variations and specific embodiments of the data analysis method of the block chain in the embodiments of fig. 2 to 6 are also applicable to the data analysis device of the present embodiment, and through the foregoing detailed description of the data analysis method of the block chain, those skilled in the art can clearly know the implementation process of the data analysis device in the present embodiment, so that the detailed description is omitted here for brevity of the description.
A third aspect of the present invention provides a data analysis apparatus of a block chain, please refer to fig. 8, which is a structural diagram of the data analysis apparatus, and the data analysis apparatus includes a processor 801, a transceiver 802, and a memory 803, wherein the processor 801, the memory 803, and the transceiver 802 are connected through a bus interface;
the processor 801 controls the transceiver 802 to obtain an intelligent contract of the user service, wherein the intelligent contract comprises a construction method, an event method and an extraordinary method for creating and realizing the user service;
the processor 801 generates a data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service according to at least one of the construction method, the event method, and the non-trivial method; and the number of the first and second groups,
and analyzing the data in each block in the block chain by using the data analysis code to acquire the event data and the transaction data.
Optionally, the processor 801 may be a central processing unit (cpu), an Application Specific Integrated Circuit (ASIC), one or more Integrated circuits for controlling program execution, a hardware Circuit developed by using a Field Programmable Gate Array (FPGA), or a baseband processor.
Optionally, processor 801 may include at least one processing core.
Optionally, the electronic device further includes a Memory 803, and the Memory 803 may include a Read Only Memory (ROM), a Random Access Memory (RAM), and a disk Memory. The memory 803 is used for storing data required by the processor 801 during its operation. The number of the memories is one or more.
Since the data analysis device is proposed under the same concept as the data analysis method of the block chain provided by the present invention, various variations and specific embodiments of the data analysis method of the block chain in the embodiments of fig. 2 to 6 are also applicable to the data analysis device of the present embodiment, and through the foregoing detailed description of the data analysis method of the block chain, those skilled in the art can clearly know the implementation process of the data analysis device in the present embodiment, so that the detailed description is omitted here for brevity of the description.
A fourth aspect of the present invention provides a computer apparatus, comprising:
at least one processor, and,
a memory communicatively coupled to the at least one processor, a communication interface;
wherein the memory stores instructions executable by the at least one processor, and the at least one processor performs the method in the embodiments shown in fig. 2-6 using the communication interface by executing the instructions stored by the memory.
A fifth aspect of the present invention provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer instructions which, when run on a computer, cause the computer to perform the method in the embodiments shown in fig. 2 to 6.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (9)
1. A method for data parsing of a blockchain, the method comprising:
acquiring an intelligent contract of a user service, wherein the intelligent contract comprises a construction method, an event method and an extraordinary method for creating and realizing the user service;
generating a data parsing code according to at least one of the construction method, the event method, and the non-trivial method, the data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service;
and analyzing the data in each block in the block chain by using the data analysis code to acquire the event data and the transaction data.
2. The method of claim 1, wherein generating the event data parsing code according to at least one of the construction method, the event method, and the non-trivial method comprises:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises an acquisition method for acquiring an event object in the event method, an event class corresponding to the event method and a binary code of the intelligent contract, and the binary code of the intelligent contract at least comprises a field type of the block chain accessed by each method in the construction method, the event method and the non-constant method;
loading the JAVA contract file, and acquiring the event class through reflection;
converting a field with the same type as the first field in the event class into a JAVA object through a first mapping relation between the JAVA object and the first field type, so as to obtain a first POJO object corresponding to the event class, wherein the first field type is a field type used for accessing the block chain in the event method;
the method comprises the steps of filling a preset event data analysis template with the first POJO object to generate an event data analysis code, wherein the preset event data analysis function template at least comprises a calling module, a first analysis module, a first instantiation module and a first storage module, the calling module is used for calling the obtaining method, the first analysis module is used for analyzing the event object and obtaining analyzed event data, the first instantiation module is used for converting the analyzed event data into a first POJO object instance, the first storage module is used for inserting the first POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
3. The method of claim 2, wherein parsing the data in each chunk of a chain of chunks using the event data parsing code to obtain the event data comprises:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
running the event data analysis code, and acquiring an event object list in the block through a calling module in the event data analysis code, wherein the event object list comprises at least one value of the event object;
analyzing at least one value of the event object through an analysis module in the event data analysis code to obtain at least one analyzed event data;
converting the at least one analyzed event data into at least one first POJO object instance respectively through an instantiation module in the event data analysis code, wherein the at least one first POJO object instance corresponds to the at least one analyzed event data one to one;
inserting the at least one POJO object instance into the database table through a storage module in the event data parsing code.
4. The method of claim 1, wherein generating the transaction data parsing code according to at least one of the construction method, the event method, and the non-trivial method comprises:
compiling the intelligent contract to obtain a JAVA contract file corresponding to the intelligent contract, wherein the JAVA contract file at least comprises a binary code and a binary character string of the intelligent contract, the binary code at least comprises the field types of the block chain accessed by each method in the construction method and the non-constant method, and the binary character string is the recursive length prefix code of the intelligent contract;
loading the JAVA contract file, analyzing the binary code, and acquiring a transaction method, wherein the transaction method comprises the construction method and the non-constant method;
converting a field with the same type as a second field in the transaction method into a JAVA object through a second mapping relation between the JAVA object and the second field type, so as to obtain a second POJO object corresponding to the transaction method, wherein the second field type is a field type used for accessing the block chain in the transaction method;
filling the second POJO object into a preset transaction data analysis template to generate the transaction data analysis code, wherein the preset transaction data analysis template at least comprises a matching module, a second analysis module, a second instantiation module and a second storage module, the matching module is used for determining that the transaction method is the construction method or the non-normal method, the second analysis module is used for analyzing the transaction method and obtaining transaction data, the second instantiation module is used for converting the transaction data into a second POJO object instance, the second storage module is used for inserting the second POJO object instance into a database table, and the database table is used for storing the event data and the transaction data.
5. The method of claim 4, wherein parsing the data in each tile in a chain of tiles using the transaction data parsing code to obtain the transaction data comprises:
acquiring one block in the block chain, wherein the one block is any one block in the block chain;
acquiring a first transaction in the block through a preset transaction acquisition interface;
running the transaction data analysis code, acquiring a target field in the first transaction through a matching module in the transaction data analysis code, and determining a transaction type of the first transaction according to the target field, wherein the transaction type comprises a first transaction type and a second transaction type, the first transaction type is a transaction type corresponding to the construction method, the second transaction type is a transaction type corresponding to the non-volatile method, and the target field is used for indicating a transaction object of the first transaction;
when the transaction type of the first transaction is determined to be the first transaction type, acquiring the recursive-length prefix code of the first transaction through the matching module, and determining whether the recursive-length prefix code of the first transaction comprises the binary character string;
if so, analyzing a first remaining character string through a second analysis module in the transaction data analysis code to obtain first transaction data of the first transaction, wherein the first remaining character string is a character string obtained after the symbols identical to the binary character string are removed from the recursive length prefix code of the first transaction;
converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
6. The method of claim 5, wherein after running the transaction data parsing code, obtaining a target field in the first transaction via a matching module in the transaction data parsing code, and determining a transaction type for the first transaction based on the target field, the method further comprises:
when the transaction type of the first transaction is the second transaction type, acquiring the recursive length prefix code of the first transaction through the matching module, and determining whether the recursive length prefix code of the first transaction comprises a signature of an extraordinary method corresponding to the transaction data analysis code;
if so, analyzing a second residual code through a second analysis module in the transaction data analysis code to obtain second transaction data of the first transaction, wherein the second residual code is a character string obtained by removing a symbol which is the same as the signature from the code of the first transaction;
converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data analysis code;
inserting the second POJO object instance into the database table through a second storage module in the transaction data parsing code.
7. A data parsing apparatus for a blockchain, comprising:
the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring an intelligent contract of a user service, and the intelligent contract comprises a construction method, an event method and an extraordinary method for creating and realizing the user service;
a generating unit for generating a data parsing code including an event data parsing code for parsing event data of the user service and a transaction data parsing code for parsing transaction data of the user service according to at least one of the constructing method, the event method, and the non-exception method;
and the analysis unit is used for analyzing the data in each block in the block chain by using the data analysis code to acquire the event data and the transaction data.
8. An electronic device, comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
9. A non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the method of any one of claims 1 to 6.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910550186.0A CN110264361A (en) | 2019-06-24 | 2019-06-24 | A kind of data analysis method and device of block chain |
PCT/CN2020/097235 WO2020259417A1 (en) | 2019-06-24 | 2020-06-19 | Data analysis method and device for block chain |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910550186.0A CN110264361A (en) | 2019-06-24 | 2019-06-24 | A kind of data analysis method and device of block chain |
Publications (1)
Publication Number | Publication Date |
---|---|
CN110264361A true CN110264361A (en) | 2019-09-20 |
Family
ID=67920915
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910550186.0A Pending CN110264361A (en) | 2019-06-24 | 2019-06-24 | A kind of data analysis method and device of block chain |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN110264361A (en) |
WO (1) | WO2020259417A1 (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110738567A (en) * | 2019-09-25 | 2020-01-31 | 支付宝(杭州)信息技术有限公司 | Transaction processing method and device of safe intelligent contract processor based on FPGA |
CN110827034A (en) * | 2019-10-31 | 2020-02-21 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for initiating a blockchain transaction |
CN111161059A (en) * | 2019-11-29 | 2020-05-15 | 合肥学院 | Method for generalizing transaction processing into transaction |
WO2020259417A1 (en) * | 2019-06-24 | 2020-12-30 | 深圳前海微众银行股份有限公司 | Data analysis method and device for block chain |
CN112860712A (en) * | 2021-04-13 | 2021-05-28 | 深圳前海移联科技有限公司 | Transaction database construction method and system based on block chain and electronic equipment |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10452998B2 (en) * | 2017-03-19 | 2019-10-22 | International Business Machines Corporation | Cognitive blockchain automation and management |
CN107038242B (en) * | 2017-04-24 | 2020-02-07 | 杭州趣链科技有限公司 | Block chain-oriented global intelligent contract service data analysis method |
CN107274186A (en) * | 2017-05-11 | 2017-10-20 | 上海点融信息科技有限责任公司 | The method and apparatus that intelligent contract-defined interface is obtained in block chain |
CN107918666B (en) * | 2017-11-24 | 2020-05-12 | 中钞信用卡产业发展有限公司杭州区块链技术研究院 | Data synchronization method and system on block chain |
CN110264361A (en) * | 2019-06-24 | 2019-09-20 | 深圳前海微众银行股份有限公司 | A kind of data analysis method and device of block chain |
-
2019
- 2019-06-24 CN CN201910550186.0A patent/CN110264361A/en active Pending
-
2020
- 2020-06-19 WO PCT/CN2020/097235 patent/WO2020259417A1/en active Application Filing
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2020259417A1 (en) * | 2019-06-24 | 2020-12-30 | 深圳前海微众银行股份有限公司 | Data analysis method and device for block chain |
CN110738567A (en) * | 2019-09-25 | 2020-01-31 | 支付宝(杭州)信息技术有限公司 | Transaction processing method and device of safe intelligent contract processor based on FPGA |
CN110827034A (en) * | 2019-10-31 | 2020-02-21 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for initiating a blockchain transaction |
CN110827034B (en) * | 2019-10-31 | 2021-10-22 | 支付宝(杭州)信息技术有限公司 | Method and apparatus for initiating a blockchain transaction |
CN111161059A (en) * | 2019-11-29 | 2020-05-15 | 合肥学院 | Method for generalizing transaction processing into transaction |
CN111161059B (en) * | 2019-11-29 | 2023-10-31 | 合肥学院 | Method for generalizing transaction processing into transaction |
CN112860712A (en) * | 2021-04-13 | 2021-05-28 | 深圳前海移联科技有限公司 | Transaction database construction method and system based on block chain and electronic equipment |
CN112860712B (en) * | 2021-04-13 | 2024-02-09 | 深圳前海移联科技有限公司 | Block chain-based transaction database construction method, system and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
WO2020259417A1 (en) | 2020-12-30 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
TWI730654B (en) | Method and device for deploying and executing smart contract | |
CN110264361A (en) | A kind of data analysis method and device of block chain | |
CN110096338B (en) | Intelligent contract execution method, device, equipment and medium | |
US10783082B2 (en) | Deploying a smart contract | |
CN110688122B (en) | Method and device for compiling and executing intelligent contract | |
CN110825363B (en) | Intelligent contract acquisition method and device, electronic equipment and storage medium | |
CN106796522A (en) | System and method for updating source code file | |
US8464230B2 (en) | Methods and systems to implement non-ABI conforming features across unseen interfaces | |
EP1717719A1 (en) | Application conversion of source data | |
CN110673856B (en) | Data processing method and device and machine-readable storage medium | |
WO2021175053A1 (en) | Method and apparatus for executing functional module in virtual machine | |
CN103218294A (en) | Debugging method for embedded system, debugging conversion device and system | |
CN110941655B (en) | Data format conversion method and device | |
CN105279399A (en) | Application anti-crack method and device | |
US9639375B2 (en) | Generation of language bindings for libraries using data from compiler generated debug information | |
CN115469894A (en) | Application program installation control method, device, equipment and storage medium | |
CN111260080A (en) | Process optimization method, device, terminal and storage medium based on machine learning | |
CN111240772A (en) | Data processing method and device based on block chain and storage medium | |
WO2021179697A1 (en) | Method and device for executing functional module in virtual machine | |
US10606569B2 (en) | Declarative configuration elements | |
CN116775127A (en) | Static symbol execution pile inserting method based on RetroWrite framework | |
US11886839B2 (en) | Non-transitory computer-readable recording medium, function generation method, and information processing device | |
WO2022068559A1 (en) | Code processing method and apparatus, and device | |
CN115599394A (en) | Serialization and deserialization method, device, computer equipment and storage medium | |
CN113031952A (en) | Method and device for determining execution code of deep learning model and storage medium |
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 |