Skip to content

Commit

Permalink
remove JSON Spirit UniValue wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jun 4, 2015
1 parent 1f263c8 commit 3df0411
Show file tree
Hide file tree
Showing 23 changed files with 239 additions and 258 deletions.
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ BITCOIN_CORE_H = \
ecwrapper.h \
hash.h \
init.h \
json_spirit_wrapper.h \
key.h \
keystore.h \
leveldbwrapper.h \
Expand Down
9 changes: 4 additions & 5 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static bool AppInitRPC(int argc, char* argv[])
return true;
}

Object CallRPC(const string& strMethod, const Array& params)
UniValue CallRPC(const string& strMethod, const Array& params)
{
if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
throw runtime_error(strprintf(
Expand Down Expand Up @@ -142,7 +142,7 @@ Object CallRPC(const string& strMethod, const Array& params)
throw runtime_error("no response from server");

// Parse reply
Value valReply(UniValue::VSTR);
UniValue valReply(UniValue::VSTR);
if (!valReply.read(strReply))
throw runtime_error("couldn't parse reply from server");
const Object& reply = valReply.get_obj();
Expand Down Expand Up @@ -170,14 +170,13 @@ int CommandLineRPC(int argc, char *argv[])

// Parameters default to strings
std::vector<std::string> strParams(&argv[2], &argv[argc]);
Array params = RPCConvertValues(strMethod, strParams);
UniValue params = RPCConvertValues(strMethod, strParams);

// Execute and handle connection failures with -rpcwait
const bool fWait = GetBoolArg("-rpcwait", false);
do {
try {
// Execute
Object reply = CallRPC(strMethod, params);
const UniValue reply = CallRPC(strMethod, params);

// Parse reply
const Value& result = find_value(reply, "result");
Expand Down
17 changes: 0 additions & 17 deletions src/json_spirit_wrapper.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class RestErr
};

extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry);
extern Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
extern UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
extern void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex);

static RestErr RESTERR(enum HTTPStatusCode status, string message)
Expand Down Expand Up @@ -221,7 +221,7 @@ static bool rest_block(AcceptedConnection* conn,
}

case RF_JSON: {
Object objBlock = blockToJSON(block, pblockindex, showTxDetails);
UniValue objBlock = blockToJSON(block, pblockindex, showTxDetails);
string strJSON = objBlock.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
Expand Down Expand Up @@ -266,7 +266,7 @@ static bool rest_chaininfo(AcceptedConnection* conn,
switch (rf) {
case RF_JSON: {
UniValue rpcParams(UniValue::VARR);
Value chainInfoObject = getblockchaininfo(rpcParams, false);
UniValue chainInfoObject = getblockchaininfo(rpcParams, false);
string strJSON = chainInfoObject.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
Expand Down
30 changes: 15 additions & 15 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ double GetDifficulty(const CBlockIndex* blockindex)
}


Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
{
UniValue result(UniValue::VOBJ);
result.push_back(Pair("hash", block.GetHash().GetHex()));
Expand Down Expand Up @@ -94,7 +94,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDe
}


Value getblockcount(const Array& params, bool fHelp)
UniValue getblockcount(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand All @@ -111,7 +111,7 @@ Value getblockcount(const Array& params, bool fHelp)
return chainActive.Height();
}

Value getbestblockhash(const Array& params, bool fHelp)
UniValue getbestblockhash(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand All @@ -128,7 +128,7 @@ Value getbestblockhash(const Array& params, bool fHelp)
return chainActive.Tip()->GetBlockHash().GetHex();
}

Value getdifficulty(const Array& params, bool fHelp)
UniValue getdifficulty(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand All @@ -146,7 +146,7 @@ Value getdifficulty(const Array& params, bool fHelp)
}


Value getrawmempool(const Array& params, bool fHelp)
UniValue getrawmempool(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
Expand Down Expand Up @@ -231,7 +231,7 @@ Value getrawmempool(const Array& params, bool fHelp)
}
}

Value getblockhash(const Array& params, bool fHelp)
UniValue getblockhash(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
Expand All @@ -256,7 +256,7 @@ Value getblockhash(const Array& params, bool fHelp)
return pblockindex->GetBlockHash().GetHex();
}

Value getblock(const Array& params, bool fHelp)
UniValue getblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
Expand Down Expand Up @@ -324,7 +324,7 @@ Value getblock(const Array& params, bool fHelp)
return blockToJSON(block, pblockindex);
}

Value gettxoutsetinfo(const Array& params, bool fHelp)
UniValue gettxoutsetinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand Down Expand Up @@ -364,7 +364,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
return ret;
}

Value gettxout(const Array& params, bool fHelp)
UniValue gettxout(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)
throw runtime_error(
Expand Down Expand Up @@ -444,7 +444,7 @@ Value gettxout(const Array& params, bool fHelp)
return ret;
}

Value verifychain(const Array& params, bool fHelp)
UniValue verifychain(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
Expand Down Expand Up @@ -472,7 +472,7 @@ Value verifychain(const Array& params, bool fHelp)
return CVerifyDB().VerifyDB(pcoinsTip, nCheckLevel, nCheckDepth);
}

Value getblockchaininfo(const Array& params, bool fHelp)
UniValue getblockchaininfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand Down Expand Up @@ -530,7 +530,7 @@ struct CompareBlocksByHeight
}
};

Value getchaintips(const Array& params, bool fHelp)
UniValue getchaintips(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand Down Expand Up @@ -620,7 +620,7 @@ Value getchaintips(const Array& params, bool fHelp)
return res;
}

Value getmempoolinfo(const Array& params, bool fHelp)
UniValue getmempoolinfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand All @@ -643,7 +643,7 @@ Value getmempoolinfo(const Array& params, bool fHelp)
return ret;
}

Value invalidateblock(const Array& params, bool fHelp)
UniValue invalidateblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down Expand Up @@ -681,7 +681,7 @@ Value invalidateblock(const Array& params, bool fHelp)
return NullUniValue;
}

Value reconsiderblock(const Array& params, bool fHelp)
UniValue reconsiderblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down
2 changes: 1 addition & 1 deletion src/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CRPCConvertTable::CRPCConvertTable()
static CRPCConvertTable rpcCvtTable;

/** Convert strings to command-specific RPC representation */
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
{
UniValue params(UniValue::VARR);

Expand Down
4 changes: 2 additions & 2 deletions src/rpcclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef BITCOIN_RPCCLIENT_H
#define BITCOIN_RPCCLIENT_H

#include "json_spirit_wrapper.h"
#include "univalue/univalue.h"

json_spirit::Array RPCConvertValues(const std::string& strMethod, const std::vector<std::string>& strParams);
UniValue RPCConvertValues(const std::string& strMethod, const std::vector<std::string>& strParams);

#endif // BITCOIN_RPCCLIENT_H
26 changes: 13 additions & 13 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using namespace std;
* or from the last difficulty change if 'lookup' is nonpositive.
* If 'height' is nonnegative, compute the estimate at the time when a given block was found.
*/
Value GetNetworkHashPS(int lookup, int height) {
UniValue GetNetworkHashPS(int lookup, int height) {
CBlockIndex *pb = chainActive.Tip();

if (height >= 0 && height < chainActive.Height())
Expand Down Expand Up @@ -71,7 +71,7 @@ Value GetNetworkHashPS(int lookup, int height) {
return (int64_t)(workDiff.getdouble() / timeDiff);
}

Value getnetworkhashps(const Array& params, bool fHelp)
UniValue getnetworkhashps(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 2)
throw runtime_error(
Expand All @@ -94,7 +94,7 @@ Value getnetworkhashps(const Array& params, bool fHelp)
}

#ifdef ENABLE_WALLET
Value getgenerate(const Array& params, bool fHelp)
UniValue getgenerate(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand All @@ -113,7 +113,7 @@ Value getgenerate(const Array& params, bool fHelp)
return GetBoolArg("-gen", false);
}

Value generate(const Array& params, bool fHelp)
UniValue generate(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
Expand Down Expand Up @@ -172,7 +172,7 @@ Value generate(const Array& params, bool fHelp)
}


Value setgenerate(const Array& params, bool fHelp)
UniValue setgenerate(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
Expand Down Expand Up @@ -220,7 +220,7 @@ Value setgenerate(const Array& params, bool fHelp)
#endif


Value getmininginfo(const Array& params, bool fHelp)
UniValue getmininginfo(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
Expand Down Expand Up @@ -266,7 +266,7 @@ Value getmininginfo(const Array& params, bool fHelp)


// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
Value prioritisetransaction(const Array& params, bool fHelp)
UniValue prioritisetransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 3)
throw runtime_error(
Expand Down Expand Up @@ -298,7 +298,7 @@ Value prioritisetransaction(const Array& params, bool fHelp)


// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
static Value BIP22ValidationResult(const CValidationState& state)
static UniValue BIP22ValidationResult(const CValidationState& state)
{
if (state.IsValid())
return Value::null;
Expand All @@ -316,7 +316,7 @@ static Value BIP22ValidationResult(const CValidationState& state)
return "valid?";
}

Value getblocktemplate(const Array& params, bool fHelp)
UniValue getblocktemplate(const Array& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
Expand Down Expand Up @@ -381,7 +381,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
LOCK(cs_main);

std::string strMode = "template";
Value lpval = NullUniValue;
UniValue lpval = NullUniValue;
if (params.size() > 0)
{
const Object& oparam = params[0].get_obj();
Expand Down Expand Up @@ -605,7 +605,7 @@ class submitblock_StateCatcher : public CValidationInterface
};
};

Value submitblock(const Array& params, bool fHelp)
UniValue submitblock(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
Expand Down Expand Up @@ -666,7 +666,7 @@ Value submitblock(const Array& params, bool fHelp)
return BIP22ValidationResult(state);
}

Value estimatefee(const Array& params, bool fHelp)
UniValue estimatefee(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down Expand Up @@ -698,7 +698,7 @@ Value estimatefee(const Array& params, bool fHelp)
return ValueFromAmount(feeRate.GetFeePerK());
}

Value estimatepriority(const Array& params, bool fHelp)
UniValue estimatepriority(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down
Loading

0 comments on commit 3df0411

Please sign in to comment.