diff options
author | Jon Atack <jon@atack.com> | 2023-03-19 10:16:09 -0700 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2023-04-10 10:41:35 -0700 |
commit | 079d8cdda8eeebe199fb6592fca2630c37662731 (patch) | |
tree | cd7f4d3bde3449e4d1919e3035b937e622141d14 | |
parent | f73782a9032a462a71569e9424db9bf9eeababf3 (diff) |
rpc: extract wallet "warnings" fields to a util helper
-rw-r--r-- | src/rpc/output_script.cpp | 2 | ||||
-rw-r--r-- | src/rpc/util.cpp | 6 | ||||
-rw-r--r-- | src/rpc/util.h | 8 | ||||
-rw-r--r-- | src/wallet/rpc/addresses.cpp | 2 | ||||
-rw-r--r-- | src/wallet/rpc/backup.cpp | 4 |
5 files changed, 18 insertions, 4 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..f01944cd0b 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1174,3 +1174,9 @@ UniValue GetServicesNames(ServiceFlags services) return servicesNames; } + +void PushWarnings(const UniValue& warnings, UniValue& obj) +{ + if (warnings.empty()) return; + obj.pushKV("warnings", warnings); +} diff --git a/src/rpc/util.h b/src/rpc/util.h index e3783c8f76..15c73068b9 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -381,4 +381,12 @@ 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); + #endif // BITCOIN_RPC_UTIL_H diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index da63d45d11..4c27b08373 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 9154632520..026acf939b 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; } |