Skip to content

Commit 5100b0a

Browse files
committed
bitcoin: add ns to rpc
1 parent f0b2d4b commit 5100b0a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/warnet/bitcoin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from datetime import datetime
66
from io import BytesIO
7+
from typing import Optional
78

89
import click
910
from test_framework.messages import ser_uint256
@@ -24,23 +25,24 @@ def bitcoin():
2425
@click.argument("tank", type=str)
2526
@click.argument("method", type=str)
2627
@click.argument("params", type=str, nargs=-1) # this will capture all remaining arguments
27-
def rpc(tank: str, method: str, params: str):
28+
@click.option("--namespace", default=None, show_default=True)
29+
def rpc(tank: str, method: str, params: str, namespace: Optional[str]):
2830
"""
2931
Call bitcoin-cli <method> [params] on <tank pod name>
3032
"""
3133
try:
32-
result = _rpc(tank, method, params)
34+
result = _rpc(tank, method, params, namespace)
3335
except Exception as e:
3436
print(f"{e}")
3537
sys.exit(1)
3638
print(result)
3739

3840

39-
def _rpc(tank: str, method: str, params: str):
41+
def _rpc(tank: str, method: str, params: str, namespace: Optional[str] = None):
4042
# bitcoin-cli should be able to read bitcoin.conf inside the container
4143
# so no extra args like port, chain, username or password are needed
42-
namespace = get_default_namespace()
43-
44+
if not namespace:
45+
namespace = get_default_namespace()
4446
if params:
4547
cmd = f"kubectl -n {namespace} exec {tank} --container {BITCOINCORE_CONTAINER} -- bitcoin-cli {method} {' '.join(map(str, params))}"
4648
else:

0 commit comments

Comments
 (0)