aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-04-12 13:02:11 -0400
committerAndrew Chow <github@achow101.com>2023-04-12 13:09:23 -0400
commit6a167325f0d74ed1167705e30e86e5b8449582f1 (patch)
tree2c5baaa657e17336582691e21fa085b4ba42a09a /src/rpc
parent7f4ab67e7be615b2425a85fb65872fc2327f58c3 (diff)
parent7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 (diff)
downloadbitcoin-6a167325f0d74ed1167705e30e86e5b8449582f1.tar.xz
Merge bitcoin/bitcoin#27279: Add "warnings", deprecate "warning" in {create,load,unload,restore}wallet
7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 test: fix importmulti/importdescriptors assertion (Jon Atack) 19d888ce407f44d90785c456a1a3e2a6870e9245 rpc: move WALLET_FLAG_CAVEATS to the compilation unit of its caller (Jon Atack) 01df011ca2bf46ee4c988b03a130eea6df692325 doc: release note for wallet RPCs "warning" field deprecation (Jon Atack) 9ea8b3739a863b0ad87593639476b3cd712ff0dc test: createwallet "warning" field deprecation test (Jon Atack) 645d7f75ac1b40e4ea88119b3711f89943d35d6c rpc: deprecate "warning" field in {create,load,unload,restore}wallet (Jon Atack) 2f4a926e95e0379397859c3ba1b5711be5f09925 test: add test coverage for "warnings" field in createwallet (Jon Atack) 4a1e479ca612056761e6247dd5b715dcd6824413 rpc: add "warnings" field to RPCs {create,load,unload,restore}wallet (Jon Atack) 079d8cdda8eeebe199fb6592fca2630c37662731 rpc: extract wallet "warnings" fields to a util helper (Jon Atack) f73782a9032a462a71569e9424db9bf9eeababf3 doc: fix/improve warning helps in {create,load,unload,restore}wallet (Jon Atack) Pull request description: Based on discussion and concept ACKed in #27138, add a `warnings` field to RPCs createwallet, loadwallet, unloadwallet, and restorewallet as a JSON array of strings to replace the `warning` string field in these 4 RPCs. The idea is to more gracefully handle multiple warning messages and for consistency with other wallet RPCs. Then, deprecate the latter fields, which represent all the remaining RPC `warning` fields. The first commit https://github.com/bitcoin/bitcoin/pull/27279/commits/f73782a9032a462a71569e9424db9bf9eeababf3 implements https://github.com/bitcoin/bitcoin/pull/27138#issuecomment-1474789198 as an alternative to #27138. One of those two could potentially be backported to our currently supported releases. ACKs for top commit: achow101: ACK 7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 1440000bytes: utACK https://github.com/bitcoin/bitcoin/pull/27279/commits/7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 vasild: ACK 7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 pinheadmz: re-ACK 7ccdd741fe1544c13b2a9b7baa5c5727e84d6e55 Tree-SHA512: 314e0a4c41fa383d95e2817bfacf359d449e460529d235c3eb902851e2f4eacbabe646d9a5a4beabc4964cdfabf6397ed8301366a58d344a2f787f83b75e9d64
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/output_script.cpp2
-rw-r--r--src/rpc/util.cpp23
-rw-r--r--src/rpc/util.h9
3 files changed, 33 insertions, 1 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