mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 22:57:56 +02:00
util: Remove brittle and confusing sp::Popen(std::string)
This commit is contained in:
@@ -9,24 +9,27 @@
|
||||
#include <core_io.h>
|
||||
#include <psbt.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/subprocess.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
ExternalSigner::ExternalSigner(std::string command, std::string chain, std::string fingerprint, std::string name)
|
||||
ExternalSigner::ExternalSigner(std::vector<std::string> command, std::string chain, std::string fingerprint, std::string name)
|
||||
: m_command{std::move(command)}, m_chain{std::move(chain)}, m_fingerprint{std::move(fingerprint)}, m_name{std::move(name)} {}
|
||||
|
||||
std::string ExternalSigner::NetworkArg() const
|
||||
std::vector<std::string> ExternalSigner::NetworkArg() const
|
||||
{
|
||||
return " --chain " + m_chain;
|
||||
return {"--chain", m_chain};
|
||||
}
|
||||
|
||||
bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string& chain)
|
||||
{
|
||||
// Call <command> enumerate
|
||||
const UniValue result = RunCommandParseJSON(command + " enumerate");
|
||||
std::vector<std::string> cmd_args = Cat(subprocess::util::split(command), {"enumerate"});
|
||||
|
||||
const UniValue result = RunCommandParseJSON(cmd_args, "");
|
||||
if (!result.isArray()) {
|
||||
throw std::runtime_error(strprintf("'%s' received invalid response, expected array of signers", command));
|
||||
}
|
||||
@@ -56,19 +59,19 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
|
||||
if (model_field.isStr() && model_field.getValStr() != "") {
|
||||
name += model_field.getValStr();
|
||||
}
|
||||
signers.emplace_back(command, chain, fingerprintStr, name);
|
||||
signers.emplace_back(subprocess::util::split(command), chain, fingerprintStr, name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
UniValue ExternalSigner::DisplayAddress(const std::string& descriptor) const
|
||||
{
|
||||
return RunCommandParseJSON(m_command + " --fingerprint " + m_fingerprint + NetworkArg() + " displayaddress --desc " + descriptor);
|
||||
return RunCommandParseJSON(Cat(m_command, Cat(Cat({"--fingerprint", m_fingerprint}, NetworkArg()), {"displayaddress", "--desc", descriptor})), "");
|
||||
}
|
||||
|
||||
UniValue ExternalSigner::GetDescriptors(const int account)
|
||||
{
|
||||
return RunCommandParseJSON(m_command + " --fingerprint " + m_fingerprint + NetworkArg() + " getdescriptors --account " + strprintf("%d", account));
|
||||
return RunCommandParseJSON(Cat(m_command, Cat(Cat({"--fingerprint", m_fingerprint}, NetworkArg()), {"getdescriptors", "--account", strprintf("%d", account)})), "");
|
||||
}
|
||||
|
||||
bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::string& error)
|
||||
@@ -94,7 +97,7 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string command = m_command + " --stdin --fingerprint " + m_fingerprint + NetworkArg();
|
||||
const std::vector<std::string> command = Cat(m_command, Cat({"--stdin", "--fingerprint", m_fingerprint}, NetworkArg()));
|
||||
const std::string stdinStr = "signtx " + EncodeBase64(ssTx.str());
|
||||
|
||||
const UniValue signer_result = RunCommandParseJSON(command, stdinStr);
|
||||
|
||||
Reference in New Issue
Block a user