xrplwin / unlreportreader
从Xahau网络上获取并解析UNL报告。
v1.0.6
2023-10-06 17:38 UTC
Requires
- php: ^8.1.0
- xrplwin/xrpl: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.1
- symfony/var-dumper: ^6.1
README
UNL报告阅读器
从Xahau网络上获取UNL报告。
这是一个PHP包,您可以为flag ledger提供标志,脚本将解析并返回最终的验证报告。对于请求的ledger_index,脚本将返回该ledger_index的最终UNL报告状态。
要求
- PHP 8.1或更高版本
- Composer
安装
composer require xrplwin/unlreportreader
范围
在获取账本索引报告数据时,每个账本索引 % 256是标志账本。 在标志账本上UNL报告尚未应用,UNL报告从下一个账本(包括最后一个标志账本在内的下一个256个账本)开始应用。请参阅下表了解查询特定账本索引时的范围。
使用示例
use XRPLWin\UNLReportReader\UNLReportReader; $reader = new UNLReportReader('https://xahau-test.net'); $response = $reader->fetchSingle(6873344); //?array /* array [ "flag_ledger_index" => 6873344 "flag_ledger_close_time" => 748969761 "report_range" => [6873089,6873344] "import_vlkey" => "E1..." "active_validators" => array [ 0 => array:2 [ "?Account" => "r2..." "PublicKey" => "E2..." ] 1 => array:2 [ "?Account" => "r3..." "PublicKey" => "E3..." ], ... ] ] */ # response below will return report for ledger range: (6873345-256) to 6873344 $response = $reader->fetchSingle(6873342); $response = $reader->fetchSingle(6873343); $response = $reader->fetchSingle(6873344); //flag ledger # response below will return report for ledger range: 6873345 to (6873344+256) $response = $reader->fetchSingle(6873345); $response = $reader->fetchSingle(6873346); // ...
获取多个报告
这是获取多个报告比使用循环和fetchSingle()
更优化的方式,因为此脚本使用Promises以批量异步查询节点,默认批量限制为10,但可以手动配置。
use XRPLWin\UNLReportReader\UNLReportReader; //this will set async batch limit to 5 (down from default 10) $reader = new UNLReportReader('https://xahau-test.net',['async_batch_limit' => 5]); $forward = true; $limit = 2; $response = $reader->fetchMulti(6873340, $forward, $limit); //array //Ledger index "6873340" is between 6873345 and 6873600 /* SAMPLE RESPONSE: array:2 [ 0 => array:4 [ "flag_ledger_index" => 6873344 "flag_ledger_close_time" => 748969761 "report_range" => array:2 [ 0 => 6873345 1 => 6873600 ] "import_vlkey" => "ED264807102805220DA0F312E71FC2C69E1552C9C5790F6C25E3729DEB573D5860" "active_validators" => array:7 [ 0 => array:2 [ "Account" => "rGhk2uLd8ShzX2Zrcgn8sQk1LWBG4jjEwf" "PublicKey" => "ED3ABC6740983BFB13FFD9728EBCC365A2877877D368FC28990819522300C92A69" ] 1 => array:2 [ "Account" => "rnr4kwS1VkJhvjVRuq2fbWZtEdN2HbpVVu" "PublicKey" => "ED49F82B2FFD537F224A1E0A10DEEFC3C25CE3882979E6B327C9F18603D21F0A22" ] 2 => array:2 [ "Account" => "rJupFrPPYgUNFBdoSqhMEJ22hiHKiZSHXQ" "PublicKey" => "ED79EB0F6A9F01A039235E536D19F812B55ACF540C9E22CF62C271E0D42BFF5174" ] 3 => array:2 [ "Account" => "roUo3ygV92bdhfE1v9LGpPETXvJv2kQv5" "PublicKey" => "ED93B2BE467CAD2F9F56FB3A82BDFF17F84B09E34232DDE8FAF2FC72382F142655" ] 4 => array:2 [ "Account" => "rGsa7f4arJ8JE9ok9LCht6jCu5xBKUKVMq" "PublicKey" => "ED96F581FED430E8CBE1F08B37408857001D4118D49FBB594B0BE007C2DBFFD367" ] 5 => array:2 [ "Account" => "r3htgPchiR2r8kMGzPK3Wfv3WTrpaRKjtU" "PublicKey" => "EDCF31B8F683345E1C49B4A1D85BF2731E55E7D6781F3D4BF45EE7ADF2D2FB3402" ] 6 => array:2 [ "Account" => "rfQtB8m51sdbWgcmddRX2mMjMpSxzX1AGr" "PublicKey" => "EDDF197FC59A7FAA09EB1AD60A4638BA6201DD51497B5C08A1745115098E229E0E" ] ] ] 1 => array:4 [ "flag_ledger_index" => 6873600 "flag_ledger_close_time" => 748970540 "report_range" => array:2 [ 0 => 6873601 1 => 6873856 ] "import_vlkey" => "ED264807102805220DA0F312E71FC2C69E1552C9C5790F6C25E3729DEB573D5860" "active_validators" => array:7 [ 0 => array:2 [ "Account" => "rGhk2uLd8ShzX2Zrcgn8sQk1LWBG4jjEwf" "PublicKey" => "ED3ABC6740983BFB13FFD9728EBCC365A2877877D368FC28990819522300C92A69" ] 1 => array:2 [ "Account" => "rnr4kwS1VkJhvjVRuq2fbWZtEdN2HbpVVu" "PublicKey" => "ED49F82B2FFD537F224A1E0A10DEEFC3C25CE3882979E6B327C9F18603D21F0A22" ] 2 => array:2 [ "Account" => "rJupFrPPYgUNFBdoSqhMEJ22hiHKiZSHXQ" "PublicKey" => "ED79EB0F6A9F01A039235E536D19F812B55ACF540C9E22CF62C271E0D42BFF5174" ] 3 => array:2 [ "Account" => "roUo3ygV92bdhfE1v9LGpPETXvJv2kQv5" "PublicKey" => "ED93B2BE467CAD2F9F56FB3A82BDFF17F84B09E34232DDE8FAF2FC72382F142655" ] 4 => array:2 [ "Account" => "rGsa7f4arJ8JE9ok9LCht6jCu5xBKUKVMq" "PublicKey" => "ED96F581FED430E8CBE1F08B37408857001D4118D49FBB594B0BE007C2DBFFD367" ] 5 => array:2 [ "Account" => "r3htgPchiR2r8kMGzPK3Wfv3WTrpaRKjtU" "PublicKey" => "EDCF31B8F683345E1C49B4A1D85BF2731E55E7D6781F3D4BF45EE7ADF2D2FB3402" ] 6 => array:2 [ "Account" => "rfQtB8m51sdbWgcmddRX2mMjMpSxzX1AGr" "PublicKey" => "EDDF197FC59A7FAA09EB1AD60A4638BA6201DD51497B5C08A1745115098E229E0E" ] ] ] ] */
获取多个账本之间的报告
use XRPLWin\UNLReportReader\UNLReportReader; $reader = new UNLReportReader('https://xahau-test.net'); //ledger start, ledger end $response = $reader->fetchRange(6100000, 6200000); //array
检查账本边缘(不完整的结果)
当检查账本边缘时,例如,您请求了一个尚不存在的账本索引,这是检查存在性的方法
对于单个账本
//this will return null if ledger_index is out of range $response = $reader->fetchSingle(9873344); if($response === null) { //Incomplete result }
对于多个账本
$requested_limit = 10; //this will return less results than requested if some or all ledgers are out of range $response = $reader->fetchMulti(9873344,true,$requested_limit); if(count($response) != $requested_limit) { //Incomplete result }
对于范围
$fromLedgerIndex = 6100000; $toLedgerIndex = 6200000; //this will give you exact limit that will be sent to ->fetchMulti() method $calculated_limit = UNLReportReader::calcNumFlagsBetweenLedgers( UNLReportFlagLedger::nextOrCurrent($fromLedgerIndex), UNLReportFlagLedger::nextOrCurrent($toLedgerIndex) ); $response = $reader->fetchRange($fromLedgerIndex, $toLedgerIndex); //array if(count($response) != $calculated_limit) { //Incomplete result }
特别感谢
@richardAH - 感谢🙏深入的说明和支持。
@dangell7 - 感谢🙏宝贵的见解。