In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to understand Omni and USDT PHP development packages, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
The OmniTool package is suitable for rapidly increasing the support for Omni Layer/USDT digital assets for PHP applications, not only for application scenarios that use their own Omni Layer nodes, but also for lightweight deployment scenarios based on third-party Omni Layer services and offline naked transactions.
1. Brief introduction of OmniTool development package
The OmniTool development package mainly includes the following features:
Perfect RPC encapsulation of Omni Layer nodes
Support the use of own nodes or third-party services to obtain utxo collections of specified addresses
Support offline generation of omni tokens transfer naked transactions
Support for broadcasting naked transactions using own nodes or third-party services
OmniTool supports locally deployed Omnicored nodes, as well as open API provided by blockchain.info and btc.com. It is also very easy to increase support for other third-party services. You only need to refer to the code to implement the following APIs:
UtxoCollectorInterface:utxo collector
UtxoSelectorInterface:utxo filter
BroadcasterInterface: naked transaction broadcaster
ExplorerInterface: data query interface
The OmniTool software package runs under the environment of * * Php 7.1 clients *. The current version 1.0.0. The main classes / interfaces and relationships are shown in the following figure:
The main code files for OmniTool are listed below:
Code file description
RPC protocol wrapper class of omni.php/src/RpcClient.php Omni Layer
Omni.php/src/RpcModule.php Omni Layer's RPC protocol sub-module access grammar sugar
Omni.php/src/protocol-spec.json Omni Layer protocol description meta-information
Omni.php/src/SerializeBuffer.php Omni Layer protocol serialization buffer
Omni.php/src/PayloadFactory.php Omni Layer protocol payload factory class
Omni.php/src/Utxo.php unconsumed transaction output class
Omni.php/src/UtxoBag.php Utxo collection class
Omni.php/src/UtxoCollectorInterface.php Utxo Collector Interface
Implementation of omni.php/src/LocalUtxoCollector.php Utxo Collector based on OmniCore Node
Implementation of Utxo Collector for omni.php/src/CloudUtxoCollector.php based on third Party Services
Omni.php/src/UtxoSelectorInterface.php Utxo filter interface
Omni.php/src/DefaultUtxoSelector.php default Utxo filter implementation
Omni.php/src/BroadcasterInterface.php naked transaction broadcaster interface
Implementation of naked transaction broadcaster based on OmniCore node in omni.php/src/LocalBroadcaster.php
Implementation of naked transaction broadcaster based on third-party service in omni.php/src/CloudBroadcaster.php
Omni.php/src/ExplorerInterface.php data query interface
Implementation of data query Interface based on third Party Service in omni.php/src/CloudExplorer.php
Implementation of data query Interface of omni.php/src/LocalExplorer.php based on OmniCore Node
Common auxiliary functions of omni.php/src/Utils.php
Omni.php/src/Wallet.php offline wallet class
Demo/rpc-demo.php RpcClient use example to complete the issuance and transfer of OMNI tokens
Demo/omni-tx-cloud.php creates and broadcasts Omni token transfer naked transactions using third-party cloud service API
Demo/omni-tx-local.php creates and broadcasts Omni token transfer naked transactions, using its own nodes
Demo/btc-tx-cloud.php creates and broadcasts naked Bitcoin transfer transactions using the third-party cloud service API
Demo/btc-tx-local.php creates and broadcasts Bitcoin transfer naked transactions, using its own nodes
Demo/explorer-cloud.php queries the specified address Bitcoin balance / Omni token balance, using the third-party cloud service API
Demo/explorer-local.php queries the Bitcoin balance / Omni token balance of the specified address, using its own node
Demo/wallet-init.php Local Wallet initialization
Demo/wallet-demo.php wallet loading, naked transaction construction and broadcast
Vendor third-party dependency package directory
Composer.json composer profile
2. Instructions for using the RpcClient class
The RpcClient class encapsulates Omni Layer's RPC interface protocol. When you create a RpcClient object, you need to pass in the node RPC URL that contains valid identity information. For example, suppose the omnicored node software installed on this machine is configured as follows:
Rpcuser:user
Rpcpassword:123456
Rpcport:8332
Then you can instantiate RpcClient using the following code:
Use\ OmniTool\ RpcClient;$client = new RpcClient (URL*/ of the RPC interface of the 'http://user:123456@localhost:8332' / * node)
In addition to the original RPC interface of Bitcoin, the Omni Core node expands additional interfaces to operate the data of the Omni layer. These extended RPC interfaces use the omni_ prefix to distinguish from the original RPC interface of Bitcoin. In order to distinguish the RPC calls of these two layers, RpcClient introduces the concept of protocol sub-module, and connects the original RPC interface of Bitcoin and the extended RPC interface of Omni to BTC sub-module and omni sub-module respectively.
For example, to get the USDT token balance of an address, you need to use the omni_getbalance call of the Omni layer, which calls the getBalance () method of the omni submodule corresponding to the RpcClient instance. The following code gets the USDT (asset ID:31) balance of the address 1EXoDusjGwvnjZUyKkxZ4UHEf77z6A5S4P:
$ret = $client- > omni- > getBalance ('1EXoDusjGwvnjZUyKxZ4UHEf77z6A5S4Please, / * address * / 31 / * Asset ID:USDT*/)
Similarly, you can use the omni_send call to perform a simple USDT transfer, which corresponds to the send () method of the omni submodule of the RpcClient instance. The following code transfers 100.0 USDT tokens from the address 3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY to the address 37FaKponF7zqoMLUjEiko25pDiuVH5YLEa:
$ret = $client- > omni- > send ('3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGYY, / * token transfer address * /' 37FaKponF7zqoMLUjEiEiko25pDiuVH5YLEafortune, / * token transfer address * / 31, / * token ID:USDT*/ "100.00" / * number of tokens transferred * /)
The original RPC interface of bitoin layer can be accessed through the BTC sub-module of RpcClient. For example, use the listunspent call to get the utxo of the specified address in the local node:
$ret = $client- > btc- > listUnspent (6, / * minimum acknowledgements * / 999999, / * maximum confirmations * / ['mgnucj8nYqdrPFh3JfZSB1NmUThUGnmsqe'] / * address list * /)
The demo/rpc-demo.php sample code in the development package uses the RpcClient class to fully demonstrate the token issuance and transfer functions in the Omni layer. If you plan to build your own Omni Core node, I believe this example will be of great help.
3. Instructions for using Wallet class
If you don't want to build your own Omni Core node, but want to add Omni Layer/USDT support to your PHP application based on third-party API, then the easiest way is to use the offline transaction entry class Wallet.
The main function of the Wallet class is to create and broadcast Omni token transfer naked transactions or bitcoin transfer naked transactions. The basic steps for its use are as follows:
Create a Wallet instance that supports cloud API services using the Wallet::cloud () static method
Use the addKey () method to add the necessary private key to the Wallet instance, such as the private key of the transfer address, because Wallet needs to sign the naked transaction with the private key
Use the omniSendTx () method to generate Omni token transfer naked transactions, or use the btcSendTx () method Bitcoin transfer naked transactions
Broadcast naked transactions using the broadcast () method
3.1 Omni token transfer
The sample code of Omni token transfer implemented with Wallet is as follows. For more information, please see the notes:
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.