From 4a1e479ca612056761e6247dd5b715dcd6824413 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 19 Mar 2023 10:19:06 -0700 Subject: rpc: add "warnings" field to RPCs {create,load,unload,restore}wallet This new "warnings" field is a JSON array of strings intended to replace the "warning" string field in these four RPCs, to better handle returning multiple warning messages and for consistency with other wallet RPCs. --- src/rpc/util.cpp | 17 +++++++++++++++++ src/rpc/util.h | 1 + 2 files changed, 18 insertions(+) (limited to 'src/rpc') diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index f01944cd0b..f95ac4cb4b 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1175,8 +1175,25 @@ 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_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& 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 15c73068b9..bb5c30a2f4 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -388,5 +388,6 @@ private: * @param[out] obj UniValue object to push the warnings array object to. */ void PushWarnings(const UniValue& warnings, UniValue& obj); +void PushWarnings(const std::vector& warnings, UniValue& obj); #endif // BITCOIN_RPC_UTIL_H -- cgit v1.2.3