-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Add standardized JSON output utilities #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
feat: Add standardized JSON output utilities #781
Conversation
thewhaleking
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, but you're neglecting a few key features: json_console is used widely, so this should be applied to everything, and all transaction commands include an extrinsic identifier.
|
Thanks for the feedback! I'll expand this to cover all json_console usages and add extrinsic_identifier to all transaction commands. Will push updates shortly. |
…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 opentensor#781 to apply standardized
JSON output to all json_console usages with extrinsic_identifier support.
Closes opentensor#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 opentensor#781 to apply standardized
JSON output to all json_console usages with extrinsic_identifier support.
Closes opentensor#635
92b056d to
0cbe07e
Compare
|
Also this is opened against |
|
Done, changed the base branch to staging. |
This PR introduces a centralized json_utils module to standardize JSON output across all btcli commands, addressing the inconsistencies noted in issue opentensor#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 opentensor#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 opentensor#781 to apply standardized
JSON output to all json_console usages with extrinsic_identifier support.
Closes opentensor#635
0cbe07e to
10b292d
Compare
|
@thewhaleking I hope my update will be helpful for you, could you please review my PR? |
Summary
This PR introduces a centralized
json_utilsmodule to standardize JSON output across all btcli commands, addressing the inconsistencies noted in issue #635.Problem
json.dumps(),print_json(), hardcoded strings)errorvserr_msgvsmessage)"error": ""instead of omitting the fieldSolution
Add
bittensor_cli/src/bittensor/json_utils.pywith standardized helpers:json_response()- Base response formatterjson_success()- Success response helperjson_error()- Error response helperjson_transaction()- Transaction response helperserialize_balance()- Consistent Balance serializationStandard Response Format
{ "success": true, "data": { ... } }{ "success": false, "error": "Error message" }Changes
bittensor_cli/src/bittensor/json_utils.py- Standardized JSON utilitiesbittensor_cli/src/commands/wallets.py- Sample migration (3 functions)tests/unit_tests/test_json_utils.py- 21 comprehensive unit testsTest Plan
Migration Strategy
This PR establishes the foundation. Additional commands can be migrated incrementally in follow-up PRs to minimize review burden and risk.
Closes #635