@@ -24,7 +24,7 @@ def bitcoin():
2424@bitcoin .command (context_settings = {"ignore_unknown_options" : True })
2525@click .argument ("tank" , type = str )
2626@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
2828@click .option ("--namespace" , default = None , show_default = True )
2929def rpc (tank : str , method : str , params : list [str ], namespace : Optional [str ]):
3030 """
@@ -39,12 +39,28 @@ def rpc(tank: str, method: str, params: list[str], namespace: Optional[str]):
3939
4040
4141def _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
4244 namespace = get_default_namespace_or (namespace )
4345
4446 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 (
54+ param_str .startswith ("'" )
55+ and param_str .endswith ("'" )
56+ or param_str .startswith ('"' )
57+ and param_str .endswith ('"' )
58+ ):
59+ param_str = param_str [1 :- 1 ]
60+ cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } { shlex .quote (param_str )} "
61+ else :
62+ # For non-JSON arguments, use simple space joining
63+ cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } { param_str } "
4864 else :
4965 cmd = f"kubectl -n { namespace } exec { tank } --container { BITCOINCORE_CONTAINER } -- bitcoin-cli { method } "
5066
0 commit comments