Skip to content

refactor(kaspa-tools): improve error handling and API design#414

Merged
danwt merged 1 commit intodanwt/claude/roundtrip-dryfrom
danwt/claude/roundtrip-dry-improvements
Dec 18, 2025
Merged

refactor(kaspa-tools): improve error handling and API design#414
danwt merged 1 commit intodanwt/claude/roundtrip-dryfrom
danwt/claude/roundtrip-dry-improvements

Conversation

@danwt
Copy link
Copy Markdown

@danwt danwt commented Dec 18, 2025

Summary

Improvements to PR #413 addressing code review feedback.

Changes

  • Consistent error handling: Replace unwrap() panics with proper error propagation using ? operator
  • Cleaner API: Change do_roundtrip() return type from Result<bool> to Result<()> - the bool was redundant since failure is now represented by the Err variant
  • Idiomatic Rust: Use let-else pattern instead of nested match for cleaner control flow
  • Reduced visibility: Changed unnecessary pub mod to private mod to minimize public API surface (only roundtrip module needs to be public)

Review feedback addressed

From the code review:

  1. ✅ Major abandoned: includes solana changes #1: Inconsistent error handling between Sim and Roundtrip commands
  2. ✅ Major DYMENSION: add memo fields to outbound ERC20 Collateral and Synthetic transfers, and Native transfers.  #2: Result<bool> return type when Result<()> suffices
  3. ✅ Major Partially improve Solana <-> Dym e2e #3: Nested match could use let-else
  4. ✅ Major demonstrate what duc will e2e test #4: Over-exported internal modules

Test plan

  • Verified cargo check -p kaspa-tools compiles with no errors

🤖 Generated with Claude Code

- Replace unwrap() panics with proper error propagation in sim command
- Change do_roundtrip() return type from Result<bool> to Result<()>
- Use let-else pattern instead of nested match for cleaner control flow
- Reduce module visibility to minimize public API surface
- Consistent error handling style across Sim and Roundtrip commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@danwt danwt merged commit 7a6173f into danwt/claude/roundtrip-dry Dec 18, 2025
1 check passed
danwt added a commit that referenced this pull request Dec 18, 2025
* claude: feat(kaspa-tools): add DRY roundtrip command

Add `kaspa-tools sim roundtrip` command for single roundtrip testing
(deposit from Kaspa to Hub, then withdraw back) that properly reuses
existing infrastructure instead of duplicating code.

Changes:
- Extract `create_cosmos_provider` and `now_millis` to shared `util.rs`
- Create `CommonBridgeArgs` for shared CLI argument configuration
- Update `SimulateTrafficCli` to use `CommonBridgeArgs` via flatten
- Add new `roundtrip.rs` that wraps existing `do_round_trip()` logic
- Make whale pool fields public for single-use construction

The new roundtrip command achieves the same functionality as PR #407
but in ~250 lines instead of ~500, by reusing the existing stress test
infrastructure rather than reimplementing balance polling, withdrawal
messages, and provider creation.

Usage:
  kaspa-tools sim roundtrip \
    --kaspa-wallet-secret <secret> \
    --hub-priv-key <hex> \
    --timeout 300 \
    --domain-kas <n> --domain-hub <n> \
    --token-kas-placeholder <h256> --token-hub <h256> \
    --escrow-address <kaspa-addr> \
    --kaspa-wrpc-url <url> --kaspa-rest-url <url> \
    --hub-rpc-url <url> --hub-grpc-url <url> \
    --hub-chain-id <id> --hub-prefix dym --hub-denom adym \
    --hub-decimals 18 \
    --deposit-amount <sompi> --withdrawal-fee-pct 0.01 \
    --kaspa-network testnet

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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

* refactor: make roundtrip a top-level command

* refactor: simplify roundtrip with progress output

* claude: refactor(kaspa-tools): improve error handling and API design (#414)

- Replace unwrap() panics with proper error propagation in sim command
- Change do_roundtrip() return type from Result<bool> to Result<()>
- Use let-else pattern instead of nested match for cleaner control flow
- Reduce module visibility to minimize public API surface
- Consistent error handling style across Sim and Roundtrip commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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