mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Replace Ledger with ReadView in most RPC handlers.
This commit is contained in:
committed by
Vinnie Falco
parent
c7ebe7205c
commit
1d09c54fdc
@@ -26,7 +26,7 @@ namespace ripple {
|
||||
namespace RPC {
|
||||
|
||||
bool
|
||||
getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
getAccountObjects (ReadView const& ledger, AccountID const& account,
|
||||
LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex,
|
||||
std::uint32_t const limit, Json::Value& jvResult)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
found = true;
|
||||
}
|
||||
|
||||
auto dir = cachedRead(ledger, dirIndex, ltDIR_NODE);
|
||||
auto dir = ledger.read({ltDIR_NODE, dirIndex});
|
||||
if (! dir)
|
||||
return false;
|
||||
|
||||
@@ -55,17 +55,17 @@ getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
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 );
|
||||
auto const sleNode = ledger.read(keylet::child(*iter));
|
||||
if (type == ltINVALID || sleNode->getType () == type)
|
||||
{
|
||||
jvObjects.append (sleNode->getJson (0));
|
||||
|
||||
|
||||
if (++i == limit)
|
||||
{
|
||||
if (++iter != entries.end ())
|
||||
@@ -86,7 +86,7 @@ getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
return true;
|
||||
|
||||
dirIndex = getDirNodeIndex (rootDirIndex, nodeIndex);
|
||||
dir = cachedRead(ledger, dirIndex, ltDIR_NODE);
|
||||
dir = ledger.read({ltDIR_NODE, dirIndex});
|
||||
if (! dir)
|
||||
return true;
|
||||
|
||||
@@ -99,7 +99,7 @@ getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
jvResult[jss::marker] = to_string (dirIndex) + ',' +
|
||||
to_string (*e.begin ());
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -107,4 +107,3 @@ getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace RPC {
|
||||
@param jvResult A JSON result that holds the request objects.
|
||||
*/
|
||||
bool
|
||||
getAccountObjects (Ledger const& ledger, AccountID const& account,
|
||||
getAccountObjects (ReadView const& ledger, AccountID const& account,
|
||||
LedgerEntryType const type, uint256 dirIndex, uint256 const& entryIndex,
|
||||
std::uint32_t const limit, Json::Value& jvResult);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/rpc/impl/LookupLedger.h>
|
||||
#include <ripple/ledger/View.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace RPC {
|
||||
@@ -34,14 +35,14 @@ bool isValidatedOld (LedgerMaster& ledgerMaster)
|
||||
Tuning::maxValidatedLedgerAge;
|
||||
}
|
||||
|
||||
Status ledgerFromRequest (Ledger::pointer& ledger, Context& context)
|
||||
template <class T>
|
||||
Status ledgerFromRequest (T& ledger, Context& context)
|
||||
{
|
||||
static auto const minSequenceGap = 10;
|
||||
|
||||
ledger.reset();
|
||||
|
||||
auto& params = context.params;
|
||||
auto& netOps = context.netOps;
|
||||
auto& ledgerMaster = context.ledgerMaster;
|
||||
|
||||
auto indexValue = params[jss::ledger_index];
|
||||
@@ -124,14 +125,12 @@ Status ledgerFromRequest (Ledger::pointer& ledger, Context& context)
|
||||
return {rpcNO_NETWORK, "InsufficientNetworkMode"};
|
||||
}
|
||||
}
|
||||
|
||||
assert (ledger->isImmutable ());
|
||||
}
|
||||
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
bool isValidated (LedgerMaster& ledgerMaster, Ledger& ledger)
|
||||
bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger)
|
||||
{
|
||||
if (ledger.info().validated)
|
||||
return true;
|
||||
@@ -146,7 +145,7 @@ bool isValidated (LedgerMaster& ledgerMaster, Ledger& ledger)
|
||||
// comes before the last validated ledger (and thus has been
|
||||
// validated).
|
||||
auto hash = ledgerMaster.walkHashBySeq (seq);
|
||||
if (ledger.getHash() != hash)
|
||||
if (ledger.info().hash != hash)
|
||||
return false;
|
||||
}
|
||||
catch (SHAMapMissingNode const&)
|
||||
@@ -157,7 +156,7 @@ bool isValidated (LedgerMaster& ledgerMaster, Ledger& ledger)
|
||||
}
|
||||
|
||||
// Mark ledger as validated to save time if we see it again.
|
||||
ledger.setValidated();
|
||||
ledger.info().validated = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -182,27 +181,62 @@ bool isValidated (LedgerMaster& ledgerMaster, Ledger& ledger)
|
||||
// return value. Otherwise, the object contains the field "validated" and
|
||||
// optionally the fields "ledger_hash", "ledger_index" and
|
||||
// "ledger_current_index", if they are defined.
|
||||
Status lookupLedger (
|
||||
Status lookupLedgerDeprecated (
|
||||
Ledger::pointer& ledger, Context& context, Json::Value& result)
|
||||
{
|
||||
if (auto status = ledgerFromRequest (ledger, context))
|
||||
return status;
|
||||
|
||||
if (! ledger->info().open)
|
||||
auto& info = ledger->info();
|
||||
|
||||
if (!info.open)
|
||||
{
|
||||
result[jss::ledger_hash] = to_string (ledger->getHash());
|
||||
result[jss::ledger_index] = ledger->info().seq;
|
||||
result[jss::ledger_hash] = to_string (info.hash);
|
||||
result[jss::ledger_index] = info.seq;
|
||||
}
|
||||
else
|
||||
{
|
||||
result[jss::ledger_current_index] = ledger->info().seq;
|
||||
result[jss::ledger_current_index] = info.seq;
|
||||
}
|
||||
|
||||
result[jss::validated] = getApp().getLedgerMaster().isValidLedger(info);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status lookupLedger (
|
||||
std::shared_ptr<ReadView const>& ledger, Context& context,
|
||||
Json::Value& result)
|
||||
{
|
||||
if (auto status = ledgerFromRequest (ledger, context))
|
||||
return status;
|
||||
|
||||
auto& info = ledger->info();
|
||||
|
||||
if (!info.open)
|
||||
{
|
||||
result[jss::ledger_hash] = to_string (info.hash);
|
||||
result[jss::ledger_index] = info.seq;
|
||||
}
|
||||
else
|
||||
{
|
||||
result[jss::ledger_current_index] = info.seq;
|
||||
}
|
||||
|
||||
result[jss::validated] = isValidated (context.ledgerMaster, *ledger);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Json::Value lookupLedger (Ledger::pointer& ledger, Context& context)
|
||||
Json::Value lookupLedgerDeprecated (Ledger::pointer& ledger, Context& context)
|
||||
{
|
||||
Json::Value result;
|
||||
if (auto status = lookupLedgerDeprecated (ledger, context, result))
|
||||
status.inject (result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Json::Value lookupLedger (
|
||||
std::shared_ptr<ReadView const>& ledger, Context& context)
|
||||
{
|
||||
Json::Value result;
|
||||
if (auto status = lookupLedger (ledger, context, result))
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
#include <ripple/rpc/Status.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class ReadView;
|
||||
|
||||
namespace RPC {
|
||||
|
||||
class Context;
|
||||
@@ -33,14 +36,15 @@ class Context;
|
||||
If there is no error in the return value, then the ledger pointer will have
|
||||
been filled.
|
||||
*/
|
||||
Json::Value lookupLedger (Ledger::pointer&, Context&);
|
||||
Json::Value lookupLedgerDeprecated (Ledger::pointer&, Context&);
|
||||
Json::Value lookupLedger (std::shared_ptr<ReadView const>&, Context&);
|
||||
|
||||
/** Look up a ledger from a request and fill a Json::Result with the data
|
||||
representing a ledger.
|
||||
|
||||
If the returned Status is OK, the ledger pointer will have been filled. */
|
||||
Status lookupLedger (
|
||||
Ledger::pointer&, Context&, Json::Value& result);
|
||||
std::shared_ptr<ReadView const>&, Context&, Json::Value& result);
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user