Skip to content

Commit

Permalink
extend conversion to UniValue
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jun 4, 2015
1 parent 15982a8 commit 53b4671
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ BITCOIN_CORE_H = \
ecwrapper.h \
hash.h \
init.h \
json_spirit_wrapper.h \
key.h \
keystore.h \
leveldbwrapper.h \
Expand Down
2 changes: 1 addition & 1 deletion src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
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;
Value valReply(UniValue::VSTR);
if (!valReply.read(strReply))
throw runtime_error("couldn't parse reply from server");
const Object& reply = valReply.get_obj();
Expand Down
9 changes: 4 additions & 5 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static bool rest_block(AcceptedConnection* conn,

case RF_JSON: {
Object objBlock = blockToJSON(block, pblockindex, showTxDetails);
string strJSON = write_string(Value(objBlock), false) + "\n";
string strJSON = objBlock.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
}
Expand Down Expand Up @@ -267,8 +267,7 @@ static bool rest_chaininfo(AcceptedConnection* conn,
case RF_JSON: {
Array rpcParams;
Value chainInfoObject = getblockchaininfo(rpcParams, false);

string strJSON = write_string(chainInfoObject, false) + "\n";
string strJSON = chainInfoObject.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
}
Expand Down Expand Up @@ -319,7 +318,7 @@ static bool rest_tx(AcceptedConnection* conn,
case RF_JSON: {
Object objTx;
TxToJSON(tx, hashBlock, objTx);
string strJSON = write_string(Value(objTx), false) + "\n";
string strJSON = objTx.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
}
Expand Down Expand Up @@ -516,7 +515,7 @@ static bool rest_getutxos(AcceptedConnection* conn,
objGetUTXOResponse.push_back(Pair("utxos", utxos));

// return json string
string strJSON = write_string(Value(objGetUTXOResponse), false) + "\n";
string strJSON = objGetUTXOResponse.write() + "\n";
conn->stream() << HTTPReply(HTTP_OK, strJSON, fRun) << std::flush;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ Value invalidateblock(const Array& params, bool fHelp)
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason());
}

return Value::null;
return NullUniValue;
}

Value reconsiderblock(const Array& params, bool fHelp)
Expand Down Expand Up @@ -717,5 +717,5 @@ Value reconsiderblock(const Array& params, bool fHelp)
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason());
}

return Value::null;
return NullUniValue;
}
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 @@ static CRPCConvertTable rpcCvtTable;
/** Convert strings to command-specific RPC representation */
Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
{
Array params;
UniValue params(UniValue::VARR);

for (unsigned int idx = 0; idx < strParams.size(); idx++) {
const std::string& strVal = strParams[idx];
Expand Down
4 changes: 2 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
if (strMode == "proposal")
{
const Value& dataval = find_value(oparam, "data");
if (dataval.type() != str_type)
if (dataval.isStr())
throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");

CBlock block;
Expand Down Expand Up @@ -519,7 +519,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
pblock->nNonce = 0;

static const Array aCaps = boost::assign::list_of("proposal");
Array aCaps; aCaps.push_back("proposal");

Array transactions;
map<uint256, int64_t> setTxIndex;
Expand Down
4 changes: 2 additions & 2 deletions src/rpcmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ Value setmocktime(const Array& params, bool fHelp)

LOCK(cs_main);

RPCTypeCheck(params, boost::assign::list_of(int_type));
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
SetMockTime(params[0].get_int64());

return Value::null;
return NullUniValue;
}
6 changes: 3 additions & 3 deletions src/rpcprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int ReadHTTPMessage(std::basic_istream<char>& stream, map<string,

string JSONRPCRequest(const string& strMethod, const Array& params, const Value& id)
{
Object request;
Object request(UniValue::VOBJ);
request.push_back(Pair("method", strMethod));
request.push_back(Pair("params", params));
request.push_back(Pair("id", id));
Expand All @@ -265,7 +265,7 @@ string JSONRPCRequest(const string& strMethod, const Array& params, const Value&

Object JSONRPCReplyObj(const Value& result, const Value& error, const Value& id)
{
Object reply;
Object reply(UniValue::VOBJ);
if (!error.isNull())
reply.push_back(Pair("result", NullUniValue));
else
Expand All @@ -283,7 +283,7 @@ string JSONRPCReply(const Value& result, const Value& error, const Value& id)

Object JSONRPCError(int code, const string& message)
{
Object error;
UniValue error(UniValue::VOBJ);
error.push_back(Pair("code", code));
error.push_back(Pair("message", message));
return error;
Expand Down
7 changes: 4 additions & 3 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ Value gettxoutproof(const Array& params, bool fHelp)
set<uint256> setTxids;
uint256 oneTxid;
Array txids = params[0].get_array();
BOOST_FOREACH(Value& txid, txids) {
for (unsigned int idx = 0; idx < txids.size(); idx++) {
const Value& txid = txids[idx];
if (txid.get_str().length() != 64 || !IsHex(txid.get_str()))
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid txid ")+txid.get_str());
uint256 hash(uint256S(txid.get_str()));
Expand Down Expand Up @@ -446,7 +447,7 @@ Value decoderawtransaction(const Array& params, bool fHelp)
if (!DecodeHexTx(tx, params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");

Object result;
UniValue result(UniValue::VOBJ);
TxToJSON(tx, uint256(), result);

return result;
Expand Down Expand Up @@ -478,7 +479,7 @@ Value decodescript(const Array& params, bool fHelp)
);

LOCK(cs_main);
RPCTypeCheck(params, boost::assign::list_of(str_type));
RPCTypeCheck(params, boost::assign::list_of(UniValue::VSTR));

Object r;
CScript script;
Expand Down
14 changes: 8 additions & 6 deletions src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,13 @@ BOOST_AUTO_TEST_CASE(script_build)
Array json_good = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid)));
Array json_bad = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid)));

BOOST_FOREACH(Value& tv, json_good) {
tests_good.insert(write_string(Value(tv.get_array()), true));
for (unsigned int idx = 0; idx < json_good.size(); idx++) {
const Value& tv = json_good[idx];
tests_good.insert(tv.get_array().write());
}
BOOST_FOREACH(Value& tv, json_bad) {
tests_bad.insert(write_string(Value(tv.get_array()), true));
for (unsigned int idx = 0; idx < json_bad.size(); idx++) {
const Value& tv = json_bad[idx];
tests_bad.insert(tv.get_array().write());
}
}

Expand All @@ -596,7 +598,7 @@ BOOST_AUTO_TEST_CASE(script_build)

BOOST_FOREACH(TestBuilder& test, good) {
test.Test(true);
std::string str = write_string(Value(test.GetJSON()), true);
std::string str = test.GetJSON().write();
#ifndef UPDATE_JSON_TESTS
if (tests_good.count(str) == 0) {
BOOST_CHECK_MESSAGE(false, "Missing auto script_valid test: " + test.GetComment());
Expand All @@ -606,7 +608,7 @@ BOOST_AUTO_TEST_CASE(script_build)
}
BOOST_FOREACH(TestBuilder& test, bad) {
test.Test(false);
std::string str = write_string(Value(test.GetJSON()), true);
std::string str = test.GetJSON().write();
#ifndef UPDATE_JSON_TESTS
if (tests_bad.count(str) == 0) {
BOOST_CHECK_MESSAGE(false, "Missing auto script_invalid test: " + test.GetComment());
Expand Down
1 change: 1 addition & 0 deletions src/test/transaction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/assign/list_of.hpp>

Expand Down
10 changes: 5 additions & 5 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::string DecodeDumpString(const std::string &str) {
Value importprivkey(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
return NullUniValue;

if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
Expand Down Expand Up @@ -147,7 +147,7 @@ Value importprivkey(const Array& params, bool fHelp)
Value importaddress(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
return NullUniValue;

if (fHelp || params.size() < 1 || params.size() > 3)
throw runtime_error(
Expand Down Expand Up @@ -220,7 +220,7 @@ Value importaddress(const Array& params, bool fHelp)
Value importwallet(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
return NullUniValue;

if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down Expand Up @@ -324,7 +324,7 @@ Value importwallet(const Array& params, bool fHelp)
Value dumpprivkey(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
return NullUniValue;

if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down Expand Up @@ -362,7 +362,7 @@ Value dumpprivkey(const Array& params, bool fHelp)
Value dumpwallet(const Array& params, bool fHelp)
{
if (!EnsureWalletIsAvailable(fHelp))
return Value::null;
return NullUniValue;

if (fHelp || params.size() != 1)
throw runtime_error(
Expand Down
Loading

0 comments on commit 53b4671

Please sign in to comment.