Skip to content

Commit

Permalink
Merge branch 'univalue/rpc/net-misc-abc' into 'master'
Browse files Browse the repository at this point in the history
Upgrade UniValue code in rpc/net.cpp, rpc/misc.cpp, rpc/abc.cpp (Bitcoin-ABC#51)

See merge request bitcoin-cash-node/bitcoin-cash-node!871
  • Loading branch information
ftrader committed Nov 26, 2020
2 parents 597fbb5 + eba4016 commit 277a6a3
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 161 deletions.
7 changes: 4 additions & 3 deletions src/rpc/abc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ static UniValue getexcessiveblock(const Config &config,
HelpExampleRpc("getexcessiveblock", ""));
}

UniValue ret(UniValue::VOBJ);
ret.pushKV("excessiveBlockSize", config.GetMaxBlockSize());
UniValue::Object ret;
ret.reserve(1);
ret.emplace_back("excessiveBlockSize", config.GetMaxBlockSize());
return ret;
}

Expand Down Expand Up @@ -74,7 +75,7 @@ static UniValue setexcessiveblock(Config &config,
// settingsToUserAgentString();
std::ostringstream ret;
ret << "Excessive Block set to " << ebs << " bytes.";
return UniValue(ret.str());
return ret.str();
}

// clang-format off
Expand Down
48 changes: 26 additions & 22 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ static UniValue createmultisig(const Config &config,
const CTxDestination dest =
AddAndGetDestinationForScript(keystore, inner, output_type);

UniValue result(UniValue::VOBJ);
result.pushKV("address", EncodeDestination(dest, config));
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
UniValue::Object result;
result.reserve(2);
result.emplace_back("address", EncodeDestination(dest, config));
result.emplace_back("redeemScript", HexStr(inner.begin(), inner.end()));

return result;
}
Expand Down Expand Up @@ -199,9 +200,9 @@ static UniValue verifymessage(const Config &config,

LOCK(cs_main);

std::string strAddress = request.params[0].get_str();
std::string strSign = request.params[1].get_str();
std::string strMessage = request.params[2].get_str();
const std::string &strAddress = request.params[0].get_str();
const std::string &strSign = request.params[1].get_str();
const std::string &strMessage = request.params[2].get_str();

CTxDestination destination =
DecodeDestination(strAddress, config.GetChainParams());
Expand Down Expand Up @@ -266,8 +267,8 @@ static UniValue signmessagewithprivkey(const Config &config,
"\"privkey\", \"my message\""));
}

std::string strPrivkey = request.params[0].get_str();
std::string strMessage = request.params[1].get_str();
const std::string &strPrivkey = request.params[0].get_str();
const std::string &strMessage = request.params[1].get_str();

CKey key = DecodeSecret(strPrivkey);
if (!key.IsValid()) {
Expand Down Expand Up @@ -325,15 +326,16 @@ static UniValue setmocktime(const Config &config,
return UniValue();
}

static UniValue RPCLockedMemoryInfo() {
static UniValue::Object RPCLockedMemoryInfo() {
LockedPool::Stats stats = LockedPoolManager::Instance().stats();
UniValue obj(UniValue::VOBJ);
obj.pushKV("used", uint64_t(stats.used));
obj.pushKV("free", uint64_t(stats.free));
obj.pushKV("total", uint64_t(stats.total));
obj.pushKV("locked", uint64_t(stats.locked));
obj.pushKV("chunks_used", uint64_t(stats.chunks_used));
obj.pushKV("chunks_free", uint64_t(stats.chunks_free));
UniValue::Object obj;
obj.reserve(6);
obj.emplace_back("used", stats.used);
obj.emplace_back("free", stats.free);
obj.emplace_back("total", stats.total);
obj.emplace_back("locked", stats.locked);
obj.emplace_back("chunks_used", stats.chunks_used);
obj.emplace_back("chunks_free", stats.chunks_free);
return obj;
}

Expand Down Expand Up @@ -402,8 +404,9 @@ static UniValue getmemoryinfo(const Config &config,
std::string mode =
request.params[0].isNull() ? "stats" : request.params[0].get_str();
if (mode == "stats") {
UniValue obj(UniValue::VOBJ);
obj.pushKV("locked", RPCLockedMemoryInfo());
UniValue::Object obj;
obj.reserve(1);
obj.emplace_back("locked", RPCLockedMemoryInfo());
return obj;
} else if (mode == "mallocinfo") {
#ifdef HAVE_MALLOC_INFO
Expand All @@ -414,7 +417,7 @@ static UniValue getmemoryinfo(const Config &config,
"mallocinfo is only available when compiled with glibc 2.10+");
#endif
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode);
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + std::move(mode));
}
}

Expand Down Expand Up @@ -518,10 +521,11 @@ static UniValue logging(const Config &config, const JSONRPCRequest &request) {
}
}

UniValue result(UniValue::VOBJ);
UniValue::Object result;
std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
for (const auto &logCatActive : vLogCatActive) {
result.pushKV(logCatActive.category, logCatActive.active);
result.reserve(vLogCatActive.size());
for (auto &logCatActive : vLogCatActive) {
result.emplace_back(std::move(logCatActive.category), logCatActive.active);
}

return result;
Expand Down

0 comments on commit 277a6a3

Please sign in to comment.