Rename RPC commands to ripple_lines_get and ripple_line_set.

This commit is contained in:
Arthur Britto
2012-07-09 21:10:51 -07:00
parent 96b314c78c
commit 164350658f
3 changed files with 170 additions and 170 deletions

View File

@@ -525,107 +525,6 @@ Json::Value RPCServer::doAccountInfo(const Json::Value &params)
return ret;
}
// account_lines <account>|<nickname>|<account_public_key> [<index>]
Json::Value RPCServer::doAccountLines(const Json::Value &params)
{
// uint256 uAccepted = mNetOps->getClosedLedger();
uint256 uCurrent = mNetOps->getCurrentLedger();
std::string strIdent = params[0u].asString();
bool bIndex;
int iIndex = 2 == params.size()? lexical_cast_s<int>(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 <seed> <paying_account> <pub_key>
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 <seed> <paying_account> <destination_account> <limit_amount> [<currency>] [<accept_rate>]
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<uint32>(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 <key>
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 <seed> <paying_account> <destination_account> <limit_amount> [<currency>] [<accept_rate>]
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<uint32>(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 <account>|<nickname>|<account_public_key> [<index>]
Json::Value RPCServer::doRippleLinesGet(const Json::Value &params)
{
// uint256 uAccepted = mNetOps->getClosedLedger();
uint256 uCurrent = mNetOps->getCurrentLedger();
std::string strIdent = params[0u].asString();
bool bIndex;
int iIndex = 2 == params.size()? lexical_cast_s<int>(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 },

View File

@@ -123,12 +123,10 @@ private:
Json::Value doAccountEmailSet(const Json::Value &params);
Json::Value doAccountInfo(const Json::Value& params);
Json::Value doAccountLines(const Json::Value &params);
Json::Value doAccountMessageSet(const Json::Value &params);
Json::Value doAccountTransactions(const Json::Value& params);
Json::Value doAccountWalletSet(const Json::Value &params);
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 &params);
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);

View File

@@ -41,11 +41,9 @@ void printHelp(const po::options_description& desc)
cout << " account_email_set <seed> <paying_account> [<email_address>]" << endl;
cout << " account_info <account>|<nickname>" << endl;
cout << " account_info <seed>|<pass_phrase>|<key> [<index>]" << endl;
cout << " account_lines <account>|<nickname>" << endl;
cout << " account_message_set <seed> <paying_account> <pub_key>" << endl;
cout << " account_wallet_set <seed> <paying_account> [<wallet_hash>]" << endl;
cout << " connect <ip> [<port>]" << endl;
cout << " credit_set <seed> <paying_account> <destination_account> <limit_amount> <currency> [<account_rate>]" << endl;
cout << " data_delete <key>" << endl;
cout << " data_fetch <key>" << endl;
cout << " data_store <key> <value>" << endl;
@@ -55,6 +53,8 @@ void printHelp(const po::options_description& desc)
cout << " password_fund <seed> <paying_account> [<account>]" << endl;
cout << " password_set <master_seed> <regular_seed> [<account>]" << endl;
cout << " peers" << endl;
cout << " ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]" << endl;
cout << " ripple_line_set <seed> <paying_account> <destination_account> <limit_amount> <currency> [<account_rate>]" << endl;
cout << " send <seed> <paying_account> <account_id> <amount> [<currency>] [<send_max>] [<send_currency>]" << endl;
cout << " stop" << endl;
cout << " tx <id>" << endl;