rpc: extract wallet "warnings" fields to a util helper

This commit is contained in:
Jon Atack 2023-03-19 10:16:09 -07:00
parent f73782a903
commit 079d8cdda8
5 changed files with 18 additions and 4 deletions

View file

@ -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;
},

View file

@ -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);
}

View file

@ -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

View file

@ -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;
},

View file

@ -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;
}