mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
kernel: move RunCommandParseJSON to its own file
Because libbitcoinkernel does not include this new object, this has the side-effect of eliminating the unnecessary boost::process dependency.
This commit is contained in:
@@ -5,19 +5,6 @@
|
||||
|
||||
#include <util/system.h>
|
||||
|
||||
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||
#if defined(__GNUC__)
|
||||
// Boost 1.78 requires the following workaround.
|
||||
// See: https://github.com/boostorg/process/issues/235
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnarrowing"
|
||||
#endif
|
||||
#include <boost/process.hpp>
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif // ENABLE_EXTERNAL_SIGNER
|
||||
|
||||
#include <chainparamsbase.h>
|
||||
#include <fs.h>
|
||||
#include <sync.h>
|
||||
@@ -1332,44 +1319,6 @@ void runCommand(const std::string& strCommand)
|
||||
}
|
||||
#endif
|
||||
|
||||
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in)
|
||||
{
|
||||
#ifdef ENABLE_EXTERNAL_SIGNER
|
||||
namespace bp = boost::process;
|
||||
|
||||
UniValue result_json;
|
||||
bp::opstream stdin_stream;
|
||||
bp::ipstream stdout_stream;
|
||||
bp::ipstream stderr_stream;
|
||||
|
||||
if (str_command.empty()) return UniValue::VNULL;
|
||||
|
||||
bp::child c(
|
||||
str_command,
|
||||
bp::std_out > stdout_stream,
|
||||
bp::std_err > stderr_stream,
|
||||
bp::std_in < stdin_stream
|
||||
);
|
||||
if (!str_std_in.empty()) {
|
||||
stdin_stream << str_std_in << std::endl;
|
||||
}
|
||||
stdin_stream.pipe().close();
|
||||
|
||||
std::string result;
|
||||
std::string error;
|
||||
std::getline(stdout_stream, result);
|
||||
std::getline(stderr_stream, error);
|
||||
|
||||
c.wait();
|
||||
const int n_error = c.exit_code();
|
||||
if (n_error) throw std::runtime_error(strprintf("RunCommandParseJSON error: process(%s) returned %d: %s\n", str_command, n_error, error));
|
||||
if (!result_json.read(result)) throw std::runtime_error("Unable to parse JSON: " + result);
|
||||
|
||||
return result_json;
|
||||
#else
|
||||
throw std::runtime_error("Compiled without external signing support (required for external signing).");
|
||||
#endif // ENABLE_EXTERNAL_SIGNER
|
||||
}
|
||||
|
||||
void SetupEnvironment()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user