Skip to content

Commit 4a1e479

Browse files
committed
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.
1 parent 079d8cd commit 4a1e479

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/rpc/util.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,25 @@ UniValue GetServicesNames(ServiceFlags services)
11751175
return servicesNames;
11761176
}
11771177

1178+
/** Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated values. */
1179+
[[nodiscard]] static UniValue BilingualStringsToUniValue(const std::vector<bilingual_str>& bilingual_strings)
1180+
{
1181+
CHECK_NONFATAL(!bilingual_strings.empty());
1182+
UniValue result{UniValue::VARR};
1183+
for (const auto& s : bilingual_strings) {
1184+
result.push_back(s.original);
1185+
}
1186+
return result;
1187+
}
1188+
11781189
void PushWarnings(const UniValue& warnings, UniValue& obj)
11791190
{
11801191
if (warnings.empty()) return;
11811192
obj.pushKV("warnings", warnings);
11821193
}
1194+
1195+
void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj)
1196+
{
1197+
if (warnings.empty()) return;
1198+
obj.pushKV("warnings", BilingualStringsToUniValue(warnings));
1199+
}

src/rpc/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,5 +388,6 @@ class RPCHelpMan
388388
* @param[out] obj UniValue object to push the warnings array object to.
389389
*/
390390
void PushWarnings(const UniValue& warnings, UniValue& obj);
391+
void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj);
391392

392393
#endif // BITCOIN_RPC_UTIL_H

src/wallet/rpc/backup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,10 @@ RPCHelpMan restorewallet()
19041904
{
19051905
{RPCResult::Type::STR, "name", "The wallet name if restored successfully."},
19061906
{RPCResult::Type::STR, "warning", "Warning messages, if any, related to restoring the wallet. Multiple messages will be delimited by newlines."},
1907+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to restoring the wallet.",
1908+
{
1909+
{RPCResult::Type::STR, "", ""},
1910+
}},
19071911
}
19081912
},
19091913
RPCExamples{
@@ -1934,6 +1938,7 @@ RPCHelpMan restorewallet()
19341938
UniValue obj(UniValue::VOBJ);
19351939
obj.pushKV("name", wallet->GetName());
19361940
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
1941+
PushWarnings(warnings, obj);
19371942

19381943
return obj;
19391944

src/wallet/rpc/wallet.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ static RPCHelpMan loadwallet()
208208
{
209209
{RPCResult::Type::STR, "name", "The wallet name if loaded successfully."},
210210
{RPCResult::Type::STR, "warning", "Warning messages, if any, related to loading the wallet. Multiple messages will be delimited by newlines."},
211+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
212+
{
213+
{RPCResult::Type::STR, "", ""},
214+
}},
211215
}
212216
},
213217
RPCExamples{
@@ -241,6 +245,7 @@ static RPCHelpMan loadwallet()
241245
UniValue obj(UniValue::VOBJ);
242246
obj.pushKV("name", wallet->GetName());
243247
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
248+
PushWarnings(warnings, obj);
244249

245250
return obj;
246251
},
@@ -336,6 +341,10 @@ static RPCHelpMan createwallet()
336341
{
337342
{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."},
338343
{RPCResult::Type::STR, "warning", "Warning messages, if any, related to creating the wallet. Multiple messages will be delimited by newlines."},
344+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to creating the wallet.",
345+
{
346+
{RPCResult::Type::STR, "", ""},
347+
}},
339348
}
340349
},
341350
RPCExamples{
@@ -406,6 +415,7 @@ static RPCHelpMan createwallet()
406415
UniValue obj(UniValue::VOBJ);
407416
obj.pushKV("name", wallet->GetName());
408417
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
418+
PushWarnings(warnings, obj);
409419

410420
return obj;
411421
},
@@ -423,6 +433,10 @@ static RPCHelpMan unloadwallet()
423433
},
424434
RPCResult{RPCResult::Type::OBJ, "", "", {
425435
{RPCResult::Type::STR, "warning", "Warning messages, if any, related to unloading the wallet. Multiple messages will be delimited by newlines."},
436+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to unloading the wallet.",
437+
{
438+
{RPCResult::Type::STR, "", ""},
439+
}},
426440
}},
427441
RPCExamples{
428442
HelpExampleCli("unloadwallet", "wallet_name")
@@ -465,6 +479,8 @@ static RPCHelpMan unloadwallet()
465479

466480
UniValue result(UniValue::VOBJ);
467481
result.pushKV("warning", Join(warnings, Untranslated("\n")).original);
482+
PushWarnings(warnings, result);
483+
468484
return result;
469485
},
470486
};

0 commit comments

Comments
 (0)