承接 xrplwin/unlreportreader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

xrplwin/unlreportreader

Composer 安装命令:

composer require xrplwin/unlreportreader

包简介

Fetches and parses UNLReports on Xahau network.

README 文档

README

main workflow GitHub license Total Downloads

UNLReport Reader

Fetches UNLReports on Xahau network.

This is PHP package where you can provide flag ledger and script will parse and return final validator report. For requested ledger_index script will return final UNLReport state for that ledger_index.

Requirements

Installation

composer require xrplwin/unlreportreader

Ranges

When fetching ledger index report data, each ledger index % 256 is flag ledger. At flag ledger UNLReport is still not applied, UNLReport is applied from next ledger (next 256 ledgers including last flag ledger). See table below to understand ranges when querying specific ledger index.

Viewing ledger_index Applied from Applied to
... ... ...
256 (flag) 1 256
... ... ...
510 (flag-2) 257 512
511 (flag-1) 257 512
512 (flag) 257 512
513 (flag+1) 513 768
514 (flag+2) 513 768
... ... ...

Usage sample

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);
// ...

Fetching multiple reports

This is more optimized way to fetch multiple reports than doing loop and using fetchSingle(), since this script uses Promises to asynchronously query node in batches, default batch limit is 10 but can be configured manually.

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"
      ]
    ]
  ]
]
*/

Fetching multiple reports between ledgers

use XRPLWin\UNLReportReader\UNLReportReader;

$reader = new UNLReportReader('https://xahau-test.net');

//ledger start, ledger end
$response = $reader->fetchRange(6100000, 6200000); //array

Checking ledger edge (incomplete results)

When checking ledger edge, eg. you requested ledger index that does not yet exists this is how will you check existance:

For single ledger

//this will return null if ledger_index is out of range
$response = $reader->fetchSingle(9873344);
if($response === null) {
  //Incomplete result
}

For multiple ledgers

$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
}

For range

$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
}

Special thanks

@richardAH - Thank you 🙏 for in-depth explanation and support.
@dangell7 - Thank you 🙏 for great insight.

xrplwin/unlreportreader 适用场景与选型建议

xrplwin/unlreportreader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 86 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「package」 「php」 「parser」 「composer」 「report」 「transaction」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 xrplwin/unlreportreader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 xrplwin/unlreportreader 我们能提供哪些服务?
定制开发 / 二次开发

基于 xrplwin/unlreportreader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 86
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-30