Repository navigation
fix(sdk): parse amount_rtc and amount_i64 in CLI wallet balance (#8580) - #8596
Open
ArtyormSatori wants to merge 3 commits into
Open
ArtyormSatori wants to merge 3 commits into
ArtyormSatori wants to merge 3 commits into
Conversation
Contributor
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
Scottcjn
requested changes
Nov 3, 2026
Scottcjn
left a comment
Owner
There was a problem hiding this comment.
Thanks for this. The balance output needs to be strict, since people act on it:
- Accept only a finite numeric balance. Today
true,nan,infor a non-numeric string inamount_rtc/balance_rtc/balanceprints as a balance. Convertingamount_i64throughfloatalso loses precision; use integer micro-RTC orDecimal. - When both
amount_rtcandamount_i64are present and disagree, error out rather than silently picking one. - A missing balance or nonce should exit non-zero instead of printing
unavailable/ inventingNonce: 0with exit 0. Also check that the response'sminer_idmatches the address that was asked for.
…d without precision loss - Require finite numeric balance and reject boolean, NaN, Inf, and non-numeric strings - Use Decimal arithmetic for amount_i64 parsing to avoid float precision loss - Error out when amount_rtc and amount_i64 disagree - Exit non-zero when balance or nonce is missing instead of inventing defaults - Validate that response miner_id/address matches the requested query address - Add comprehensive test suite covering all validation branches
Contributor
Author
|
Addressed all review points in b501c14:
|
elvergon8888
reviewed
Nov 5, 2026
elvergon8888
left a comment
There was a problem hiding this comment.
Revisando el parseo de montos:
- Puntos correctos: La prioridad
amount_rtc→balance→amount_i64 / 1e6es correcta para mantener la retrocompatibilidad. - Sugerencia (Testing): Falta un test unitario específico que pruebe la rama donde viene
amount_i64pero no vieneamount_rtc, para asegurar que la división entre 1e6 se aplica correctamente y no se rompe en el futuro.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8580:
rustchain wallet balance <address>displaying0 RTCfor funded wallets when connected to canonical RustChain nodes.Problem Statement
In
sdk/python/rustchain_sdk/cli.py,_wallet_balancelooked strictly forresult.get("balance", 0).However, canonical RustChain node balance responses (from
GET /wallet/balance) return:{ "amount_i64": 1000000, "amount_rtc": 1.0, "miner_id": "RTC..." }Because the legacy
"balance"key is absent,result.get("balance", 0)evaluated to0, displayingBalance: 0 RTCeven for wallets with positive balances.Solution
amount_rtcas the primary balance field if present.amount_rtcfirst.balance_rtcor legacybalanceif present.amount_i64 / 1_000_000if numericamount_i64is provided.unavailableif no recognized balance field is returned in the payload instead of misleadingly printing0 RTC.sdk/python/rustchain_sdk/tests/test_cli.pycovering canonicalamount_rtc, legacybalance/nonce,amount_i64conversion,unavailabledisplay, and the--jsonoutput flag.Verification
Ran test suite against canonical mock endpoints:
Live CLI verification against
https://rustchain.org:Before:
Balance: 0 RTCAfter:
Balance: 1.0 RTCClaimant: @ArtyormSatori
Native RTC Wallet:
RTC22ad34877d8c24944c0601a8594e9d8166e8bc56