xrplwin/xrpl-txmutationparser
Composer 安装命令:
composer require xrplwin/xrpl-txmutationparser
包简介
Parse XRPL transaction to context aware object.
README 文档
README
XRPL Transaction Mutation Parser for PHP
Demo
See this in action on XRPLWin Playground
Description
Parse XRPL transaction to context aware object for visual representation. It takes a XRPL transaction (outcome, meta) and an XRPL account. The XRPL account is the context from which the XPRL transaction is to be interpreted.
The account can be the sender, recipient, or an intermediate account. An intermediate account applies if e.g. there's a trade happening, touching your own offer asynchronously. You put up an offer and at some point down the road it gets (possibly partially) consumed. Alternatively, you can be an Intermediate account if you are a regular key signer or if something is rippling through your account.
The lib. then parses everything, performs all logic (include fee or not, etc.) and returns an object that is ready for use in e.g. an event list, or transaction details view, with all relevant objects parsed & calculated.
This is PHP port of https://github.com/XRPL-Labs/TxMutationParser by @XRPL Labs
Note
This package is provided as is, please test it yourself first.
Found a bug? Report issue here
Requirements
- PHP 8.1 or higher
- Composer
Installation
To install run
composer require xrplwin/xrpl-txmutationparser
Usage
use XRPLWin\XRPLTxMutatationParser\TxMutationParser; $referenceAccount = "rA..."; $tx = (object)[ // Full XRPL transaction, containing Account, Destination, meta, ...) "Account": "rA...", "Amount": "100300000", "Destination": "rD....", "Fee": "10000", ... "meta" => [ ... ], ... ]; //Enable to include trading fees calculation in allBalanceChanges results $calculateTradingFees = false; $TxMutationParser = new TxMutationParser($referenceAccount, $tx, $calculateTradingFees); $parsedTransaction = $TxMutationParserRef->result(); print_r($parsedTransaction);
A sample response (as JSON):
{ self: { feePayer: true, account: 'rA...', balanceChangesExclFee: [ [Object], [Object], ... ], balanceChanges: [ [Object], [Object], ... ], tradingFees: [ [Object], ... ] //Optional }, type: 'TRADE', eventList: { primary: { ... }, secondary: { ... }, }, eventFlow: { start: { account: 'rB...', mutation: [Object] }, intermediate: { account: 'rA...', mutations: {'in' => ?Object, 'out' => ?Object} }, end: { account: 'rC...', mutation: [Object] } }, allBalanceChanges: { rB: [ [Object], [Object], ... ], rA: [ [Object], [Object], ... ], rC: [ [Object], ... ] } }
Scenario's (data contents)
Event List (eventList, e.g. a list with transactions belonging to the context account)
If no balance changes to your context account applied: empty. If only one relevant change (e.g. payment in / out): only the eventList.primary object exists. If a trade happened and your account both sent and received / exchanged something, the eventList.primary object is the main balance change. For reference, the eventList.secondary value can be displayed as well.
eventList.secondary.counterparty can be array of counterparties if viewing account is issuer and multi balances of currency is adjusted (rippled) trough multiple parties (see sample here) where eventList.secondary.value is SUM of balance changes of that currency - this behaviour is different from XRPL Labs package.
A common scenario where the eventList is completely empty, is if your context account is eg. the account an issued currency
rippled through, or the context account is the regular key, signing the transaction parsed.
Event Flow (eventFlow, e.g. transaction details page viewed by the context account)
The eventFlow object can contain a eventFlow.start, eventFlow.intermediate and eventFlow.end object. The start and end object can contain a mutation (one, so e.g. eventFlow.start.mutation).
The eventFlow.intermediate object can contain multiple mutations, an in and out (or only in, or (more commonly) only out) mutation: eventFlow.intermediate.mutations.in / eventFlow.intermediate.mutations.out.
The eventFlow object can contain only a intermediate object (so no start and end object) if:
- The transaction is of the mutation type
SET(e.g. Regular Key set, AccountSet, putting up an XRPL offer, etc.) - The context account is the issuer of a transaction, and the transaction is rippling through
- The context account is the signer using a regular key, and no balance changes apply to the context account
Display logic:
Always show then in this order (if present)
- start
- intermediate
- end
... And only (but always) show them if they are present.
Balance changes (allBalanceChanges)
All Balance Changes returns balance changes for every participant. If calculateTradingFees enabled, balance changes also include trading fee calculations.
Running tests
Run all tests in "tests" directory.
composer test
or
./vendor/bin/phpunit --testdox
xrplwin/xrpl-txmutationparser 适用场景与选型建议
xrplwin/xrpl-txmutationparser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 201 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「parser」 「composer」 「transaction」 「ripple」 「mutation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xrplwin/xrpl-txmutationparser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xrplwin/xrpl-txmutationparser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xrplwin/xrpl-txmutationparser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Laravel integration for the jsonapi.org parser
统计信息
- 总下载量: 201
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-03