Skip to content

CLI: readable wallet commands (status, balance, address, send) - #896

Open
awizardxch wants to merge 1 commit into
xch-dev:mainfrom
awizardxch:feat/cli-wallet-commands
Open

awizardxch wants to merge 1 commit into
xch-dev:mainfrom
awizardxch:feat/cli-wallet-commands

Conversation

@awizardxch

Copy link
Copy Markdown
Contributor

A first increment for #397, following the steps Rigidity described there: convert user arguments into the sage-api types, call the RPC (several requests where a command needs them), and format the output into something more readable than JSON.

sage wallet

sage wallet status                 # wallet name and fingerprint, network, spendable balance, sync progress, receive address
sage wallet balance                # XCH, and every visible token with a balance
sage wallet address                # the current receive address
sage wallet send <address> <amount> [--fee 0.0001] [--asset <cat id>] [--memo "text"] [--yes]

--json on any of them prints the RPC responses instead. sage rpc <endpoint> '<json>' is unchanged.

How send stays safe

  • Exact amounts. 0.25 is parsed digit by digit at the asset's precision: 12 for XCH, read from the wallet's unit; a CAT's own from get_token. There's no floating point. More decimals than the asset has is an error, not a rounding. Signs, exponents, separators and overflow are refused. Unit tests cover all of these.
  • Preview what was built, then sign exactly that. The wallet first builds the transaction with auto_submit: false. The CLI prints what leaves the wallet, the fee and the number of coins spent, all read from the built transaction's summary rather than echoed from the arguments, so a wrong address or amount shows before anything is signed. On confirmation, the CLI signs and submits those same coin spends with sign_coin_spends. It never re-requests the send, which could select different coins than the ones shown.
  • No silent signing. Without a terminal to confirm on, send refuses unless --yes is given.
  • Text memos are hex-encoded the way the Send page does it. Token sends include the hint, which is the API default.

Also: the CLI no longer overflows its stack

On upstream main, a Windows debug build of sage overflows its stack on any command, sage --help included. The rpc command's clap tree (one subcommand per endpoint) and its handler future outgrow the 1 MiB main-thread stack. The CLI now runs on a 16 MiB thread, with the same size for the tokio workers. After the change, sage --help, sage wallet --help and sage rpc … all start normally.

Tests

  • cargo test -p sage-cli: 5 tests for amount parsing and formatting (exact parsing, refusing to round, refusing non-amounts and overflow, formatting without trailing zeros, round trips).
  • cargo clippy -p sage-cli --all-targets and cargo fmt --check are clean.
  • Checked by hand: sage --help, sage wallet --help, and sage rpc get_version reaching the client (no wallet RPC was running here, so it reports the connection error instead of crashing).

Next steps for #397 (not in this PR)

More commands in the same style: offers (make, take, cancel, list), NFTs, coin management (split, combine), and transactions. Plus a shared table/text formatter if the command count grows.

🤖 Generated with Claude Code

A first step for xch-dev#397: `sage wallet` takes arguments in the units people use
and prints output people can read, over the same RPC client `sage rpc` uses.

- status / balance / address: the logged-in wallet, sync progress, XCH and
  token balances, receive address. --json prints the RPC responses.
- send <address> <amount> [--fee] [--asset] [--memo] [--yes]: amounts in whole
  units, parsed exactly (no floating point; more decimals than the asset has
  is an error, not a rounding). The wallet builds the transaction unsubmitted,
  the CLI shows what leaves the wallet as read from that transaction, asks,
  then signs and submits those exact coin spends with sign_coin_spends. With
  no terminal to confirm on it refuses unless --yes is given.

The CLI also runs on a 16 MiB-stack thread: the rpc command's clap tree and
handler future overflowed the 1 MiB main stack of a Windows debug build, so
even `sage --help` crashed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant