Skip to content

Commit d14bb22

Browse files
committed
bitcoin: add ns to rpc
1 parent 2b4e28e commit d14bb22

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
@@ -3,6 +3,7 @@
33
import sys
44
from datetime import datetime
55
from io import BytesIO
6+
from typing import Optional
67

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

3739

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

0 commit comments

Comments
 (0)