@@ -24,7 +24,7 @@ def bitcoin():
24
24
@bitcoin .command (context_settings = {"ignore_unknown_options" : True })
25
25
@click .argument ("tank" , type = str )
26
26
@click .argument ("method" , type = str )
27
- @click .argument ("params" , type = str , nargs = - 1 ) # this will capture all remaining arguments
27
+ @click .argument ("params" , type = click . UNPROCESSED , nargs = - 1 ) # get raw unprocessed arguments
28
28
@click .option ("--namespace" , default = None , show_default = True )
29
29
def rpc (tank : str , method : str , params : list [str ], namespace : Optional [str ]):
30
30
"""
@@ -39,12 +39,23 @@ def rpc(tank: str, method: str, params: list[str], namespace: Optional[str]):
39
39
40
40
41
41
def _rpc (tank : str , method : str , params : list [str ], namespace : Optional [str ] = None ):
42
+ # bitcoin-cli should be able to read bitcoin.conf inside the container
43
+ # so no extra args like port, chain, username or password are needed
42
44
namespace = get_default_namespace_or (namespace )
43
45
44
46
if params :
45
- # Shell-escape each param to preserve quotes and special characters
46
- bitcoin_cli_args = " " .join (shlex .quote (p ) for p in params )
47
- cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } { bitcoin_cli_args } "
47
+ # Check if this looks like a JSON argument (starts with [ or {)
48
+ param_str = " " .join (params )
49
+ if param_str .strip ().startswith ("[" ) or param_str .strip ().startswith ("{" ):
50
+ # For JSON arguments, ensure it's passed as a single argument
51
+ # Remove any extra quotes that might have been added by the shell
52
+ param_str = param_str .strip ()
53
+ if param_str .startswith ("'" ) and param_str .endswith ("'" ) or param_str .startswith ('"' ) and param_str .endswith ('"' ):
54
+ param_str = param_str [1 :- 1 ]
55
+ cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } { shlex .quote (param_str )} "
56
+ else :
57
+ # For non-JSON arguments, use simple space joining
58
+ cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } { param_str } "
48
59
else :
49
60
cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } "
50
61
0 commit comments