refactor(kaspa-tools): improve error handling and API design#414
Merged
danwt merged 1 commit intodanwt/claude/roundtrip-dryfrom Dec 18, 2025
Merged
Conversation
- 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
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>
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
Improvements to PR #413 addressing code review feedback.
Changes
unwrap()panics with proper error propagation using?operatordo_roundtrip()return type fromResult<bool>toResult<()>- the bool was redundant since failure is now represented by the Err variantlet-elsepattern instead of nestedmatchfor cleaner control flowpub modto privatemodto minimize public API surface (onlyroundtripmodule needs to be public)Review feedback addressed
From the code review:
SimandRoundtripcommandsResult<bool>return type whenResult<()>sufficeslet-elseTest plan
cargo check -p kaspa-toolscompiles with no errors🤖 Generated with Claude Code