Disclosure of Invention
In order to solve the problems, the invention provides a method, equipment and a storage medium for extracting the cross-chain asset, which coordinate the extraction operation of the cross-chain asset through a repeater, so that the asset extraction performance is more stable, the frequency of failure of the extraction of the cross-chain asset is reduced, and the user experience is improved.
The invention adopts the following technical scheme.
In a first aspect, the present invention provides a method for cross-chain asset extraction, the method being applicable to a repeater, the method comprising:
acquiring a first cross-chain asset extraction transaction in a first blockchain, wherein the first cross-chain asset extraction transaction takes a second blockchain as a target chain;
analyzing the first cross-link asset extraction transaction to obtain transaction information of the first cross-link asset extraction transaction, and generating a first extraction and certification transaction according to the transaction information;
inquiring the balance of the online wallet in the second block chain, and judging whether the balance of the online wallet is sufficient;
If the balance of the online wallet is sufficient, the first certificate-extracting transaction is sent to the second blockchain, the first certificate-extracting transaction is used for extracting second blockchain assets with a first amount in the second blockchain, meanwhile, the transaction hash and the asset quantity of the first certificate-extracting transaction are recorded, and the state corresponding to the transaction hash of the first certificate-extracting transaction is set to be in a pending state;
If the balance of the online wallet is insufficient, suspending the first certificate-extracting transaction and suspending generating the certificate-extracting transaction;
Receiving recharging journal information of the second blockchain, restarting the first extraction and evidence-storage transaction, and judging whether the balance of the online wallet in the second blockchain is sufficient or not;
After the first extraction and verification transaction is sent to the second blockchain, judging whether the first extraction and verification transaction is successfully executed in the second blockchain according to the log of the second blockchain, if yes, modifying the state corresponding to the transaction hash of the first extraction and verification transaction into success in the repeater, otherwise, modifying the state corresponding to the transaction hash of the first extraction and verification transaction into failure in the repeater.
Preferably, the method for judging whether the balance of the online wallet is sufficient comprises the following steps:
acquiring all the extraction and evidence-storage transactions which are recorded in the repeater and take the state of the second blockchain as a target chain as a pending state, and calculating the total amount of the assets to be extracted;
Comparing the queried online wallet balance of the second blockchain with the total amount of the assets to be extracted, if the sum of the total amount of the assets to be extracted and the first amount is smaller than the queried online wallet balance of the second blockchain, determining that the online wallet balance is sufficient, and if the sum of the total amount of the assets to be extracted and the first amount is larger than the queried online wallet balance of the second blockchain, determining that the online wallet balance is insufficient.
Preferably, the repeater obtains the first cross-chain asset extraction transaction by listening to a transaction log of the first blockchain.
Preferably, the method of judging whether the first extracted and stored transaction is successfully executed in the second blockchain according to the log of the second blockchain is to monitor the log event when the second blockchain generates a block, inquire whether the generated block contains the transaction information of the first extracted and stored transaction, and if so, analyze the transaction information of the first extracted and stored transaction to judge whether the first extracted and stored transaction is successfully executed.
Preferably, when the balance of the online wallet is insufficient, the first certificate-extracting transaction is suspended, and after the generation of the certificate-extracting transaction is suspended, the repeater sends alarm information to the background to prompt that the balance of the online wallet is insufficient.
In a second aspect, a computer device is provided that includes one or more processors;
A memory for storing one or more programs,
The one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method as described in the first aspect above.
In a third aspect, there is provided a storage medium storing a computer program which, when executed by a processor, implements a method as described in the first aspect above.
The method has the beneficial effects that the relay is used for coordinating the asset cross-chain extraction transaction, so that the situation that the asset extraction failure is caused by taking the balance of the same online wallet as a reference object in the high-incidence period of the cross-chain extraction of the asset and the concurrent multi-asset cross-chain extraction transaction is avoided, and the relay is used for comparing the total number of the assets to be extracted of all the undetermined asset cross-chain extraction transaction and the first asset cross-chain extraction transaction with the balance of the online wallet of the target blockchain, so that the successful execution of the asset cross-chain extraction transaction is ensured, the asset cross-chain extraction is more stable, and the user experience is improved.
Detailed Description
The application is described in further detail below with reference to specific examples and figures of the specification. Those of ordinary skill in the art will be able to implement the application based on these descriptions. In addition, the embodiments of the present application referred to in the following description are typically only some, but not all, embodiments of the present application. Therefore, all other embodiments, which can be made by one of ordinary skill in the art without undue burden, are intended to be within the scope of the present application, based on the embodiments of the present application. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The methods outlined in the examples of the present application are all those known to those skilled in the art unless specifically stated otherwise.
Fig. 1 is a flowchart of a method for extracting a cross-chain asset according to an embodiment of the present invention.
As shown in fig. 1, the present embodiment provides a method for extracting a cross-chain asset, which is applicable to a repeater, and the method includes:
acquiring a first cross-chain asset extraction transaction in a first blockchain, wherein the first cross-chain asset extraction transaction takes a second blockchain as a target chain;
analyzing the first cross-link asset extraction transaction to obtain transaction information of the first cross-link asset extraction transaction, and generating a first extraction and certification transaction according to the transaction information;
inquiring the balance of the online wallet in the second block chain, and judging whether the balance of the online wallet is sufficient;
If the balance of the online wallet is sufficient, the first certificate-extracting transaction is sent to the second blockchain, the first certificate-extracting transaction is used for extracting second blockchain assets with a first amount in the second blockchain, meanwhile, the transaction hash and the asset quantity of the first certificate-extracting transaction are recorded, and the state corresponding to the transaction hash of the first certificate-extracting transaction is set to be in a pending state;
If the balance of the online wallet is insufficient, suspending the first certificate-extracting transaction and suspending generating the certificate-extracting transaction;
Receiving recharging journal information of the second blockchain, restarting the first extraction and evidence-storage transaction, and judging whether the balance of the online wallet in the second blockchain is sufficient or not;
After the first extraction and verification transaction is sent to the second blockchain, judging whether the first extraction and verification transaction is successfully executed in the second blockchain according to the log of the second blockchain, if yes, modifying the state corresponding to the transaction hash of the first extraction and verification transaction into success in the repeater, otherwise, modifying the state corresponding to the transaction hash of the first extraction and verification transaction into failure in the repeater.
Further, the method for judging whether the balance of the online wallet is sufficient comprises the following steps:
acquiring all the extraction and evidence-storage transactions which are recorded in the repeater and take the state of the second blockchain as a target chain as a pending state, and calculating the total amount of the assets to be extracted;
Comparing the queried online wallet balance of the second blockchain with the total amount of the assets to be extracted, if the sum of the total amount of the assets to be extracted and the first amount is smaller than the queried online wallet balance of the second blockchain, determining that the online wallet balance is sufficient, and if the sum of the total amount of the assets to be extracted and the first amount is larger than the queried online wallet balance of the second blockchain, determining that the online wallet balance is insufficient.
Further, the repeater obtains the first cross-chain asset extraction transaction by listening to a transaction log of the first blockchain.
Further, the method of judging whether the first extracted and stored transaction is successfully executed in the second blockchain according to the log of the second blockchain is to monitor the log event when the second blockchain generates a block, inquire whether the generated block contains the transaction information of the first extracted and stored transaction, and if yes, analyze the transaction information of the first extracted and stored transaction to judge whether the first extracted and stored transaction is successfully executed.
Further, when the balance of the online wallet is insufficient, the first extraction and deposit transaction is paused, and after the generation of the extraction and deposit transaction is paused, the repeater sends alarm information to the background to prompt that the balance of the online wallet is insufficient.
In order to not lose generality, the present embodiment exemplifies the extraction of assets from the a-chain to the B-chain, and the above method is exemplarily described. In this embodiment, the asset of the A chain is defined as assetA, the asset of the B chain is defined as assetB, and the characterization of assetA on the B chain is B_ assetA. The asset extraction process is as follows:
1. user a initiates a cross-chain asset extraction transaction on the a-chain, illustratively denoted as a first cross-chain asset extraction transaction, for extracting the a-chain asset of 100 on the B-chain, i.e., extracting 100b_assea, the repeater listens to the log of the a-chain, finds the first cross-chain asset extraction transaction, parses the asset type (b_ assetA) and the number (100) therein, and prepares to initiate a first extraction certification transaction to the B-chain;
2. The repeater inquires whether the balance of the online wallet on the B chain can fully support the asset extraction operation of the first certificate-extracting transaction, and judges whether the balance of the online wallet on the B chain can fully support the asset extraction operation of the first certificate-extracting transaction or not, wherein the judgment condition is that the balance of the online wallet which is initiated to the B chain is accumulated as much as 30000, the balance of the current certificate-extracting transaction is 29999, the balance of the online wallet is insufficient to support the asset extraction operation of the first certificate-extracting transaction, if the balance of the online wallet is balance, the first certificate-extracting transaction is continuously initiated to the B chain, otherwise, the subsequent asset extraction operation is suspended, for example, the balance of the B chain is 30000, the balance of the current certificate-extracting transaction is accumulated as much as 29999, and the balance of the online wallet is insufficient to support the asset extraction operation of the first certificate-extracting transaction, and the subsequent asset extraction operation is required to be suspended.
3. If the asset extraction operation is normally initiated to the B chain, the hash and the amount of the first asset extraction transaction (namely, the transaction hash of the first asset extraction transaction) are recorded, the state corresponding to the hash of the first asset extraction transaction is set to be pending, when a new B chain block is generated, whether the asset extraction is successful or not is determined by monitoring log events (whether the asset extraction is successful or not cannot be determined simply by inquiring a single transaction) is determined, if the asset extraction is successful, the state corresponding to the hash of the transaction is updated to be success, and if the hash is unsuccessful, the state corresponding to the hash of the transaction is updated to be fail.
4. If the current online wallet balance is not enough, the repeater can send out alarm information (e-mail or other alarm paths) in the background after suspending all pending withdrawal and deposit transactions.
5. After the operator successfully supplements the online wallet with money through the transaction, the repeater receives the recharging journal information, then the asset extraction transaction cached locally is restarted, the inspection conditions of the step 2 are operated again by one, the condition is initiated, and otherwise, the operation is paused.
According to the embodiment, the relay is used for coordinating the asset cross-chain extraction transaction, so that the situation that the asset extraction failure is caused by taking the same online wallet balance as a reference object in the high-incidence period of the cross-chain extraction of the asset and the concurrent multiple asset cross-chain extraction transactions is avoided, and the relay is used for comparing the total number of the assets to be extracted of all the undetermined asset cross-chain extraction transactions and the first asset cross-chain extraction transaction with the online wallet balance of the target blockchain, so that successful execution of the asset cross-chain extraction transactions is ensured, the asset cross-chain extraction is more stable, and the user experience is improved.
Fig. 2 is a schematic structural diagram of an apparatus according to an embodiment of the present invention.
As shown in fig. 2, as another aspect, the present application also provides a computer apparatus 500 including one or more Central Processing Units (CPUs) 501, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage part 508 into a Random Access Memory (RAM) 503. In the RAM503, various programs and data required for the operation of the device 500 are also stored. The CPU501, ROM502, and RAM503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
Connected to the I/O interface 505 are an input section 506 including a keyboard, a mouse, and the like, an output section 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like, a storage section 508 including a hard disk, and the like, and a communication section 509 including a network interface card such as a LAN card, a modem, and the like. The communication section 509 is also connected to the I/O interface 505 as needed via a network execution communication processing driver 510 such as the internet. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to the disclosed embodiment of the application, the method described in the above embodiment 1 may be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing the method described in any of the embodiments above. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511.
As a further aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiment, or may be a computer-readable storage medium that exists alone and is not assembled into a device. The computer-readable storage medium stores one or more programs for use by one or more processors in performing the methods described herein.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present application may be implemented in software or in hardware. The described units or modules may also be provided in a processor, for example, each of the units may be a software program provided in a computer or a mobile smart device, or may be separately configured hardware devices. Wherein the names of the units or modules do not in some cases constitute a limitation of the units or modules themselves.
The above description is only illustrative of the preferred embodiments of the present application and of the principles of the technology employed. It will be appreciated by persons skilled in the art that the scope of the application referred to in the present application is not limited to the specific combinations of the technical features described above, but also covers other technical features formed by any combination of the technical features described above or their equivalents without departing from the spirit of the application. Such as the above-mentioned features and the technical features disclosed in the present application (but not limited to) having similar functions are replaced with each other.