MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / RunCommandParseJSON

Function RunCommandParseJSON

src/common/run_command.cpp:17–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#endif // ENABLE_EXTERNAL_SIGNER
16
17UniValue RunCommandParseJSON(const std::vector<std::string>& cmd_args, const std::string& str_std_in)
18{
19#ifdef ENABLE_EXTERNAL_SIGNER
20 namespace sp = subprocess;
21
22 UniValue result_json;
23 std::istringstream stdout_stream;
24 std::istringstream stderr_stream;
25
26 if (cmd_args.empty()) return UniValue::VNULL;
27
28 auto c = sp::Popen(cmd_args, sp::input{sp::PIPE}, sp::output{sp::PIPE}, sp::error{sp::PIPE});
29 if (!str_std_in.empty()) {
30 c.send(str_std_in);
31 }
32 auto [out_res, err_res] = c.communicate();
33 stdout_stream.str(std::string{out_res.buf.begin(), out_res.buf.end()});
34 stderr_stream.str(std::string{err_res.buf.begin(), err_res.buf.end()});
35
36 std::string result;
37 std::string error;
38 std::getline(stdout_stream, result);
39 std::getline(stderr_stream, error);
40
41 const int n_error = c.retcode();
42 if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", util::Join(cmd_args, " "), n_error, error));
43 if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result);
44
45 return result_json;
46#else
47 throw std::runtime_error("Compiled without external signing support (required for external signing).");
48#endif // ENABLE_EXTERNAL_SIGNER
49}

Callers 5

EnumerateMethod · 0.85
DisplayAddressMethod · 0.85
GetDescriptorsMethod · 0.85
SignTransactionMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 10

PopenClass · 0.85
JoinFunction · 0.85
strMethod · 0.80
retcodeMethod · 0.80
emptyMethod · 0.45
sendMethod · 0.45
communicateMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
readMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68