0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-08 10:31:50 -05:00

external_signer: improve fingerprint matching logic (stop on first match)

This commit is contained in:
Sebastian Falbesoner 2021-08-24 11:19:43 +02:00
parent d3203a99d8
commit d047ed729f

View file

@ -9,6 +9,7 @@
#include <util/system.h> #include <util/system.h>
#include <external_signer.h> #include <external_signer.h>
#include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <vector> #include <vector>
@ -75,15 +76,14 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
ssTx << psbtx; ssTx << psbtx;
// Check if signer fingerprint matches any input master key fingerprint // Check if signer fingerprint matches any input master key fingerprint
bool match = false; auto matches_signer_fingerprint = [&](const PSBTInput& input) {
for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
const PSBTInput& input = psbtx.inputs[i];
for (const auto& entry : input.hd_keypaths) { 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()); error = "Signer fingerprint " + m_fingerprint + " does not match any of the inputs:\n" + EncodeBase64(ssTx.str());
return false; return false;
} }