Skip to content

Commit 04352d4

Browse files
committed
bitcoin: add primary container logic to rpc
1 parent 3298bc7 commit 04352d4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/warnet/bitcoin.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from test_framework.messages import ser_uint256
1111
from test_framework.p2p import MESSAGEMAP
1212

13-
from .k8s import get_default_namespace, get_mission
13+
from .k8s import get_default_namespace, get_mission, get_pod
1414
from .process import run_command
1515

1616

@@ -39,10 +39,19 @@ def _rpc(tank: str, method: str, params: str):
3939
# bitcoin-cli should be able to read bitcoin.conf inside the container
4040
# so no extra args like port, chain, username or password are needed
4141
namespace = get_default_namespace()
42+
43+
try:
44+
pod = get_pod(tank)
45+
container_names = [container.name for container in pod.spec.containers]
46+
container_name = container_names[0]
47+
except Exception as e:
48+
print(f"Could not determine primary container: {e}")
49+
return
50+
4251
if params:
43-
cmd = f"kubectl -n {namespace} exec {tank} -- bitcoin-cli {method} {' '.join(map(str, params))}"
52+
cmd = f"kubectl -n {namespace} exec {tank} --container {container_name} -- bitcoin-cli {method} {' '.join(map(str, params))}"
4453
else:
45-
cmd = f"kubectl -n {namespace} exec {tank} -- bitcoin-cli {method}"
54+
cmd = f"kubectl -n {namespace} exec {tank} --container {container_name} -- bitcoin-cli {method}"
4655
return run_command(cmd)
4756

4857

0 commit comments

Comments
 (0)