v29.4-roots.1 · Commit 4: [PATCH 04/13] wallet: harden database and signing behavior
src/wallet/external_signer_scriptpubkeyman.cpp
Before: src/wallet/external_signer_scriptpubkeyman.cpp · After: src/wallet/external_signer_scriptpubkeyman.cpp
File metadata
index 32e9941453b076e9035f054607ba77a03021964f..ebfec62c70494b92557136308f8346cb3f06b8e5 100644
Download original patch · Release notes
Diff rows 1–40 of 40. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/wallet/external_signer_scriptpubkeyman.cpp
CHANGED
|
@@ -46,13 +46,19 @@ bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::uni
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() {
|
|
49
|
+
auto signer{GetExternalSigner2()};
|
|
50
|
+
if (!signer) throw std::runtime_error(util::ErrorString(signer).original);
|
|
51
|
+
return *signer;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
util::Result<ExternalSigner> ExternalSignerScriptPubKeyMan::GetExternalSigner2() {
|
|
49
55
|
const std::string command = gArgs.GetArg("-signer", "");
|
|
50
|
-
if (command == "") throw std::runtime_error(std::string(__func__) + ": restart bitcoind with -signer=<cmd>");
|
|
56
|
+
if (command == "") return util::Error{Untranslated("restart bitcoind with -signer=<cmd>")};
|
|
51
57
|
std::vector<ExternalSigner> signers;
|
|
52
58
|
ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
|
|
53
|
-
if (signers.empty()) throw std::runtime_error(std::string(__func__) + ": No external signers found");
|
|
59
|
+
if (signers.empty()) return util::Error{Untranslated("No external signers found")};
|
|
54
60
|
// TODO: add fingerprint argument instead of failing in case of multiple signers.
|
|
55
|
-
if (signers.size() > 1) throw std::runtime_error(std::string(__func__) + ": More than one external signer found. Please connect only one at a time.");
|
|
61
|
+
if (signers.size() > 1) return util::Error{Untranslated("More than one external signer found. Please connect only one at a time.")};
|
|
56
62
|
return signers[0];
|
|
57
63
|
}
|
|
58
64
|
|
|
@@ -93,9 +99,15 @@ std::optional<PSBTError> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySigned
|
|
|
93
99
|
}
|
|
94
100
|
if (complete) return {};
|
|
95
101
|
|
|
96
|
-
std::string strFailReason;
|
|
97
|
-
if(!GetExternalSigner().SignTransaction(psbt, strFailReason)) {
|
|
98
|
-
tfm::format(std::cerr, "Failed to sign: %s\n", strFailReason);
|
|
102
|
+
auto signer{GetExternalSigner2()};
|
|
103
|
+
if (!signer) {
|
|
104
|
+
LogWarning("%s", util::ErrorString(signer).original);
|
|
105
|
+
return PSBTError::EXTERNAL_SIGNER_NOT_FOUND;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
std::string failure_reason;
|
|
109
|
+
if(!signer->SignTransaction(psbt, failure_reason)) {
|
|
110
|
+
LogWarning("Failed to sign: %s\n", failure_reason);
|
|
99
111
|
return PSBTError::EXTERNAL_SIGNER_FAILED;
|
|
100
112
|
}
|
|
101
113
|
if (finalize) FinalizePSBT(psbt); // This won't work in a multisig setup
|