Skip to content

Commit

Permalink
rpc: Notate copies into UniValue
Browse files Browse the repository at this point in the history
Many of these are legitimate, but some could probably be avoided.
  • Loading branch information
theuni committed May 13, 2024
1 parent 8ed8830 commit d63cfed
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ bool WriteSettings(const fs::path& path,
"is running, as any changes might be ignored or overwritten.", PACKAGE_NAME));
// Push settings values
for (const auto& value : values) {
// TODO
out.pushKVEnd(value.first, value.second);
}
std::ofstream file;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,7 @@ static RPCHelpMan getblockstats()
if (value.isNull()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid selected statistic '%s'", stat));
}
// TODO
ret.pushKV(stat, value);
}
return ret;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/rawtransaction_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ UniValue NormalizeOutputs(const UniValue& outputs_in)
if (output.size() != 1) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, key-value pair must contain exactly one key");
}
// TODO
outputs_dict.pushKVs(output);
}
outputs = std::move(outputs_dict);
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params,
{
UniValue request(UniValue::VOBJ);
request.pushKV("method", strMethod);
// TODO
request.pushKV("params", params);
// TODO
request.pushKV("id", id);
return request;
}
Expand All @@ -41,6 +43,7 @@ UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const Un
{
UniValue reply(UniValue::VOBJ);
if (!error.isNull())
// TODO
reply.pushKV("result", NullUniValue);
else
reply.pushKV("result", result);
Expand Down
4 changes: 4 additions & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
if (options.exists(fr->first)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + fr->first + " specified multiple times");
}
// TODO
options.pushKVEnd(fr->first, *fr->second);
argsIn.erase(fr);
}
Expand Down Expand Up @@ -468,6 +469,7 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
if (!options.empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Parameter " + fr->first + " conflicts with parameter " + options.getKeys().front());
}
//TODO
out.params.push_back(*fr->second);
argsIn.erase(fr);
}
Expand All @@ -489,6 +491,7 @@ static inline JSONRPCRequest transformNamedArguments(const JSONRPCRequest& in, c
UniValue named_args{std::move(out.params)};
out.params = *positional_args.mapped();
for (size_t i{out.params.size()}; i < named_args.size(); ++i) {
// TODO
out.params.push_back(named_args[i]);
}
}
Expand Down Expand Up @@ -565,6 +568,7 @@ UniValue CRPCTable::dumpArgMap(const JSONRPCRequest& args_request) const
UniValue result;
if (ExecuteCommands(cmd.second, request, result)) {
for (const auto& values : result.getValues()) {
// TODO
ret.push_back(values);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList&
{
UniValue params(UniValue::VOBJ);
for (const auto& param: args) {
// TODO
params.pushKV(param.first, param.second);
}

Expand Down Expand Up @@ -1353,6 +1354,7 @@ std::vector<CScript> EvalDescriptorStringOrObject(const UniValue& scanobject, Fl
void PushWarnings(const UniValue& warnings, UniValue& obj)
{
if (warnings.empty()) return;
// TODO
obj.pushKV("warnings", warnings);
}

Expand Down
1 change: 1 addition & 0 deletions src/wallet/rpc/addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class DescribeWalletAddressVisitor
subobj.pushKV("address", EncodeDestination(embedded));
subobj.pushKV("scriptPubKey", HexStr(subscript));
// Always report the pubkey at the top level, so that `getnewaddress()['pubkey']` always works.
// TODO
if (subobj.exists("pubkey")) obj.pushKV("pubkey", subobj["pubkey"]);
obj.pushKV("embedded", std::move(subobj));
} else if (which_type == TxoutType::MULTISIG) {
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ RPCHelpMan importmulti()
// the result stand unmodified. Otherwise replace the result
// with an error message.
if (scannedTime <= GetImportTimestamp(request, now) || results.at(i).exists("error")) {
// TODO
response.push_back(results.at(i));
} else {
UniValue result = UniValue(UniValue::VOBJ);
Expand Down Expand Up @@ -1706,6 +1707,7 @@ RPCHelpMan importdescriptors()
// the result stand unmodified. Otherwise replace the result
// with an error message.
if (scanned_time <= GetImportTimestamp(request, now) || results.at(i).exists("error")) {
// TODO
response.push_back(results.at(i));
} else {
UniValue result = UniValue(UniValue::VOBJ);
Expand Down
6 changes: 6 additions & 0 deletions src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ static void InterpretFeeEstimationInstructions(const UniValue& conf_target, cons
throw JSONRPCError(RPC_INVALID_PARAMETER, "Pass conf_target and estimate_mode either as arguments or in the options object, but not both");
}
} else {
// TODO
options.pushKV("conf_target", conf_target);
// TODO
options.pushKV("estimate_mode", estimate_mode);
}
if (options.exists("fee_rate")) {
if (!fee_rate.isNull()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Pass the fee_rate either as an argument, or in the options object, but not both");
}
} else {
// TODO
options.pushKV("fee_rate", fee_rate);
}
if (!options["conf_target"].isNull() && (options["estimate_mode"].isNull() || (options["estimate_mode"].get_str() == "unset"))) {
Expand Down Expand Up @@ -302,6 +305,7 @@ RPCHelpMan sendtoaddress()

UniValue address_amounts(UniValue::VOBJ);
const std::string address = request.params[0].get_str();
// TODO
address_amounts.pushKV(address, request.params[1]);
std::vector<CRecipient> recipients = CreateRecipients(
ParseOutputs(address_amounts),
Expand Down Expand Up @@ -715,6 +719,7 @@ static void SetOptionsInputWeights(const UniValue& inputs, UniValue& options)
UniValue weights(UniValue::VARR);
for (const UniValue& input : inputs.getValues()) {
if (input.exists("weight")) {
// TODO
weights.push_back(input);
}
}
Expand Down Expand Up @@ -1391,6 +1396,7 @@ RPCHelpMan sendall()
recipient_key_value_pairs.push_back(std::move(rkvp));
addresses_without_amount.insert(recipient.get_str());
} else {
// TODO
recipient_key_value_pairs.push_back(recipient);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool RemoveWalletSetting(interfaces::Chain& chain, const std::string& wallet_nam
if (!setting_value.isArray()) return true;
common::SettingsValue new_value(common::SettingsValue::VARR);
for (const common::SettingsValue& value : setting_value.getValues()) {
// TODO
if (!value.isStr() || value.get_str() != wallet_name) new_value.push_back(value);
}
if (new_value.size() == setting_value.size()) return true;
Expand Down

0 comments on commit d63cfed

Please sign in to comment.