feat: Add standardized JSON output utilities#781
Open
DanielDerefaka wants to merge 5 commits intoopentensor:stagingfrom
Open
feat: Add standardized JSON output utilities#781DanielDerefaka wants to merge 5 commits intoopentensor:stagingfrom
DanielDerefaka wants to merge 5 commits intoopentensor:stagingfrom
Conversation
thewhaleking
requested changes
Dec 22, 2025
Contributor
thewhaleking
left a comment
There was a problem hiding this comment.
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.
Author
|
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. |
DanielDerefaka
added a commit
to DanielDerefaka/btcli
that referenced
this pull request
Dec 22, 2025
…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
DanielDerefaka
added a commit
to DanielDerefaka/btcli
that referenced
this pull request
Dec 22, 2025
…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
Contributor
|
Also this is opened against |
Author
|
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
Author
|
@thewhaleking I hope my update will be helpful for you, could you please review my PR? |
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.
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
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
Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=101010297