Skip to content

Commit 2f05005

Browse files
committed
cli: implement 'bitcoin rpc' using kubectl
1 parent f0d1214 commit 2f05005

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

src/warnet/cli/bitcoin.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import click
22

3-
from .rpc import rpc_call
3+
from .util import run_command
44

55

66
@click.group(name="bitcoin")
@@ -17,51 +17,51 @@ def rpc(node, method, params, network):
1717
"""
1818
Call bitcoin-cli <method> [params] on <node> in [network]
1919
"""
20-
print(
21-
rpc_call(
22-
"tank_bcli", {"network": network, "node": node, "method": method, "params": params}
23-
)
24-
)
20+
if params:
21+
cmd = f"kubectl exec warnet-node-{node} -- bitcoin-cli -regtest -rpcuser='user' -rpcpassword='password' {method} {' '.join(map(str, params))}"
22+
else:
23+
cmd = f"kubectl exec warnet-node-{node} -- bitcoin-cli -regtest -rpcuser='user' -rpcpassword='password' {method}"
24+
run_command(cmd)
2525

2626

27-
@bitcoin.command()
28-
@click.argument("node", type=int, required=True)
29-
@click.option("--network", default="warnet", show_default=True)
30-
def debug_log(node, network):
31-
"""
32-
Fetch the Bitcoin Core debug log from <node> in [network]
33-
"""
34-
print(rpc_call("tank_debug_log", {"node": node, "network": network}))
35-
36-
37-
@bitcoin.command()
38-
@click.argument("node_a", type=int, required=True)
39-
@click.argument("node_b", type=int, required=True)
40-
@click.option("--network", default="warnet", show_default=True)
41-
def messages(node_a, node_b, network):
42-
"""
43-
Fetch messages sent between <node_a> and <node_b> in [network]
44-
"""
45-
print(rpc_call("tank_messages", {"network": network, "node_a": node_a, "node_b": node_b}))
46-
47-
48-
@bitcoin.command()
49-
@click.argument("pattern", type=str, required=True)
50-
@click.option("--show-k8s-timestamps", is_flag=True, default=False, show_default=True)
51-
@click.option("--no-sort", is_flag=True, default=False, show_default=True)
52-
@click.option("--network", default="warnet", show_default=True)
53-
def grep_logs(pattern, network, show_k8s_timestamps, no_sort):
54-
"""
55-
Grep combined logs via fluentd using regex <pattern>
56-
"""
57-
print(
58-
rpc_call(
59-
"logs_grep",
60-
{
61-
"network": network,
62-
"pattern": pattern,
63-
"k8s_timestamps": show_k8s_timestamps,
64-
"no_sort": no_sort,
65-
},
66-
)
67-
)
27+
# @bitcoin.command()
28+
# @click.argument("node", type=int, required=True)
29+
# @click.option("--network", default="warnet", show_default=True)
30+
# def debug_log(node, network):
31+
# """
32+
# Fetch the Bitcoin Core debug log from <node> in [network]
33+
# """
34+
# print(rpc_call("tank_debug_log", {"node": node, "network": network}))
35+
#
36+
#
37+
# @bitcoin.command()
38+
# @click.argument("node_a", type=int, required=True)
39+
# @click.argument("node_b", type=int, required=True)
40+
# @click.option("--network", default="warnet", show_default=True)
41+
# def messages(node_a, node_b, network):
42+
# """
43+
# Fetch messages sent between <node_a> and <node_b> in [network]
44+
# """
45+
# print(rpc_call("tank_messages", {"network": network, "node_a": node_a, "node_b": node_b}))
46+
#
47+
#
48+
# @bitcoin.command()
49+
# @click.argument("pattern", type=str, required=True)
50+
# @click.option("--show-k8s-timestamps", is_flag=True, default=False, show_default=True)
51+
# @click.option("--no-sort", is_flag=True, default=False, show_default=True)
52+
# @click.option("--network", default="warnet", show_default=True)
53+
# def grep_logs(pattern, network, show_k8s_timestamps, no_sort):
54+
# """
55+
# Grep combined logs via fluentd using regex <pattern>
56+
# """
57+
# print(
58+
# rpc_call(
59+
# "logs_grep",
60+
# {
61+
# "network": network,
62+
# "pattern": pattern,
63+
# "k8s_timestamps": show_k8s_timestamps,
64+
# "no_sort": no_sort,
65+
# },
66+
# )
67+
# )

src/warnet/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import click
66
from rich import print as richprint
77

8-
# from .bitcoin import bitcoin
8+
from .bitcoin import bitcoin
99
from .graph import graph
1010
from .image import image
1111

@@ -21,7 +21,7 @@ def cli():
2121
pass
2222

2323

24-
# cli.add_command(bitcoin)
24+
cli.add_command(bitcoin)
2525
cli.add_command(graph)
2626
cli.add_command(image)
2727
# cli.add_command(ln)

0 commit comments

Comments
 (0)