Disclosure of Invention
The invention aims to provide a method for improving the expansibility of an intelligent contract field of an Ethernet, which is used for carrying out standardized design on the format of the field, improving the expansibility of the field, reducing the repeated construction of a system and ensuring the updating requirement on the business.
To achieve the purpose, the invention adopts the following technical scheme:
the method for improving the expansibility of the intelligent contract field of the Ethernet comprises the following steps:
s10, defining a field to be stored on a block chain;
s20, classifying and integrating the fields needing to be uplink to extract similar fields;
s30, the front-end server integrates the similar fields and performs Json formatting conversion so that an object or an array formed by a plurality of fields is converted into a character string of a single field;
s40, calling an intelligent contract Api interface on the blockchain to transmit the corresponding character string, and storing the character string into a field of the blockchain after the intelligent contract is verified;
s50, when the front-end server needs to acquire data, json analysis is needed to be carried out on the character string, and therefore an original storage field is obtained.
As a preferred scheme of the method for improving the extensibility of the ethernet intelligent contract field, in step S40, the front-end server accesses the intelligent contract Api interface in a Post manner according to the URL link provided by the interface through the HTTP network protocol.
As a preferred scheme of the method for improving the extensibility of the ethernet intelligent contract field, in step S40, the intelligent contract Api interface calls the corresponding intelligent contract after performing one-time transfer according to the URL link, the intelligent contract verifies the identity of the call, and executes the storage logic on the intelligent contract after the verification is passed, where the storage logic stores the request after the storage logic is confirmed by the consensus mechanism of the blockchain.
As a preferable scheme of the method for improving the expansibility of the intelligent contract field of the Ethernet, when the character string needs to be added with a new field, the new field is only needed to be added into the original field on the front-end server.
The invention has the beneficial effects that: the invention makes some standardization design to the format of the field, so as to make several pieces of information converted according to a certain rule, thereby improving the data quantity stored in a single field, improving the expansibility of the field, reducing the variable generated by storing in a single function, making the contract able to complete the service demand update under the limitation of the system, reducing the repeated construction of the system, reducing the required field for storing in the contract realization, and at the same time, as the setting of the storage field is character string size, when the data format before conversion needs to be added and deleted, it will not have any influence to the storage format, making the storage content more flexible, without modifying the underlying storage contract, increasing the flexibility of the contract storage structure.
Detailed Description
The technical scheme of the invention is further described below by the specific embodiments with reference to the accompanying drawings.
Wherein the drawings are for illustrative purposes only and are shown in schematic, non-physical, and not intended to be limiting of the present patent; for the purpose of better illustrating embodiments of the invention, certain elements of the drawings may be omitted, enlarged or reduced and do not represent the size of the actual product; it will be appreciated by those skilled in the art that certain well-known structures in the drawings and descriptions thereof may be omitted.
The same or similar reference numbers in the drawings of embodiments of the invention correspond to the same or similar components; in the description of the present invention, it should be understood that, if the terms "upper", "lower", "left", "right", "inner", "outer", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, only for convenience in describing the present invention and simplifying the description, rather than indicating or implying that the apparatus or elements being referred to must have a specific orientation, be constructed and operated in a specific orientation, so that the terms describing the positional relationships in the drawings are merely for exemplary illustration and should not be construed as limiting the present patent, and that the specific meaning of the terms described above may be understood by those of ordinary skill in the art according to specific circumstances.
In the description of the present invention, unless explicitly stated and limited otherwise, the term "coupled" or the like should be interpreted broadly, as it may be fixedly coupled, detachably coupled, or integrally formed, as indicating the relationship of components; can be mechanically or electrically connected; can be directly connected or indirectly connected through an intermediate medium, and can be communication between the two parts or interaction relationship between the two parts. The specific meaning of the above terms in the present invention will be understood in specific cases by those of ordinary skill in the art.
As shown in fig. 1, the method for improving the extensibility of the intelligent contract field of the ethernet comprises the following steps:
s10, defining a field to be stored on a block chain;
s20, classifying and integrating the fields needing to be uplink to extract similar fields;
s30, the front-end server integrates similar fields and performs Json formatting conversion so that an object or an array formed by a plurality of fields is converted into a character string of a single field;
s40, calling an intelligent contract Api interface on the blockchain to transmit a corresponding character string, and storing the character string into a field of the blockchain after the intelligent contract is verified;
s50, when the front-end server needs to acquire data, the character string needs to be subjected to Json analysis, so that an original storage field is obtained.
According to the embodiment, through carrying out some standardized designs on the formats of the fields, a plurality of pieces of information are converted according to a certain rule, so that the data quantity stored in a single field is improved, the expansibility of the fields is improved, the variable generated by storing in a single function is reduced, the demand update on business of contracts can be completed under the limitation of a system, the repeated construction of the system is reduced, the fields required by storing are reduced on the contract realization, meanwhile, the size of a character string is set for the stored fields, when the data format before conversion needs to be added and deleted, no influence is exerted on the stored formats, the storage content is more flexible, the underlying storage contracts are not required to be modified, and the flexibility of the contract storage structure is improved.
In this embodiment, in step S40, the front-end server accesses the smart contract Api interface in a Post manner according to the URL link provided by the interface through the network protocol of HTTP.
In this embodiment, in step S40, the intelligent contract Api interface transfers the corresponding intelligent contract after transferring the URL link once, the intelligent contract verifies the identity of the transfer, and after the verification is passed, the storage logic on the intelligent contract is executed, and after the storage logic is confirmed by the common identification mechanism of the blockchain, the blockchain stores the request.
In this embodiment, when a new field needs to be added to the character string, the new field is only required to be added to the original field on the front-end server.
As shown in fig. 2 and 3, for example, the information required to be uplinked includes mailing destination, logistics company, logistics list number, on-chain user name and uplink time, the above information is classified and integrated according to defined fields, information under the same category, such as mailing destination, logistics company and logistics list number, is extracted, the front end server performs Json formatting conversion on the mailing destination, logistics company and logistics list number information into Json character strings, then the Json character strings, on-chain user name and uplink time and other character strings are transmitted into the intelligent contract Api interface on the blockchain together, the intelligent contract Api interface invokes the corresponding intelligent contract, the intelligent contract verifies the identity of the call, after verification, the storage logic on the contract is executed, and after the storage logic is confirmed by the consensus mechanism of the blockchain, the blockchain stores the request, so that a plurality of variables generated during execution of the intelligent contract are reduced to receive the information. When new fields need to be added to express information as in fig. 1, the new fields need to be added to be converted before the conversion of the front-end server, and the new fields are stored by one field on the chain, so that only one variable is needed to store when the information is received, and the field format of a storage contract does not need to be changed.
According to the embodiment, a plurality of pieces of information are recorded on a single string field through string types supported in a stability language, and are converted according to rules before being transmitted to storage, so that the data size stored in the single field is improved, the variables generated by storage in a single function are reduced, the problem that the single function exceeds 16 variables limited by the bottom layer is solved, the problem that the stack top error is caused by using too many variables is prevented, more variables can be used when logic in a contract is realized, and the realized effect is more flexible and more design ideas are provided.
Interpretation of proper nouns:
json: a lightweight data storage format independent of development language, full scale JavaScript Object Notation, a standard specification for data formats, originally derived from JavaScript, and later with widespread use, almost every development language has an Api that handles Json.
Intelligent contract Api interface: a set of Api interfaces which are in accordance with the Restful Api specification and are developed by the bottom layer expansion of the blockchain provides convenience for calling.
Restful Api specification: is a set of specifications for front-end and back-end separation.
Intelligent contract: is a computer protocol aimed at propagating, verifying or executing contracts in an informative manner, intelligent contracts allow trusted transactions to be made without third parties, which transactions are traceable and irreversible.
URL link: is a representation method for specifying information positions on a web service program of the internet.
HTTP network protocol: the method is a standard for request and response of a client and a server, and is mainly used for the client to initiate an HTTP request to a designated port in the server through a page browser or other tools, and the server returns corresponding response content after receiving the request.
Post mode: refers to one of the common basic methods of HTTP requests, mainly used as a request way to submit data to a server.
Consensus mechanism: refers to an algorithm in a blockchain, mainly to ensure the correctness of a transaction. In the blockchain, each time the uplink is performed, each user checks whether the operation meets the requirement, then all users vote on the operation, and finally consensus is achieved to determine whether the operation is wrong, and if so, the operation is recorded on the blockchain.
Solidity: is a high-level programming language for intelligent contracts that run on ethernet virtual machines.
Ethernet: ethernet is an open-source public blockchain platform with smart contract functionality that handles point-to-point contracts by providing a de-centralized ethernet virtual machine with its dedicated cryptocurrency, ethernet.
Ethernet virtual machine: the ethernet virtual machine is the running environment for the intelligent contracts on the ethernet. The ethernet virtual machine runs in a sandbox, which is completely separate from the blockchain backbone, the code runs in the ethernet virtual machine without a network, and the intelligent appointments of the file system or other processes are restricted from accessing other intelligent contracts.
"stack to deep" error: this error is due to the fact that the ethernet virtual machine limits the stack to get stack 15 at most, i.e. the 16 th stack element from the stack top down, which results in that if the number of parameters in the function, the return value, and the parameter in the function of a function method are greater than a certain amount, this error is likely to be triggered, and if the contract business logic is complex, a "stack to deep" error is likely to be triggered.
It should be understood that the above description is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be apparent to those skilled in the art that various modifications, equivalents, variations, and the like can be made to the present invention. However, such modifications are intended to fall within the scope of the present invention without departing from the spirit of the present invention. In addition, some terms used in the specification and claims of the present application are not limiting, but are merely for convenience of description.