Skip to content

Commit 7eed5ef

Browse files
committed
_rpc: fix goofy json parsing workaround
I went with the _preload_content=False approach
1 parent f5a3b26 commit 7eed5ef

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/warnet/bitcoin.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import ast
21
import base64
32
import codecs
4-
import json
53
import os
64
import re
75
import sys
@@ -62,16 +60,19 @@ def _rpc(tank: str, method: str, params: tuple[str, ...]) -> str:
6260
stdin=False,
6361
stdout=True,
6462
tty=False,
63+
_preload_content=False,
6564
)
66-
# The k8s lib seems to convert json into its python representation. The following dance seems to
67-
# avoid the worst of it.
68-
if resp.startswith("{") or resp.startswith("["):
69-
literal = ast.literal_eval(resp)
70-
json_string = json.dumps(literal)
71-
return json_string
72-
else:
73-
# When bitcoin-cli responds with a txid or similar, don't try to `literal_eval` it.
74-
return resp
65+
stdout = ""
66+
stderr = ""
67+
while resp.is_open():
68+
resp.update(timeout=1)
69+
if resp.peek_stdout():
70+
stdout_chunk = resp.read_stdout()
71+
stdout += stdout_chunk
72+
if resp.peek_stderr():
73+
stderr_chunk = resp.read_stderr()
74+
stderr += stderr_chunk
75+
return stdout + stderr
7576

7677

7778
@bitcoin.command()

0 commit comments

Comments
 (0)