diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/output_script.cpp | 2 | ||||
-rw-r--r-- | src/rpc/util.cpp | 23 | ||||
-rw-r--r-- | src/rpc/util.h | 9 | ||||
-rw-r--r-- | src/wallet/rpc/addresses.cpp | 2 | ||||
-rw-r--r-- | src/wallet/rpc/backup.cpp | 15 | ||||
-rw-r--r-- | src/wallet/rpc/wallet.cpp | 45 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 7 | ||||
-rw-r--r-- | src/wallet/wallet.h | 2 |
8 files changed, 82 insertions, 23 deletions
diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp index bb04f58424..990ec3ab0c 100644 --- a/src/rpc/output_script.cpp +++ b/src/rpc/output_script.cpp @@ -162,7 +162,7 @@ static RPCHelpMan createmultisig() // Only warns if the user has explicitly chosen an address type we cannot generate warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present."); } - if (!warnings.empty()) result.pushKV("warnings", warnings); + PushWarnings(warnings, result); return result; }, diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index ee9e3544a4..f95ac4cb4b 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1174,3 +1174,26 @@ UniValue GetServicesNames(ServiceFlags services) return servicesNames; } + +/** Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated values. */ +[[nodiscard]] static UniValue BilingualStringsToUniValue(const std::vector<bilingual_str>& bilingual_strings) +{ + CHECK_NONFATAL(!bilingual_strings.empty()); + UniValue result{UniValue::VARR}; + for (const auto& s : bilingual_strings) { + result.push_back(s.original); + } + return result; +} + +void PushWarnings(const UniValue& warnings, UniValue& obj) +{ + if (warnings.empty()) return; + obj.pushKV("warnings", warnings); +} + +void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj) +{ + if (warnings.empty()) return; + obj.pushKV("warnings", BilingualStringsToUniValue(warnings)); +} diff --git a/src/rpc/util.h b/src/rpc/util.h index e3783c8f76..bb5c30a2f4 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -381,4 +381,13 @@ private: const RPCExamples m_examples; }; +/** + * Push warning messages to an RPC "warnings" field as a JSON array of strings. + * + * @param[in] warnings Warning messages to push. + * @param[out] obj UniValue object to push the warnings array object to. + */ +void PushWarnings(const UniValue& warnings, UniValue& obj); +void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj); + #endif // BITCOIN_RPC_UTIL_H diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index 838d66c1e1..633f606747 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -300,7 +300,7 @@ RPCHelpMan addmultisigaddress() // Only warns if the user has explicitly chosen an address type we cannot generate warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present."); } - if (!warnings.empty()) result.pushKV("warnings", warnings); + PushWarnings(warnings, result); return result; }, diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 31a8954259..d9712f05d2 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1225,7 +1225,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64 result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, "Missing required fields")); } - if (warnings.size()) result.pushKV("warnings", warnings); + PushWarnings(warnings, result); return result; } @@ -1579,7 +1579,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c result.pushKV("success", UniValue(false)); result.pushKV("error", e); } - if (warnings.size()) result.pushKV("warnings", warnings); + PushWarnings(warnings, result); return result; } @@ -1903,7 +1903,11 @@ RPCHelpMan restorewallet() RPCResult::Type::OBJ, "", "", { {RPCResult::Type::STR, "name", "The wallet name if restored successfully."}, - {RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."}, + {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to restoring the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"}, + {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to restoring the wallet.", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -1933,7 +1937,10 @@ RPCHelpMan restorewallet() UniValue obj(UniValue::VOBJ); obj.pushKV("name", wallet->GetName()); - obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + if (wallet->chain().rpcEnableDeprecated("walletwarningfield")) { + obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + } + PushWarnings(warnings, obj); return obj; diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 16595267b4..ea3507bc75 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -13,6 +13,7 @@ #include <wallet/rpc/wallet.h> #include <wallet/rpc/util.h> #include <wallet/wallet.h> +#include <wallet/walletutil.h> #include <optional> @@ -20,6 +21,14 @@ namespace wallet { + +static const std::map<uint64_t, std::string> WALLET_FLAG_CAVEATS{ + {WALLET_FLAG_AVOID_REUSE, + "You need to rescan the blockchain in order to correctly mark used " + "destinations in the past. Until this is done, some destinations may " + "be considered unused, even if the opposite is the case."}, +}; + /** Checks if a CKey is in the given CWallet compressed or otherwise*/ bool HaveKey(const SigningProvider& wallet, const CKey& key) { @@ -207,7 +216,11 @@ static RPCHelpMan loadwallet() RPCResult::Type::OBJ, "", "", { {RPCResult::Type::STR, "name", "The wallet name if loaded successfully."}, - {RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."}, + {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to loading the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"}, + {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -240,7 +253,10 @@ static RPCHelpMan loadwallet() UniValue obj(UniValue::VOBJ); obj.pushKV("name", wallet->GetName()); - obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + if (wallet->chain().rpcEnableDeprecated("walletwarningfield")) { + obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + } + PushWarnings(warnings, obj); return obj; }, @@ -335,7 +351,11 @@ static RPCHelpMan createwallet() RPCResult::Type::OBJ, "", "", { {RPCResult::Type::STR, "name", "The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path."}, - {RPCResult::Type::STR, "warning", "Warning message if wallet was not loaded cleanly."}, + {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"}, + {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to creating the wallet.", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -405,7 +425,10 @@ static RPCHelpMan createwallet() UniValue obj(UniValue::VOBJ); obj.pushKV("name", wallet->GetName()); - obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + if (wallet->chain().rpcEnableDeprecated("walletwarningfield")) { + obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); + } + PushWarnings(warnings, obj); return obj; }, @@ -422,7 +445,11 @@ static RPCHelpMan unloadwallet() {"load_on_startup", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged."}, }, RPCResult{RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::STR, "warning", "Warning message if wallet was not unloaded cleanly."}, + {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning messages, if any, related to unloading the wallet. Multiple messages will be delimited by newlines. (DEPRECATED, returned only if config option -deprecatedrpc=walletwarningfield is passed.)"}, + {RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to unloading the wallet.", + { + {RPCResult::Type::STR, "", ""}, + }}, }}, RPCExamples{ HelpExampleCli("unloadwallet", "wallet_name") @@ -460,11 +487,13 @@ static RPCHelpMan unloadwallet() throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded"); } } + UniValue result(UniValue::VOBJ); + if (wallet->chain().rpcEnableDeprecated("walletwarningfield")) { + result.pushKV("warning", Join(warnings, Untranslated("\n")).original); + } + PushWarnings(warnings, result); UnloadWallet(std::move(wallet)); - - UniValue result(UniValue::VOBJ); - result.pushKV("warning", Join(warnings, Untranslated("\n")).original); return result; }, }; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6df0d12df6..4e8c0c0e5e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -52,13 +52,6 @@ using interfaces::FoundBlock; namespace wallet { -const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS{ - {WALLET_FLAG_AVOID_REUSE, - "You need to rescan the blockchain in order to correctly mark used " - "destinations in the past. Until this is done, some destinations may " - "be considered unused, even if the opposite is the case." - }, -}; bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 586f215499..581a6bd9cb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -146,8 +146,6 @@ static const std::map<std::string,WalletFlags> WALLET_FLAG_MAP{ {"external_signer", WALLET_FLAG_EXTERNAL_SIGNER} }; -extern const std::map<uint64_t,std::string> WALLET_FLAG_CAVEATS; - /** A wrapper to reserve an address from a wallet * * ReserveDestination is used to reserve an address. |