Skip to content

fix: Serialize MPToken UInt64 amounts as base-10 strings#3139

Open
ckeshava wants to merge 7 commits into
XRPLF:developfrom
ckeshava:updateAmtReprToStr
Open

fix: Serialize MPToken UInt64 amounts as base-10 strings#3139
ckeshava wants to merge 7 commits into
XRPLF:developfrom
ckeshava:updateAmtReprToStr

Conversation

@ckeshava

@ckeshava ckeshava commented Jul 7, 2026

Copy link
Copy Markdown

Summary

The account_mptokens and account_mpt_issuances RPCs emitted MPToken amount fields as JSON numbers. Because many JSON parsers back numbers with IEEE-754 doubles, any value greater than 2^53 was silently rounded, so clients could not recover the exact on-ledger amount.

This change serializes the affected UInt64 amount fields as base-10 JSON strings, matching rippled's STUInt64::getJson behavior so Clio's output is consistent with the reference implementation:

  • account_mptokens: mpt_amount, locked_amount
  • account_mpt_issuances: maximum_amount, outstanding_amount, locked_amount

Changes

  • Serialize the UInt64 amount fields via xrpl::STUInt64{field, value}.getJson(...) instead of inserting the raw integer into the JSON object, so the encoding matches rippled's string representation exactly.
  • Add regression tests in both handlers asserting that large amounts (2^63 - 1, 2^53 + 1, and an odd value > 2^53) round-trip as exact strings.

Test plan

  • New unit tests: RPCAccountMPTokensHandlerTest.LargeAmountsSerializedAsStrings and RPCAccountMPTokenIssuancesHandlerTest.LargeAmountsSerializedAsStrings.
  • Existing MPToken handler tests updated to expect string-typed amount fields.

Notes

mpt_holders already serializes mpt_amount correctly via STUInt64::getJson; all other handlers that expose ledger UInt64 fields (e.g. vault_info, get_aggregate_price, gateway_balances) route through rippled's own serialization or STAmount, so they were already emitting strings and are unaffected.

🤖 Generated with Claude Code

…ision of very large numbers (greater than 2^53). This commit returns a string representation instead of Number representation in the RPC outputs to solve this issue.
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.66%. Comparing base (52d28f8) to head (560501a).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3139   +/-   ##
========================================
  Coverage    82.65%   82.66%           
========================================
  Files          398      398           
  Lines        16118    16127    +9     
  Branches      8443     8450    +7     
========================================
+ Hits         13323    13331    +8     
  Misses        1674     1674           
- Partials      1121     1122    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckeshava

ckeshava commented Jul 8, 2026

Copy link
Copy Markdown
Author

/ai-reviewer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant