Browse Source

Refactor: Remove using namespace <xxx> from rpc/

0.15
Karl-Johan Alm 8 years ago
parent
commit
f3c264e9a6
No known key found for this signature in database
GPG Key ID: 57AF762DB3353322
  1. 57
      src/rpc/blockchain.cpp
  2. 4
      src/rpc/client.cpp
  3. 24
      src/rpc/mining.cpp
  4. 58
      src/rpc/misc.cpp
  5. 40
      src/rpc/net.cpp
  6. 8
      src/rpc/protocol.cpp
  7. 72
      src/rpc/rawtransaction.cpp
  8. 55
      src/rpc/server.cpp

57
src/rpc/blockchain.cpp

@ -28,7 +28,6 @@
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
using namespace std;
struct CUpdatedBlock struct CUpdatedBlock
{ {
@ -154,7 +153,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
UniValue getblockcount(const JSONRPCRequest& request) UniValue getblockcount(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getblockcount\n" "getblockcount\n"
"\nReturns the number of blocks in the longest blockchain.\n" "\nReturns the number of blocks in the longest blockchain.\n"
"\nResult:\n" "\nResult:\n"
@ -171,7 +170,7 @@ UniValue getblockcount(const JSONRPCRequest& request)
UniValue getbestblockhash(const JSONRPCRequest& request) UniValue getbestblockhash(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getbestblockhash\n" "getbestblockhash\n"
"\nReturns the hash of the best (tip) block in the longest blockchain.\n" "\nReturns the hash of the best (tip) block in the longest blockchain.\n"
"\nResult:\n" "\nResult:\n"
@ -198,7 +197,7 @@ void RPCNotifyBlockChange(bool ibd, const CBlockIndex * pindex)
UniValue waitfornewblock(const JSONRPCRequest& request) UniValue waitfornewblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 1) if (request.fHelp || request.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"waitfornewblock (timeout)\n" "waitfornewblock (timeout)\n"
"\nWaits for a specific new block and returns useful info about it.\n" "\nWaits for a specific new block and returns useful info about it.\n"
"\nReturns the current block on timeout or exit.\n" "\nReturns the current block on timeout or exit.\n"
@ -236,7 +235,7 @@ UniValue waitfornewblock(const JSONRPCRequest& request)
UniValue waitforblock(const JSONRPCRequest& request) UniValue waitforblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"waitforblock <blockhash> (timeout)\n" "waitforblock <blockhash> (timeout)\n"
"\nWaits for a specific new block and returns useful info about it.\n" "\nWaits for a specific new block and returns useful info about it.\n"
"\nReturns the current block on timeout or exit.\n" "\nReturns the current block on timeout or exit.\n"
@ -278,7 +277,7 @@ UniValue waitforblock(const JSONRPCRequest& request)
UniValue waitforblockheight(const JSONRPCRequest& request) UniValue waitforblockheight(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"waitforblockheight <height> (timeout)\n" "waitforblockheight <height> (timeout)\n"
"\nWaits for (at least) block height and returns the height and hash\n" "\nWaits for (at least) block height and returns the height and hash\n"
"of the current tip.\n" "of the current tip.\n"
@ -320,7 +319,7 @@ UniValue waitforblockheight(const JSONRPCRequest& request)
UniValue getdifficulty(const JSONRPCRequest& request) UniValue getdifficulty(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getdifficulty\n" "getdifficulty\n"
"\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n" "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
"\nResult:\n" "\nResult:\n"
@ -368,7 +367,7 @@ void entryToJSON(UniValue &info, const CTxMemPoolEntry &e)
info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors())); info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors()));
info.push_back(Pair("ancestorfees", e.GetModFeesWithAncestors())); info.push_back(Pair("ancestorfees", e.GetModFeesWithAncestors()));
const CTransaction& tx = e.GetTx(); const CTransaction& tx = e.GetTx();
set<string> setDepends; std::set<std::string> setDepends;
BOOST_FOREACH(const CTxIn& txin, tx.vin) BOOST_FOREACH(const CTxIn& txin, tx.vin)
{ {
if (mempool.exists(txin.prevout.hash)) if (mempool.exists(txin.prevout.hash))
@ -376,7 +375,7 @@ void entryToJSON(UniValue &info, const CTxMemPoolEntry &e)
} }
UniValue depends(UniValue::VARR); UniValue depends(UniValue::VARR);
BOOST_FOREACH(const string& dep, setDepends) BOOST_FOREACH(const std::string& dep, setDepends)
{ {
depends.push_back(dep); depends.push_back(dep);
} }
@ -401,7 +400,7 @@ UniValue mempoolToJSON(bool fVerbose = false)
} }
else else
{ {
vector<uint256> vtxid; std::vector<uint256> vtxid;
mempool.queryHashes(vtxid); mempool.queryHashes(vtxid);
UniValue a(UniValue::VARR); UniValue a(UniValue::VARR);
@ -415,7 +414,7 @@ UniValue mempoolToJSON(bool fVerbose = false)
UniValue getrawmempool(const JSONRPCRequest& request) UniValue getrawmempool(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 1) if (request.fHelp || request.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"getrawmempool ( verbose )\n" "getrawmempool ( verbose )\n"
"\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n" "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
"\nArguments:\n" "\nArguments:\n"
@ -446,7 +445,7 @@ UniValue getrawmempool(const JSONRPCRequest& request)
UniValue getmempoolancestors(const JSONRPCRequest& request) UniValue getmempoolancestors(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
throw runtime_error( throw std::runtime_error(
"getmempoolancestors txid (verbose)\n" "getmempoolancestors txid (verbose)\n"
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n" "\nIf txid is in the mempool, returns all in-mempool ancestors.\n"
"\nArguments:\n" "\nArguments:\n"
@ -510,7 +509,7 @@ UniValue getmempoolancestors(const JSONRPCRequest& request)
UniValue getmempooldescendants(const JSONRPCRequest& request) UniValue getmempooldescendants(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) { if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
throw runtime_error( throw std::runtime_error(
"getmempooldescendants txid (verbose)\n" "getmempooldescendants txid (verbose)\n"
"\nIf txid is in the mempool, returns all in-mempool descendants.\n" "\nIf txid is in the mempool, returns all in-mempool descendants.\n"
"\nArguments:\n" "\nArguments:\n"
@ -574,7 +573,7 @@ UniValue getmempooldescendants(const JSONRPCRequest& request)
UniValue getmempoolentry(const JSONRPCRequest& request) UniValue getmempoolentry(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) { if (request.fHelp || request.params.size() != 1) {
throw runtime_error( throw std::runtime_error(
"getmempoolentry txid\n" "getmempoolentry txid\n"
"\nReturns mempool data for given transaction\n" "\nReturns mempool data for given transaction\n"
"\nArguments:\n" "\nArguments:\n"
@ -607,7 +606,7 @@ UniValue getmempoolentry(const JSONRPCRequest& request)
UniValue getblockhash(const JSONRPCRequest& request) UniValue getblockhash(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"getblockhash height\n" "getblockhash height\n"
"\nReturns hash of block in best-block-chain at height provided.\n" "\nReturns hash of block in best-block-chain at height provided.\n"
"\nArguments:\n" "\nArguments:\n"
@ -632,7 +631,7 @@ UniValue getblockhash(const JSONRPCRequest& request)
UniValue getblockheader(const JSONRPCRequest& request) UniValue getblockheader(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"getblockheader \"hash\" ( verbose )\n" "getblockheader \"hash\" ( verbose )\n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n" "\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
"If verbose is true, returns an Object with information about blockheader <hash>.\n" "If verbose is true, returns an Object with information about blockheader <hash>.\n"
@ -691,7 +690,7 @@ UniValue getblockheader(const JSONRPCRequest& request)
UniValue getblock(const JSONRPCRequest& request) UniValue getblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"getblock \"blockhash\" ( verbose )\n" "getblock \"blockhash\" ( verbose )\n"
"\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n" "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
"If verbose is true, returns an Object with information about block <hash>.\n" "If verbose is true, returns an Object with information about block <hash>.\n"
@ -818,7 +817,7 @@ static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats)
UniValue pruneblockchain(const JSONRPCRequest& request) UniValue pruneblockchain(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"pruneblockchain\n" "pruneblockchain\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp\n" "1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp\n"
@ -867,7 +866,7 @@ UniValue pruneblockchain(const JSONRPCRequest& request)
UniValue gettxoutsetinfo(const JSONRPCRequest& request) UniValue gettxoutsetinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"gettxoutsetinfo\n" "gettxoutsetinfo\n"
"\nReturns statistics about the unspent transaction output set.\n" "\nReturns statistics about the unspent transaction output set.\n"
"Note this call may take some time.\n" "Note this call may take some time.\n"
@ -907,7 +906,7 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
UniValue gettxout(const JSONRPCRequest& request) UniValue gettxout(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error( throw std::runtime_error(
"gettxout \"txid\" n ( include_mempool )\n" "gettxout \"txid\" n ( include_mempool )\n"
"\nReturns details about an unspent transaction output.\n" "\nReturns details about an unspent transaction output.\n"
"\nArguments:\n" "\nArguments:\n"
@ -989,7 +988,7 @@ UniValue verifychain(const JSONRPCRequest& request)
int nCheckLevel = GetArg("-checklevel", DEFAULT_CHECKLEVEL); int nCheckLevel = GetArg("-checklevel", DEFAULT_CHECKLEVEL);
int nCheckDepth = GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); int nCheckDepth = GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
if (request.fHelp || request.params.size() > 2) if (request.fHelp || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"verifychain ( checklevel nblocks )\n" "verifychain ( checklevel nblocks )\n"
"\nVerifies blockchain database.\n" "\nVerifies blockchain database.\n"
"\nArguments:\n" "\nArguments:\n"
@ -1075,7 +1074,7 @@ void BIP9SoftForkDescPushBack(UniValue& bip9_softforks, const std::string &name,
UniValue getblockchaininfo(const JSONRPCRequest& request) UniValue getblockchaininfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getblockchaininfo\n" "getblockchaininfo\n"
"Returns an object containing various state info regarding blockchain processing.\n" "Returns an object containing various state info regarding blockchain processing.\n"
"\nResult:\n" "\nResult:\n"
@ -1168,7 +1167,7 @@ struct CompareBlocksByHeight
UniValue getchaintips(const JSONRPCRequest& request) UniValue getchaintips(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getchaintips\n" "getchaintips\n"
"Return information about all known tips in the block tree," "Return information about all known tips in the block tree,"
" including the main chain as well as orphaned branches.\n" " including the main chain as well as orphaned branches.\n"
@ -1201,7 +1200,7 @@ UniValue getchaintips(const JSONRPCRequest& request)
LOCK(cs_main); LOCK(cs_main);
/* /*
* Idea: the set of chain tips is chainActive.tip, plus orphan blocks which do not have another orphan building off of them. * Idea: the set of chain tips is chainActive.tip, plus orphan blocks which do not have another orphan building off of them.
* Algorithm: * Algorithm:
* - Make one pass through mapBlockIndex, picking out the orphan blocks, and also storing a set of the orphan block's pprev pointers. * - Make one pass through mapBlockIndex, picking out the orphan blocks, and also storing a set of the orphan block's pprev pointers.
* - Iterate through the orphan blocks. If the block isn't pointed to by another orphan, it is a chain tip. * - Iterate through the orphan blocks. If the block isn't pointed to by another orphan, it is a chain tip.
@ -1240,7 +1239,7 @@ UniValue getchaintips(const JSONRPCRequest& request)
const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight; const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
obj.push_back(Pair("branchlen", branchLen)); obj.push_back(Pair("branchlen", branchLen));
string status; std::string status;
if (chainActive.Contains(block)) { if (chainActive.Contains(block)) {
// This block is part of the currently active chain. // This block is part of the currently active chain.
status = "active"; status = "active";
@ -1284,7 +1283,7 @@ UniValue mempoolInfoToJSON()
UniValue getmempoolinfo(const JSONRPCRequest& request) UniValue getmempoolinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getmempoolinfo\n" "getmempoolinfo\n"
"\nReturns details on the active state of the TX memory pool.\n" "\nReturns details on the active state of the TX memory pool.\n"
"\nResult:\n" "\nResult:\n"
@ -1306,7 +1305,7 @@ UniValue getmempoolinfo(const JSONRPCRequest& request)
UniValue preciousblock(const JSONRPCRequest& request) UniValue preciousblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"preciousblock \"blockhash\"\n" "preciousblock \"blockhash\"\n"
"\nTreats a block as if it were received before others with the same work.\n" "\nTreats a block as if it were received before others with the same work.\n"
"\nA later preciousblock call can override the effect of an earlier one.\n" "\nA later preciousblock call can override the effect of an earlier one.\n"
@ -1344,7 +1343,7 @@ UniValue preciousblock(const JSONRPCRequest& request)
UniValue invalidateblock(const JSONRPCRequest& request) UniValue invalidateblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"invalidateblock \"blockhash\"\n" "invalidateblock \"blockhash\"\n"
"\nPermanently marks a block as invalid, as if it violated a consensus rule.\n" "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n"
"\nArguments:\n" "\nArguments:\n"
@ -1382,7 +1381,7 @@ UniValue invalidateblock(const JSONRPCRequest& request)
UniValue reconsiderblock(const JSONRPCRequest& request) UniValue reconsiderblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"reconsiderblock \"blockhash\"\n" "reconsiderblock \"blockhash\"\n"
"\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n" "\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n"
"This can be used to undo the effects of invalidateblock.\n" "This can be used to undo the effects of invalidateblock.\n"

4
src/rpc/client.cpp

@ -13,8 +13,6 @@
#include <boost/algorithm/string/case_conv.hpp> // for to_lower() #include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <univalue.h> #include <univalue.h>
using namespace std;
class CRPCConvertParam class CRPCConvertParam
{ {
public: public:
@ -168,7 +166,7 @@ UniValue ParseNonRFCJSONValue(const std::string& strVal)
UniValue jVal; UniValue jVal;
if (!jVal.read(std::string("[")+strVal+std::string("]")) || if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
!jVal.isArray() || jVal.size()!=1) !jVal.isArray() || jVal.size()!=1)
throw runtime_error(string("Error parsing JSON:")+strVal); throw std::runtime_error(std::string("Error parsing JSON:")+strVal);
return jVal[0]; return jVal[0];
} }

24
src/rpc/mining.cpp

@ -30,8 +30,6 @@
#include <univalue.h> #include <univalue.h>
using namespace std;
/** /**
* Return average network hashes per second based on the last 'lookup' blocks, * Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive. * or from the last difficulty change if 'lookup' is nonpositive.
@ -77,7 +75,7 @@ UniValue GetNetworkHashPS(int lookup, int height) {
UniValue getnetworkhashps(const JSONRPCRequest& request) UniValue getnetworkhashps(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 2) if (request.fHelp || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"getnetworkhashps ( nblocks height )\n" "getnetworkhashps ( nblocks height )\n"
"\nReturns the estimated network hashes per second based on the last n blocks.\n" "\nReturns the estimated network hashes per second based on the last n blocks.\n"
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n" "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
@ -149,7 +147,7 @@ UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nG
UniValue generate(const JSONRPCRequest& request) UniValue generate(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"generate nblocks ( maxtries )\n" "generate nblocks ( maxtries )\n"
"\nMine up to nblocks blocks immediately (before the RPC call returns)\n" "\nMine up to nblocks blocks immediately (before the RPC call returns)\n"
"\nArguments:\n" "\nArguments:\n"
@ -185,7 +183,7 @@ UniValue generate(const JSONRPCRequest& request)
UniValue generatetoaddress(const JSONRPCRequest& request) UniValue generatetoaddress(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error( throw std::runtime_error(
"generatetoaddress nblocks address (maxtries)\n" "generatetoaddress nblocks address (maxtries)\n"
"\nMine blocks immediately to a specified address (before the RPC call returns)\n" "\nMine blocks immediately to a specified address (before the RPC call returns)\n"
"\nArguments:\n" "\nArguments:\n"
@ -208,7 +206,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
CBitcoinAddress address(request.params[1].get_str()); CBitcoinAddress address(request.params[1].get_str());
if (!address.IsValid()) if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
boost::shared_ptr<CReserveScript> coinbaseScript(new CReserveScript()); boost::shared_ptr<CReserveScript> coinbaseScript(new CReserveScript());
coinbaseScript->reserveScript = GetScriptForDestination(address.Get()); coinbaseScript->reserveScript = GetScriptForDestination(address.Get());
@ -218,7 +216,7 @@ UniValue generatetoaddress(const JSONRPCRequest& request)
UniValue getmininginfo(const JSONRPCRequest& request) UniValue getmininginfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getmininginfo\n" "getmininginfo\n"
"\nReturns a json object containing mining-related information." "\nReturns a json object containing mining-related information."
"\nResult:\n" "\nResult:\n"
@ -259,7 +257,7 @@ UniValue getmininginfo(const JSONRPCRequest& request)
UniValue prioritisetransaction(const JSONRPCRequest& request) UniValue prioritisetransaction(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 2) if (request.fHelp || request.params.size() != 2)
throw runtime_error( throw std::runtime_error(
"prioritisetransaction <txid> <fee delta>\n" "prioritisetransaction <txid> <fee delta>\n"
"Accepts the transaction into mined blocks at a higher (or lower) priority\n" "Accepts the transaction into mined blocks at a higher (or lower) priority\n"
"\nArguments:\n" "\nArguments:\n"
@ -315,7 +313,7 @@ std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
UniValue getblocktemplate(const JSONRPCRequest& request) UniValue getblocktemplate(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 1) if (request.fHelp || request.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"getblocktemplate ( TemplateRequest )\n" "getblocktemplate ( TemplateRequest )\n"
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n" "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
"It returns data needed to construct a block to work on.\n" "It returns data needed to construct a block to work on.\n"
@ -553,7 +551,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal"); UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
UniValue transactions(UniValue::VARR); UniValue transactions(UniValue::VARR);
map<uint256, int64_t> setTxIndex; std::map<uint256, int64_t> setTxIndex;
int i = 0; int i = 0;
for (const auto& it : pblock->vtx) { for (const auto& it : pblock->vtx) {
const CTransaction& tx = *it; const CTransaction& tx = *it;
@ -712,7 +710,7 @@ protected:
UniValue submitblock(const JSONRPCRequest& request) UniValue submitblock(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"submitblock \"hexdata\" ( \"jsonparametersobject\" )\n" "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
"\nAttempts to submit new block to network.\n" "\nAttempts to submit new block to network.\n"
"The 'jsonparametersobject' parameter is currently ignored.\n" "The 'jsonparametersobject' parameter is currently ignored.\n"
@ -777,7 +775,7 @@ UniValue submitblock(const JSONRPCRequest& request)
UniValue estimatefee(const JSONRPCRequest& request) UniValue estimatefee(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"estimatefee nblocks\n" "estimatefee nblocks\n"
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
"confirmation within nblocks blocks. Uses virtual transaction size of transaction\n" "confirmation within nblocks blocks. Uses virtual transaction size of transaction\n"
@ -811,7 +809,7 @@ UniValue estimatefee(const JSONRPCRequest& request)
UniValue estimatesmartfee(const JSONRPCRequest& request) UniValue estimatesmartfee(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"estimatesmartfee nblocks\n" "estimatesmartfee nblocks\n"
"\nWARNING: This interface is unstable and may disappear or change!\n" "\nWARNING: This interface is unstable and may disappear or change!\n"
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"

58
src/rpc/misc.cpp

@ -25,8 +25,6 @@
#include <univalue.h> #include <univalue.h>
using namespace std;
/** /**
* @note Do not add or change anything in the information returned by this * @note Do not add or change anything in the information returned by this
* method. `getinfo` exists for backwards-compatibility only. It combines * method. `getinfo` exists for backwards-compatibility only. It combines
@ -43,7 +41,7 @@ using namespace std;
UniValue getinfo(const JSONRPCRequest& request) UniValue getinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getinfo\n" "getinfo\n"
"\nDEPRECATED. Returns an object containing various state info.\n" "\nDEPRECATED. Returns an object containing various state info.\n"
"\nResult:\n" "\nResult:\n"
@ -94,7 +92,7 @@ UniValue getinfo(const JSONRPCRequest& request)
obj.push_back(Pair("timeoffset", GetTimeOffset())); obj.push_back(Pair("timeoffset", GetTimeOffset()));
if(g_connman) if(g_connman)
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET)); obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
@ -159,7 +157,7 @@ public:
UniValue validateaddress(const JSONRPCRequest& request) UniValue validateaddress(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"validateaddress \"address\"\n" "validateaddress \"address\"\n"
"\nReturn information about the given bitcoin address.\n" "\nReturn information about the given bitcoin address.\n"
"\nArguments:\n" "\nArguments:\n"
@ -200,7 +198,7 @@ UniValue validateaddress(const JSONRPCRequest& request)
if (isValid) if (isValid)
{ {
CTxDestination dest = address.Get(); CTxDestination dest = address.Get();
string currentAddress = address.ToString(); std::string currentAddress = address.ToString();
ret.push_back(Pair("address", currentAddress)); ret.push_back(Pair("address", currentAddress));
CScript scriptPubKey = GetScriptForDestination(dest); CScript scriptPubKey = GetScriptForDestination(dest);
@ -248,13 +246,13 @@ CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& pa
// Gather public keys // Gather public keys
if (nRequired < 1) if (nRequired < 1)
throw runtime_error("a multisignature address must require at least one key to redeem"); throw std::runtime_error("a multisignature address must require at least one key to redeem");
if ((int)keys.size() < nRequired) if ((int)keys.size() < nRequired)
throw runtime_error( throw std::runtime_error(
strprintf("not enough keys supplied " strprintf("not enough keys supplied "
"(got %u keys, but need at least %d to redeem)", keys.size(), nRequired)); "(got %u keys, but need at least %d to redeem)", keys.size(), nRequired));
if (keys.size() > 16) if (keys.size() > 16)
throw runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number"); throw std::runtime_error("Number of addresses involved in the multisignature address creation > 16\nReduce the number");
std::vector<CPubKey> pubkeys; std::vector<CPubKey> pubkeys;
pubkeys.resize(keys.size()); pubkeys.resize(keys.size());
for (unsigned int i = 0; i < keys.size(); i++) for (unsigned int i = 0; i < keys.size(); i++)
@ -266,15 +264,15 @@ CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& pa
if (pwallet && address.IsValid()) { if (pwallet && address.IsValid()) {
CKeyID keyID; CKeyID keyID;
if (!address.GetKeyID(keyID)) if (!address.GetKeyID(keyID))
throw runtime_error( throw std::runtime_error(
strprintf("%s does not refer to a key",ks)); strprintf("%s does not refer to a key",ks));
CPubKey vchPubKey; CPubKey vchPubKey;
if (!pwallet->GetPubKey(keyID, vchPubKey)) { if (!pwallet->GetPubKey(keyID, vchPubKey)) {
throw runtime_error( throw std::runtime_error(
strprintf("no full public key for address %s",ks)); strprintf("no full public key for address %s",ks));
} }
if (!vchPubKey.IsFullyValid()) if (!vchPubKey.IsFullyValid())
throw runtime_error(" Invalid public key: "+ks); throw std::runtime_error(" Invalid public key: "+ks);
pubkeys[i] = vchPubKey; pubkeys[i] = vchPubKey;
} }
@ -285,18 +283,18 @@ CScript _createmultisig_redeemScript(CWallet * const pwallet, const UniValue& pa
{ {
CPubKey vchPubKey(ParseHex(ks)); CPubKey vchPubKey(ParseHex(ks));
if (!vchPubKey.IsFullyValid()) if (!vchPubKey.IsFullyValid())
throw runtime_error(" Invalid public key: "+ks); throw std::runtime_error(" Invalid public key: "+ks);
pubkeys[i] = vchPubKey; pubkeys[i] = vchPubKey;
} }
else else
{ {
throw runtime_error(" Invalid public key: "+ks); throw std::runtime_error(" Invalid public key: "+ks);
} }
} }
CScript result = GetScriptForMultisig(nRequired, pubkeys); CScript result = GetScriptForMultisig(nRequired, pubkeys);
if (result.size() > MAX_SCRIPT_ELEMENT_SIZE) if (result.size() > MAX_SCRIPT_ELEMENT_SIZE)
throw runtime_error( throw std::runtime_error(
strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE)); strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE));
return result; return result;
@ -312,7 +310,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
if (request.fHelp || request.params.size() < 2 || request.params.size() > 2) if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
{ {
string msg = "createmultisig nrequired [\"key\",...]\n" std::string msg = "createmultisig nrequired [\"key\",...]\n"
"\nCreates a multi-signature address with n signature of m keys required.\n" "\nCreates a multi-signature address with n signature of m keys required.\n"
"It returns a json object with the address and redeemScript.\n" "It returns a json object with the address and redeemScript.\n"
@ -336,7 +334,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
"\nAs a json rpc call\n" "\nAs a json rpc call\n"
+ HelpExampleRpc("createmultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + HelpExampleRpc("createmultisig", "2, \"[\\\"16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"")
; ;
throw runtime_error(msg); throw std::runtime_error(msg);
} }
// Construct using pay-to-script-hash: // Construct using pay-to-script-hash:
@ -354,7 +352,7 @@ UniValue createmultisig(const JSONRPCRequest& request)
UniValue verifymessage(const JSONRPCRequest& request) UniValue verifymessage(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 3) if (request.fHelp || request.params.size() != 3)
throw runtime_error( throw std::runtime_error(
"verifymessage \"address\" \"signature\" \"message\"\n" "verifymessage \"address\" \"signature\" \"message\"\n"
"\nVerify a signed message\n" "\nVerify a signed message\n"
"\nArguments:\n" "\nArguments:\n"
@ -376,9 +374,9 @@ UniValue verifymessage(const JSONRPCRequest& request)
LOCK(cs_main); LOCK(cs_main);
string strAddress = request.params[0].get_str(); std::string strAddress = request.params[0].get_str();
string strSign = request.params[1].get_str(); std::string strSign = request.params[1].get_str();
string strMessage = request.params[2].get_str(); std::string strMessage = request.params[2].get_str();
CBitcoinAddress addr(strAddress); CBitcoinAddress addr(strAddress);
if (!addr.IsValid()) if (!addr.IsValid())
@ -389,7 +387,7 @@ UniValue verifymessage(const JSONRPCRequest& request)
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
bool fInvalid = false; bool fInvalid = false;
vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid); std::vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
if (fInvalid) if (fInvalid)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
@ -408,7 +406,7 @@ UniValue verifymessage(const JSONRPCRequest& request)
UniValue signmessagewithprivkey(const JSONRPCRequest& request) UniValue signmessagewithprivkey(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 2) if (request.fHelp || request.params.size() != 2)
throw runtime_error( throw std::runtime_error(
"signmessagewithprivkey \"privkey\" \"message\"\n" "signmessagewithprivkey \"privkey\" \"message\"\n"
"\nSign a message with the private key of an address\n" "\nSign a message with the private key of an address\n"
"\nArguments:\n" "\nArguments:\n"
@ -425,8 +423,8 @@ UniValue signmessagewithprivkey(const JSONRPCRequest& request)
+ HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"") + HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")
); );
string strPrivkey = request.params[0].get_str(); std::string strPrivkey = request.params[0].get_str();
string strMessage = request.params[1].get_str(); std::string strMessage = request.params[1].get_str();
CBitcoinSecret vchSecret; CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strPrivkey); bool fGood = vchSecret.SetString(strPrivkey);
@ -440,7 +438,7 @@ UniValue signmessagewithprivkey(const JSONRPCRequest& request)
ss << strMessageMagic; ss << strMessageMagic;
ss << strMessage; ss << strMessage;
vector<unsigned char> vchSig; std::vector<unsigned char> vchSig;
if (!key.SignCompact(ss.GetHash(), vchSig)) if (!key.SignCompact(ss.GetHash(), vchSig))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
@ -450,7 +448,7 @@ UniValue signmessagewithprivkey(const JSONRPCRequest& request)
UniValue setmocktime(const JSONRPCRequest& request) UniValue setmocktime(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"setmocktime timestamp\n" "setmocktime timestamp\n"
"\nSet the local time to given timestamp (-regtest only)\n" "\nSet the local time to given timestamp (-regtest only)\n"
"\nArguments:\n" "\nArguments:\n"
@ -459,7 +457,7 @@ UniValue setmocktime(const JSONRPCRequest& request)
); );
if (!Params().MineBlocksOnDemand()) if (!Params().MineBlocksOnDemand())
throw runtime_error("setmocktime for regression testing (-regtest mode) only"); throw std::runtime_error("setmocktime for regression testing (-regtest mode) only");
// For now, don't change mocktime if we're in the middle of validation, as // For now, don't change mocktime if we're in the middle of validation, as
// this could have an effect on mempool time-based eviction, as well as // this could have an effect on mempool time-based eviction, as well as
@ -493,7 +491,7 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
* as users will undoubtedly confuse it with the other "memory pool" * as users will undoubtedly confuse it with the other "memory pool"
*/ */
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getmemoryinfo\n" "getmemoryinfo\n"
"Returns an object containing information about memory usage.\n" "Returns an object containing information about memory usage.\n"
"\nResult:\n" "\nResult:\n"
@ -519,7 +517,7 @@ UniValue getmemoryinfo(const JSONRPCRequest& request)
UniValue echo(const JSONRPCRequest& request) UniValue echo(const JSONRPCRequest& request)
{ {
if (request.fHelp) if (request.fHelp)
throw runtime_error( throw std::runtime_error(
"echo|echojson \"message\" ...\n" "echo|echojson \"message\" ...\n"
"\nSimply echo back the input arguments. This command is for testing.\n" "\nSimply echo back the input arguments. This command is for testing.\n"
"\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in" "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in"

40
src/rpc/net.cpp

@ -23,12 +23,10 @@
#include <univalue.h> #include <univalue.h>
using namespace std;
UniValue getconnectioncount(const JSONRPCRequest& request) UniValue getconnectioncount(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getconnectioncount\n" "getconnectioncount\n"
"\nReturns the number of connections to other nodes.\n" "\nReturns the number of connections to other nodes.\n"
"\nResult:\n" "\nResult:\n"
@ -47,7 +45,7 @@ UniValue getconnectioncount(const JSONRPCRequest& request)
UniValue ping(const JSONRPCRequest& request) UniValue ping(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"ping\n" "ping\n"
"\nRequests that a ping be sent to all other nodes, to measure ping time.\n" "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
"Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n" "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
@ -70,7 +68,7 @@ UniValue ping(const JSONRPCRequest& request)
UniValue getpeerinfo(const JSONRPCRequest& request) UniValue getpeerinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getpeerinfo\n" "getpeerinfo\n"
"\nReturns data about each connected network node as a json array of objects.\n" "\nReturns data about each connected network node as a json array of objects.\n"
"\nResult:\n" "\nResult:\n"
@ -102,7 +100,7 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
" n, (numeric) The heights of blocks we're currently asking from this peer\n" " n, (numeric) The heights of blocks we're currently asking from this peer\n"
" ...\n" " ...\n"
" ],\n" " ],\n"
" \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n" " \"whitelisted\": true|false, (boolean) Whether the peer is whitelisted\n"
" \"bytessent_per_msg\": {\n" " \"bytessent_per_msg\": {\n"
" \"addr\": n, (numeric) The total bytes sent aggregated by message type\n" " \"addr\": n, (numeric) The total bytes sent aggregated by message type\n"
" ...\n" " ...\n"
@ -122,7 +120,7 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
if(!g_connman) if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
vector<CNodeStats> vstats; std::vector<CNodeStats> vstats;
g_connman->GetNodeStats(vstats); g_connman->GetNodeStats(vstats);
UniValue ret(UniValue::VARR); UniValue ret(UniValue::VARR);
@ -191,12 +189,12 @@ UniValue getpeerinfo(const JSONRPCRequest& request)
UniValue addnode(const JSONRPCRequest& request) UniValue addnode(const JSONRPCRequest& request)
{ {
string strCommand; std::string strCommand;
if (request.params.size() == 2) if (request.params.size() == 2)
strCommand = request.params[1].get_str(); strCommand = request.params[1].get_str();
if (request.fHelp || request.params.size() != 2 || if (request.fHelp || request.params.size() != 2 ||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) (strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw runtime_error( throw std::runtime_error(
"addnode \"node\" \"add|remove|onetry\"\n" "addnode \"node\" \"add|remove|onetry\"\n"
"\nAttempts add or remove a node from the addnode list.\n" "\nAttempts add or remove a node from the addnode list.\n"
"Or try a connection to a node once.\n" "Or try a connection to a node once.\n"
@ -211,7 +209,7 @@ UniValue addnode(const JSONRPCRequest& request)
if(!g_connman) if(!g_connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
string strNode = request.params[0].get_str(); std::string strNode = request.params[0].get_str();
if (strCommand == "onetry") if (strCommand == "onetry")
{ {
@ -237,7 +235,7 @@ UniValue addnode(const JSONRPCRequest& request)
UniValue disconnectnode(const JSONRPCRequest& request) UniValue disconnectnode(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"disconnectnode \"node\" \n" "disconnectnode \"node\" \n"
"\nImmediately disconnects from the specified node.\n" "\nImmediately disconnects from the specified node.\n"
"\nArguments:\n" "\nArguments:\n"
@ -260,7 +258,7 @@ UniValue disconnectnode(const JSONRPCRequest& request)
UniValue getaddednodeinfo(const JSONRPCRequest& request) UniValue getaddednodeinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 1) if (request.fHelp || request.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"getaddednodeinfo ( \"node\" )\n" "getaddednodeinfo ( \"node\" )\n"
"\nReturns information about the given added node, or all added nodes\n" "\nReturns information about the given added node, or all added nodes\n"
"(note that onetry addnodes are not listed here)\n" "(note that onetry addnodes are not listed here)\n"
@ -328,7 +326,7 @@ UniValue getaddednodeinfo(const JSONRPCRequest& request)
UniValue getnettotals(const JSONRPCRequest& request) UniValue getnettotals(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() > 0) if (request.fHelp || request.params.size() > 0)
throw runtime_error( throw std::runtime_error(
"getnettotals\n" "getnettotals\n"
"\nReturns information about network traffic, including bytes in, bytes out,\n" "\nReturns information about network traffic, including bytes in, bytes out,\n"
"and current time.\n" "and current time.\n"
@ -384,7 +382,7 @@ static UniValue GetNetworksInfo()
obj.push_back(Pair("name", GetNetworkName(network))); obj.push_back(Pair("name", GetNetworkName(network)));
obj.push_back(Pair("limited", IsLimited(network))); obj.push_back(Pair("limited", IsLimited(network)));
obj.push_back(Pair("reachable", IsReachable(network))); obj.push_back(Pair("reachable", IsReachable(network)));
obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())); obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string()));
obj.push_back(Pair("proxy_randomize_credentials", proxy.randomize_credentials)); obj.push_back(Pair("proxy_randomize_credentials", proxy.randomize_credentials));
networks.push_back(obj); networks.push_back(obj);
} }
@ -394,7 +392,7 @@ static UniValue GetNetworksInfo()
UniValue getnetworkinfo(const JSONRPCRequest& request) UniValue getnetworkinfo(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"getnetworkinfo\n" "getnetworkinfo\n"
"Returns an object containing various state info regarding P2P networking.\n" "Returns an object containing various state info regarding P2P networking.\n"
"\nResult:\n" "\nResult:\n"
@ -469,12 +467,12 @@ UniValue getnetworkinfo(const JSONRPCRequest& request)
UniValue setban(const JSONRPCRequest& request) UniValue setban(const JSONRPCRequest& request)
{ {
string strCommand; std::string strCommand;
if (request.params.size() >= 2) if (request.params.size() >= 2)
strCommand = request.params[1].get_str(); strCommand = request.params[1].get_str();
if (request.fHelp || request.params.size() < 2 || if (request.fHelp || request.params.size() < 2 ||
(strCommand != "add" && strCommand != "remove")) (strCommand != "add" && strCommand != "remove"))
throw runtime_error( throw std::runtime_error(
"setban \"subnet\" \"add|remove\" (bantime) (absolute)\n" "setban \"subnet\" \"add|remove\" (bantime) (absolute)\n"
"\nAttempts add or remove a IP/Subnet from the banned list.\n" "\nAttempts add or remove a IP/Subnet from the banned list.\n"
"\nArguments:\n" "\nArguments:\n"
@ -494,7 +492,7 @@ UniValue setban(const JSONRPCRequest& request)
CNetAddr netAddr; CNetAddr netAddr;
bool isSubnet = false; bool isSubnet = false;
if (request.params[0].get_str().find("/") != string::npos) if (request.params[0].get_str().find("/") != std::string::npos)
isSubnet = true; isSubnet = true;
if (!isSubnet) { if (!isSubnet) {
@ -534,7 +532,7 @@ UniValue setban(const JSONRPCRequest& request)
UniValue listbanned(const JSONRPCRequest& request) UniValue listbanned(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"listbanned\n" "listbanned\n"
"\nList all banned IPs/Subnets.\n" "\nList all banned IPs/Subnets.\n"
"\nExamples:\n" "\nExamples:\n"
@ -567,7 +565,7 @@ UniValue listbanned(const JSONRPCRequest& request)
UniValue clearbanned(const JSONRPCRequest& request) UniValue clearbanned(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 0) if (request.fHelp || request.params.size() != 0)
throw runtime_error( throw std::runtime_error(
"clearbanned\n" "clearbanned\n"
"\nClear all banned IPs.\n" "\nClear all banned IPs.\n"
"\nExamples:\n" "\nExamples:\n"
@ -585,7 +583,7 @@ UniValue clearbanned(const JSONRPCRequest& request)
UniValue setnetworkactive(const JSONRPCRequest& request) UniValue setnetworkactive(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) { if (request.fHelp || request.params.size() != 1) {
throw runtime_error( throw std::runtime_error(
"setnetworkactive true|false\n" "setnetworkactive true|false\n"
"\nDisable/enable all p2p network activity.\n" "\nDisable/enable all p2p network activity.\n"
"\nArguments:\n" "\nArguments:\n"

8
src/rpc/protocol.cpp

@ -15,8 +15,6 @@
#include <stdint.h> #include <stdint.h>
#include <fstream> #include <fstream>
using namespace std;
/** /**
* JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility, * JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility,
* but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were * but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
@ -26,7 +24,7 @@ using namespace std;
* 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html * 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html
*/ */
UniValue JSONRPCRequestObj(const string& strMethod, const UniValue& params, const UniValue& id) UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id)
{ {
UniValue request(UniValue::VOBJ); UniValue request(UniValue::VOBJ);
request.push_back(Pair("method", strMethod)); request.push_back(Pair("method", strMethod));
@ -47,13 +45,13 @@ UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const Un
return reply; return reply;
} }
string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id) std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id)
{ {
UniValue reply = JSONRPCReplyObj(result, error, id); UniValue reply = JSONRPCReplyObj(result, error, id);
return reply.write() + "\n"; return reply.write() + "\n";
} }
UniValue JSONRPCError(int code, const string& message) UniValue JSONRPCError(int code, const std::string& message)
{ {
UniValue error(UniValue::VOBJ); UniValue error(UniValue::VOBJ);
error.push_back(Pair("code", code)); error.push_back(Pair("code", code));

72
src/rpc/rawtransaction.cpp

@ -34,12 +34,10 @@
#include <univalue.h> #include <univalue.h>
using namespace std;
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex) void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
{ {
txnouttype type; txnouttype type;
vector<CTxDestination> addresses; std::vector<CTxDestination> addresses;
int nRequired; int nRequired;
out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey))); out.push_back(Pair("asm", ScriptToAsmStr(scriptPubKey)));
@ -127,7 +125,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
UniValue getrawtransaction(const JSONRPCRequest& request) UniValue getrawtransaction(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"getrawtransaction \"txid\" ( verbose )\n" "getrawtransaction \"txid\" ( verbose )\n"
"\nNOTE: By default this function only works for mempool transactions. If the -txindex option is\n" "\nNOTE: By default this function only works for mempool transactions. If the -txindex option is\n"
@ -215,7 +213,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
} }
else { else {
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid type provided. Verbose parameter must be a boolean."); throw JSONRPCError(RPC_TYPE_ERROR, "Invalid type provided. Verbose parameter must be a boolean.");
} }
} }
CTransactionRef tx; CTransactionRef tx;
@ -225,7 +223,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries") + : "No such mempool transaction. Use -txindex to enable blockchain transaction queries") +
". Use gettransaction for wallet transactions."); ". Use gettransaction for wallet transactions.");
string strHex = EncodeHexTx(*tx, RPCSerializationFlags()); std::string strHex = EncodeHexTx(*tx, RPCSerializationFlags());
if (!fVerbose) if (!fVerbose)
return strHex; return strHex;
@ -239,7 +237,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
UniValue gettxoutproof(const JSONRPCRequest& request) UniValue gettxoutproof(const JSONRPCRequest& request)
{ {
if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2)) if (request.fHelp || (request.params.size() != 1 && request.params.size() != 2))
throw runtime_error( throw std::runtime_error(
"gettxoutproof [\"txid\",...] ( blockhash )\n" "gettxoutproof [\"txid\",...] ( blockhash )\n"
"\nReturns a hex-encoded proof that \"txid\" was included in a block.\n" "\nReturns a hex-encoded proof that \"txid\" was included in a block.\n"
"\nNOTE: By default this function only works sometimes. This is when there is an\n" "\nNOTE: By default this function only works sometimes. This is when there is an\n"
@ -257,16 +255,16 @@ UniValue gettxoutproof(const JSONRPCRequest& request)
"\"data\" (string) A string that is a serialized, hex-encoded data for the proof.\n" "\"data\" (string) A string that is a serialized, hex-encoded data for the proof.\n"
); );
set<uint256> setTxids; std::set<uint256> setTxids;
uint256 oneTxid; uint256 oneTxid;
UniValue txids = request.params[0].get_array(); UniValue txids = request.params[0].get_array();
for (unsigned int idx = 0; idx < txids.size(); idx++) { for (unsigned int idx = 0; idx < txids.size(); idx++) {
const UniValue& txid = txids[idx]; const UniValue& txid = txids[idx];
if (txid.get_str().length() != 64 || !IsHex(txid.get_str())) if (txid.get_str().length() != 64 || !IsHex(txid.get_str()))
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid txid ")+txid.get_str()); throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid txid ")+txid.get_str());
uint256 hash(uint256S(txid.get_str())); uint256 hash(uint256S(txid.get_str()));
if (setTxids.count(hash)) if (setTxids.count(hash))
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated txid: ")+txid.get_str()); throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ")+txid.get_str());
setTxids.insert(hash); setTxids.insert(hash);
oneTxid = hash; oneTxid = hash;
} }
@ -319,7 +317,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request)
UniValue verifytxoutproof(const JSONRPCRequest& request) UniValue verifytxoutproof(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"verifytxoutproof \"proof\"\n" "verifytxoutproof \"proof\"\n"
"\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n" "\nVerifies that a proof points to a transaction in a block, returning the transaction it commits to\n"
"and throwing an RPC error if the block is not in our best chain\n" "and throwing an RPC error if the block is not in our best chain\n"
@ -335,8 +333,8 @@ UniValue verifytxoutproof(const JSONRPCRequest& request)
UniValue res(UniValue::VARR); UniValue res(UniValue::VARR);
vector<uint256> vMatch; std::vector<uint256> vMatch;
vector<unsigned int> vIndex; std::vector<unsigned int> vIndex;
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot) if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
return res; return res;
@ -353,7 +351,7 @@ UniValue verifytxoutproof(const JSONRPCRequest& request)
UniValue createrawtransaction(const JSONRPCRequest& request) UniValue createrawtransaction(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
throw runtime_error( throw std::runtime_error(
"createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n" "createrawtransaction [{\"txid\":\"id\",\"vout\":n},...] {\"address\":amount,\"data\":\"hex\",...} ( locktime )\n"
"\nCreate a transaction spending the given inputs and creating new outputs.\n" "\nCreate a transaction spending the given inputs and creating new outputs.\n"
"Outputs can be addresses or data.\n" "Outputs can be addresses or data.\n"
@ -434,9 +432,9 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
rawTx.vin.push_back(in); rawTx.vin.push_back(in);
} }
set<CBitcoinAddress> setAddress; std::set<CBitcoinAddress> setAddress;
vector<string> addrList = sendTo.getKeys(); std::vector<std::string> addrList = sendTo.getKeys();
BOOST_FOREACH(const string& name_, addrList) { BOOST_FOREACH(const std::string& name_, addrList) {
if (name_ == "data") { if (name_ == "data") {
std::vector<unsigned char> data = ParseHexV(sendTo[name_].getValStr(),"Data"); std::vector<unsigned char> data = ParseHexV(sendTo[name_].getValStr(),"Data");
@ -446,10 +444,10 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
} else { } else {
CBitcoinAddress address(name_); CBitcoinAddress address(name_);
if (!address.IsValid()) if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Bitcoin address: ")+name_); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ")+name_);
if (setAddress.count(address)) if (setAddress.count(address))
throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ")+name_);
setAddress.insert(address); setAddress.insert(address);
CScript scriptPubKey = GetScriptForDestination(address.Get()); CScript scriptPubKey = GetScriptForDestination(address.Get());
@ -466,7 +464,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
UniValue decoderawtransaction(const JSONRPCRequest& request) UniValue decoderawtransaction(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"decoderawtransaction \"hexstring\"\n" "decoderawtransaction \"hexstring\"\n"
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n" "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n"
@ -535,7 +533,7 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
UniValue decodescript(const JSONRPCRequest& request) UniValue decodescript(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw runtime_error( throw std::runtime_error(
"decodescript \"hexstring\"\n" "decodescript \"hexstring\"\n"
"\nDecode a hex-encoded script.\n" "\nDecode a hex-encoded script.\n"
"\nArguments:\n" "\nArguments:\n"
@ -562,7 +560,7 @@ UniValue decodescript(const JSONRPCRequest& request)
UniValue r(UniValue::VOBJ); UniValue r(UniValue::VOBJ);
CScript script; CScript script;
if (request.params[0].get_str().size() > 0){ if (request.params[0].get_str().size() > 0){
vector<unsigned char> scriptData(ParseHexV(request.params[0], "argument")); std::vector<unsigned char> scriptData(ParseHexV(request.params[0], "argument"));
script = CScript(scriptData.begin(), scriptData.end()); script = CScript(scriptData.begin(), scriptData.end());
} else { } else {
// Empty scripts are valid // Empty scripts are valid
@ -600,7 +598,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
#endif #endif
if (request.fHelp || request.params.size() < 1 || request.params.size() > 4) if (request.fHelp || request.params.size() < 1 || request.params.size() > 4)
throw runtime_error( throw std::runtime_error(
"signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n" "signrawtransaction \"hexstring\" ( [{\"txid\":\"id\",\"vout\":n,\"scriptPubKey\":\"hex\",\"redeemScript\":\"hex\"},...] [\"privatekey1\",...] sighashtype )\n"
"\nSign inputs for raw transaction (serialized, hex-encoded).\n" "\nSign inputs for raw transaction (serialized, hex-encoded).\n"
"The second optional argument (may be null) is an array of previous transaction outputs that\n" "The second optional argument (may be null) is an array of previous transaction outputs that\n"
@ -665,9 +663,9 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
#endif #endif
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true); RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VSTR)(UniValue::VARR)(UniValue::VARR)(UniValue::VSTR), true);
vector<unsigned char> txData(ParseHexV(request.params[0], "argument 1")); std::vector<unsigned char> txData(ParseHexV(request.params[0], "argument 1"));
CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION);
vector<CMutableTransaction> txVariants; std::vector<CMutableTransaction> txVariants;
while (!ssData.empty()) { while (!ssData.empty()) {
try { try {
CMutableTransaction tx; CMutableTransaction tx;
@ -750,13 +748,13 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
if (nOut < 0) if (nOut < 0)
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey")); std::vector<unsigned char> pkData(ParseHexO(prevOut, "scriptPubKey"));
CScript scriptPubKey(pkData.begin(), pkData.end()); CScript scriptPubKey(pkData.begin(), pkData.end());
{ {
CCoinsModifier coins = view.ModifyCoins(txid); CCoinsModifier coins = view.ModifyCoins(txid);
if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) { if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
string err("Previous output scriptPubKey mismatch:\n"); std::string err("Previous output scriptPubKey mismatch:\n");
err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+ err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+
ScriptToAsmStr(scriptPubKey); ScriptToAsmStr(scriptPubKey);
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, err);
@ -782,7 +780,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
}); });
UniValue v = find_value(prevOut, "redeemScript"); UniValue v = find_value(prevOut, "redeemScript");
if (!v.isNull()) { if (!v.isNull()) {
vector<unsigned char> rsData(ParseHexV(v, "redeemScript")); std::vector<unsigned char> rsData(ParseHexV(v, "redeemScript"));
CScript redeemScript(rsData.begin(), rsData.end()); CScript redeemScript(rsData.begin(), rsData.end());
tempKeystore.AddCScript(redeemScript); tempKeystore.AddCScript(redeemScript);
} }
@ -798,16 +796,16 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
int nHashType = SIGHASH_ALL; int nHashType = SIGHASH_ALL;
if (request.params.size() > 3 && !request.params[3].isNull()) { if (request.params.size() > 3 && !request.params[3].isNull()) {
static map<string, int> mapSigHashValues = static std::map<std::string, int> mapSigHashValues =
boost::assign::map_list_of boost::assign::map_list_of
(string("ALL"), int(SIGHASH_ALL)) (std::string("ALL"), int(SIGHASH_ALL))
(string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)) (std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY))
(string("NONE"), int(SIGHASH_NONE)) (std::string("NONE"), int(SIGHASH_NONE))
(string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)) (std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY))
(string("SINGLE"), int(SIGHASH_SINGLE)) (std::string("SINGLE"), int(SIGHASH_SINGLE))
(string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)) (std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY))
; ;
string strHashType = request.params[3].get_str(); std::string strHashType = request.params[3].get_str();
if (mapSigHashValues.count(strHashType)) if (mapSigHashValues.count(strHashType))
nHashType = mapSigHashValues[strHashType]; nHashType = mapSigHashValues[strHashType];
else else
@ -867,7 +865,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
UniValue sendrawtransaction(const JSONRPCRequest& request) UniValue sendrawtransaction(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw runtime_error( throw std::runtime_error(
"sendrawtransaction \"hexstring\" ( allowhighfees )\n" "sendrawtransaction \"hexstring\" ( allowhighfees )\n"
"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n" "\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
"\nAlso see createrawtransaction and signrawtransaction calls.\n" "\nAlso see createrawtransaction and signrawtransaction calls.\n"

55
src/rpc/server.cpp

@ -26,9 +26,6 @@
#include <memory> // for unique_ptr #include <memory> // for unique_ptr
#include <unordered_map> #include <unordered_map>
using namespace RPCServer;
using namespace std;
static bool fRPCRunning = false; static bool fRPCRunning = false;
static bool fRPCInWarmup = true; static bool fRPCInWarmup = true;
static std::string rpcWarmupStatus("RPC server started"); static std::string rpcWarmupStatus("RPC server started");
@ -67,7 +64,7 @@ void RPCServer::OnPostCommand(boost::function<void (const CRPCCommand&)> slot)
} }
void RPCTypeCheck(const UniValue& params, void RPCTypeCheck(const UniValue& params,
const list<UniValue::VType>& typesExpected, const std::list<UniValue::VType>& typesExpected,
bool fAllowNull) bool fAllowNull)
{ {
unsigned int i = 0; unsigned int i = 0;
@ -92,7 +89,7 @@ void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected)
} }
void RPCTypeCheckObj(const UniValue& o, void RPCTypeCheckObj(const UniValue& o,
const map<string, UniValueType>& typesExpected, const std::map<std::string, UniValueType>& typesExpected,
bool fAllowNull, bool fAllowNull,
bool fStrict) bool fStrict)
{ {
@ -102,7 +99,7 @@ void RPCTypeCheckObj(const UniValue& o,
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first)); throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) { if (!(t.second.typeAny || v.type() == t.second.type || (fAllowNull && v.isNull()))) {
string err = strprintf("Expected type %s for %s, got %s", std::string err = strprintf("Expected type %s for %s, got %s",
uvTypeName(t.second.type), t.first, uvTypeName(v.type())); uvTypeName(t.second.type), t.first, uvTypeName(v.type()));
throw JSONRPCError(RPC_TYPE_ERROR, err); throw JSONRPCError(RPC_TYPE_ERROR, err);
} }
@ -110,11 +107,11 @@ void RPCTypeCheckObj(const UniValue& o,
if (fStrict) if (fStrict)
{ {
BOOST_FOREACH(const string& k, o.getKeys()) BOOST_FOREACH(const std::string& k, o.getKeys())
{ {
if (typesExpected.count(k) == 0) if (typesExpected.count(k) == 0)
{ {
string err = strprintf("Unexpected key %s", k); std::string err = strprintf("Unexpected key %s", k);
throw JSONRPCError(RPC_TYPE_ERROR, err); throw JSONRPCError(RPC_TYPE_ERROR, err);
} }
} }
@ -143,9 +140,9 @@ UniValue ValueFromAmount(const CAmount& amount)
strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder)); strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder));
} }
uint256 ParseHashV(const UniValue& v, string strName) uint256 ParseHashV(const UniValue& v, std::string strName)
{ {
string strHex; std::string strHex;
if (v.isStr()) if (v.isStr())
strHex = v.get_str(); strHex = v.get_str();
if (!IsHex(strHex)) // Note: IsHex("") is false if (!IsHex(strHex)) // Note: IsHex("") is false
@ -156,20 +153,20 @@ uint256 ParseHashV(const UniValue& v, string strName)
result.SetHex(strHex); result.SetHex(strHex);
return result; return result;
} }
uint256 ParseHashO(const UniValue& o, string strKey) uint256 ParseHashO(const UniValue& o, std::string strKey)
{ {
return ParseHashV(find_value(o, strKey), strKey); return ParseHashV(find_value(o, strKey), strKey);
} }
vector<unsigned char> ParseHexV(const UniValue& v, string strName) std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName)
{ {
string strHex; std::string strHex;
if (v.isStr()) if (v.isStr())
strHex = v.get_str(); strHex = v.get_str();
if (!IsHex(strHex)) if (!IsHex(strHex))
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')"); throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
return ParseHex(strHex); return ParseHex(strHex);
} }
vector<unsigned char> ParseHexO(const UniValue& o, string strKey) std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey)
{ {
return ParseHexV(find_value(o, strKey), strKey); return ParseHexV(find_value(o, strKey), strKey);
} }
@ -180,12 +177,12 @@ vector<unsigned char> ParseHexO(const UniValue& o, string strKey)
std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
{ {
string strRet; std::string strRet;
string category; std::string category;
set<rpcfn_type> setDone; std::set<rpcfn_type> setDone;
vector<pair<string, const CRPCCommand*> > vCommands; std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
for (map<string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi) for (std::map<std::string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi)
vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second)); vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second));
sort(vCommands.begin(), vCommands.end()); sort(vCommands.begin(), vCommands.end());
@ -193,10 +190,10 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
jreq.fHelp = true; jreq.fHelp = true;
jreq.params = UniValue(); jreq.params = UniValue();
BOOST_FOREACH(const PAIRTYPE(string, const CRPCCommand*)& command, vCommands) BOOST_FOREACH(const PAIRTYPE(std::string, const CRPCCommand*)& command, vCommands)
{ {
const CRPCCommand *pcmd = command.second; const CRPCCommand *pcmd = command.second;
string strMethod = pcmd->name; std::string strMethod = pcmd->name;
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
continue; continue;
jreq.strMethod = strMethod; jreq.strMethod = strMethod;
@ -209,10 +206,10 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
catch (const std::exception& e) catch (const std::exception& e)
{ {
// Help text is returned in an exception // Help text is returned in an exception
string strHelp = string(e.what()); std::string strHelp = std::string(e.what());
if (strCommand == "") if (strCommand == "")
{ {
if (strHelp.find('\n') != string::npos) if (strHelp.find('\n') != std::string::npos)
strHelp = strHelp.substr(0, strHelp.find('\n')); strHelp = strHelp.substr(0, strHelp.find('\n'));
if (category != pcmd->category) if (category != pcmd->category)
@ -220,7 +217,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
if (!category.empty()) if (!category.empty())
strRet += "\n"; strRet += "\n";
category = pcmd->category; category = pcmd->category;
string firstLetter = category.substr(0,1); std::string firstLetter = category.substr(0,1);
boost::to_upper(firstLetter); boost::to_upper(firstLetter);
strRet += "== " + firstLetter + category.substr(1) + " ==\n"; strRet += "== " + firstLetter + category.substr(1) + " ==\n";
} }
@ -237,7 +234,7 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
UniValue help(const JSONRPCRequest& jsonRequest) UniValue help(const JSONRPCRequest& jsonRequest)
{ {
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"help ( \"command\" )\n" "help ( \"command\" )\n"
"\nList all commands, or get help for a specified command.\n" "\nList all commands, or get help for a specified command.\n"
"\nArguments:\n" "\nArguments:\n"
@ -246,7 +243,7 @@ UniValue help(const JSONRPCRequest& jsonRequest)
"\"text\" (string) The help text\n" "\"text\" (string) The help text\n"
); );
string strCommand; std::string strCommand;
if (jsonRequest.params.size() > 0) if (jsonRequest.params.size() > 0)
strCommand = jsonRequest.params[0].get_str(); strCommand = jsonRequest.params[0].get_str();
@ -258,7 +255,7 @@ UniValue stop(const JSONRPCRequest& jsonRequest)
{ {
// Accept the deprecated and ignored 'detach' boolean argument // Accept the deprecated and ignored 'detach' boolean argument
if (jsonRequest.fHelp || jsonRequest.params.size() > 1) if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
throw runtime_error( throw std::runtime_error(
"stop\n" "stop\n"
"\nStop Bitcoin server."); "\nStop Bitcoin server.");
// Event loop will exit after current HTTP requests have been handled, so // Event loop will exit after current HTTP requests have been handled, so
@ -292,7 +289,7 @@ CRPCTable::CRPCTable()
const CRPCCommand *CRPCTable::operator[](const std::string &name) const const CRPCCommand *CRPCTable::operator[](const std::string &name) const
{ {
map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name); std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
if (it == mapCommands.end()) if (it == mapCommands.end())
return NULL; return NULL;
return (*it).second; return (*it).second;
@ -304,7 +301,7 @@ bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
return false; return false;
// don't allow overwriting for now // don't allow overwriting for now
map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name); std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
if (it != mapCommands.end()) if (it != mapCommands.end())
return false; return false;

Loading…
Cancel
Save