A data analysis method and device for blockchain
By generating data analysis code based on smart contracts and directly analyzing blockchain data, the problems of high cost and poor performance of parsing blockchain data in the existing technology are solved, and more efficient data analysis is achieved.
Patent Information
- Application Number
- CN201910550186.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-24
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2039-06-24
AI Technical Summary
The prior art has problems of high cost and poor performance when analyzing blockchain data, especially due to the large storage space of the dedicated interface and the complex interface calls, resulting in poor performance.
By obtaining the construction methods, event methods and non-constant methods in the smart contract for user business, the corresponding data analysis code is generated, including event data analysis code and transaction data analysis code, and the blockchain data is directly analyzed.
It reduces the storage space of data parsing code, reduces the cost of analyzing blockchain data, and improves the performance of data parsing.
Smart Images

Figure CN110264361B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Fintech, and in particular to a data parsing method and device for a blockchain. Background Art
[0002] The combination of blockchain technology and the financial field has led to the gradual transformation of the traditional financial industry into technology finance (Finteh). In technology finance combined with blockchain technology, it is more important to process the data in the blockchain (for example, contract account data, transaction data and event data), for example, parsing data or synchronizing data.
[0003] There are currently two solutions proposed for parsing data:
[0004] The first solution is to design a set of dedicated interfaces at the smart contract level. When the business needs it, the data in the blockchain can be parsed by intelligently calling the dedicated interfaces in the smart contract.
[0005] The second solution is to save the address of the data to be parsed on the blockchain in advance, and then call the relevant interface according to the address to obtain the data.
[0006] However, for the first solution mentioned above, since the code of the dedicated interface needs to occupy a certain amount of storage space, especially when the number of the dedicated interfaces is large, the dedicated interface will cause a large storage space overhead, resulting in higher costs. Moreover, when the dedicated interface is more complex, it may be necessary to call different interfaces multiple times to obtain data, resulting in poor performance. For the second solution, since the addresses are all for specific smart contracts, when there are new businesses or smart contracts change, they cannot be reused, and technicians need to modify the code again. Moreover, when obtaining data, the second solution needs to calculate the data address according to the addressing rules in the data structure definition, which increases the amount of calculation.
[0007] It can be seen that the existing technology for parsing data in blockchain has technical problems of high cost and poor performance. Summary of the invention
[0008] The present invention provides a data parsing method and device for blockchain, which are used to reduce the cost of parsing data in blockchain and improve the performance of data parsing.
[0009] A first aspect of the present invention provides a blockchain data parsing method, the method comprising:
[0010] Obtaining a smart contract for a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service;
[0011] Generate a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service;
[0012] The data parsing code is used to parse the data in each block in the blockchain to obtain the event data and the transaction data.
[0013] In the embodiment of the present application, the process of generating event data parsing code and transaction data parsing code has different generation methods depending on the methods they rely on.
[0014] In a possible implementation, generating the event data parsing code according to at least one of the construction method, the event method, and the non-constant method includes:
[0015] Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein 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, wherein the binary code of the smart contract includes at least a field type of each method accessing the blockchain in the construction method, the event method, and the non-constant method;
[0016] Load the JAVA contract file and obtain the event class through reflection;
[0017] Converting a field in the event class that is the same as the first field type into a JAVA object through a first mapping relationship between a JAVA object and a first field type, thereby obtaining a first POJO object corresponding to the event class, wherein the first field type is a field type used in the event method to access the blockchain;
[0018] Fill the first POJO object into a preset event data parsing template to generate the event data parsing code, the preset event data parsing function template includes at least a calling module, a first parsing module, a first instantiation module and a first storage module, the calling module is used to call the acquisition method, the first parsing module is used to parse the event object and obtain the parsed event data, the first instantiation module is used to convert the parsed event data into a first POJO object instance, and the first storage module is used to insert the first POJO object instance into a database table, and the database table is used to store the event data and the transaction data.
[0019] Accordingly, the event data parsing code is used to parse the data in each block in the blockchain to obtain the event data, including:
[0020] Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain;
[0021] Run the event data parsing code, and obtain a list of event objects in the block through a calling module in the event data parsing code, wherein the list of event objects includes at least one value of the event object;
[0022] Parsing at least one value of the event object by a parsing module in the event data parsing code to obtain at least one parsed event data;
[0023] Convert the at least one parsed event data into at least one first POJO object instance through an instantiation module in the event data parsing code, wherein the at least one POJO first object instance corresponds to the at least one parsed event data in a one-to-one manner;
[0024] The at least one POJO object instance is inserted into the database table through the storage module in the event data parsing code.
[0025] In a possible implementation, generating the transaction data parsing code according to at least one of the construction method, the event method and the non-constant method includes:
[0026] Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein the JAVA contract file includes at least a binary code and a binary string of the smart contract, wherein the binary code of the smart contract includes at least the construction method and the field type of each method in the non-constant method accessing the blockchain, and the binary string is a recursive length prefix code of the smart contract;
[0027] Load the JAVA contract file, parse the binary code, and obtain the transaction method, which includes the construction method and the non-constant method;
[0028] The field of the transaction method that is the same as the second field type is converted into a JAVA object through a second mapping relationship between the JAVA object and the second field type, thereby obtaining a second POJO object corresponding to the transaction method, wherein the second field type is a field type used in the transaction method to access the blockchain;
[0029] The second POJO object is filled with a preset transaction data parsing template to generate the transaction data parsing code, the preset transaction data parsing template at least includes a matching module, a second parsing module, a second instantiation module and a second storage module, the matching module is used to determine whether the transaction method is the construction method or the non-constant method, the second parsing module is used to parse the transaction method and obtain transaction data, the second instantiation module is used to convert the transaction data into a second POJO object instance, and the second storage module is used to insert the second POJO object instance into a database table, and the database table is used to store the event data and the transaction data.
[0030] 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 situations:
[0031] In the first case, the transaction data parsing code is used to parse the data in each block in the blockchain to obtain the transaction data, including:
[0032] Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain;
[0033] Obtaining the first transaction in the block through a preset transaction acquisition interface;
[0034] Running the transaction data parsing code, obtaining a target field in the first transaction through a matching module in the transaction data parsing code, and determining a transaction type of the first transaction according to the target field, the transaction type including a first transaction type and a second transaction type, the first transaction type being a transaction type corresponding to the construction method, the second transaction type being a transaction type corresponding to the non-constant method, and the target field being used to indicate a transaction object of the first transaction;
[0035] When determining that the transaction type of the first transaction is the first transaction type, obtaining 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 string;
[0036] If the answer is yes, the first remaining character string is parsed by a second parsing module in the transaction data parsing code to obtain first transaction data of the first transaction, where the first remaining character string is a character string obtained by removing symbols identical to the binary character string from the recursive length prefix encoding of the first transaction;
[0037] Converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code;
[0038] The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
[0039] In a second case, after running the transaction data parsing code, obtaining a target field in the first transaction through a matching module in the transaction data parsing code, and determining a transaction type of the first transaction according to the target field, the method further includes:
[0040] When the transaction type of the first transaction is the second transaction type, obtaining the recursive length prefix encoding of the first transaction through the matching module, and determining whether the recursive length prefix encoding of the first transaction includes a signature of a non-constant method corresponding to the transaction data parsing code;
[0041] If the answer is yes, the second remaining code is parsed by the second parsing module in the transaction data parsing code to obtain the second transaction data of the first transaction, where the second remaining code is a character string obtained by removing the symbol identical to the signature from the code of the first transaction;
[0042] Converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code;
[0043] The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
[0044] A second aspect of the present invention provides a data parsing device for a blockchain, comprising:
[0045] An acquisition unit, used to acquire a smart contract for a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service;
[0046] a generating unit, configured to generate a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service;
[0047] A parsing unit is used to parse the data in each block in the blockchain using the data parsing code to obtain the event data and the transaction data.
[0048] In a possible implementation manner, the generating unit is specifically configured to:
[0049] Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein 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, wherein the binary code of the smart contract includes at least a field type of each method accessing the blockchain in the construction method, the event method, and the non-constant method;
[0050] Load the JAVA contract file and obtain the event class through reflection;
[0051] Converting a field in the event class that is the same as the first field type into a JAVA object through a first mapping relationship between a JAVA object and a first field type, thereby obtaining a first POJO object corresponding to the event class, wherein the first field type is a field type used in the event method to access the blockchain;
[0052] Fill the first POJO object into a preset event data parsing template to generate the event data parsing code, the preset event data parsing function template includes at least a calling module, a first parsing module, a first instantiation module and a first storage module, the calling module is used to call the acquisition method, the first parsing module is used to parse the event object and obtain the parsed event data, the first instantiation module is used to convert the parsed event data into a first POJO object instance, and the first storage module is used to insert the first POJO object instance into a database table, and the database table is used to store the event data and the transaction data.
[0053] In a possible implementation manner, the parsing unit is specifically used for:
[0054] Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain;
[0055] Run the event data parsing code, and obtain a list of event objects in the block through a calling module in the event data parsing code, wherein the list of event objects includes at least one value of the event object;
[0056] Parsing at least one value of the event object by a parsing module in the event data parsing code to obtain at least one parsed event data;
[0057] Convert the at least one parsed event data into at least one first POJO object instance through an instantiation module in the event data parsing code, wherein the at least one POJO first object instance corresponds to the at least one parsed event data in a one-to-one manner;
[0058] The at least one POJO object instance is inserted into the database table through the storage module in the event data parsing code.
[0059] In a possible implementation manner, the generating unit is specifically configured to:
[0060] Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein the JAVA contract file includes at least a binary code and a binary string of the smart contract, wherein the binary code includes at least the field type of each method in the construction method and the non-constant method accessing the blockchain, and the binary string is a recursive length prefix code of the smart contract;
[0061] Load the JAVA contract file, parse the binary code, and obtain the transaction method, which includes the construction method and the non-constant method;
[0062] The field of the transaction method that is the same as the second field type is converted into a JAVA object through a second mapping relationship between the JAVA object and the second field type, thereby obtaining a second POJO object corresponding to the transaction method, wherein the second field type is a field type used in the transaction method to access the blockchain;
[0063] The second POJO object is filled into a preset transaction data parsing template to generate the transaction data parsing code, wherein the preset transaction data parsing template at least includes a matching module, a second parsing module, a second instantiation module and a second storage module, wherein the matching module is used to determine whether the transaction method is the construction method or the non-constant method, the second parsing module is used to parse the transaction method and obtain transaction data, the second instantiation module is used to convert the transaction data into a second POJO object instance, and the second storage module is used to insert the second POJO object instance into a database table, and the database table is used to store the event data and the transaction data.
[0064] In a possible implementation manner, the parsing unit is specifically used for:
[0065] Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain;
[0066] Obtaining the first transaction in the block through a preset transaction acquisition interface;
[0067] Running the transaction data parsing code, obtaining a target field in the first transaction through a matching module in the transaction data parsing code, and determining a transaction type of the first transaction according to the target field, the transaction type including a first transaction type and a second transaction type, the first transaction type being a transaction type corresponding to the construction method, the second transaction type being a transaction type corresponding to the non-constant method, and the target field being used to indicate a transaction object of the first transaction;
[0068] When determining that the transaction type of the first transaction is the first transaction type, obtaining 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 string;
[0069] If the answer is yes, the first remaining character string is parsed by a second parsing module in the transaction data parsing code to obtain first transaction data of the first transaction, where the first remaining character string is a character string obtained by removing symbols identical to the binary character string from the recursive length prefix encoding of the first transaction;
[0070] Converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code;
[0071] The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
[0072] In a possible implementation manner, the parsing unit is further used for:
[0073] When the transaction type of the first transaction is the second transaction type, obtaining the recursive length prefix encoding of the first transaction through the matching module, and determining whether the recursive length prefix encoding of the first transaction includes a signature of a non-constant method corresponding to the transaction data parsing code;
[0074] If the answer is yes, the second remaining code is parsed by the second parsing module in the transaction data parsing code to obtain at least one second transaction data of the first transaction, where the second remaining code is a character string obtained by removing the symbol identical to the signature from the code of the first transaction;
[0075] Converting the second transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code;
[0076] The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
[0077] A third aspect of the present invention provides an electronic device, comprising:
[0078] at least one processor; and,
[0079] a memory communicatively connected to the at least one processor; wherein,
[0080] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data parsing method of the blockchain.
[0081] A third aspect of the present invention provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the data parsing method of the blockchain.
[0082] In the embodiment of the present invention, the code for parsing data can be automatically generated according to the smart contract of the user service. That is to say, for different user services, the user only needs to import the smart contract corresponding to each user service, without adding new interfaces or pre-storing the code for data parsing, thereby reducing the storage space occupied by the code for data parsing and reducing the cost of parsing data in the blockchain. Moreover, the code generated according to the smart contract corresponds one-to-one with the interface in the smart contract, so when performing data parsing, there is no need to call multiple interfaces or calculate the address of the data to be parsed, thereby improving the performance of data parsing. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0084] Figure 1 A structural block diagram of a system architecture applicable to a data analysis method provided in an embodiment of the present invention;
[0085] Figure 2 A flowchart of a blockchain data parsing method provided by an embodiment of the present invention;
[0086] Figure 3 A flowchart of generating event data parsing code in an embodiment of the present invention;
[0087] Figure 4 A flowchart of generating a transaction data parsing code in an embodiment of the present invention;
[0088] Figure 5 This is a flow chart of parsing event data in a block in an embodiment of the present invention;
[0089] Figure 6 This is a flow chart of parsing transaction data of the first transaction in a block in an embodiment of the present invention;
[0090] Figure 7 This is a structural diagram of an example of data parsing of a blockchain provided in an embodiment of the present invention;
[0091] Figure 8 This is a structural diagram of another example of data parsing of the blockchain provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0092] The present invention provides a data parsing method and device for blockchain, which are used to reduce the cost of parsing data in blockchain and improve the performance of data parsing.
[0093] To facilitate understanding, the terms that may be involved in the embodiments of the present invention are defined and explained below.
[0094] Blockchain: It is a chain composed of a series of blocks. In addition to recording the data of the current block, each block also records the Hash value of the previous block, forming a chain in this way. There are two core concepts of blockchain, one is cryptography technology, and the other is decentralization. Based on these two concepts, the historical information on the blockchain cannot be tampered with. A block consists of a block header and a block body. The block header definition includes important fields such as the block height h and the Hash value prevHash of the previous block, while the block body mainly stores transaction data.
[0095] Smart contract: a computer protocol designed to disseminate, verify or execute contracts in an information-based manner. The execution process of a smart contract will be consensus-based and confirmed on the blockchain in the form of a transaction. It allows trusted transactions without a third party, and these transactions are traceable and irreversible.
[0096] web3jsdk: A bridge layer for accessing the blockchain using JAVA language, providing relevant application programming interfaces (APIs) to access the blockchain.
[0097] Solidity: A high-level smart contract language that runs on the Ethereum Virtual Machine (EVM) and is mainly used to write smart contracts.
[0098] JAVA: An object-oriented programming language used to write desktop applications, web applications, distributed systems, embedded system applications, etc.
[0099] opcode: The operation instructions after smart contract compilation.
[0100] Event: A method type of smart contract that can store parameters in the transaction log to facilitate tracking of smart contract execution.
[0101] Simple Java Object (POJO): It is actually ordinary JavaBeans, which can be understood as interfaces, classes and objects in JAVA.
[0102] Recursive Length Prefix (RLP): is an encoding rule that can be used to encode arbitrarily nested binary array data. The result of RLP encoding is also a binary sequence, which is mainly used to serialize / deserialize data.
[0103] Application Binary Interface (ABI): describes the low-level interface between an application and the operating system, between an application and its libraries, or between application components.
[0104] It should be noted that, in the embodiment of the present invention, the first and the second are only used to distinguish different objects, and do not indicate the importance or priority of each object.
[0105] The following describes the application scenarios of the embodiments of the present invention.
[0106] Figure 1 The system architecture applicable to the data analysis method provided by the embodiment of the present invention is exemplarily shown, and the system architecture may include a data analysis device 100 and a blockchain 200. It should be noted that Figure 1 In the example, the data analysis device 100 and the blockchain 200 are two independent modules. In other examples, the data analysis device 100 can also be set in the blockchain 200, which is not limited here.
[0107] The blockchain 200 may include multiple blocks, for example, Figure 1 In the system architecture shown, the blockchain 200 includes two blocks, namely block A and block B. Multiple smart contracts can be set in each block according to user services. For example, smart contract 1 is set in block A and smart contract 2 is set in block B.
[0108] The data analysis device 100 can obtain and analyze any data in each block in the blockchain 200 through different interfaces. For example, the contract account data can be obtained through the contract interface, and the block data can be obtained through the block interface. These two types of data are not analyzed. However, since the event data and transaction data in the blockchain rely on smart contracts and are relatively complex, the data analysis device 100 needs to analyze these two types of data.
[0109] In the prior art, when parsing event data or transaction data, either a dedicated interface corresponding to each smart contract is pre-set, or the address of the data to be parsed is pre-saved. For details, please refer to the first solution and the second solution described in the background technology, which will not be described here. However, the method of parsing event data or transaction data using the prior art has the technical problems of high cost and poor performance.
[0110] In order to solve the above technical problems, the present invention provides a blockchain data analysis method, which is applied to Figure 1 Please refer to the data analysis device 100 shown in FIG. Figure 2 , is a flow chart of the method, and the description of the flow chart is as follows:
[0111] S21. Obtain a smart contract for the user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service.
[0112] In the specific implementation process, the data analysis device 100 can obtain the smart contract provided by the user through a preset interface, or can also obtain the smart contract through other methods, which is not limited in the embodiment of the present invention. Smart contracts can be written in different programming languages. For the convenience of explanation, the following takes the smart contract written in the Solidity programming language as an example.
[0113] As an example, assuming that the user service is to save user information (UserInfo), the UserInfo smart contract obtained by the data analysis device 100 can be as follows:
[0114] Contract UserInfo{
[0115] bytes32_userName;
[0116] uint8_sex;
[0117] function UserInfo(bytes32 userName,uint8 sex)public{
[0118] _userName = userName;
[0119] _sex = sex;
[0120] }
[0121] event modifyUserNameEvent(bytes32 userName, uint8 sex, address con);
[0122] function modifyUserName(bytes32 userName)public returns(bytes32){
[0123] _userName = userName;
[0124] modifyUserNameEvent(_userName,_sex,address(this));
[0125] return_userName;
[0126] }
[0127] }
[0128] The UserInfo smart contract includes a constructor for creating an instance of the UserInfo smart contract, namely:
[0129] function UserInfo(bytes32 userName,uint8 sex)public{
[0130] _userName = userName;
[0131] _sex = sex;
[0132] }
[0133] And, an event method for recording the user's information after each username modification, namely: eventmodifyUserNameEvent(byte32 userName, uint8 sex, address con). And, a non-constant method for modifying the user's name, namely:
[0134] function modifyUserName(bytes32 userName)public returns(bytes32){
[0135] _userName = userName;
[0136] modifyUserNameEvent(_userName,_sex,address(this));
[0137] return_userName;
[0138] }
[0139] In the above UserInfo smart contract, the smart contract only includes one construction method, one event method and one non-constant method. It should be understood as an example of a smart contract, rather than limiting the smart contract to include only one construction method, one event method and one non-constant method. In actual use, a smart contract may also include multiple construction methods or multiple event methods or multiple non-constant methods, which will not be repeated here.
[0140] S22. Generate data parsing code according to at least one of the construction method, event method and non-constant method.
[0141] In the embodiment of the present invention, it is mainly used to parse the transaction data and event data in the block. Therefore, the generated data parsing code includes an event data parsing code for parsing the event data of the user business and a transaction data parsing code for parsing the transaction data of the user business.
[0142] The following will introduce the generation process of event data parsing code and the generation process of transaction data parsing code respectively.
[0143] For event data parsing code, please refer to Figure 3 , is a flowchart for generating event data parsing code, which is described as follows:
[0144] S31. Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract.
[0145] Before generating event data parsing code based on a smart contract, the smart contract must first be compiled through a compiler to obtain a compiled contract file.
[0146] As an example, a smart contract can be compiled into a JAVA code file through a compiler. Continuing to take the UserInfo smart contract as an example, the code for compiling the UserInfo smart contract can be as follows:
[0147] pragma solidity^0.4.7;
[0148] Contract UserInfo{
[0149] bytes32_userName;
[0150] uint8_sex;
[0151] function UserInfo(bytes32 userName,uint8 sex)public{
[0152] _userName = userName;
[0153] _sex = sex;
[0154] }
[0155] event modifyUserNameEvent(bytes32 userName, uint8 sex, address con);
[0156] function modifyUserName(bytes32 userName)public returns(bytes32){
[0157] _userName = userName;
[0158] modifyUserNameEvent(_userName,_sex,address(this));
[0159] return_userName;
[0160] }
[0161] }
[0162] After the UserInfo smart contract is compiled using the above code, the corresponding JAVA file is obtained, which is the JAVA contract file. Of course, depending on the programming language used for compilation, the contract file can also be other types of files. For example, if the PHP programming language is used for compilation, a compiled PHP file is obtained. The type of contract file is not limited here. For the convenience of explanation, the contract file is taken as an example as a JAVA file in the following text.
[0163] In an embodiment of the present invention, the JAVA contract file includes at least an acquisition method for acquiring the event object in the event method, an event class corresponding to the event method, and a binary code of the smart contract. The binary code in the smart contract includes at least the field type of each method accessing the blockchain in the construction method, the event method, and the non-constant method.
[0164] Specifically, when the UserInfo smart contract is compiled using the JAVA compiler, a JAVA file including but not limited to the following contents can be obtained:
[0165]
[0166] In the above JAVA file, getModifyUserNameEventEvents is the method for obtaining the event object in the event method, public static class ModifyUserNameEventResponse{} is the event class corresponding to the event method, String ABI is the binary code of the smart contract, which includes the types, input parameters, output parameters of all methods in the smart contract, and the field types and field names of each method used to access the blockchain, etc. The binary string is the RLP code of the smart contract, which is used to sign the contract instance. Of course, the JAVA file can also include other content, which will not be listed here one by one.
[0167] S32. Load the JAVA contract file and obtain the event class through reflection.
[0168] In the above JAVA file, the event class is the modifyUserNameEvent class.
[0169] S33. Convert the field of the event class that is the same as the first field type into a JAVA object through a first mapping relationship between the JAVA object and the first field type, thereby obtaining a first POJO object corresponding to the event class.
[0170] In an embodiment of the present invention, the first field type is a field type used in the event method to access the blockchain. As an example, the first field type may be a web3jsdk type.
[0171] Continuing with the above example, after obtaining the modifyUserNameEvent class in the JAVA file, first locate the field in the modifyUserNameEvent class whose field type is the web3jsdk type. For example, the field of the web3jsdk type may include Bytes32, Uint8, and Address. Then, according to the first mapping relationship, convert the field into a JAVA object. The first mapping relationship may be: Bytes32 corresponds to String, Uint8 corresponds to int, and Address corresponds to String. The first mapping relationship may be pre-stored in the data parsing device 100. After the field of the web3jsdk type in the JAVA file is converted into a JAVA object, a first POJO object corresponding to the modifyUserNameEvent class may be generated. For example, the code of the POJO object of the modifyUserNameEvent class is as follows:
[0172]
[0173] S34: Fill the first POJO object into a preset event data parsing template to generate the event data parsing code.
[0174] The applicant learned through studying the event data parsing process that: for all event data, the processing flow is basically the same, which can be divided into the following steps: calling the get function to obtain the event object, then parsing the event object, obtaining the event data of the event object, and then converting the parsed event data into a JAVA object instance, thereby inserting the JAVA object instance into a database table. Therefore, in an embodiment of the present invention, the processing flow can be pre-set to multiple modules to form a preset event data parsing template, which is stored in the data parsing device 100. Therefore, after obtaining the event object in the smart contract to be parsed, the event object is directly filled into the preset event data parsing template according to the field type, thereby obtaining the event data parsing code for parsing the event data in the smart contract. In this way, when parsing event data in different smart contracts, it is only necessary to obtain the corresponding smart contract, without adding a new interface or re-modifying the code. The implementation method is simple and supports secondary development.
[0175] As an example, the preset event data parsing function template includes at least a calling module, a first parsing module, a first instantiation module and a first storage module. The calling module is used to call the acquisition method, the first parsing module is used to parse the event object and obtain the parsed event data, the first instantiation module is used to convert the parsed event data into a first POJO object instance, and the first storage module is used to insert the first POJO object instance into a database table, and the database table is used to store the event data and the transaction data.
[0176] For transaction data parsing code, please refer to Figure 4 , is a flowchart for generating transaction data parsing code, which is described as follows:
[0177] S41. Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract.
[0178] In an embodiment of the present invention, the JAVA contract file includes at least a binary code and a binary string of the smart contract, the binary code includes at least the field type of each method in the construction method and the non-constant method accessing the blockchain, and the binary string is a recursive length prefix encoding of the smart contract.
[0179] Step S41 is the same as step S31 and will not be described again.
[0180] S42: Load the JAVA contract file, parse the binary code, and obtain the transaction method.
[0181] After loading the JAVA file, obtain the ABI string in the JAVA file, parse the ABI string, and obtain the transaction method in the JAVA file. For example, the name of the transaction method and parameter fields can be obtained. The transaction method includes the construction method and non-constant method in step S21, which will not be repeated here.
[0182] As another example, the transaction method may also be obtained from an operation instruction (opcode). For example, after obtaining the opcode in the JAVA file, the opcode is parsed to obtain the transaction method in the opcode.
[0183] In order to ensure the accuracy of the acquired transaction method, after acquiring the transaction method, it is possible to determine whether the transaction method is a construction method or a non-constant method based on the name and / or parameter field of the acquired transaction method. If not, exit the process; if so, continue with the subsequent process.
[0184] S43. Convert the field in the transaction method that is the same as the second field type into a JAVA object through a second mapping relationship between the JAVA object and the second field type, thereby obtaining a second POJO object corresponding to the transaction method, where the second field type is a field type in the transaction method for accessing the blockchain.
[0185] In an embodiment of the present invention, the second field type is a field type used to access the blockchain in the transaction method. As an example, the second field type may be the same as the first field type, such as a web3jsdk type, or the second field type may be another type different from the first field type, which is not limited here.
[0186] Step S43 is similar to step S33 and will not be described again.
[0187] S44: Fill the second POJO object with a preset transaction data parsing template to generate the transaction data parsing code.
[0188] Similar to the principle in step S34, the applicant studied the transaction data parsing process and found that the processing process for transaction data is divided into steps: Since transaction data parsing is relatively complicated, there is no way to directly locate it like event data (for example, it is not directly obtained through the get function), and transaction matching can only be performed through matching, so as to determine whether the transaction method is a construction method or a constant method, and then parse the encoding string of the transaction method (for example, the RLP encoding string), obtain the transaction data of the transaction method, and convert the parsed transaction data into a POJO object instance, so as to insert the POJO object instance into the database table according to the field type. Therefore, in an embodiment of the present invention, the processing flow can be pre-set to multiple modules to form a preset transaction data parsing template, which is stored in the data parsing device 100, so that when the transaction method in the smart contract to be parsed is obtained, the POJO object corresponding to the transaction method is directly filled into the preset transaction data parsing template, so as to obtain the transaction data parsing code for parsing the transaction data in the smart contract.
[0189] 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 to determine whether the transaction method is the construction method or the non-constant method, the second parsing module is used to parse the transaction method and obtain transaction data, the second instantiation module is used to convert the transaction data into a second POJO object instance, and the second storage module is used to insert the second POJO object instance into a database table.
[0190] It should be noted that when the smart contract includes both event methods and transaction methods, the data analysis device 100 can first generate the event data analysis code and then generate the transaction data analysis code; it can also first generate the transaction data analysis code and then generate the event data analysis code, or generate the transaction data analysis code and the event data analysis code in parallel, without limiting the order of their execution.
[0191] S23. Use the data parsing code to parse the data in each block in the blockchain to obtain data.
[0192] After obtaining the transaction data parsing code and event data parsing code corresponding to the smart contract, the transaction data parsing code and event data parsing code can be run to obtain the transaction data and event data corresponding to the smart contract in each block.
[0193] The following describes the method for obtaining event data and the method for obtaining transaction data respectively.
[0194] For event data, see Figure 5 , is a flowchart of using the event data parsing code to obtain event data. The flowchart is described as follows:
[0195] S51. Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain.
[0196] The data analysis device 100 can obtain each block in the blockchain in sequence, for example, Figure 1 Taking the blockchain shown in FIG. 1 as an example, first obtain block A, and after parsing the event data in block A, obtain block B. Alternatively, the data parsing device 100 can also randomly obtain one of the blocks, which is not limited here. It should be noted that for each block, the method of obtaining the event data in the block is the same, and one of the blocks in the blockchain is used as an example for explanation below.
[0197] S52: Run the event data parsing code, and obtain the event object list in the block through the calling module in the event data parsing code.
[0198] When the data analysis device 100 obtains a block, it calls the generated event data analysis code and determines whether there is event data corresponding to the smart contract in the block by calling the module. It can be understood that if the corresponding event object list can be obtained by calling the module, it means that there is event data corresponding to the smart contract in the block, otherwise, it does not include event data corresponding to the smart contract.
[0199] For the aforementioned UserInfo smart contract, the calling module will obtain the corresponding event data list through the get function, for example, getModifyUserNameEventEvents, for example, List <modifyusernameeventresponse>If you can get the List <modifyusername--eventresponse>, it indicates that there is event data in the block, otherwise, there is no event data in the block.
[0200] In an 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 aforementioned UserInfo smart contract, at the first moment, the user sets the userName to the first value, and at the second moment, the user sets the userName to the second value, then the event object list corresponding to the userName includes the first value and the second value.
[0201] It should also be noted that in the embodiment of the present invention, the UserInfo smart contract includes only one event method, so the data parsing device 100 only generates one event data parsing code, but in actual use, a smart contract may include multiple event methods, so the data parsing device 100 will generate multiple event data parsing codes for one smart contract. In this case, when the data parsing device 100 parses the event data in a block, it is necessary to traverse multiple event data parsing codes corresponding to the smart contract. If the event data list cannot be obtained by running all the event data parsing codes, it means that there is no event data in the block, otherwise there is event data in the block.
[0202] S53: Parse at least one value of the event object through a parsing module in the event data parsing code to obtain at least one parsed event data.
[0203] After obtaining at least one value of the event object, the at least one value is analyzed by a parsing module to obtain corresponding event data.
[0204] S54. Convert the at least one parsed event data into at least one first POJO object instance through the instantiation module in the event data parsing code.
[0205] Specifically, the at least one POJO first object instance corresponds to the at least one parsed event data. For example, if the event object includes two values, the two values are parsed to obtain two event data, and then each event data is converted into a POJO object instance, thereby obtaining two first POJO object instances.
[0206] S55. Insert the at least one POJO object instance into the database table through the storage module in the event data parsing code.
[0207] After the first POJO object instance corresponding to each event data is obtained, the obtained first POJO object instance is inserted into the database table to complete the process of parsing and synchronizing the event data.
[0208] For transaction data, please refer to Figure 6 , is a flowchart of using the transaction data parsing code to obtain transaction data. The flowchart is described as follows:
[0209] S601. Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain.
[0210] Step S601 is the same as step S51 and will not be described again here.
[0211] S602: Obtain the first transaction in the block through a preset transaction acquisition interface.
[0212] The transaction acquisition interface is similar to that in the prior art and will not be described in detail here.
[0213] S603: Run the transaction data parsing code, obtain a target field in the first transaction through a matching module in the transaction data parsing code, and determine a transaction type of the first transaction according to the target field.
[0214] In an embodiment of the present invention, the transaction type includes a first transaction type and a second transaction type, wherein 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-constant method. The target field is used to indicate the transaction object of the first transaction. As an example, the target field is a To field. After the first transaction is obtained, the transaction data parsing code is run to obtain the To field in the transaction and determine whether it is null. If it is null, the first transaction is determined to be a first transaction type. Otherwise, the first transaction is determined to be a second transaction type.
[0215] In the embodiment of the present application, when it is determined that the transaction type of the first transaction is the first transaction type, steps S604 to S606 and step S610 are executed, and when it is determined that the transaction type of the first transaction is the second transaction type, steps S607 to S610 are executed.
[0216] In addition, similar to the event data analysis process, if the data analysis device 100 generates multiple transaction data analysis codes for a smart contract, the data analysis device 100 needs to traverse the multiple transaction data analysis codes corresponding to the smart contract. In an embodiment of the present invention, running a transaction data analysis code is taken as an example for explanation.
[0217] S604: When the transaction type of the first transaction is the first transaction type, obtain the recursive length prefix code of the first transaction through the matching module, and determine whether the recursive length prefix code of the first transaction includes the binary string.
[0218] In the embodiment of the present invention, the storage format of the transaction data corresponding to the construction method is: binary+encode(data), where binary is the RLP encoding string of the smart contract, and encode is the encoding function of the transaction data. Therefore, after determining that the transaction type of the first transaction is the transaction type corresponding to the construction method, it is necessary to compare the binary strings of all smart contracts to determine which smart contract construction method the transaction corresponds to.
[0219] Specifically, the construction method in the aforementioned UserInfo smart contract is UserInfo(bytes32userName,uint8 sex). When it is determined that the first transaction is a transaction corresponding to the construction method, the binary (length M) in the JAVA file of the UserInfo smart contract is obtained, and then the RLP code (length N) of the first transaction is obtained. If the first M strings of the RLP code of the first transaction are the same as the binary in the JAVA file, then the first transaction is obtained by executing the construction method of the UserInfo smart contract.
[0220] S605: When the answer is yes, parse the first remaining string through the second parsing module in the transaction data parsing code to obtain the first transaction data of the first transaction, where the first remaining string is a string obtained by removing symbols identical to the binary string from the recursive length prefix encoding of the first transaction.
[0221] After determining that the first M characters of the RLP encoding of the first transaction are the same as the binary in the JAVA file, the first M characters of the RLP encoding of the first transaction are removed, that is, the binary header of the first transaction is removed to obtain a first remaining character string with a length of (NM), and then a decode(data) operation is performed on the first remaining character string. The decode() operation is calculated based on the type offset of each field, so as to obtain the value of each field in the first transaction, and the value of each field is at least one first transaction data.
[0222] Specifically, the first transaction is obtained by executing the construction method of the UserInfo smart contract. The values of the field userName and the field sex can be obtained by parsing. Then, the values of these two fields are parsed to obtain at least one first transaction data in the first transaction.
[0223] S606: Convert the first transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code.
[0224] Step S606 is similar to step S54 and will not be described again.
[0225] S607: When the transaction type of the first transaction is the second transaction type, obtain the recursive length prefix encoding of the first transaction through the matching module, and determine whether the recursive length prefix encoding of the first transaction includes the signature of the non-constant method corresponding to the transaction data parsing code.
[0226] 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 the non-constant method. Therefore, after determining that the transaction type of the first transaction is the transaction type corresponding to the non-constant method, it is necessary to compare the signatures of the non-constant methods of all smart contracts to determine which transaction corresponds to which non-constant method.
[0227] Specifically, the non-constant method in the aforementioned UserInfo smart contract is modifyUserName(bytes32userName). When it is determined that the first transaction is a transaction corresponding to a non-constant method, the signature (length L) of the modifyUserName(bytes32 userName) method in the JAVA file of the UserInfo smart contract is obtained, and then the RLP encoding (length N) of the first transaction is obtained. If the first L strings of the RLP encoding of the first transaction are the same as the signature of the modifyUserName(bytes32 userName) method, then the first transaction is obtained by executing the non-constant method of the UserInfo smart contract.
[0228] S608. When the answer is yes, parse the second remaining code through the second parsing module in the transaction data parsing code to obtain the second transaction data of the first transaction, where the second remaining code is a character string obtained by removing the symbol identical to the signature from the code of the first transaction.
[0229] After determining that the first L characters of the RLP encoding of the first transaction are the same as the signature of the modifyUserName(bytes32userName) method, the first L characters of the RLP encoding of the first transaction are removed, that is, the signature header of the first transaction is removed to obtain a second remaining character string of length (NL), and then a decode(data) operation is performed on the second remaining character string to obtain the values of each field in the first transaction, and the values of each field are at least one first transaction data.
[0230] Specifically, the first transaction is obtained by executing the non-constant method of the UserInfo smart contract. The values of the fields userName, sex, and address can be obtained by parsing. Then, the values of these three fields are parsed to obtain at least one first transaction data in the first transaction.
[0231] S609: Convert the second transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code.
[0232] S610: Insert the second POJO object instance into the database table through the second storage module in the transaction data parsing code.
[0233] Steps S609 to S610 are similar to steps S54 to S55 and will not be described in detail herein.
[0234] In the above technical solution, the code for parsing data is automatically generated according to the smart contract of the user business. That is to say, for different user businesses, the user only needs to import the smart contract corresponding to each user business, without adding new interfaces or pre-storing the code for data parsing, thereby reducing the storage space occupied by the code for data parsing and reducing the cost of parsing data in the blockchain. Moreover, the code generated according to the smart contract corresponds one-to-one with the interface in the smart contract. Therefore, when performing data parsing, there is no need to call multiple interfaces or calculate the address of the data to be parsed, thereby improving the performance of data parsing.
[0235] The second aspect of the present invention provides a data analysis device for blockchain, please refer to Figure 7 FIG. 1 is a schematic diagram of the structure of the data analysis device, which includes:
[0236] An acquisition unit 701 is used to acquire a smart contract of a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service;
[0237] A generating unit 702, configured to generate a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service;
[0238] The parsing unit 703 is used to parse the data in each block in the blockchain using the data parsing code to obtain the event data and the transaction data.
[0239] Since the data analysis device is proposed under the same concept as the blockchain data analysis method provided by the present invention, the aforementioned Figure 2-Figure 6 The various variations and specific embodiments of the data parsing method of the blockchain in the embodiment are also applicable to the data parsing device of the present embodiment. Through the above detailed description of the data parsing method of the blockchain, those skilled in the art can clearly understand the implementation process of the data parsing device of the present embodiment, so for the sake of brevity of the specification, it will not be described in detail here.
[0240] The third aspect of the present invention provides a data analysis device for blockchain, please refer to Figure 8 , which is a structural diagram of the data analysis device, the data analysis device includes a processor 801, a transceiver 802, and a memory 803, wherein the processor 801, the memory 803 and the transceiver 802 are connected via a bus interface;
[0241] The processor 801 controls the transceiver 802 to obtain a smart contract of a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service;
[0242] The processor 801 generates a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service; and,
[0243] The data parsing code is used to parse the data in each block in the blockchain to obtain the event data and the transaction data.
[0244] Optionally, the processor 801 may be a central processing unit, an application specific integrated circuit (ASIC), one or more integrated circuits for controlling program execution, a hardware circuit developed using a field programmable gate array (FPGA), or a baseband processor.
[0245] Optionally, the processor 801 may include at least one processing core.
[0246] Optionally, the electronic device further includes a memory 803, which may include a read-only memory (ROM), a random access memory (RAM), and a disk memory. The memory 803 is used to store data required by the processor 801 when it is running. The number of memories is one or more.
[0247] Since the data analysis device is proposed under the same concept as the blockchain data analysis method provided by the present invention, the aforementioned Figure 2-Figure 6 The various variations and specific embodiments of the data parsing method of the blockchain in the embodiment are also applicable to the data parsing device of the present embodiment. Through the above detailed description of the data parsing method of the blockchain, those skilled in the art can clearly understand the implementation process of the data parsing device of the present embodiment, so for the sake of brevity of the specification, it will not be described in detail here.
[0248] A fourth aspect of the present invention provides a computer device, the computer device comprising:
[0249] at least one processor, and
[0250] A memory and a communication interface communicatively connected to the at least one processor;
[0251] The memory stores instructions that can be executed by the at least one processor, and the at least one processor executes the instructions stored in the memory and uses the communication interface to perform the following operations: Figure 2 to Figure 6 The method in the embodiment shown.
[0252] A fifth aspect of the present invention provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer instructions, and when the computer instructions are executed on a computer, the computer executes Figure 2 to Figure 6 The method in the embodiment shown.
[0253] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program code.
[0254] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0255] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0256] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0257] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these 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 these modifications and variations. < / modifyusernameeventresponse>
Claims
1. A data analysis method for blockchain, characterized in that: The method comprises: Obtaining a smart contract for a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service; Generate a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service; Use the data parsing code to parse the data in each block in the blockchain to obtain the event data and the transaction data; The event data parsing code is generated according to at least one of the construction method, the event method and the non-constant method, including: Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein 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, wherein the binary code of the smart contract includes at least a field type of each method accessing the blockchain in the construction method, the event method, and the non-constant method; Load the JAVA contract file and obtain the event class through reflection; Converting a field in the event class that is the same as the first field type into a JAVA object through a first mapping relationship between a JAVA object and a first field type, thereby obtaining a first POJO object corresponding to the event class, wherein the first field type is a field type used in the event method to access the blockchain; Filling the first POJO object into a preset event data parsing template to generate the event data parsing code, wherein 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, wherein the calling module is used to call the acquisition method, the first parsing module is used to parse the event object and obtain the parsed event data, the first instantiation module is used to convert the parsed event data into a first POJO object instance, and the first storage module is used to insert the first POJO object instance into a database table, and the database table is used to store the event data and the transaction data; The event data parsing code is used to parse the data in each block in the blockchain to obtain the event data, including: Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain; Run the event data parsing code, and obtain a list of event objects in the block through a calling module in the event data parsing code, wherein the list of event objects includes at least one value of the event object; Parsing at least one value of the event object by a parsing module in the event data parsing code to obtain at least one parsed event data; Convert the at least one parsed event data into at least one first POJO object instance through an instantiation module in the event data parsing code, wherein the at least one first POJO object instance corresponds to the at least one parsed event data in a one-to-one manner; Inserting the at least one POJO object instance into the database table through the storage module in the event data parsing code; Generating the transaction data parsing code according to at least one of the construction method, the event method and the non-constant method includes: Compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein the JAVA contract file includes at least a binary code and a binary string of the smart contract, wherein the binary code includes at least the field type of each method in the construction method and the non-constant method accessing the blockchain, and the binary string is a recursive length prefix code of the smart contract; Load the JAVA contract file, parse the binary code, and obtain the transaction method, which includes the construction method and the non-constant method; The field of the transaction method that is the same as the second field type is converted into a JAVA object through a second mapping relationship between the JAVA object and the second field type, thereby obtaining a second POJO object corresponding to the transaction method, wherein the second field type is a field type used in the transaction method to access the blockchain; Filling the second POJO object into a preset transaction data parsing template to generate the transaction data parsing code, the preset transaction data parsing template at least includes a matching module, a second parsing module, a second instantiation module and a second storage module, the matching module is used to determine whether the transaction method is the construction method or the non-constant method, the second parsing module is used to parse the transaction method and obtain transaction data, the second instantiation module is used to convert the transaction data into a second POJO object instance, and the second storage module is used to insert the second POJO object instance into a database table, and the database table is used to store the event data and the transaction data; The transaction data parsing code is used to parse the data in each block in the blockchain to obtain the transaction data, including: Obtain one of the blocks in the blockchain, where the one of the blocks is any block in the blockchain; Obtaining the first transaction in the block through a preset transaction acquisition interface; Running the transaction data parsing code, obtaining a target field in the first transaction through a matching module in the transaction data parsing code, and determining a transaction type of the first transaction according to the target field, the transaction type including a first transaction type and a second transaction type, the first transaction type being a transaction type corresponding to the construction method, the second transaction type being a transaction type corresponding to the non-constant method, and the target field being used to indicate a transaction object of the first transaction; When determining that the transaction type of the first transaction is the first transaction type, obtaining 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 string; If the answer is yes, the first remaining character string is parsed by a second parsing module in the transaction data parsing code to obtain first transaction data of the first transaction, where the first remaining character string is a character string obtained by removing symbols identical to the binary character string from the recursive length prefix encoding of the first transaction; Converting the first transaction data into a second POJO object instance through a second instantiation module in the transaction data parsing code; The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
2. The method according to claim 1, characterized in that: After running the transaction data parsing code, acquiring a target field in the first transaction through a matching module in the transaction data parsing code, and determining a transaction type of the first transaction according to the target field, the method further includes: When the transaction type of the first transaction is the second transaction type, obtaining the recursive length prefix encoding of the first transaction through the matching module, and determining whether the recursive length prefix encoding of the first transaction includes a signature of a non-constant method corresponding to the transaction data parsing code; If the answer is yes, the second remaining code is parsed by the second parsing module in the transaction data parsing code to obtain the second transaction data of the first transaction, where the second remaining code is a character string obtained by removing the symbol identical to 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 parsing code; The second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
3. A data analysis device for blockchain, characterized in that: include: An acquisition unit, used to acquire a smart contract for a user service, wherein the smart contract includes a construction method, an event method, and a non-constant method for creating and implementing the user service; a generating unit, configured to generate a data parsing code according to at least one of the construction method, the event method and the non-constant method, wherein the data parsing code includes an event data parsing code for parsing the event data of the user service and a transaction data parsing code for parsing the transaction data of the user service; A parsing unit, configured to parse the data in each block in the blockchain using the data parsing code to obtain the event data and the transaction data; The generating unit is specifically used to compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein the JAVA contract file at least includes 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, wherein the binary code of the smart contract at least includes the construction method, the event method, and the field type of each method in the non-constant method accessing the blockchain; load the JAVA contract file, and obtain the event class through reflection; convert the field in the event class that is the same as the first field type into a JAVA object through a first mapping relationship between a JAVA object and a first field type, thereby obtaining a first P corresponding to the event class. OJO object, the first field type is the field type used in the event method to access the blockchain; the first POJO object is filled into a preset event data parsing template to generate the event data parsing code, 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 to call the acquisition method, the first parsing module is used to parse the event object and obtain the parsed event data, the first instantiation module is used to convert the parsed event data into a first POJO object instance, and the first storage module is used to insert the first POJO object instance into a database table, and the database table is used to store the event data and the transaction data; The parsing unit is specifically used to obtain one of the blocks in the blockchain, wherein the one of the blocks is any block in the blockchain; run the event data parsing code, and obtain the event object list in the block through the calling module in the event data parsing code, wherein the event object list includes at least one value of the event object; parse the at least one value of the event object through the parsing module in the event data parsing code to obtain at least one parsed event data; convert the at least one parsed event data into at least one first POJO object instance through the instantiation module in the event data parsing code, and the at least one first POJO object instance corresponds to the at least one parsed event data one by one; insert the at least one POJO object instance into the database table through the storage module in the event data parsing code; The generating unit is specifically used to compile the smart contract to obtain a JAVA contract file corresponding to the smart contract, wherein the JAVA contract file includes at least a binary code and a binary string of the smart contract, wherein the binary code includes at least the construction method and the field type of each method in the non-constant method accessing the blockchain, and the binary string is a recursive length prefix encoding of the smart contract; load the JAVA contract file, parse the binary code, and obtain a transaction method, wherein the transaction method includes the construction method and the non-constant method; and convert the field in the transaction method that is the same as the second field type into a JAVA object through a second mapping relationship between a JAVA object and a second field type, thereby obtaining a field corresponding to the transaction method. a second POJO object corresponding to the transaction method, wherein the second field type is the field type used in the transaction method to access the blockchain; the second POJO object is filled into a preset transaction data parsing template to generate the transaction data parsing code, wherein the preset transaction data parsing template at least includes a matching module, a second parsing module, a second instantiation module and a second storage module, wherein the matching module is used to determine whether the transaction method is the construction method or the non-constant method, the second parsing module is used to parse the transaction method and obtain transaction data, the second instantiation module is used to convert the transaction data into a second POJO object instance, and the second storage module is used to insert the second POJO object instance into a database table, and the database table is used to store the event data and the transaction data; The parsing unit is specifically used to obtain one of the blocks in the blockchain, wherein the one of the blocks is any one of the blocks in the blockchain; obtain a first transaction in the block through a preset transaction acquisition interface; run the transaction data parsing code, obtain a target field in the first transaction through a matching module in the transaction data parsing code, and determine a transaction type of the first transaction according to the target field, wherein the transaction type includes a first transaction type and a second transaction type, wherein 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-constant method, and the target field is used to indicate a transaction object of the first transaction; when determining that the transaction type of the first transaction is the first transaction type, obtain a recursive length prefix encoding of the first transaction through the matching module, and determine whether the recursive length prefix encoding of the first transaction includes the binary string; When the answer is yes, the first remaining string is parsed through the second parsing module in the transaction data parsing code to obtain the first transaction data of the first transaction, where the first remaining string is a string obtained by removing symbols identical to the binary string from the recursive length prefix encoding of the first transaction; the first transaction data is converted into a second POJO object instance through the second instantiation module in the transaction data parsing code; and the second POJO object instance is inserted into the database table through the second storage module in the transaction data parsing code.
4. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method of claim 1 or 2.
5. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to cause the computer to execute the method of claim 1 or 2.
Citation Information
Patent Citations
Business data analysis method for block chain global intelligent contract
CN107038242A
Method and equipment for obtaining smart contract interface in blockchain
CN107274186A