Skip to content

fix(sdk): allow fractional RTC amount and fee in CLI wallet send (#8564) - #8598

Open
ArtyormSatori wants to merge 2 commits into
Scottcjn:mainfrom
ArtyormSatori:fix/cli-wallet-send-fractional-rtc-8564
Open

ArtyormSatori wants to merge 2 commits into
Scottcjn:mainfrom
ArtyormSatori:fix/cli-wallet-send-fractional-rtc-8564

Conversation

@ArtyormSatori

Copy link
Copy Markdown
Contributor

BCOS Checklist (Required For Non-Doc PRs)

  • Add a tier label: BCOS-L1 or BCOS-L2 (also accepted: bcos:l1, bcos:l2)
  • If adding new code files, include SPDX header near the top (example: # SPDX-License-Identifier: MIT)
  • Provide test evidence (commands + output or screenshots)

Summary

Fixes #8564: rustchain wallet send CLI command rejects fractional amounts (e.g. 0.5 RTC) and fees with Invalid value for 'AMOUNT': '0.5' is not a valid integer.

What Changed

  • In sdk/python/rustchain_sdk/cli.py:
    • Updated @click.argument("amount", type=float) in wallet_send (previously type=int).
    • Updated @click.option("--fee", type=float, default=0.0) in wallet_send (previously type=int, default=0).
    • Updated type annotations in wallet_send and _wallet_send from int to float.
  • In sdk/python/rustchain_sdk/tests/test_cli.py:
    • Added unit test suite TestCliWalletSend covering fractional amount and fee, integer amount compatibility, JSON output format, and invalid non-numeric validation.

Testing / Evidence

Test execution with pytest:

$ pytest sdk/python/rustchain_sdk/tests/test_cli.py
============================= test session starts ==============================
collected 5 items

sdk/python/rustchain_sdk/tests/test_cli.py::TestCliWalletSend::test_wallet_send_accepts_fractional_amount_and_fee PASSED [ 20%]
sdk/python/rustchain_sdk/tests/test_cli.py::TestCliWalletSend::test_wallet_send_accepts_integer_amount_and_default_fee PASSED [ 40%]
sdk/python/rustchain_sdk/tests/test_cli.py::TestCliWalletSend::test_wallet_send_json_output PASSED [ 60%]
sdk/python/rustchain_sdk/tests/test_cli.py::TestCliWalletSend::test_wallet_send_rejects_non_numeric_amount PASSED [ 80%]
sdk/python/rustchain_sdk/tests/test_cli.py::TestCliWalletSend::test_wallet_send_rejects_non_numeric_fee PASSED [100%]

============================== 5 passed in 0.13s ===============================

Full SDK test suite:

================ 106 passed in 0.56s ================

CLI mechanical verification:

  • Before:
    $ python -m rustchain_sdk.cli wallet send <from> <to> 0.5 --fee 0.01
    Error: Invalid value for 'AMOUNT': '0.5' is not a valid integer.

  • After:
    $ python -m rustchain_sdk.cli wallet send <from> <to> 0.5 --fee 0.01
    Amount and fee are accepted as floats and submitted to the signed transfer endpoint.

  • Claimant: @ArtyormSatori

  • Native RTC Wallet: RTC22ad34877d8c24944c0601a8594e9d8166e8bc56

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

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!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/L PR: 201-500 lines labels Oct 29, 2026

@Scottcjn Scottcjn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding fractional sends. Amounts that get signed can't go through binary floats:

  1. Parse amount and fee as Decimal (or integer base units) and refuse any value that isn't exact at chain scale before signing. 0.01 as a float is not 0.01, and the test currently asserts the float value.
  2. Reject non-finite values, amount <= 0 and fee < 0 before sign/submit.
  3. HTTP 200 with status: "pending" shouldn't exit 0 as a completed send. Report it as pending and use a distinct exit code, or wait for settlement.

Please add tests for each rejection case.

ArtyormSatori pushed a commit to ArtyormSatori/Rustchain that referenced this pull request Nov 3, 2026
@github-actions github-actions Bot added BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) wallet Wallet/transfer related size/XL PR: 500+ lines and removed size/L PR: 201-500 lines labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This PR is quite large (XL). Consider splitting into smaller, focused PRs for faster review. Large PRs take longer to review and have higher risk of issues.

@ArtyormSatori

Copy link
Copy Markdown
Contributor Author

Addressed all review points in e0c85dc:

  • Parsed amount and fee as Decimal, rejecting values exceeding chain precision (maximum 6 decimal places / micro-RTC). Asserted Decimal values in test suite instead of float approximations.
  • Rejected non-finite values (NaN, Inf), amount <= 0, and fee < 0 before sign and submission.
  • Handled HTTP 200 with status 'pending' by reporting pending status and exiting with code 2 (EXIT_PENDING) in both human-readable and JSON modes.
  • Added comprehensive unit tests for each rejection case and pending status handling; all pass.

ArtyormSatori pushed a commit to ArtyormSatori/Rustchain that referenced this pull request Nov 3, 2026
@ArtyormSatori
ArtyormSatori force-pushed the fix/cli-wallet-send-fractional-rtc-8564 branch from 714edad to 1aa74e5 Compare November 3, 2026 03:22
Scottcjn added a commit that referenced this pull request Nov 19, 2026
…ounts (fixes #8618) (#8623)

RustChainWallet.sign_transfer took float(amount)/float(fee) with no
precision check. The node stores balances as integer micro-RTC
(amount_i64, ACCOUNT_UNIT=1_000_000) and quantizes amount_rtc with
Decimal(str(x)) rounded DOWN (node/payout_preflight.py), so anything
finer than 0.000001 RTC was signed by the user and then silently
dropped by the node.

- new rustchain_sdk.amounts: to_micro_rtc() parses str/int/Decimal/float
  exactly (floats via their shortest repr), rejects non-finite, negative,
  zero amounts, >6 decimal places and values >= 1e9 RTC (beyond which
  the float wire format can no longer carry 6 exact decimals)
- sign_transfer validates before signing and derives the wire/signature
  float from the exact integer; returns amount_i64/fee_i64; drops a
  duplicate 'fee' dict key; payload is now JSON-safe for Decimal input
- exported to_micro_rtc / micro_rtc_to_str / MICRO_RTC_PER_RTC so the
  CLI (#8564 work) can parse user input with the same rules
- tests include a cross-check against node/payout_preflight.py: same
  amount_i64 and a byte-identical rebuilt signed message

cli.py is deliberately untouched to avoid colliding with the open
#8564 PRs (#8598, #8610).

Co-authored-by: Scott <scottbphone12@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…n#8564)

- Update Click argument amount to type=float in wallet send command
- Update --fee option to type=float with default=0.0
- Update type annotations in wallet_send and _wallet_send
- Add CLI unit tests covering fractional and integer values, JSON output, and validation
@ArtyormSatori
ArtyormSatori force-pushed the fix/cli-wallet-send-fractional-rtc-8564 branch from 1aa74e5 to cfc92a7 Compare November 26, 2026 18:23

This branch has not been deployed

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

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) size/XL PR: 500+ lines wallet Wallet/transfer related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK CLI rejects fractional RTC amount and fee before sending

3 participants