Draft
Conversation
This PR introduces a centralized json_utils module to standardize JSON output across all btcli commands, addressing the inconsistencies noted in issue #635. Changes: - Add `bittensor_cli/src/bittensor/json_utils.py` with standardized helpers: - `json_response()` - Base response formatter - `json_success()` - Success response helper - `json_error()` - Error response helper - `json_transaction()` - Transaction response helper - `serialize_balance()` - Consistent Balance serialization - Update `wallets.py` with sample usage (3 functions updated as POC) - Add comprehensive unit tests (21 tests) for schema compliance Standard Response Format: ```json { "success": bool, "data": {...}, // Optional: command-specific data "error": str // Optional: error message } ``` This establishes the foundation for full migration of all commands to use consistent JSON schemas. Additional commands can be migrated incrementally. Closes #635
…identifier
- Add TransactionResult and MultiTransactionResult classes for consistent
transaction responses across all commands
- Add print_transaction_response() helper function
- Update schema to use {success, message, extrinsic_identifier} format
- Migrate wallets.py: transfer, swap_hotkey, set_id
- Migrate sudo.py: trim command
- Migrate stake/add.py and stake/remove.py
- Migrate liquidity.py: add_liquidity, remove_liquidity, modify_liquidity
- Update tests for new transaction response utilities (25 tests passing)
This addresses feedback from @thewhaleking on PR #781 to apply standardized
JSON output to all json_console usages with extrinsic_identifier support.
Closes #635
Complete migration of 169 json_console usages across 22 files to use the standardized print_json_data, print_transaction_response, and print_transaction_with_data utilities from json_utils.py. Files migrated: - crowd/*.py (6 files) - subnets/*.py (3 files) - stake/*.py (6 files) - wallets.py - sudo.py - proxy.py - liquidity/liquidity.py - axon/axon.py - weights.py - json_utils.py (added print_transaction_with_data helper)
Resolved conflicts in: - stake/auto_staking.py: Keep print_success, remove json_console (migrated) - wallets.py: Remove both err_console and json_console (unused after migration)
Migrated one more json_console.print_json call in proxy.py that came from upstream merge to use print_transaction_response instead.
# Conflicts: # bittensor_cli/src/commands/crowd/view.py # bittensor_cli/src/commands/stake/auto_staking.py # bittensor_cli/src/commands/wallets.py
…` arg to print_error and print_success for future consolidation
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.
Building upon #781