diff --git a/src/LedgerIndex.cpp b/src/LedgerIndex.cpp index 1bcf17062f..94728cdf75 100644 --- a/src/LedgerIndex.cpp +++ b/src/LedgerIndex.cpp @@ -49,7 +49,7 @@ uint256 Ledger::getBookBase(const uint160& uCurrencyIn, const uint160& uAccountI assert(!bInNative || !bOutNative); // Stamps to stamps not allowed. assert(bInNative == uAccountIn.isZero()); // Make sure issuer is specified as needed. - assert(bOutNative == uAccountOut.isZero()); // Make sure issuer is specified as needed. + assert(bOutNative == uAccountOut.isZero()); // Make sure issuer is specified as needed. assert(uCurrencyIn != uCurrencyOut || uAccountIn != uAccountOut); // Currencies or accounts must differ. Serializer s(82); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index c5d89decab..aed15e198e 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -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& 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 // diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 9458af50b3..15f5b0355f 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -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 // diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 623dc1d94d..39ecbba081 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -948,6 +948,40 @@ Json::Value RPCServer::doOfferCancel(const Json::Value ¶ms) return obj; } +// owner_info || +Json::Value RPCServer::doOwnerInfo(const Json::Value& params) +{ + 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; + + // 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 [] // YYY Make making account default to first account for seed. Json::Value RPCServer::doPasswordFund(const Json::Value ¶ms) @@ -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 }, diff --git a/src/RPCServer.h b/src/RPCServer.h index eda4e403b8..6f62b4e570 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -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);