In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use the PHP development kit OmniMon". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the PHP development kit OmniMon".
1. Overview of the development package
The OmniMon development package has the following features:
Monitor Omni/USDT token transfer / transfer transactions at any specified address
Monitor Bitcoin transfer / transfer transactions at any specified address
Customize the business logic when a token transaction occurs
OmniMon can currently monitor four types of transaction events:
Bitcoin inflow event: triggered when Bitcoin flows into the listening address
Bitcoin outflow event: triggered when Bitcoin flows out of the listening address
Omni/USDT token inflow event: triggered when the Omni/USDT token is transferred to the listening address
Omni/USDT token outflow event: triggered when the Omni/USDT token is transferred out of the listening address
OmniMon supports resolution of all types of Omni Layer transactions.
OmniMon runs in the PHP 7.1 + environment, and the main classes and their relationships are shown in the following figure:
2. Basic usage
Monitor is the entry class of the OmniMon development package. The general steps for using Monitor to monitor Omni/USDT token or bitcoin transfer transactions are as follows:
Create a Monitor instance
Use the instance's watch () method to add an address to monitor, which can be called multiple times to add multiple addresses to monitor
Use the instance's addEventListener () method to add a transfer transaction event listener, which can be called multiple times to add different listening processing logic
Periodically call the instance's scanBlocks () method to scan the new block, which automatically triggers the previously added transaction event listener
2.1Creating Monitor instance object
Instantiating Monitor requires passing in two parameters, which are used to access the blockchain and to parse Omni token metadata. For example, the following code creates an Monitor instance using a ChainRpc object and a CloudPropertyMetaResolver object:
Use OmniTool\ Monitor;use OmniTool\ ChainRpc;use OmniTool\ CloudPropertyMetaResolver;$monitor = new Monitor (new ChainRpc ('http://user:123456@127.0.0.1:8332'), new CloudPropertyMetaResolver); 2.2 add addresses to listen on
Using the watch () method of the Monitor instance, you can add addresses to listen on. For example, the following code adds three addresses to listen on:
$addressList = ['15VSP7X29kR3yoaN2Xv3GQ898JeUp5dAtkkeeper,' 19i2mRtUeThfFyPd1j1Ui3LVbTFM9sdiekeeper, '3AqUTUsBkAkDBRM8zoAUbBhPxw8x541cZk'; foreach ($addressList as $address) $monitor- > watch ($address); add transaction event listener processor
Use the addEventListener () method of the Monitor instance to add custom processing logic. For example, the following code defines a listening interface implementation class UtxoSaver, which is responsible for storing the newly discovered UTXO in the database:
Use OmniTool\ IEventListener;class UtxoSaver implements IEventListener {protected $db; function _ construct ($db) {$this- > db = $db;} function handleEvent ($event) {if ($event- > type! = 'in_btc') return; $db- > saveUtxo ($event- > height, $event- > txid, $event- > vout, $event- > value, $event- > address, $event- > script);} $monitor- > addEventListener (new UtxoSaver)
OmniMon currently supports four kinds of events, and the structure of their event objects is also different:
In_btc: Bitcoin inflow. The event structure is as follows:
Height: block height
Txid: transaction ID
Vout: transaction output serial number
Value: transaction amount (in satoshi)
Address: inflow address
Script: a public key script that flows into an address
Out_btc: Bitcoin outflow. The event structure is as follows:
Height: block height
Txid: transaction ID
Vout: transaction output serial number
Value: transaction amount (in satoshi)
Address: outflow address
Script: the public key script of the outgoing address
In_omni:omni/usdt token inflow, the event structure is as follows:
Address: send account address
Script: send account public key script
Height: block height
Txid: transaction ID
Sender: send the account object with the following structure:
Reference: receive the account object with the same structure as above
Omin:omni transaction object, which varies according to the transaction type
Out_omni:omni/usdt token outflow
Address: send account address
Script: send account public key script
Height: block height
Txid: transaction ID
Sender: send the account object with the following structure:
Reference: receive the account object with the same structure as above
Omin:omni transaction object, which varies according to the transaction type
2.4 scan block chain
You need to periodically call the scanBlocks () method of the Monitor instance to scan the blockchain to track new Omni/USDT tokens or bitcoin transactions. The two parameters of scanBlocks () are used to specify the start block number and the end block number of the scan, respectively, and when a special latest string is used, the latest block is used.
For example, the following code scans the latest block every 10 minutes:
While (true) {$monitor- > scanBlocks ('latest','latest'); sleep (60: 10);} Thank you for reading, the above is the content of "how to use the PHP development package OmniMon". After the study of this article, I believe you have a deeper understanding of how to use the PHP development package OmniMon, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.