Skip to content

Commit d047ed7

Browse files
committed
external_signer: improve fingerprint matching logic (stop on first match)
1 parent d3203a9 commit d047ed7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/external_signer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <util/system.h>
1010
#include <external_signer.h>
1111

12+
#include <algorithm>
1213
#include <stdexcept>
1314
#include <string>
1415
#include <vector>
@@ -75,15 +76,14 @@ bool ExternalSigner::SignTransaction(PartiallySignedTransaction& psbtx, std::str
7576
ssTx << psbtx;
7677

7778
// Check if signer fingerprint matches any input master key fingerprint
78-
bool match = false;
79-
for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) {
80-
const PSBTInput& input = psbtx.inputs[i];
79+
auto matches_signer_fingerprint = [&](const PSBTInput& input) {
8180
for (const auto& entry : input.hd_keypaths) {
82-
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) match = true;
81+
if (m_fingerprint == strprintf("%08x", ReadBE32(entry.second.fingerprint))) return true;
8382
}
84-
}
83+
return false;
84+
};
8585

86-
if (!match) {
86+
if (!std::any_of(psbtx.inputs.begin(), psbtx.inputs.end(), matches_signer_fingerprint)) {
8787
error = "Signer fingerprint " + m_fingerprint + " does not match any of the inputs:\n" + EncodeBase64(ssTx.str());
8888
return false;
8989
}

0 commit comments

Comments
 (0)