diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-08-24 11:19:43 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-08-24 11:30:09 +0200 |
commit | d047ed729f1d4732d23324fc76849f3c657cdbe4 (patch) | |
tree | dd1ce4501ec41aee9972752074cc52f21eabe032 /src | |
parent | d3203a99d886177eee9d1f9cd8411e215118a4e6 (diff) | |
download | bitcoin-d047ed729f1d4732d23324fc76849f3c657cdbe4.tar.xz |
external_signer: improve fingerprint matching logic (stop on first match)
Diffstat (limited to 'src')
-rw-r--r-- | src/external_signer.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/external_signer.cpp b/src/external_signer.cpp index d6388b759a..75070899c6 100644 --- a/src/external_signer.cpp +++ b/src/external_signer.cpp @@ -9,6 +9,7 @@ #include <util/system.h> #include <external_signer.h> +#include <algorithm> #include <stdexcept> #include <string> #include <vector> @@ -75,15 +76,14 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str ssTx << psbtx; // Check if signer fingerprint matches any input master key fingerprint - bool match = false; - for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { - const PSBTInput& input = psbtx.inputs[i]; + auto matches_signer_fingerprint = [&](const PSBTInput& input) { for (const auto& entry : input.hd_keypaths) { - if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true; + if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) return true; } - } + return false; + }; - if (!match) { + if (!std::any_of(psbtx.inputs.begin(), psbtx.inputs.end(), matches_signer_fingerprint)) { error = "Signer fingerprint " + m_fingerprint + " does not match any of the inputs:\n" + EncodeBase64(ssTx.str()); return false; } |