Skip to content

Commit 51c16ba

Browse files
committed
optimize JSON parameter handling
1 parent 7dbbe60 commit 51c16ba

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/warnet/bitcoin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ def rpc(tank: str, method: str, params: list[str], namespace: Optional[str]):
3939

4040

4141
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
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+
# Check if any parameter looks like JSON (starts with [ or {)
48+
has_json = any(p.strip().startswith("[") or p.strip().startswith("{") for p in params)
49+
if has_json:
50+
# For JSON parameters, use shell escaping to preserve the structure
51+
bitcoin_cli_args = " ".join(shlex.quote(p) for p in params)
52+
else:
53+
# For non-JSON parameters, use simple space joining
54+
bitcoin_cli_args = " ".join(map(str, params))
55+
4756
cmd = f"kubectl -n {namespace} exec {tank} --container {BITCOINCORE_CONTAINER} -- bitcoin-cli {method} {bitcoin_cli_args}"
4857
else:
4958
cmd = f"kubectl -n {namespace} exec {tank} --container {BITCOINCORE_CONTAINER} -- bitcoin-cli {method}"

0 commit comments

Comments
 (0)