Remove JSON Spirit wrapper, remove JSON Spirit leftovers

- implement find_value() function for UniValue
- replace all Array/Value/Object types with UniValues, remove JSON Spirit to UniValue wrapper
- remove JSON Spirit sources
This commit is contained in:
Jonas Schnelli
2015-05-18 14:02:18 +02:00
parent 3df0411ad9
commit 9a8897f4ac
37 changed files with 213 additions and 2203 deletions

View File

@@ -25,12 +25,12 @@
#include <stdint.h>
#include <boost/assign/list_of.hpp>
#include "json_spirit_wrapper.h"
using namespace json_spirit;
#include "univalue/univalue.h"
using namespace std;
void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeHex)
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
{
txnouttype type;
vector<CTxDestination> addresses;
@@ -54,7 +54,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH
out.push_back(Pair("addresses", a));
}
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
{
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("version", tx.nVersion));
@@ -105,7 +105,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, Object& entry)
}
}
UniValue getrawtransaction(const Array& params, bool fHelp)
UniValue getrawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
@@ -195,7 +195,7 @@ UniValue getrawtransaction(const Array& params, bool fHelp)
return result;
}
UniValue gettxoutproof(const Array& params, bool fHelp)
UniValue gettxoutproof(const UniValue& params, bool fHelp)
{
if (fHelp || (params.size() != 1 && params.size() != 2))
throw runtime_error(
@@ -221,7 +221,7 @@ UniValue gettxoutproof(const Array& params, bool fHelp)
uint256 oneTxid;
UniValue txids = params[0].get_array();
for (unsigned int idx = 0; idx < txids.size(); idx++) {
const Value& txid = txids[idx];
const UniValue& 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()));
@@ -276,7 +276,7 @@ UniValue gettxoutproof(const Array& params, bool fHelp)
return strHex;
}
UniValue verifytxoutproof(const Array& params, bool fHelp)
UniValue verifytxoutproof(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
@@ -309,7 +309,7 @@ UniValue verifytxoutproof(const Array& params, bool fHelp)
return res;
}
UniValue createrawtransaction(const Array& params, bool fHelp)
UniValue createrawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error(
@@ -351,12 +351,12 @@ UniValue createrawtransaction(const Array& params, bool fHelp)
CMutableTransaction rawTx;
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
const Value& input = inputs[idx];
const Object& o = input.get_obj();
const UniValue& input = inputs[idx];
const UniValue& o = input.get_obj();
uint256 txid = ParseHashO(o, "txid");
const Value& vout_v = find_value(o, "vout");
const UniValue& vout_v = find_value(o, "vout");
if (!vout_v.isNum())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
int nOutput = vout_v.get_int();
@@ -388,7 +388,7 @@ UniValue createrawtransaction(const Array& params, bool fHelp)
return EncodeHexTx(rawTx);
}
UniValue decoderawtransaction(const Array& params, bool fHelp)
UniValue decoderawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
@@ -453,7 +453,7 @@ UniValue decoderawtransaction(const Array& params, bool fHelp)
return result;
}
UniValue decodescript(const Array& params, bool fHelp)
UniValue decodescript(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
@@ -496,7 +496,7 @@ UniValue decodescript(const Array& params, bool fHelp)
}
/** Pushes a JSON object for script verification or signing errors to vErrorsRet. */
static void TxInErrorToJSON(const CTxIn& txin, Array& vErrorsRet, const std::string& strMessage)
static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::string& strMessage)
{
UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("txid", txin.prevout.hash.ToString()));
@@ -507,7 +507,7 @@ static void TxInErrorToJSON(const CTxIn& txin, Array& vErrorsRet, const std::str
vErrorsRet.push_back(entry);
}
UniValue signrawtransaction(const Array& params, bool fHelp)
UniValue signrawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 4)
throw runtime_error(
@@ -639,7 +639,7 @@ UniValue signrawtransaction(const Array& params, bool fHelp)
if (params.size() > 1 && !params[1].isNull()) {
UniValue prevTxs = params[1].get_array();
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
const Value& p = prevTxs[idx];
const UniValue& p = prevTxs[idx];
if (!p.isObject())
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "expected object with {\"txid'\",\"vout\",\"scriptPubKey\"}");
@@ -749,7 +749,7 @@ UniValue signrawtransaction(const Array& params, bool fHelp)
return result;
}
UniValue sendrawtransaction(const Array& params, bool fHelp)
UniValue sendrawtransaction(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(