Work toward RPC refactor and do not print to cout.

This commit is contained in:
Arthur Britto
2012-12-01 17:58:32 -08:00
parent c2d6dc0ab7
commit 17b2506cd7
7 changed files with 246 additions and 379 deletions

View File

@@ -282,7 +282,7 @@ void Application::loadOldLedger()
if (!lastLedger)
{
std::cout << "No Ledger found?" << std::endl;
cLog(lsFATAL) << "No Ledger found?" << std::endl;
exit(-1);
}
lastLedger->setClosed();

View File

@@ -101,7 +101,7 @@ bool ConnectionPool::savePeer(const std::string& strIp, int iPort, char code)
}
else
{
std::cout << "Error saving Peer" << std::endl;
std::cerr << "Error saving Peer" << std::endl;
}
if (bNew)

View File

@@ -54,7 +54,7 @@ void PeerDoor::handleConnect(Peer::pointer new_connection,
{
new_connection->connected(error);
}
else cout << "Error: " << error;
else cerr << "Error: " << error;
startListening();
}

View File

@@ -10,6 +10,7 @@
#include "Wallet.h"
#include "RippleAddress.h"
#include "RippleCalc.h"
#include "RPCErr.h"
#include "AccountState.h"
#include "NicknameState.h"
#include "InstanceCounter.h"
@@ -20,77 +21,6 @@
SETUP_LOG();
Json::Value RPCHandler::rpcError(int iError)
{
static struct {
int iError;
const char* pToken;
const char* pMessage;
} errorInfoA[] = {
{ rpcACT_EXISTS, "actExists", "Account already exists." },
{ rpcACT_MALFORMED, "actMalformed", "Account malformed." },
{ rpcACT_NOT_FOUND, "actNotFound", "Account not found." },
{ rpcBAD_SEED, "badSeed", "Disallowed seed." },
{ rpcDST_ACT_MALFORMED, "dstActMalformed", "Destination account is malformed." },
{ rpcDST_ACT_MISSING, "dstActMissing", "Destination account does not exists." },
{ rpcDST_AMT_MALFORMED, "dstAmtMalformed", "Destination amount/currency/issuer is malformed." },
{ rpcFAIL_GEN_DECRPYT, "failGenDecrypt", "Failed to decrypt generator." },
{ rpcGETS_ACT_MALFORMED, "getsActMalformed", "Gets account malformed." },
{ rpcGETS_AMT_MALFORMED, "getsAmtMalformed", "Gets amount malformed." },
{ rpcHOST_IP_MALFORMED, "hostIpMalformed", "Host IP is malformed." },
{ rpcINSUF_FUNDS, "insufFunds", "Insufficient funds." },
{ rpcINTERNAL, "internal", "Internal error." },
{ rpcINVALID_PARAMS, "invalidParams", "Invalid parameters." },
{ rpcLGR_IDXS_INVALID, "lgrIdxsInvalid", "Ledger indexes invalid." },
{ rpcLGR_IDX_MALFORMED, "lgrIdxMalformed", "Ledger index malformed." },
{ rpcLGR_NOT_FOUND, "lgrNotFound", "Ledger not found." },
{ rpcNICKNAME_MALFORMED, "nicknameMalformed","Nickname is malformed." },
{ rpcNICKNAME_MISSING, "nicknameMissing", "Nickname does not exist." },
{ rpcNICKNAME_PERM, "nicknamePerm", "Account does not control nickname." },
{ rpcNOT_IMPL, "notImpl", "Not implemented." },
{ rpcNO_ACCOUNT, "noAccount", "No such account." },
{ rpcNO_CLOSED, "noClosed", "Closed ledger is unavailable." },
{ rpcNO_CURRENT, "noCurrent", "Current ledger is unavailable." },
{ rpcNO_EVENTS, "noEvents", "Current transport does not support events." },
{ rpcNO_GEN_DECRPYT, "noGenDectypt", "Password failed to decrypt master public generator." },
{ rpcNO_NETWORK, "noNetwork", "Network not available." },
{ rpcNO_PATH, "noPath", "Unable to find a ripple path." },
{ rpcNO_PERMISSION, "noPermission", "You don't have permission for this command." },
{ rpcNOT_STANDALONE, "notStandAlone", "Operation valid in debug mode only." },
{ rpcPASSWD_CHANGED, "passwdChanged", "Wrong key, password changed." },
{ rpcPAYS_ACT_MALFORMED, "paysActMalformed", "Pays account malformed." },
{ rpcPAYS_AMT_MALFORMED, "paysAmtMalformed", "Pays amount malformed." },
{ rpcPORT_MALFORMED, "portMalformed", "Port is malformed." },
{ rpcPUBLIC_MALFORMED, "publicMalformed", "Public key is malformed." },
{ rpcQUALITY_MALFORMED, "qualityMalformed", "Quality malformed." },
{ rpcSRC_ACT_MALFORMED, "srcActMalformed", "Source account is malformed." },
{ rpcSRC_ACT_MISSING, "srcActMissing", "Source account does not exist." },
{ rpcSRC_AMT_MALFORMED, "srcAmtMalformed", "Source amount/currency/issuer is malformed." },
{ rpcSRC_UNCLAIMED, "srcUnclaimed", "Source account is not claimed." },
{ rpcSUCCESS, "success", "Success." },
{ rpcTXN_NOT_FOUND, "txnNotFound", "Transaction not found." },
{ rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown command." },
{ rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key." },
};
int i;
for (i=NUMBER(errorInfoA); i-- && errorInfoA[i].iError != iError;)
;
Json::Value jsonResult(Json::objectValue);
jsonResult["error"] = i >= 0 ? errorInfoA[i].pToken : lexical_cast_i(iError);
jsonResult["error_message"] = i >= 0 ? errorInfoA[i].pMessage : lexical_cast_i(iError);
jsonResult["error_code"] = iError;
if (i >= 0)
std::cerr << "rpcError: "
<< errorInfoA[i].pToken << ": " << errorInfoA[i].pMessage << std::endl;
return jsonResult;
}
RPCHandler::RPCHandler(NetworkOPs* netOps)
{
mNetOps=netOps;
@@ -103,7 +33,7 @@ RPCHandler::RPCHandler(NetworkOPs* netOps, InfoSub* infoSub)
mInfoSub=infoSub;
}
int RPCHandler::getParamCount(const Json::Value& params)
int RPCHandler::getParamCount(Json::Value params)
{ // If non-array, only counts strings
if (params.isNull()) return 0;
if (params.isArray()) return params.size();
@@ -325,19 +255,21 @@ Json::Value RPCHandler::accountFromString(const uint256& uLedger, RippleAddress&
return Json::Value(Json::objectValue);
}
Json::Value RPCHandler::doAcceptLedger(const Json::Value &params)
Json::Value RPCHandler::doAcceptLedger(Json::Value jvRequest)
{
if (!theConfig.RUN_STANDALONE)
return rpcError(rpcNOT_STANDALONE);
Json::Value obj(Json::objectValue);
obj["newLedger"] = theApp->getOPs().acceptLedger();
return obj;
jvRequest["newLedger"] = theApp->getOPs().acceptLedger();
return jvRequest;
}
// account_info <account>|<nickname>|<account_public_key>
// account_info <seed>|<pass_phrase>|<key> [<index>]
Json::Value RPCHandler::doAccountInfo(const Json::Value &params)
Json::Value RPCHandler::doAccountInfo(Json::Value params)
{
std::string strIdent = params[0u].asString();
bool bIndex;
@@ -388,7 +320,7 @@ Json::Value RPCHandler::doAccountInfo(const Json::Value &params)
Json::Value RPCHandler::doConnect(const Json::Value& params)
Json::Value RPCHandler::doConnect(Json::Value params)
{
if (theConfig.RUN_STANDALONE)
return "cannot connect in standalone mode";
@@ -419,7 +351,7 @@ Json::Value RPCHandler::doConnect(const Json::Value& params)
}
// data_delete <key>
Json::Value RPCHandler::doDataDelete(const Json::Value& params)
Json::Value RPCHandler::doDataDelete(Json::Value params)
{
std::string strKey = params[0u].asString();
@@ -438,7 +370,7 @@ Json::Value RPCHandler::doDataDelete(const Json::Value& params)
}
// data_fetch <key>
Json::Value RPCHandler::doDataFetch(const Json::Value& params)
Json::Value RPCHandler::doDataFetch(Json::Value params)
{
std::string strKey = params[0u].asString();
std::string strValue;
@@ -453,7 +385,7 @@ Json::Value RPCHandler::doDataFetch(const Json::Value& params)
}
// data_store <key> <value>
Json::Value RPCHandler::doDataStore(const Json::Value& params)
Json::Value RPCHandler::doDataStore(Json::Value params)
{
std::string strKey = params[0u].asString();
std::string strValue = params[1u].asString();
@@ -475,7 +407,7 @@ Json::Value RPCHandler::doDataStore(const Json::Value& params)
// nickname_info <nickname>
// Note: Nicknames are not automatically looked up by commands as they are advisory and can be changed.
Json::Value RPCHandler::doNicknameInfo(const Json::Value& params)
Json::Value RPCHandler::doNicknameInfo(Json::Value params)
{
std::string strNickname = params[0u].asString();
boost::trim(strNickname);
@@ -503,7 +435,7 @@ Json::Value RPCHandler::doNicknameInfo(const Json::Value& params)
// owner_info <account>|<nickname>|<account_public_key>
// owner_info <seed>|<pass_phrase>|<key> [<index>]
Json::Value RPCHandler::doOwnerInfo(const Json::Value& params)
Json::Value RPCHandler::doOwnerInfo(Json::Value params)
{
std::string strIdent = params[0u].asString();
bool bIndex;
@@ -527,7 +459,7 @@ Json::Value RPCHandler::doOwnerInfo(const Json::Value& params)
}
Json::Value RPCHandler::doPeers(const Json::Value& params)
Json::Value RPCHandler::doPeers(Json::Value params)
{
Json::Value obj(Json::objectValue);
@@ -541,7 +473,7 @@ Json::Value RPCHandler::doPeers(const Json::Value& params)
// issuer is the offering account
// --> submit: 'submit|true|false': defaults to false
// Prior to running allow each to have a credit line of what they will be getting from the other account.
Json::Value RPCHandler::doProfile(const Json::Value &params)
Json::Value RPCHandler::doProfile(Json::Value params)
{
/* need to fix now that sharedOfferCreate is gone
int iArgs = params.size();
@@ -629,7 +561,7 @@ Json::Value RPCHandler::doProfile(const Json::Value &params)
}
// ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]
Json::Value RPCHandler::doRippleLinesGet(const Json::Value &params)
Json::Value RPCHandler::doRippleLinesGet(Json::Value params)
{
// uint256 uAccepted = mNetOps->getClosedLedgerHash();
@@ -702,7 +634,7 @@ Json::Value RPCHandler::doRippleLinesGet(const Json::Value &params)
// - Allows clients to verify path exists.
// - Return canonicalized path.
// - From a trusted server, allows clients to use path without manipulation.
Json::Value RPCHandler::doRipplePathFind(const Json::Value& jvRequest)
Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest)
{
Json::Value jvResult(Json::objectValue);
RippleAddress raSrc;
@@ -871,7 +803,7 @@ Json::Value RPCHandler::doRipplePathFind(const Json::Value& jvRequest)
// submit any transaction to the network
// submit private_key json
Json::Value RPCHandler::doSubmit(const Json::Value& params)
Json::Value RPCHandler::doSubmit(Json::Value params)
{
Json::Value txJSON;
Json::Reader reader;
@@ -891,13 +823,13 @@ Json::Value RPCHandler::doSubmit(const Json::Value& params)
return rpcError(rpcINVALID_PARAMS);
}
Json::Value RPCHandler::doSubmitJson(const Json::Value& jvRequest)
Json::Value RPCHandler::doSubmitJson(Json::Value jvRequest)
{
return handleJSONSubmit(jvRequest);
}
Json::Value RPCHandler::handleJSONSubmit(const Json::Value& jvRequest)
Json::Value RPCHandler::handleJSONSubmit(Json::Value jvRequest)
{
Json::Value jvResult;
RippleAddress naSeed;
@@ -1142,7 +1074,7 @@ Json::Value RPCHandler::handleJSONSubmit(const Json::Value& jvRequest)
}
}
Json::Value RPCHandler::doServerInfo(const Json::Value& params)
Json::Value RPCHandler::doServerInfo(Json::Value params)
{
Json::Value ret(Json::objectValue);
@@ -1151,7 +1083,7 @@ Json::Value RPCHandler::doServerInfo(const Json::Value& params)
return ret;
}
Json::Value RPCHandler::doTxHistory(const Json::Value& params)
Json::Value RPCHandler::doTxHistory(Json::Value params)
{
if (params.size() == 1)
{
@@ -1184,7 +1116,7 @@ Json::Value RPCHandler::doTxHistory(const Json::Value& params)
return rpcError(rpcSRC_ACT_MALFORMED);
}
Json::Value RPCHandler::doTx(const Json::Value& params)
Json::Value RPCHandler::doTx(Json::Value params)
{
// tx <txID>
// tx <account>
@@ -1210,7 +1142,7 @@ Json::Value RPCHandler::doTx(const Json::Value& params)
return rpcError(rpcNOT_IMPL);
}
Json::Value RPCHandler::doLedgerClosed(const Json::Value& params)
Json::Value RPCHandler::doLedgerClosed(Json::Value params)
{
Json::Value jvResult;
uint256 uLedger = mNetOps->getClosedLedgerHash();
@@ -1221,7 +1153,7 @@ Json::Value RPCHandler::doLedgerClosed(const Json::Value& params)
return jvResult;
}
Json::Value RPCHandler::doLedgerCurrent(const Json::Value& params)
Json::Value RPCHandler::doLedgerCurrent(Json::Value params)
{
Json::Value jvResult;
jvResult["ledger_current_index"] = mNetOps->getCurrentLedgerID();
@@ -1229,7 +1161,7 @@ Json::Value RPCHandler::doLedgerCurrent(const Json::Value& params)
}
// ledger [id|current|lastclosed] [full]
Json::Value RPCHandler::doLedger(const Json::Value& params)
Json::Value RPCHandler::doLedger(Json::Value params)
{
if (getParamCount(params) == 0)
{
@@ -1268,7 +1200,7 @@ Json::Value RPCHandler::doLedger(const Json::Value& params)
// account_tx <account> <minledger> <maxledger>
// account_tx <account> <ledger>
Json::Value RPCHandler::doAccountTransactions(const Json::Value& params)
Json::Value RPCHandler::doAccountTransactions(Json::Value params)
{
std::string param;
uint32 minLedger, maxLedger;
@@ -1325,7 +1257,7 @@ Json::Value RPCHandler::doAccountTransactions(const Json::Value& params)
}
// unl_add <domain>|<node_public> [<comment>]
Json::Value RPCHandler::doUnlAdd(const Json::Value& params)
Json::Value RPCHandler::doUnlAdd(Json::Value params)
{
std::string strNode = params[0u].asString();
std::string strComment = (params.size() == 2) ? params[1u].asString() : "";
@@ -1350,7 +1282,7 @@ Json::Value RPCHandler::doUnlAdd(const Json::Value& params)
//
// NOTE: It is poor security to specify secret information on the command line. This information might be saved in the command
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value RPCHandler::doValidationCreate(const Json::Value& params) {
Json::Value RPCHandler::doValidationCreate(Json::Value params) {
RippleAddress naSeed;
Json::Value obj(Json::objectValue);
@@ -1376,7 +1308,7 @@ Json::Value RPCHandler::doValidationCreate(const Json::Value& params) {
//
// NOTE: It is poor security to specify secret information on the command line. This information might be saved in the command
// shell history file (e.g. .bash_history) and it may be leaked via the process status command (i.e. ps).
Json::Value RPCHandler::doValidationSeed(const Json::Value& params) {
Json::Value RPCHandler::doValidationSeed(Json::Value params) {
Json::Value obj(Json::objectValue);
if (params.empty())
@@ -1437,7 +1369,7 @@ Json::Value RPCHandler::accounts(const uint256& uLedger, const RippleAddress& na
}
// wallet_accounts <seed>
Json::Value RPCHandler::doWalletAccounts(const Json::Value& params)
Json::Value RPCHandler::doWalletAccounts(Json::Value params)
{
RippleAddress naSeed;
@@ -1474,143 +1406,14 @@ Json::Value RPCHandler::doWalletAccounts(const Json::Value& params)
}
}
Json::Value RPCHandler::doLogRotate(const Json::Value& params)
Json::Value RPCHandler::doLogRotate(Json::Value params)
{
return Log::rotateLog();
}
Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& params, int role)
{
cLog(lsTRACE) << "RPC:" << command;
cLog(lsTRACE) << "RPC params:" << params;
LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC));
mRole = role;
static struct {
const char* pCommand;
doFuncPtr dfpFunc;
int iMinParams;
int iMaxParams;
bool bAdminRequired;
bool bEvented;
unsigned int iOptions;
} commandsA[] = {
// Request-response methods
{ "accept_ledger", &RPCHandler::doAcceptLedger, 0, 0, true, false, optNone },
{ "account_info", &RPCHandler::doAccountInfo, 1, 2, false, false, optCurrent },
{ "account_tx", &RPCHandler::doAccountTransactions, 2, 3, false, false, optNetwork },
{ "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone },
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
{ "get_counts", &RPCHandler::doGetCounts, 0, 1, true, false, optNone },
{ "ledger", &RPCHandler::doLedger, 0, 2, false, false, optNetwork },
{ "ledger_accept", &RPCHandler::doLedgerAccept, 0, 0, true, false, optCurrent },
{ "ledger_closed", &RPCHandler::doLedgerClosed, 0, 0, false, false, optClosed },
{ "ledger_current", &RPCHandler::doLedgerCurrent, 0, 0, false, false, optCurrent },
{ "ledger_entry", &RPCHandler::doLedgerEntry, -1, -1, false, false, optCurrent },
{ "ledger_header", &RPCHandler::doLedgerHeader, -1, -1, false, false, optCurrent },
{ "log_level", &RPCHandler::doLogLevel, 0, 2, true, false, optNone },
{ "logrotate", &RPCHandler::doLogRotate, 0, 0, true, false, optNone },
{ "nickname_info", &RPCHandler::doNicknameInfo, 1, 1, false, false, optCurrent },
{ "owner_info", &RPCHandler::doOwnerInfo, 1, 2, false, false, optCurrent },
{ "peers", &RPCHandler::doPeers, 0, 0, true, false, optNone },
{ "profile", &RPCHandler::doProfile, 1, 9, false, false, optCurrent },
{ "ripple_lines_get", &RPCHandler::doRippleLinesGet, 1, 2, false, false, optCurrent },
{ "ripple_path_find", &RPCHandler::doRipplePathFind, -1, -1, false, false, optCurrent },
{ "submit", &RPCHandler::doSubmit, 2, 2, false, false, optCurrent },
{ "submit_json", &RPCHandler::doSubmitJson, -1, -1, false, false, optCurrent },
{ "server_info", &RPCHandler::doServerInfo, 0, 0, true, false, optNone },
{ "stop", &RPCHandler::doStop, 0, 0, true, false, optNone },
{ "transaction_entry", &RPCHandler::doTransactionEntry, -1, -1, false, false, optCurrent },
{ "tx", &RPCHandler::doTx, 1, 1, true, false, optNone },
{ "tx_history", &RPCHandler::doTxHistory, 1, 1, false, false, optNone },
{ "unl_add", &RPCHandler::doUnlAdd, 1, 2, true, false, optNone },
{ "unl_delete", &RPCHandler::doUnlDelete, 1, 1, true, false, optNone },
{ "unl_list", &RPCHandler::doUnlList, 0, 0, true, false, optNone },
{ "unl_load", &RPCHandler::doUnlLoad, 0, 0, true, false, optNone },
{ "unl_network", &RPCHandler::doUnlNetwork, 0, 0, true, false, optNone },
{ "unl_reset", &RPCHandler::doUnlReset, 0, 0, true, false, optNone },
{ "unl_score", &RPCHandler::doUnlScore, 0, 0, true, false, optNone },
{ "validation_create", &RPCHandler::doValidationCreate, 0, 1, false, false, optNone },
{ "validation_seed", &RPCHandler::doValidationSeed, 0, 1, false, false, optNone },
{ "wallet_accounts", &RPCHandler::doWalletAccounts, 1, 1, false, false, optCurrent },
{ "wallet_propose", &RPCHandler::doWalletPropose, 0, 1, false, false, optNone },
{ "wallet_seed", &RPCHandler::doWalletSeed, 0, 1, false, false, optNone },
{ "login", &RPCHandler::doLogin, 2, 2, true, false, optNone },
// Evented methods
{ "subscribe", &RPCHandler::doSubscribe, -1, -1, false, true, optNone },
{ "unsubscribe", &RPCHandler::doUnsubscribe, -1, -1, false, true, optNone },
};
int i = NUMBER(commandsA);
while (i-- && command != commandsA[i].pCommand)
;
if (i < 0)
{
return rpcError(rpcUNKNOWN_COMMAND);
}
else if (commandsA[i].bAdminRequired && mRole != ADMIN)
{
return rpcError(rpcNO_PERMISSION);
}
else if (commandsA[i].bEvented && mInfoSub == NULL)
{
return rpcError(rpcNO_EVENTS);
}
else if (commandsA[i].iMinParams >= 0
? commandsA[i].iMaxParams
? (params.size() < commandsA[i].iMinParams
|| (commandsA[i].iMaxParams >= 0 && params.size() > commandsA[i].iMaxParams))
: false
: params.isArray())
{
return rpcError(rpcINVALID_PARAMS);
}
else if ((commandsA[i].iOptions & optNetwork) && !mNetOps->available())
{
return rpcError(rpcNO_NETWORK);
}
// XXX Should verify we have a current ledger.
boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock());
if ((commandsA[i].iOptions & optCurrent) && false)
{
return rpcError(rpcNO_CURRENT);
}
else if ((commandsA[i].iOptions & optClosed) && !mNetOps->getClosedLedger())
{
return rpcError(rpcNO_CLOSED);
}
else
{
try {
return (this->*(commandsA[i].dfpFunc))(params);
}
catch (std::exception& e)
{
cLog(lsINFO) << "Caught throw: " << e.what();
return rpcError(rpcINTERNAL);
}
}
}
// wallet_propose [<passphrase>]
// <passphrase> is only for testing. Master seeds should only be generated randomly.
Json::Value RPCHandler::doWalletPropose(const Json::Value& params)
Json::Value RPCHandler::doWalletPropose(Json::Value params)
{
RippleAddress naSeed;
RippleAddress naAccount;
@@ -1637,7 +1440,7 @@ Json::Value RPCHandler::doWalletPropose(const Json::Value& params)
}
// wallet_seed [<seed>|<passphrase>|<passkey>]
Json::Value RPCHandler::doWalletSeed(const Json::Value& params)
Json::Value RPCHandler::doWalletSeed(Json::Value params)
{
RippleAddress naSeed;
@@ -1672,7 +1475,7 @@ Json::Value RPCHandler::doWalletSeed(const Json::Value& params)
// TODO: for now this simply checks if this is the admin account
// TODO: need to prevent them hammering this over and over
// TODO: maybe a better way is only allow admin from local host
Json::Value RPCHandler::doLogin(const Json::Value& params)
Json::Value RPCHandler::doLogin(Json::Value params)
{
std::string username = params[0u].asString();
std::string password = params[1u].asString();
@@ -1688,7 +1491,7 @@ Json::Value RPCHandler::doLogin(const Json::Value& params)
}
}
Json::Value RPCHandler::doGetCounts(const Json::Value& params)
Json::Value RPCHandler::doGetCounts(Json::Value params)
{
int minCount = 10;
if (params.size() > 0)
@@ -1702,7 +1505,7 @@ Json::Value RPCHandler::doGetCounts(const Json::Value& params)
return ret;
}
Json::Value RPCHandler::doLogLevel(const Json::Value& params)
Json::Value RPCHandler::doLogLevel(Json::Value params)
{
if (params.size() == 0)
{ // get log severities
@@ -1745,7 +1548,7 @@ Json::Value RPCHandler::doLogLevel(const Json::Value& params)
// Populate the UNL from ripple.com's validators.txt file.
Json::Value RPCHandler::doUnlNetwork(const Json::Value& params)
Json::Value RPCHandler::doUnlNetwork(Json::Value params)
{
theApp->getUNL().nodeNetwork();
@@ -1753,7 +1556,7 @@ Json::Value RPCHandler::doUnlNetwork(const Json::Value& params)
}
// unl_reset
Json::Value RPCHandler::doUnlReset(const Json::Value& params)
Json::Value RPCHandler::doUnlReset(Json::Value params)
{
theApp->getUNL().nodeReset();
@@ -1761,14 +1564,14 @@ Json::Value RPCHandler::doUnlReset(const Json::Value& params)
}
// unl_score
Json::Value RPCHandler::doUnlScore(const Json::Value& params)
Json::Value RPCHandler::doUnlScore(Json::Value params)
{
theApp->getUNL().nodeScore();
return "scoring requested";
}
Json::Value RPCHandler::doStop(const Json::Value& params)
Json::Value RPCHandler::doStop(Json::Value params)
{
theApp->stop();
@@ -1776,7 +1579,7 @@ Json::Value RPCHandler::doStop(const Json::Value& params)
}
// unl_delete <domain>|<public_key>
Json::Value RPCHandler::doUnlDelete(const Json::Value& params)
Json::Value RPCHandler::doUnlDelete(Json::Value params)
{
std::string strNode = params[0u].asString();
@@ -1796,7 +1599,7 @@ Json::Value RPCHandler::doUnlDelete(const Json::Value& params)
}
}
Json::Value RPCHandler::doUnlList(const Json::Value& params)
Json::Value RPCHandler::doUnlList(Json::Value params)
{
Json::Value obj(Json::objectValue);
@@ -1806,7 +1609,7 @@ Json::Value RPCHandler::doUnlList(const Json::Value& params)
}
// Populate the UNL from a local validators.txt file.
Json::Value RPCHandler::doUnlLoad(const Json::Value& params)
Json::Value RPCHandler::doUnlLoad(Json::Value params)
{
if (theConfig.VALIDATORS_FILE.empty() || !theApp->getUNL().nodeLoad(theConfig.VALIDATORS_FILE))
{
@@ -1816,7 +1619,7 @@ Json::Value RPCHandler::doUnlLoad(const Json::Value& params)
return "loading";
}
Json::Value RPCHandler::doLedgerAccept(const Json::Value& )
Json::Value RPCHandler::doLedgerAccept(Json::Value )
{
Json::Value jvResult;
@@ -1834,7 +1637,7 @@ Json::Value RPCHandler::doLedgerAccept(const Json::Value& )
return jvResult;
}
Json::Value RPCHandler::doTransactionEntry(const Json::Value& jvRequest)
Json::Value RPCHandler::doTransactionEntry(Json::Value jvRequest)
{
Json::Value jvResult;
@@ -1884,7 +1687,7 @@ Json::Value RPCHandler::doTransactionEntry(const Json::Value& jvRequest)
return jvResult;
}
Json::Value RPCHandler::lookupLedger(const Json::Value& jvRequest, Ledger::pointer& lpLedger)
Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger)
{
Json::Value jvResult;
@@ -1936,7 +1739,7 @@ Json::Value RPCHandler::lookupLedger(const Json::Value& jvRequest, Ledger::point
return jvResult;
}
Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
Json::Value RPCHandler::doLedgerEntry(Json::Value jvRequest)
{
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
@@ -2139,7 +1942,7 @@ Json::Value RPCHandler::doLedgerEntry(const Json::Value& jvRequest)
return jvResult;
}
Json::Value RPCHandler::doLedgerHeader(const Json::Value& jvRequest)
Json::Value RPCHandler::doLedgerHeader(Json::Value jvRequest)
{
Ledger::pointer lpLedger;
Json::Value jvResult = lookupLedger(jvRequest, lpLedger);
@@ -2189,7 +1992,7 @@ rt_transactions
accounts
rt_accounts
*/
Json::Value RPCHandler::doSubscribe(const Json::Value& jvRequest)
Json::Value RPCHandler::doSubscribe(Json::Value jvRequest)
{
Json::Value jvResult(Json::objectValue);
@@ -2263,7 +2066,7 @@ Json::Value RPCHandler::doSubscribe(const Json::Value& jvRequest)
return jvResult;
}
Json::Value RPCHandler::doUnsubscribe(const Json::Value& jvRequest)
Json::Value RPCHandler::doUnsubscribe(Json::Value jvRequest)
{
Json::Value jvResult(Json::objectValue);
@@ -2337,4 +2140,130 @@ Json::Value RPCHandler::doUnsubscribe(const Json::Value& jvRequest)
return jvResult;
}
Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& params, int role)
{
cLog(lsTRACE) << "RPC:" << command;
cLog(lsTRACE) << "RPC params:" << params;
LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC));
mRole = role;
static struct {
const char* pCommand;
doFuncPtr dfpFunc;
int iMinParams;
int iMaxParams;
bool bAdminRequired;
bool bEvented;
unsigned int iOptions;
} commandsA[] = {
// Request-response methods
{ "accept_ledger", &RPCHandler::doAcceptLedger, -1, -1, true, false, optNone },
{ "account_info", &RPCHandler::doAccountInfo, 1, 2, false, false, optCurrent },
{ "account_tx", &RPCHandler::doAccountTransactions, 2, 3, false, false, optNetwork },
{ "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone },
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
{ "get_counts", &RPCHandler::doGetCounts, 0, 1, true, false, optNone },
{ "ledger", &RPCHandler::doLedger, 0, 2, false, false, optNetwork },
{ "ledger_accept", &RPCHandler::doLedgerAccept, 0, 0, true, false, optCurrent },
{ "ledger_closed", &RPCHandler::doLedgerClosed, 0, 0, false, false, optClosed },
{ "ledger_current", &RPCHandler::doLedgerCurrent, 0, 0, false, false, optCurrent },
{ "ledger_entry", &RPCHandler::doLedgerEntry, -1, -1, false, false, optCurrent },
{ "ledger_header", &RPCHandler::doLedgerHeader, -1, -1, false, false, optCurrent },
{ "log_level", &RPCHandler::doLogLevel, 0, 2, true, false, optNone },
{ "logrotate", &RPCHandler::doLogRotate, 0, 0, true, false, optNone },
{ "nickname_info", &RPCHandler::doNicknameInfo, 1, 1, false, false, optCurrent },
{ "owner_info", &RPCHandler::doOwnerInfo, 1, 2, false, false, optCurrent },
{ "peers", &RPCHandler::doPeers, 0, 0, true, false, optNone },
{ "profile", &RPCHandler::doProfile, 1, 9, false, false, optCurrent },
{ "ripple_lines_get", &RPCHandler::doRippleLinesGet, 1, 2, false, false, optCurrent },
{ "ripple_path_find", &RPCHandler::doRipplePathFind, -1, -1, false, false, optCurrent },
{ "submit", &RPCHandler::doSubmit, 2, 2, false, false, optCurrent },
{ "submit_json", &RPCHandler::doSubmitJson, -1, -1, false, false, optCurrent },
{ "server_info", &RPCHandler::doServerInfo, 0, 0, true, false, optNone },
{ "stop", &RPCHandler::doStop, 0, 0, true, false, optNone },
{ "transaction_entry", &RPCHandler::doTransactionEntry, -1, -1, false, false, optCurrent },
{ "tx", &RPCHandler::doTx, 1, 1, true, false, optNone },
{ "tx_history", &RPCHandler::doTxHistory, 1, 1, false, false, optNone },
{ "unl_add", &RPCHandler::doUnlAdd, 1, 2, true, false, optNone },
{ "unl_delete", &RPCHandler::doUnlDelete, 1, 1, true, false, optNone },
{ "unl_list", &RPCHandler::doUnlList, 0, 0, true, false, optNone },
{ "unl_load", &RPCHandler::doUnlLoad, 0, 0, true, false, optNone },
{ "unl_network", &RPCHandler::doUnlNetwork, 0, 0, true, false, optNone },
{ "unl_reset", &RPCHandler::doUnlReset, 0, 0, true, false, optNone },
{ "unl_score", &RPCHandler::doUnlScore, 0, 0, true, false, optNone },
{ "validation_create", &RPCHandler::doValidationCreate, 0, 1, false, false, optNone },
{ "validation_seed", &RPCHandler::doValidationSeed, 0, 1, false, false, optNone },
{ "wallet_accounts", &RPCHandler::doWalletAccounts, 1, 1, false, false, optCurrent },
{ "wallet_propose", &RPCHandler::doWalletPropose, 0, 1, false, false, optNone },
{ "wallet_seed", &RPCHandler::doWalletSeed, 0, 1, false, false, optNone },
{ "login", &RPCHandler::doLogin, 2, 2, true, false, optNone },
// Evented methods
{ "subscribe", &RPCHandler::doSubscribe, -1, -1, false, true, optNone },
{ "unsubscribe", &RPCHandler::doUnsubscribe, -1, -1, false, true, optNone },
};
int i = NUMBER(commandsA);
while (i-- && command != commandsA[i].pCommand)
;
if (i < 0)
{
return rpcError(rpcUNKNOWN_COMMAND);
}
else if (commandsA[i].bAdminRequired && mRole != ADMIN)
{
return rpcError(rpcNO_PERMISSION);
}
else if (commandsA[i].bEvented && mInfoSub == NULL)
{
return rpcError(rpcNO_EVENTS);
}
else if (commandsA[i].iMinParams >= 0
? commandsA[i].iMaxParams
? (params.size() < commandsA[i].iMinParams
|| (commandsA[i].iMaxParams >= 0 && params.size() > commandsA[i].iMaxParams))
: false
: params.isArray())
{
return rpcError(rpcINVALID_PARAMS);
}
else if ((commandsA[i].iOptions & optNetwork) && !mNetOps->available())
{
return rpcError(rpcNO_NETWORK);
}
// XXX Should verify we have a current ledger.
boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock());
if ((commandsA[i].iOptions & optCurrent) && false)
{
return rpcError(rpcNO_CURRENT);
}
else if ((commandsA[i].iOptions & optClosed) && !mNetOps->getClosedLedger())
{
return rpcError(rpcNO_CLOSED);
}
else
{
try {
return (this->*(commandsA[i].dfpFunc))(params);
}
catch (std::exception& e)
{
cLog(lsINFO) << "Caught throw: " << e.what();
return rpcError(rpcINTERNAL);
}
}
}
// vim:ts=4

View File

@@ -1,5 +1,5 @@
#ifndef RPCHANDLER__H
#define RPCHANDLER__H
#ifndef __RPCHANDLER__
#define __RPCHANDLER__
// used by the RPCServer or WSDoor to carry out these RPC commands
class NetworkOPs;
@@ -10,7 +10,7 @@ class RPCHandler
InfoSub* mInfoSub;
int mRole;
typedef Json::Value (RPCHandler::*doFuncPtr)(const Json::Value& params);
typedef Json::Value (RPCHandler::*doFuncPtr)(Json::Value params);
enum {
optNone = 0,
optNetwork = 1, // Need network
@@ -21,10 +21,10 @@ class RPCHandler
// Utilities
void addSubmitPath(Json::Value& txJSON);
boost::unordered_set<RippleAddress> parseAccountIds(const Json::Value& jvArray);
int getParamCount(const Json::Value& params);
int getParamCount(Json::Value params);
bool extractString(std::string& param, const Json::Value& params, int index);
Json::Value lookupLedger(const Json::Value& jvRequest, Ledger::pointer& lpLedger);
Json::Value lookupLedger(Json::Value jvRequest, Ledger::pointer& lpLedger);
Json::Value getMasterGenerator(const uint256& uLedger, const RippleAddress& naRegularSeed, RippleAddress& naMasterGenerator);
Json::Value authorize(const uint256& uLedger, const RippleAddress& naRegularSeed, const RippleAddress& naSrcAccountID,
@@ -35,131 +35,71 @@ class RPCHandler
Json::Value accountFromString(const uint256& uLedger, RippleAddress& naAccount, bool& bIndex, const std::string& strIdent, const int iIndex);
Json::Value doAcceptLedger(const Json::Value& params);
Json::Value doAcceptLedger(Json::Value jvRequest);
Json::Value doAccountInfo(const Json::Value& params);
Json::Value doAccountTransactions(const Json::Value& params);
Json::Value doConnect(const Json::Value& params);
Json::Value doDataDelete(const Json::Value& params);
Json::Value doDataFetch(const Json::Value& params);
Json::Value doDataStore(const Json::Value& params);
Json::Value doGetCounts(const Json::Value& params);
Json::Value doLedger(const Json::Value& params);
Json::Value doLogRotate(const Json::Value& params);
Json::Value doNicknameInfo(const Json::Value& params);
Json::Value doAccountInfo(Json::Value params);
Json::Value doAccountTransactions(Json::Value params);
Json::Value doConnect(Json::Value params);
Json::Value doDataDelete(Json::Value params);
Json::Value doDataFetch(Json::Value params);
Json::Value doDataStore(Json::Value params);
Json::Value doGetCounts(Json::Value params);
Json::Value doLedger(Json::Value params);
Json::Value doLogRotate(Json::Value params);
Json::Value doNicknameInfo(Json::Value params);
Json::Value doOwnerInfo(const Json::Value& params);
Json::Value doOwnerInfo(Json::Value params);
Json::Value doProfile(const Json::Value& params);
Json::Value doPeers(const Json::Value& params);
Json::Value doProfile(Json::Value params);
Json::Value doPeers(Json::Value params);
Json::Value doRippleLinesGet(const Json::Value& params);
Json::Value doRipplePathFind(const Json::Value& jvRequest);
Json::Value doServerInfo(const Json::Value& params);
Json::Value doSessionClose(const Json::Value& params);
Json::Value doSessionOpen(const Json::Value& params);
Json::Value doLogLevel(const Json::Value& params);
Json::Value doStop(const Json::Value& params);
Json::Value doSubmit(const Json::Value& params);
Json::Value doSubmitJson(const Json::Value& jvRequest);
Json::Value doTx(const Json::Value& params);
Json::Value doTxHistory(const Json::Value& params);
Json::Value doRippleLinesGet(Json::Value params);
Json::Value doRipplePathFind(Json::Value jvRequest);
Json::Value doServerInfo(Json::Value params);
Json::Value doSessionClose(Json::Value params);
Json::Value doSessionOpen(Json::Value params);
Json::Value doLogLevel(Json::Value params);
Json::Value doStop(Json::Value params);
Json::Value doSubmit(Json::Value params);
Json::Value doSubmitJson(Json::Value jvRequest);
Json::Value doTx(Json::Value params);
Json::Value doTxHistory(Json::Value params);
Json::Value doUnlAdd(const Json::Value& params);
Json::Value doUnlDelete(const Json::Value& params);
Json::Value doUnlFetch(const Json::Value& params);
Json::Value doUnlList(const Json::Value& params);
Json::Value doUnlLoad(const Json::Value& params);
Json::Value doUnlNetwork(const Json::Value& params);
Json::Value doUnlReset(const Json::Value& params);
Json::Value doUnlScore(const Json::Value& params);
Json::Value doUnlAdd(Json::Value params);
Json::Value doUnlDelete(Json::Value params);
Json::Value doUnlFetch(Json::Value params);
Json::Value doUnlList(Json::Value params);
Json::Value doUnlLoad(Json::Value params);
Json::Value doUnlNetwork(Json::Value params);
Json::Value doUnlReset(Json::Value params);
Json::Value doUnlScore(Json::Value params);
Json::Value doValidationCreate(const Json::Value& params);
Json::Value doValidationSeed(const Json::Value& params);
Json::Value doValidationCreate(Json::Value params);
Json::Value doValidationSeed(Json::Value params);
Json::Value doWalletAccounts(const Json::Value& params);
Json::Value doWalletLock(const Json::Value& params);
Json::Value doWalletPropose(const Json::Value& params);
Json::Value doWalletSeed(const Json::Value& params);
Json::Value doWalletUnlock(const Json::Value& params);
Json::Value doWalletVerify(const Json::Value& params);
Json::Value doWalletAccounts(Json::Value params);
Json::Value doWalletLock(Json::Value params);
Json::Value doWalletPropose(Json::Value params);
Json::Value doWalletSeed(Json::Value params);
Json::Value doWalletUnlock(Json::Value params);
Json::Value doWalletVerify(Json::Value params);
Json::Value doLogin(const Json::Value& params);
Json::Value doLogin(Json::Value params);
Json::Value doLedgerAccept(const Json::Value& params);
Json::Value doLedgerClosed(const Json::Value& params);
Json::Value doLedgerCurrent(const Json::Value& params);
Json::Value doLedgerEntry(const Json::Value& params);
Json::Value doLedgerHeader(const Json::Value& params);
Json::Value doTransactionEntry(const Json::Value& params);
Json::Value doLedgerAccept(Json::Value params);
Json::Value doLedgerClosed(Json::Value params);
Json::Value doLedgerCurrent(Json::Value params);
Json::Value doLedgerEntry(Json::Value params);
Json::Value doLedgerHeader(Json::Value params);
Json::Value doTransactionEntry(Json::Value params);
Json::Value doSubscribe(const Json::Value& params);
Json::Value doUnsubscribe(const Json::Value& params);
Json::Value doSubscribe(Json::Value params);
Json::Value doUnsubscribe(Json::Value params);
public:
enum {
rpcSUCCESS,
// Misc failure
rpcLOAD_FAILED,
rpcNO_PERMISSION,
rpcNO_EVENTS,
rpcNOT_STANDALONE,
// Networking
rpcNO_CLOSED,
rpcNO_CURRENT,
rpcNO_NETWORK,
// Ledger state
rpcACT_EXISTS,
rpcACT_NOT_FOUND,
rpcINSUF_FUNDS,
rpcLGR_NOT_FOUND,
rpcNICKNAME_MISSING,
rpcNO_ACCOUNT,
rpcNO_PATH,
rpcPASSWD_CHANGED,
rpcSRC_MISSING,
rpcSRC_UNCLAIMED,
rpcTXN_NOT_FOUND,
rpcWRONG_SEED,
// Malformed command
rpcINVALID_PARAMS,
rpcUNKNOWN_COMMAND,
// Bad parameter
rpcACT_MALFORMED,
rpcQUALITY_MALFORMED,
rpcBAD_SEED,
rpcDST_ACT_MALFORMED,
rpcDST_ACT_MISSING,
rpcDST_AMT_MALFORMED,
rpcGETS_ACT_MALFORMED,
rpcGETS_AMT_MALFORMED,
rpcHOST_IP_MALFORMED,
rpcLGR_IDXS_INVALID,
rpcLGR_IDX_MALFORMED,
rpcNICKNAME_MALFORMED,
rpcNICKNAME_PERM,
rpcPAYS_ACT_MALFORMED,
rpcPAYS_AMT_MALFORMED,
rpcPORT_MALFORMED,
rpcPUBLIC_MALFORMED,
rpcSRC_ACT_MALFORMED,
rpcSRC_ACT_MISSING,
rpcSRC_AMT_MALFORMED,
// Internal error (should never happen)
rpcINTERNAL, // Generic internal error.
rpcFAIL_GEN_DECRPYT,
rpcNOT_IMPL,
rpcNO_GEN_DECRPYT,
};
enum { GUEST, USER, ADMIN };
@@ -167,10 +107,8 @@ public:
RPCHandler(NetworkOPs* netOps, InfoSub* infoSub);
Json::Value doCommand(const std::string& command, Json::Value& params, int role);
Json::Value rpcError(int iError);
Json::Value handleJSONSubmit(const Json::Value& jvRequest);
Json::Value handleJSONSubmit(Json::Value jvRequest);
};
#endif

View File

@@ -12,12 +12,12 @@ RippleLines::RippleLines(const uint160& accountID, Ledger::ref ledger)
fillLines(accountID, ledger);
}
void RippleLines::printRippleLines()
void RippleLines::printRippleLines()
{
for (unsigned int i =0; i < mLines.size(); i++) {
std::cout << i << ": " << mLines[i]->getAccountID().humanAccountID() << std::endl;
std::cerr << i << ": " << mLines[i]->getAccountID().humanAccountID() << std::endl;
}
std::cout << std::endl;
std::cerr << std::endl;
}
RippleLines::RippleLines(const uint160& accountID )

View File

@@ -30,25 +30,25 @@ SerializedType& SerializedType::operator=(const SerializedType& t)
void STPathSet::printDebug() {
for (int i = 0; i < value.size(); i++) {
std::cout << i << ": ";
std::cerr << i << ": ";
for (int j = 0; j < value[i].mPath.size(); j++) {
//STPathElement pe = value[i].mPath[j];
RippleAddress nad;
nad.setAccountID(value[i].mPath[j].mAccountID);
std::cout << " " << nad.humanAccountID();
//std::cout << " " << pe.mAccountID.GetHex();
std::cerr << " " << nad.humanAccountID();
//std::cerr << " " << pe.mAccountID.GetHex();
}
std::cout << std::endl;
std::cerr << std::endl;
}
}
void STPath::printDebug() {
std::cout << "STPath:" << std::endl;
std::cerr << "STPath:" << std::endl;
for(int i =0; i < mPath.size(); i++) {
RippleAddress nad;
nad.setAccountID(mPath[i].mAccountID);
std::cout << " " << i << ": " << nad.humanAccountID() << std::endl;
std::cerr << " " << i << ": " << nad.humanAccountID() << std::endl;
}
}