-
Notifications
You must be signed in to change notification settings - Fork 55
Fix JSON parameter parsing in warnet bitcoin rpc command #725
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: main
Are you sure you want to change the base?
Fix JSON parameter parsing in warnet bitcoin rpc command #725
Conversation
5b3383a
to
8557356
Compare
Expected this to work:
It did work with slashes: |
Another thing that may be out of scope for this PR is there can be a swallowed error for example this beast, which I'd love to see working at some point:
|
src/warnet/bitcoin.py
Outdated
@@ -346,3 +384,96 @@ def to_jsonable(obj: str): | |||
return obj.hex() | |||
else: | |||
return obj | |||
|
|||
|
|||
def _reconstruct_json_params(params: list[str]) -> list[str]: |
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.
This seems like a lot of work, implementing our own JSON parsing? Did you try any other approaches? Is there a better way to get the raw input string from click
perhaps?
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 will adjust the changes..thank you for the review
I cherry-picked the lint fix to main, if you wanna rebase to run ci |
- Add _reconstruct_json_params() function to handle JSON parameters split by shell parsing - Update _rpc() to properly process JSON arrays and primitive values for bitcoin-cli - Fix issue where shell parsing would break JSON parameters into separate arguments - Handle edge cases like unquoted string arrays [network] -> [network] - Maintain backward compatibility with non-JSON parameters This fixes the issue where commands like: warnet bitcoin rpc tank-0000 getnetmsgstats '[network]' would fail due to shell parsing breaking the JSON array. Fixes bitcoin-dev-project#714
fb816d4
to
86c22e6
Compare
- Accepts JSON params with or without backslash-escaped quotes (e.g. '[http]' and '["http"]') - Wraps JSON params in single quotes for correct shell and bitcoin-cli parsing
7d22984
to
8449337
Compare
The following is fixed:
|
…hods - Fix getblock '[blockhash]' issue by extracting first element from JSON arrays - Maintain backward compatibility for plain string parameters - Support JSON arrays as-is for methods like logging and importdescriptors - Extract only first element for single-parameter methods (getblock, getblockhash, gettransaction) - Extract all elements for multi-parameter methods - Fix malformed JSON patterns with escaped quotes
For the long importdescriptors command you mentioned, a few potential solutions could be explored in a future PR: |
I still don't think we need to maintain our own JSON parsing code like this. I think the issue in #714 is that |
Description
This PR addresses issue #714 by implementing JSON parameter handling for the
warnet bitcoin rpc
command. Currently, the command fails when users attempt to pass JSON parameters due to missing parameter processing logic.Problem Analysis
The issue manifests when users attempt to pass JSON parameters to Bitcoin Core RPC methods:
Root Cause: The current
_rpc()
function has incorrect parameter handling:params: str
but should beparams: List[str]
[146cc34515ae4ad2e938c4b8a899ac2889b37f603e9bba51854eb14540250805]
instead of the actual hashTechnical Solution
Parameter Type Fix
params: str
toparams: List[str]
to properly handle multiple argumentsJSON Reconstruction Logic
Add
_reconstruct_json_params()
function that:[network]
→["network"]
)RPC Parameter Processing
Enhance
_rpc()
function with:Verification
Current Behavior (Broken)
Expected Behavior (After Fix)
Impact
This fix will enable:
Files Modified
src/warnet/bitcoin.py
: Fix parameter type and add JSON reconstruction logicFixes #714