mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Merge bitcoin/bitcoin#22789: external_signer: improve fingerprint matching logic (stop on first match)
d047ed729f
external_signer: improve fingerprint matching logic (stop on first match) (Sebastian Falbesoner) Pull request description: The fingerprint matching logic in `ExternalSigner::SignTransaction` currently always iterates all inputs of a PSBT, even after a match has already been found. I guess the reason for that is not that it was not thought of, but rather the fact that breaking out of a nested loop is simply not possible (at least not without adding ugly constructs like gotos or extra state variables). This PR fixes this by using `std::any_of` from C++'s standard library, see http://www.cplusplus.com/reference/algorithm/any_of/ ACKs for top commit: lsilva01: Code Review ACKd047ed729f
Sjors: utACKd047ed7
Zero-1729: crACKd047ed729f
mjdietzx: Code review ACKd047ed729f
hebasto: ACKd047ed729f
, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 447e7c0c6a5b5549a2c09d52e55ba4146302c1a06e4d96de11f6945d09f98c89129cba221202dff7e0718e01a83dd173b9f19b1f02b6be228978f3f6e35d8096
This commit is contained in:
commit
91c7d66c8b
1 changed files with 6 additions and 6 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue