Skip to content

Commit 466f0ea

Browse files
committed
Merge pull request #6121
44c7474 univalue: add type check unit tests (Jonas Schnelli) c023092 univalue: add strict type checking (Wladimir J. van der Laan) 7e98a3c util: Add ParseInt64 and ParseDouble functions (Wladimir J. van der Laan) 043df2b Simplify RPCclient, adapt json_parse_error test (Wladimir J. van der Laan) 519eede fix univalue json parse tests (Jonas Schnelli) c7fbbc7 fix missing univalue types during constructing (Jonas Schnelli) 8f7e4ab fix rpc batching univalue issue (Jonas Schnelli) 9a8897f Remove JSON Spirit wrapper, remove JSON Spirit leftovers (Jonas Schnelli) 3df0411 remove JSON Spirit UniValue wrapper (Jonas Schnelli) 1f263c8 fix rpc unit test, plain numbers are not JSON compatible object (Jonas Schnelli) e04d9c2 univalue: correct bool support (Jonas Schnelli) 0c5b2cf univalue: add support for real, fix percision and make it json_spirit compatible (Jonas Schnelli) 21c10de special threatment for null,true,false because they are non valid json (Jonas Schnelli) 6c7bee0 expicit set UniValue type to avoid empty values (Jonas Schnelli) 53b4671 extend conversion to UniValue (Jonas Schnelli) 15982a8 Convert tree to using univalue. Eliminate all json_spirit uses. (Jeff Garzik) 5e3060c UniValue: export NullUniValue global constant (Jeff Garzik) efc7883 UniValue: prefer .size() to .count(), to harmonize w/ existing tree (Jeff Garzik)
2 parents dbd8550 + 44c7474 commit 466f0ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1129
-2742
lines changed

src/Makefile.am

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,6 @@ BITCOIN_CORE_H = \
154154
wallet/wallet_ismine.h \
155155
wallet/walletdb.h
156156

157-
JSON_H = \
158-
json/json_spirit.h \
159-
json/json_spirit_error_position.h \
160-
json/json_spirit_reader.h \
161-
json/json_spirit_reader_template.h \
162-
json/json_spirit_stream_reader.h \
163-
json/json_spirit_utils.h \
164-
json/json_spirit_value.h \
165-
json/json_spirit_writer.h \
166-
json/json_spirit_writer_template.h
167-
168157
obj/build.h: FORCE
169158
@$(MKDIR_P) $(builddir)/obj
170159
@$(top_srcdir)/share/genbuild.sh $(abs_top_builddir)/src/obj/build.h \
@@ -200,7 +189,6 @@ libbitcoin_server_a_SOURCES = \
200189
txdb.cpp \
201190
txmempool.cpp \
202191
validationinterface.cpp \
203-
$(JSON_H) \
204192
$(BITCOIN_CORE_H)
205193

206194
# wallet: shared between bitcoind and bitcoin-qt, but only linked
@@ -342,6 +330,7 @@ endif
342330

343331
bitcoin_cli_LDADD = \
344332
$(LIBBITCOIN_CLI) \
333+
$(LIBBITCOIN_UNIVALUE) \
345334
$(LIBBITCOIN_UTIL) \
346335
$(LIBSECP256K1)
347336

src/bitcoin-cli.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
#include <boost/filesystem/operations.hpp>
1414

15+
#include "univalue/univalue.h"
16+
1517
using namespace std;
16-
using namespace json_spirit;
1718

1819
std::string HelpMessageCli()
1920
{
@@ -94,7 +95,7 @@ static bool AppInitRPC(int argc, char* argv[])
9495
return true;
9596
}
9697

97-
Object CallRPC(const string& strMethod, const Array& params)
98+
UniValue CallRPC(const string& strMethod, const UniValue& params)
9899
{
99100
if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "")
100101
throw runtime_error(strprintf(
@@ -142,10 +143,10 @@ Object CallRPC(const string& strMethod, const Array& params)
142143
throw runtime_error("no response from server");
143144

144145
// Parse reply
145-
Value valReply;
146-
if (!read_string(strReply, valReply))
146+
UniValue valReply(UniValue::VSTR);
147+
if (!valReply.read(strReply))
147148
throw runtime_error("couldn't parse reply from server");
148-
const Object& reply = valReply.get_obj();
149+
const UniValue& reply = valReply.get_obj();
149150
if (reply.empty())
150151
throw runtime_error("expected reply to have result, error and id properties");
151152

@@ -170,35 +171,34 @@ int CommandLineRPC(int argc, char *argv[])
170171

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

175176
// Execute and handle connection failures with -rpcwait
176177
const bool fWait = GetBoolArg("-rpcwait", false);
177178
do {
178179
try {
179-
const Object reply = CallRPC(strMethod, params);
180+
const UniValue reply = CallRPC(strMethod, params);
180181

181182
// Parse reply
182-
const Value& result = find_value(reply, "result");
183-
const Value& error = find_value(reply, "error");
183+
const UniValue& result = find_value(reply, "result");
184+
const UniValue& error = find_value(reply, "error");
184185

185-
if (error.type() != null_type) {
186+
if (!error.isNull()) {
186187
// Error
187-
const int code = find_value(error.get_obj(), "code").get_int();
188+
int code = error["code"].get_int();
188189
if (fWait && code == RPC_IN_WARMUP)
189190
throw CConnectionFailed("server in warmup");
190-
strPrint = "error: " + write_string(error, false);
191+
strPrint = "error: " + error.write();
191192
nRet = abs(code);
192193
} else {
193194
// Result
194-
if (result.type() == null_type)
195+
if (result.isNull())
195196
strPrint = "";
196-
else if (result.type() == str_type)
197+
else if (result.isStr())
197198
strPrint = result.get_str();
198199
else
199-
strPrint = write_string(result, true);
200+
strPrint = result.write(2);
200201
}
201-
202202
// Connection succeeded, no need to retry.
203203
break;
204204
}

src/bitcoin-tx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
346346
UniValue keysObj = registers["privatekeys"];
347347
fGivenKeys = true;
348348

349-
for (unsigned int kidx = 0; kidx < keysObj.count(); kidx++) {
349+
for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
350350
if (!keysObj[kidx].isStr())
351351
throw runtime_error("privatekey not a string");
352352
CBitcoinSecret vchSecret;
@@ -363,7 +363,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
363363
throw runtime_error("prevtxs register variable must be set.");
364364
UniValue prevtxsObj = registers["prevtxs"];
365365
{
366-
for (unsigned int previdx = 0; previdx < prevtxsObj.count(); previdx++) {
366+
for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
367367
UniValue prevOut = prevtxsObj[previdx];
368368
if (!prevOut.isObject())
369369
throw runtime_error("expected prevtxs internal object");

src/json/LICENSE.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/json/json_spirit.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/json/json_spirit_error_position.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/json/json_spirit_reader.cpp

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)