Skip to content
Bitcoin Roots

v29.4-roots.2 · Commit 4: [PATCH 04/21] 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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/wallet/external_signer_scriptpubkeyman.cpp CHANGED
@@ -46,13 +46,19 @@ bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::uni
46
  }
47
 
48
  ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() {
 
 
 
 
 
 
49
  const std::string command = gArgs.GetArg("-signer", "");
50
- if (command == "") throw std::runtime_error(std::string(__func__) + ": restart bitcoind with -signer=<cmd>");
51
  std::vector<ExternalSigner> signers;
52
  ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
53
- if (signers.empty()) throw std::runtime_error(std::string(__func__) + ": No external signers found");
54
  // 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.");
56
  return signers[0];
57
  }
58
 
@@ -93,9 +99,15 @@ std::optional<PSBTError> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySigned
93
  }
94
  if (complete) return {};
95
 
96
- std::string strFailReason;
97
- if(!GetExternalSigner().SignTransaction(psbt, strFailReason)) {
98
- tfm::format(std::cerr, "Failed to sign: %s\n", strFailReason);
 
 
 
 
 
 
99
  return PSBTError::EXTERNAL_SIGNER_FAILED;
100
  }
101
  if (finalize) FinalizePSBT(psbt); // This won't work in a multisig setup
 
46
  }
47
 
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() {
55
  const std::string command = gArgs.GetArg("-signer", "");
56
+ if (command == "") return util::Error{Untranslated("restart bitcoind with -signer=<cmd>")};
57
  std::vector<ExternalSigner> signers;
58
  ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
59
+ if (signers.empty()) return util::Error{Untranslated("No external signers found")};
60
  // TODO: add fingerprint argument instead of failing in case of multiple signers.
61
+ if (signers.size() > 1) return util::Error{Untranslated("More than one external signer found. Please connect only one at a time.")};
62
  return signers[0];
63
  }
64
 
 
99
  }
100
  if (complete) return {};
101
 
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);
111
  return PSBTError::EXTERNAL_SIGNER_FAILED;
112
  }
113
  if (finalize) FinalizePSBT(psbt); // This won't work in a multisig setup