Files
xahaud/src/ripple/rpc/impl/GetAccountObjects.cpp
Vinnie Falco 367c3a5bfc Refactor View classes:
The View hierarchy of classes is reorganized to include new
classes with member functions moved and renamed, to solve
defects in the original design:

OpenView accumulates raw state and tx changes and
can be applied to the base. ApplyView accumulates changes
for a single transaction, including metadata, and can be
applied to an OpenView. The Sandbox allows changes with
the option to apply or throw them out. The PaymentSandbox
provides a sandbox with account credit deferral.

Call sites are changed to use the class appropriate for
the task.
2015-07-09 13:25:18 -07:00

111 lines
3.4 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/rpc/impl/GetAccountObjects.h>
#include <ripple/app/main/Application.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/JsonFields.h>
namespace ripple {
namespace RPC {
bool
getAccountObjects (Ledger const& ledger, AccountID const& account,
LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex,
std::uint32_t const limit, Json::Value& jvResult)
{
auto const rootDirIndex = getOwnerDirIndex (account);
auto found = false;
if (dirIndex.isZero ())
{
dirIndex = rootDirIndex;
found = true;
}
auto dir = cachedRead(ledger, dirIndex, ltDIR_NODE);
if (! dir)
return false;
std::uint32_t i = 0;
auto& jvObjects = jvResult[jss::account_objects];
for (;;)
{
auto const& entries = dir->getFieldV256 (sfIndexes);
auto iter = entries.begin ();
if (! found)
{
iter = std::find (iter, entries.end (), entryIndex);
if (iter == entries.end ())
return false;
found = true;
}
for (; iter != entries.end (); ++iter)
{
auto const sleNode = cachedRead(ledger, *iter );
if (type == ltINVALID || sleNode->getType () == type)
{
jvObjects.append (sleNode->getJson (0));
if (++i == limit)
{
if (++iter != entries.end ())
{
jvResult[jss::limit] = limit;
jvResult[jss::marker] = to_string (dirIndex) + ',' +
to_string (*iter);
return true;
}
break;
}
}
}
auto const nodeIndex = dir->getFieldU64 (sfIndexNext);
if (nodeIndex == 0)
return true;
dirIndex = getDirNodeIndex (rootDirIndex, nodeIndex);
dir = cachedRead(ledger, dirIndex, ltDIR_NODE);
if (! dir)
return true;
if (i == limit)
{
auto const& e = dir->getFieldV256 (sfIndexes);
if (! e.empty ())
{
jvResult[jss::limit] = limit;
jvResult[jss::marker] = to_string (dirIndex) + ',' +
to_string (*e.begin ());
}
return true;
}
}
}
} // RPC
} // ripple