From 164350658f8e43132f383f9b21c91062e9084be6 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 9 Jul 2012 21:10:51 -0700 Subject: [PATCH] Rename RPC commands to ripple_lines_get and ripple_line_set. --- src/RPCServer.cpp | 332 +++++++++++++++++++++++----------------------- src/RPCServer.h | 4 +- src/main.cpp | 4 +- 3 files changed, 170 insertions(+), 170 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 3c27ac2429..68aab99bf0 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -525,107 +525,6 @@ Json::Value RPCServer::doAccountInfo(const Json::Value ¶ms) return ret; } -// account_lines || [] -Json::Value RPCServer::doAccountLines(const Json::Value ¶ms) -{ -// uint256 uAccepted = mNetOps->getClosedLedger(); - uint256 uCurrent = mNetOps->getCurrentLedger(); - - std::string strIdent = params[0u].asString(); - bool bIndex; - int iIndex = 2 == params.size()? lexical_cast_s(params[1u].asString()) : 0; - - NewcoinAddress naAccount; - - Json::Value ret; - - ret = accountFromString(uCurrent, naAccount, bIndex, strIdent, iIndex); - - if (!ret.empty()) - return ret; - - // Get info on account. - ret = Json::Value(Json::objectValue); - - ret["account"] = naAccount.humanAccountID(); - if (bIndex) - ret["index"] = iIndex; - - AccountState::pointer as = mNetOps->getAccountState(uCurrent, naAccount); - if (as) - { - Json::Value jsonLines = Json::Value(Json::objectValue); - - ret["account"] = naAccount.humanAccountID(); - - // We access a committed ledger and need not worry about changes. - uint256 uRootIndex; - - if (mNetOps->getDirLineInfo(uCurrent, naAccount, uRootIndex)) - { - bool bDone = false; - - while (!bDone) - { - uint64 uNodePrevious; - uint64 uNodeNext; - STVector256 svRippleNodes = mNetOps->getDirNodeInfo(uCurrent, uRootIndex, uNodePrevious, uNodeNext); - - BOOST_FOREACH(uint256& uNode, svRippleNodes.peekValue()) - { - NewcoinAddress naAccountPeer; - STAmount saBalance; - STAmount saLimit; - STAmount saLimitPeer; - - RippleState::pointer rsLine = mNetOps->getRippleState(uCurrent, uNode); - - if (rsLine) - { - rsLine->setViewAccount(naAccount); - - naAccountPeer = rsLine->getAccountIDPeer(); - saBalance = rsLine->getBalance(); - saLimit = rsLine->getLimit(); - saLimitPeer = rsLine->getLimitPeer(); - - Json::Value jPeer = Json::Value(Json::objectValue); - - jPeer["node"] = uNode.ToString(); - - jPeer["balance"] = saBalance.getText(); - jPeer["currency"] = saBalance.getCurrencyHuman(); - jPeer["limit"] = saLimit.getJson(0); - jPeer["limit_peer"] = saLimitPeer.getJson(0); - - jsonLines[naAccountPeer.humanAccountID()] = jPeer; - } - else - { - std::cerr << "doAccountLines: Bad index: " << uNode.ToString() << std::endl; - } - } - - if (uNodeNext) - { - uCurrent = Ledger::getDirNodeIndex(uRootIndex, uNodeNext); - } - else - { - bDone = true; - } - } - } - ret["lines"] = jsonLines; - } - else - { - ret["status"] = "NotFound"; - } - - return ret; -} - // account_message_set Json::Value RPCServer::doAccountMessageSet(const Json::Value& params) { NewcoinAddress naSrcAccountID; @@ -759,69 +658,6 @@ Json::Value RPCServer::doConnect(const Json::Value& params) return "connecting"; } -// credit_set [] [] -Json::Value RPCServer::doCreditSet(const Json::Value& params) -{ - NewcoinAddress naSeed; - NewcoinAddress naSrcAccountID; - NewcoinAddress naDstAccountID; - STAmount saLimitAmount; - uint256 uLedger = mNetOps->getCurrentLedger(); - uint32 uAcceptRate = params.size() >= 6 ? lexical_cast_s(params[5u].asString()) : 0; - - if (!naSeed.setSeedGeneric(params[0u].asString())) - { - return RPCError(rpcBAD_SEED); - } - else if (!naSrcAccountID.setAccountID(params[1u].asString())) - { - return RPCError(rpcSRC_ACT_MALFORMED); - } - else if (!naDstAccountID.setAccountID(params[2u].asString())) - { - return RPCError(rpcDST_ACT_MALFORMED); - } - else if (!saLimitAmount.setValue(params[3u].asString(), params.size() >= 5 ? params[4u].asString() : "")) - { - return RPCError(rpcSRC_AMT_MALFORMED); - } - else - { - NewcoinAddress naMasterGenerator; - NewcoinAddress naAccountPublic; - NewcoinAddress naAccountPrivate; - AccountState::pointer asSrc; - STAmount saSrcBalance; - Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, - saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naMasterGenerator); - - if (!obj.empty()) - return obj; - - Transaction::pointer trans = Transaction::sharedCreditSet( - naAccountPublic, naAccountPrivate, - naSrcAccountID, - asSrc->getSeq(), - theConfig.FEE_DEFAULT, - 0, // YYY No source tag - naDstAccountID, - saLimitAmount, - uAcceptRate); - - (void) mNetOps->processTransaction(trans); - - obj["transaction"] = trans->getSTransaction()->getJson(0); - obj["status"] = trans->getStatus(); - obj["seed"] = naSeed.humanSeed(); - obj["srcAccountID"] = naSrcAccountID.humanAccountID(); - obj["dstAccountID"] = naDstAccountID.humanAccountID(); - obj["limitAmount"] = saLimitAmount.getText(); - obj["acceptRate"] = uAcceptRate; - - return obj; - } -} - // data_delete Json::Value RPCServer::doDataDelete(const Json::Value& params) { @@ -1154,6 +990,170 @@ Json::Value RPCServer::doPeers(const Json::Value& params) return obj; } +// ripple_line_set [] [] +Json::Value RPCServer::doRippleLineSet(const Json::Value& params) +{ + NewcoinAddress naSeed; + NewcoinAddress naSrcAccountID; + NewcoinAddress naDstAccountID; + STAmount saLimitAmount; + uint256 uLedger = mNetOps->getCurrentLedger(); + uint32 uAcceptRate = params.size() >= 6 ? lexical_cast_s(params[5u].asString()) : 0; + + if (!naSeed.setSeedGeneric(params[0u].asString())) + { + return RPCError(rpcBAD_SEED); + } + else if (!naSrcAccountID.setAccountID(params[1u].asString())) + { + return RPCError(rpcSRC_ACT_MALFORMED); + } + else if (!naDstAccountID.setAccountID(params[2u].asString())) + { + return RPCError(rpcDST_ACT_MALFORMED); + } + else if (!saLimitAmount.setValue(params[3u].asString(), params.size() >= 5 ? params[4u].asString() : "")) + { + return RPCError(rpcSRC_AMT_MALFORMED); + } + else + { + NewcoinAddress naMasterGenerator; + NewcoinAddress naAccountPublic; + NewcoinAddress naAccountPrivate; + AccountState::pointer asSrc; + STAmount saSrcBalance; + Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, + saSrcBalance, theConfig.FEE_DEFAULT, asSrc, naMasterGenerator); + + if (!obj.empty()) + return obj; + + Transaction::pointer trans = Transaction::sharedCreditSet( + naAccountPublic, naAccountPrivate, + naSrcAccountID, + asSrc->getSeq(), + theConfig.FEE_DEFAULT, + 0, // YYY No source tag + naDstAccountID, + saLimitAmount, + uAcceptRate); + + (void) mNetOps->processTransaction(trans); + + obj["transaction"] = trans->getSTransaction()->getJson(0); + obj["status"] = trans->getStatus(); + obj["seed"] = naSeed.humanSeed(); + obj["srcAccountID"] = naSrcAccountID.humanAccountID(); + obj["dstAccountID"] = naDstAccountID.humanAccountID(); + obj["limitAmount"] = saLimitAmount.getText(); + obj["acceptRate"] = uAcceptRate; + + return obj; + } +} + +// ripple_lines_get || [] +Json::Value RPCServer::doRippleLinesGet(const Json::Value ¶ms) +{ +// uint256 uAccepted = mNetOps->getClosedLedger(); + uint256 uCurrent = mNetOps->getCurrentLedger(); + + std::string strIdent = params[0u].asString(); + bool bIndex; + int iIndex = 2 == params.size()? lexical_cast_s(params[1u].asString()) : 0; + + NewcoinAddress naAccount; + + Json::Value ret; + + ret = accountFromString(uCurrent, naAccount, bIndex, strIdent, iIndex); + + if (!ret.empty()) + return ret; + + // Get info on account. + ret = Json::Value(Json::objectValue); + + ret["account"] = naAccount.humanAccountID(); + if (bIndex) + ret["index"] = iIndex; + + AccountState::pointer as = mNetOps->getAccountState(uCurrent, naAccount); + if (as) + { + Json::Value jsonLines = Json::Value(Json::objectValue); + + ret["account"] = naAccount.humanAccountID(); + + // We access a committed ledger and need not worry about changes. + uint256 uRootIndex; + + if (mNetOps->getDirLineInfo(uCurrent, naAccount, uRootIndex)) + { + bool bDone = false; + + while (!bDone) + { + uint64 uNodePrevious; + uint64 uNodeNext; + STVector256 svRippleNodes = mNetOps->getDirNodeInfo(uCurrent, uRootIndex, uNodePrevious, uNodeNext); + + BOOST_FOREACH(uint256& uNode, svRippleNodes.peekValue()) + { + NewcoinAddress naAccountPeer; + STAmount saBalance; + STAmount saLimit; + STAmount saLimitPeer; + + RippleState::pointer rsLine = mNetOps->getRippleState(uCurrent, uNode); + + if (rsLine) + { + rsLine->setViewAccount(naAccount); + + naAccountPeer = rsLine->getAccountIDPeer(); + saBalance = rsLine->getBalance(); + saLimit = rsLine->getLimit(); + saLimitPeer = rsLine->getLimitPeer(); + + Json::Value jPeer = Json::Value(Json::objectValue); + + jPeer["node"] = uNode.ToString(); + + jPeer["balance"] = saBalance.getText(); + jPeer["currency"] = saBalance.getCurrencyHuman(); + jPeer["limit"] = saLimit.getJson(0); + jPeer["limit_peer"] = saLimitPeer.getJson(0); + + jsonLines[naAccountPeer.humanAccountID()] = jPeer; + } + else + { + std::cerr << "doAccountLines: Bad index: " << uNode.ToString() << std::endl; + } + } + + if (uNodeNext) + { + uCurrent = Ledger::getDirNodeIndex(uRootIndex, uNodeNext); + } + else + { + bDone = true; + } + } + } + ret["lines"] = jsonLines; + } + else + { + ret["status"] = "NotFound"; + } + + return ret; +} + // send regular_seed paying_account account_id amount [currency] [send_max] [send_currency] Json::Value RPCServer::doSend(const Json::Value& params) { @@ -1970,12 +1970,10 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params } commandsA[] = { { "account_email_set", &RPCServer::doAccountEmailSet, 2, 3, false, optCurrent }, { "account_info", &RPCServer::doAccountInfo, 1, 2, false, optCurrent }, - { "account_lines", &RPCServer::doAccountLines, 1, 2, false, optCurrent|optClosed }, { "account_message_set", &RPCServer::doAccountMessageSet, 3, 3, false, optCurrent }, { "account_tx", &RPCServer::doAccountTransactions, 2, 3, false, optNetwork }, { "account_wallet_set", &RPCServer::doAccountWalletSet, 2, 3, false, optCurrent }, { "connect", &RPCServer::doConnect, 1, 2, true }, - { "credit_set", &RPCServer::doCreditSet, 4, 6, false, optCurrent }, { "data_delete", &RPCServer::doDataDelete, 1, 1, true }, { "data_fetch", &RPCServer::doDataFetch, 1, 1, true }, { "data_store", &RPCServer::doDataStore, 2, 2, true }, @@ -1987,6 +1985,8 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params { "password_fund", &RPCServer::doPasswordFund, 2, 3, false, optCurrent }, { "password_set", &RPCServer::doPasswordSet, 2, 3, false, optNetwork }, { "peers", &RPCServer::doPeers, 0, 0, true }, + { "ripple_lines_get", &RPCServer::doRippleLinesGet, 1, 2, false, optCurrent|optClosed }, + { "ripple_line_set", &RPCServer::doRippleLineSet, 4, 6, false, optCurrent }, { "send", &RPCServer::doSend, 3, 7, false, optCurrent }, { "server_info", &RPCServer::doServerInfo, 0, 0, true }, { "stop", &RPCServer::doStop, 0, 0, true }, diff --git a/src/RPCServer.h b/src/RPCServer.h index c57871d753..fa6be57e9d 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -123,12 +123,10 @@ private: Json::Value doAccountEmailSet(const Json::Value ¶ms); Json::Value doAccountInfo(const Json::Value& params); - Json::Value doAccountLines(const Json::Value ¶ms); Json::Value doAccountMessageSet(const Json::Value ¶ms); Json::Value doAccountTransactions(const Json::Value& params); Json::Value doAccountWalletSet(const Json::Value ¶ms); Json::Value doConnect(const Json::Value& params); - Json::Value doCreditSet(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); @@ -140,6 +138,8 @@ private: Json::Value doPasswordFund(const Json::Value& params); Json::Value doPasswordSet(const Json::Value& params); Json::Value doPeers(const Json::Value& params); + Json::Value doRippleLinesGet(const Json::Value ¶ms); + Json::Value doRippleLineSet(const Json::Value& params); Json::Value doSend(const Json::Value& params); Json::Value doServerInfo(const Json::Value& params); Json::Value doSessionClose(const Json::Value& params); diff --git a/src/main.cpp b/src/main.cpp index 0962728b69..75832a912b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,11 +41,9 @@ void printHelp(const po::options_description& desc) cout << " account_email_set []" << endl; cout << " account_info |" << endl; cout << " account_info || []" << endl; - cout << " account_lines |" << endl; cout << " account_message_set " << endl; cout << " account_wallet_set []" << endl; cout << " connect []" << endl; - cout << " credit_set []" << endl; cout << " data_delete " << endl; cout << " data_fetch " << endl; cout << " data_store " << endl; @@ -55,6 +53,8 @@ void printHelp(const po::options_description& desc) cout << " password_fund []" << endl; cout << " password_set []" << endl; cout << " peers" << endl; + cout << " ripple_lines_get || []" << endl; + cout << " ripple_line_set []" << endl; cout << " send [] [] []" << endl; cout << " stop" << endl; cout << " tx " << endl;