Add RPC owner_info.

This commit is contained in:
Arthur Britto
2012-07-14 17:21:43 -07:00
parent d6af13330a
commit 6feb16709e
5 changed files with 88 additions and 1 deletions

View File

@@ -215,6 +215,51 @@ NicknameState::pointer NetworkOPs::getNicknameState(const uint256& uLedger, cons
return mLedgerMaster->getLedgerByHash(uLedger)->getNicknameState(strNickname);
}
//
// Owner functions
//
Json::Value NetworkOPs::getOwnerInfo(const uint256& uLedger, const NewcoinAddress& naAccount)
{
Json::Value jvObjects(Json::arrayValue);
Ledger::pointer lpLedger = mLedgerMaster->getLedgerByHash(uLedger);
uint256 uRootIndex = lpLedger->getOwnerDirIndex(naAccount.getAccountID());
LedgerStateParms lspNode = lepNONE;
SLE::pointer sleNode = lpLedger->getDirNode(lspNode, uRootIndex);
if (sleNode)
{
uint64 uNodeDir;
do
{
STVector256 svIndexes = sleNode->getIFieldV256(sfIndexes);
std::vector<uint256>& vuiIndexes = svIndexes.peekValue();
BOOST_FOREACH(uint256& uDirEntry, vuiIndexes)
{
LedgerStateParms lspOffer = lepNONE;
SLE::pointer sleOffer = lpLedger->getOffer(lspOffer, uDirEntry);
jvObjects.append(sleOffer->getJson(0));
}
uNodeDir = sleNode->getIFieldU64(sfIndexNext);
if (uNodeDir)
{
lspNode = lepNONE;
sleNode = lpLedger->getDirNode(lspNode, Ledger::getDirNodeIndex(uRootIndex, uNodeDir));
assert(sleNode);
}
} while (uNodeDir);
}
return jvObjects;
}
//
// Ripple functions
//

View File

@@ -118,6 +118,12 @@ public:
NicknameState::pointer getNicknameState(const uint256& uLedger, const std::string& strNickname);
//
// Owner functions
//
Json::Value getOwnerInfo(const uint256& uLedger, const NewcoinAddress& naAccount);
//
// Ripple functions
//

View File

@@ -948,6 +948,40 @@ Json::Value RPCServer::doOfferCancel(const Json::Value &params)
return obj;
}
// owner_info <account>|<nickname>|<account_public_key>
Json::Value RPCServer::doOwnerInfo(const Json::Value& params)
{
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;
// Get info on account.
uint256 uAccepted = mNetOps->getClosedLedger();
Json::Value jAccepted = accountFromString(uAccepted, naAccount, bIndex, strIdent, iIndex);
if (jAccepted.empty())
{
jAccepted["offers"] = mNetOps->getOwnerInfo(uAccepted, naAccount);
}
ret["accepted"] = jAccepted;
uint256 uCurrent = mNetOps->getCurrentLedger();
Json::Value jCurrent = accountFromString(uCurrent, naAccount, bIndex, strIdent, iIndex);
if (jCurrent.empty())
{
jCurrent["offers"] = mNetOps->getOwnerInfo(uCurrent, naAccount);
}
ret["current"] = jCurrent;
return ret;
}
// password_fund <seed> <paying_account> [<account>]
// YYY Make making account default to first account for seed.
Json::Value RPCServer::doPasswordFund(const Json::Value &params)
@@ -2105,6 +2139,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
{ "nickname_set", &RPCServer::doNicknameSet, 2, 3, false, optCurrent },
{ "offer_create", &RPCServer::doOfferCreate, 9, 10, false, optCurrent },
{ "offer_cancel", &RPCServer::doOfferCancel, 3, 3, false, optCurrent },
{ "owner_info", &RPCServer::doOwnerInfo, 1, 2, false, optCurrent },
{ "password_fund", &RPCServer::doPasswordFund, 2, 3, false, optCurrent },
{ "password_set", &RPCServer::doPasswordSet, 2, 3, false, optNetwork },
{ "peers", &RPCServer::doPeers, 0, 0, true },

View File

@@ -139,6 +139,7 @@ private:
Json::Value doNicknameSet(const Json::Value& params);
Json::Value doOfferCreate(const Json::Value& params);
Json::Value doOfferCancel(const Json::Value& params);
Json::Value doOwnerInfo(const Json::Value& params);
Json::Value doPasswordFund(const Json::Value& params);
Json::Value doPasswordSet(const Json::Value& params);
Json::Value doPeers(const Json::Value& params);