diff options
Diffstat (limited to 'src/external_signer.cpp')
-rw-r--r-- | src/external_signer.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/external_signer.cpp b/src/external_signer.cpp index b82dcc503d..f16d21fa60 100644 --- a/src/external_signer.cpp +++ b/src/external_signer.cpp @@ -9,43 +9,44 @@ #include <util/system.h> #include <external_signer.h> -ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint, std::string chain, std::string name): m_command(command), m_fingerprint(fingerprint), m_chain(chain), m_name(name) {} +#include <stdexcept> +#include <string> +#include <vector> + +#ifdef ENABLE_EXTERNAL_SIGNER + +ExternalSigner::ExternalSigner(const std::string& command, const std::string& fingerprint, const std::string chain, const std::string name): m_command(command), m_fingerprint(fingerprint), m_chain(chain), m_name(name) {} const std::string ExternalSigner::NetworkArg() const { return " --chain " + m_chain; } -#ifdef ENABLE_EXTERNAL_SIGNER - -bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, std::string chain, bool ignore_errors) +bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalSigner>& signers, const std::string chain) { // Call <command> enumerate const UniValue result = RunCommandParseJSON(command + " enumerate"); if (!result.isArray()) { - if (ignore_errors) return false; - throw ExternalSignerException(strprintf("'%s' received invalid response, expected array of signers", command)); + throw std::runtime_error(strprintf("'%s' received invalid response, expected array of signers", command)); } for (UniValue signer : result.getValues()) { // Check for error const UniValue& error = find_value(signer, "error"); if (!error.isNull()) { - if (ignore_errors) return false; if (!error.isStr()) { - throw ExternalSignerException(strprintf("'%s' error", command)); + throw std::runtime_error(strprintf("'%s' error", command)); } - throw ExternalSignerException(strprintf("'%s' error: %s", command, error.getValStr())); + throw std::runtime_error(strprintf("'%s' error: %s", command, error.getValStr())); } // Check if fingerprint is present const UniValue& fingerprint = find_value(signer, "fingerprint"); if (fingerprint.isNull()) { - if (ignore_errors) return false; - throw ExternalSignerException(strprintf("'%s' received invalid response, missing signer fingerprint", command)); + throw std::runtime_error(strprintf("'%s' received invalid response, missing signer fingerprint", command)); } - std::string fingerprintStr = fingerprint.get_str(); + const std::string fingerprintStr = fingerprint.get_str(); // Skip duplicate signer bool duplicate = false; - for (ExternalSigner signer : signers) { + for (const ExternalSigner& signer : signers) { if (signer.m_fingerprint.compare(fingerprintStr) == 0) duplicate = true; } if (duplicate) break; @@ -64,7 +65,7 @@ UniValue ExternalSigner::DisplayAddress(const std::string& descriptor) const return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " displayaddress --desc \"" + descriptor + "\""); } -UniValue ExternalSigner::GetDescriptors(int account) +UniValue ExternalSigner::GetDescriptors(const int account) { return RunCommandParseJSON(m_command + " --fingerprint \"" + m_fingerprint + "\"" + NetworkArg() + " getdescriptors --account " + strprintf("%d", account)); } @@ -79,7 +80,7 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str bool match = false; for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { const PSBTInput& input = psbtx.inputs[i]; - for (auto entry : input.hd_keypaths) { + for (const auto& entry : input.hd_keypaths) { if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true; } } @@ -89,8 +90,8 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str return false; } - std::string command = m_command + " --stdin --fingerprint \"" + m_fingerprint + "\"" + NetworkArg(); - std::string stdinStr = "signtx \"" + EncodeBase64(ssTx.str()) + "\""; + const std::string command = m_command + " --stdin --fingerprint \"" + m_fingerprint + "\"" + NetworkArg(); + const std::string stdinStr = "signtx \"" + EncodeBase64(ssTx.str()) + "\""; const UniValue signer_result = RunCommandParseJSON(command, stdinStr); @@ -116,4 +117,4 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str return true; } -#endif +#endif // ENABLE_EXTERNAL_SIGNER |