mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-01 11:26:03 +02:00
refactor: use util::Result for GetExternalSigner()
This commit does not change behavior, except that the error message no longer contains the function name.
This commit is contained in:
@@ -45,14 +45,14 @@ bool ExternalSignerScriptPubKeyMan::SetupDescriptor(WalletBatch& batch, std::uni
|
||||
return true;
|
||||
}
|
||||
|
||||
ExternalSigner ExternalSignerScriptPubKeyMan::GetExternalSigner() {
|
||||
util::Result<ExternalSigner> ExternalSignerScriptPubKeyMan::GetExternalSigner() {
|
||||
const std::string command = gArgs.GetArg("-signer", "");
|
||||
if (command == "") throw std::runtime_error(std::string(__func__) + ": restart bitcoind with -signer=<cmd>");
|
||||
if (command == "") return util::Error{Untranslated("restart bitcoind with -signer=<cmd>")};
|
||||
std::vector<ExternalSigner> signers;
|
||||
ExternalSigner::Enumerate(command, signers, Params().GetChainTypeString());
|
||||
if (signers.empty()) throw std::runtime_error(std::string(__func__) + ": No external signers found");
|
||||
if (signers.empty()) return util::Error{Untranslated("No external signers found")};
|
||||
// TODO: add fingerprint argument instead of failing in case of multiple signers.
|
||||
if (signers.size() > 1) throw std::runtime_error(std::string(__func__) + ": More than one external signer found. Please connect only one at a time.");
|
||||
if (signers.size() > 1) return util::Error{Untranslated("More than one external signer found. Please connect only one at a time.")};
|
||||
return signers[0];
|
||||
}
|
||||
|
||||
@@ -93,9 +93,12 @@ std::optional<PSBTError> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySigned
|
||||
}
|
||||
if (complete) return {};
|
||||
|
||||
std::string strFailReason;
|
||||
if(!GetExternalSigner().SignTransaction(psbt, strFailReason)) {
|
||||
tfm::format(std::cerr, "Failed to sign: %s\n", strFailReason);
|
||||
auto signer{GetExternalSigner()};
|
||||
if (!signer) throw std::runtime_error(util::ErrorString(signer).original);
|
||||
|
||||
std::string failure_reason;
|
||||
if(!signer->SignTransaction(psbt, failure_reason)) {
|
||||
tfm::format(std::cerr, "Failed to sign: %s\n", failure_reason);
|
||||
return PSBTError::EXTERNAL_SIGNER_FAILED;
|
||||
}
|
||||
if (finalize) FinalizePSBT(psbt); // This won't work in a multisig setup
|
||||
|
||||
Reference in New Issue
Block a user