Skip to content

Commit

Permalink
Upgrade UniValue code in rpc/blockchain.cpp (Bitcoin-ABC#51)
Browse files Browse the repository at this point in the history
Brings `rpc/blockchain.cpp` in line with latest Bitcoin-ABC#51 tech.

Also removes some casts (a surprising number of these casts is actually
wrong; depends on !870) and contains a few other nits that should be
self-explanatory.

This MR includes some changes to `rest.cpp` where it uses functions
defined in `rpc/blockchain.cpp`. A few lines in `rpc/blockchain.cpp` are
not upgraded yet because they require changes to `core_write.cpp`, to be
done later.

Test plan: `ninja check check-univalue`
  • Loading branch information
BigBlockIfTrue committed Nov 25, 2020
1 parent f0dc1de commit f08c7ae
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 257 deletions.
11 changes: 6 additions & 5 deletions src/rest.cpp
@@ -1,5 +1,6 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Copyright (c) 2020 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -193,9 +194,10 @@ static bool rest_headers(Config &config, HTTPRequest *req,
return true;
}
case RetFormat::JSON: {
UniValue jsonHeaders(UniValue::VARR);
UniValue::Array jsonHeaders;
jsonHeaders.reserve(headers.size());
for (const CBlockIndex *pindex : headers) {
jsonHeaders.push_back(blockheaderToJSON(tip, pindex));
jsonHeaders.emplace_back(blockheaderToJSON(tip, pindex));
}
std::string strJSON = UniValue::stringify(jsonHeaders) + "\n";
req->WriteHeader("Content-Type", "application/json");
Expand Down Expand Up @@ -269,8 +271,7 @@ static bool rest_block(const Config &config, HTTPRequest *req,
}

case RetFormat::JSON: {
UniValue objBlock =
blockToJSON(block, tip, pblockindex, showTxDetails);
UniValue::Object objBlock = blockToJSON(block, tip, pblockindex, showTxDetails);
std::string strJSON = UniValue::stringify(objBlock) + "\n";
req->WriteHeader("Content-Type", "application/json");
req->WriteReply(HTTP_OK, strJSON);
Expand Down Expand Up @@ -332,7 +333,7 @@ static bool rest_mempool_info(Config &config, HTTPRequest *req,

switch (rf) {
case RetFormat::JSON: {
UniValue mempoolInfoObject = MempoolInfoToJSON(config, ::g_mempool);
UniValue::Object mempoolInfoObject = MempoolInfoToJSON(config, ::g_mempool);

std::string strJSON = UniValue::stringify(mempoolInfoObject) + "\n";
req->WriteHeader("Content-Type", "application/json");
Expand Down

0 comments on commit f08c7ae

Please sign in to comment.