mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Replace Ledger with ReadView in most RPC handlers.
This commit is contained in:
committed by
Vinnie Falco
parent
c7ebe7205c
commit
1d09c54fdc
@@ -29,7 +29,7 @@ Json::Value doAccountCurrencies (RPC::Context& context)
|
||||
auto& params = context.params;
|
||||
|
||||
// Get the current ledger
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
if (!ledger)
|
||||
return result;
|
||||
|
||||
@@ -37,7 +37,7 @@ Json::Value doAccountInfo (RPC::Context& context)
|
||||
{
|
||||
auto& params = context.params;
|
||||
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
|
||||
if (!ledger)
|
||||
@@ -58,16 +58,13 @@ Json::Value doAccountInfo (RPC::Context& context)
|
||||
if (jvAccepted)
|
||||
return jvAccepted;
|
||||
|
||||
auto const sleAccepted = cachedRead(*ledger,
|
||||
keylet::account(accountID).key, ltACCOUNT_ROOT);
|
||||
|
||||
auto const sleAccepted = ledger->read(keylet::account(accountID));
|
||||
if (sleAccepted)
|
||||
{
|
||||
injectSLE(jvAccepted, *sleAccepted);
|
||||
|
||||
// See if there's a SignerEntries for this account.
|
||||
uint256 const signerListIndex = getSignerListIndex (accountID);
|
||||
auto const signerList = cachedRead(*ledger, signerListIndex);
|
||||
auto const signerList = ledger->read (keylet::signers(accountID));
|
||||
|
||||
if (signerList)
|
||||
{
|
||||
|
||||
@@ -81,7 +81,7 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error (jss::account);
|
||||
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
if (! ledger)
|
||||
return result;
|
||||
@@ -152,9 +152,9 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
return RPC::expected_field_error (jss::marker, "string");
|
||||
|
||||
startAfter.SetHex (marker.asString ());
|
||||
auto const sleLine = cachedRead(*ledger, startAfter);
|
||||
auto const sleLine = ledger->read({ltRIPPLE_STATE, startAfter});
|
||||
|
||||
if (sleLine == nullptr || sleLine->getType () != ltRIPPLE_STATE)
|
||||
if (! sleLine)
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
|
||||
if (sleLine->getFieldAmount (sfLowLimit).getIssuer () == accountID)
|
||||
@@ -180,7 +180,6 @@ Json::Value doAccountLines (RPC::Context& context)
|
||||
}
|
||||
|
||||
{
|
||||
// VFALCO Needs a caching view here
|
||||
if (! forEachItemAfter(*ledger, accountID,
|
||||
startAfter, startHint, reserve,
|
||||
[&visitData](std::shared_ptr<SLE const> const& sleCur)
|
||||
|
||||
@@ -46,7 +46,7 @@ Json::Value doAccountObjects (RPC::Context& context)
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error (jss::account);
|
||||
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
if (ledger == nullptr)
|
||||
return result;
|
||||
|
||||
@@ -49,7 +49,7 @@ Json::Value doAccountOffers (RPC::Context& context)
|
||||
if (! params.isMember (jss::account))
|
||||
return RPC::missing_field_error (jss::account);
|
||||
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
if (! ledger)
|
||||
return result;
|
||||
@@ -108,11 +108,9 @@ Json::Value doAccountOffers (RPC::Context& context)
|
||||
return RPC::expected_field_error (jss::marker, "string");
|
||||
|
||||
startAfter.SetHex (marker.asString ());
|
||||
auto const sleOffer = cachedRead (*ledger, startAfter);
|
||||
auto const sleOffer = ledger->read({ltOFFER, startAfter});
|
||||
|
||||
if (sleOffer == nullptr ||
|
||||
sleOffer->getType () != ltOFFER ||
|
||||
accountID != sleOffer->getAccountID (sfAccount))
|
||||
if (! sleOffer || accountID != sleOffer->getAccountID (sfAccount))
|
||||
{
|
||||
return rpcError (rpcINVALID_PARAMS);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ Json::Value doAccountTx (RPC::Context& context)
|
||||
}
|
||||
else
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto ret = RPC::lookupLedger (ledger, context);
|
||||
|
||||
if (! ledger)
|
||||
|
||||
@@ -103,7 +103,7 @@ Json::Value doAccountTxOld (RPC::Context& context)
|
||||
}
|
||||
else
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto ret = RPC::lookupLedger (ledger, context);
|
||||
|
||||
if (!ledger)
|
||||
|
||||
@@ -30,7 +30,7 @@ Json::Value doBookOffers (RPC::Context& context)
|
||||
if (getApp().getJobQueue ().getJobCountGE (jtCLIENT) > 200)
|
||||
return rpcError (rpcTOO_BUSY);
|
||||
|
||||
Ledger::pointer lpLedger;
|
||||
std::shared_ptr<ReadView const> lpLedger;
|
||||
auto jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
|
||||
if (!lpLedger)
|
||||
|
||||
@@ -70,7 +70,7 @@ Json::Value doCanDelete (RPC::Context& context)
|
||||
canDeleteStr.find_first_not_of("0123456789abcdef") ==
|
||||
std::string::npos)
|
||||
{
|
||||
Ledger::pointer ledger = context.ledgerMaster.getLedgerByHash (
|
||||
auto ledger = context.ledgerMaster.getLedgerByHash (
|
||||
from_hex_text<uint256>(canDeleteStr));
|
||||
|
||||
if (!ledger)
|
||||
|
||||
@@ -49,7 +49,7 @@ Json::Value doGatewayBalances (RPC::Context& context)
|
||||
auto& params = context.params;
|
||||
|
||||
// Get the current ledger
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
|
||||
if (!ledger)
|
||||
|
||||
@@ -41,7 +41,7 @@ Status LedgerHandler::check ()
|
||||
if (!needsLedger)
|
||||
return Status::OK;
|
||||
|
||||
if (auto s = RPC::lookupLedger (ledger_, context_, result_))
|
||||
if (auto s = lookupLedger (ledger_, context_, result_))
|
||||
return s;
|
||||
|
||||
bool bFull = params[jss::full].asBool();
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
Context& context_;
|
||||
Ledger::pointer ledger_;
|
||||
std::shared_ptr<ReadView const> ledger_;
|
||||
Json::Value result_;
|
||||
int options_ = 0;
|
||||
};
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace ripple {
|
||||
// marker: resume point, if any
|
||||
Json::Value doLedgerData (RPC::Context& context)
|
||||
{
|
||||
int const BINARY_PAGE_LENGTH = 2048;
|
||||
int const JSON_PAGE_LENGTH = 256;
|
||||
static int const BINARY_PAGE_LENGTH = 2048;
|
||||
static int const JSON_PAGE_LENGTH = 256;
|
||||
|
||||
Ledger::pointer lpLedger;
|
||||
std::shared_ptr<ReadView const> lpLedger;
|
||||
auto const& params = context.params;
|
||||
|
||||
auto jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
auto jvResult = RPC::lookupLedger(lpLedger, context);
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
@@ -48,9 +48,7 @@ Json::Value doLedgerData (RPC::Context& context)
|
||||
if (params.isMember (jss::marker))
|
||||
{
|
||||
Json::Value const& jMarker = params[jss::marker];
|
||||
if (!jMarker.isString ())
|
||||
return RPC::expected_field_error (jss::marker, "valid");
|
||||
if (!resumePoint.SetHex (jMarker.asString ()))
|
||||
if (! (jMarker.isString () && resumePoint.SetHex (jMarker.asString ())))
|
||||
return RPC::expected_field_error (jss::marker, "valid");
|
||||
}
|
||||
|
||||
@@ -71,40 +69,33 @@ Json::Value doLedgerData (RPC::Context& context)
|
||||
if ((limit < 0) || ((limit > maxLimit) && (context.role != Role::ADMIN)))
|
||||
limit = maxLimit;
|
||||
|
||||
jvResult[jss::ledger_hash] = to_string (lpLedger->getHash());
|
||||
jvResult[jss::ledger_index] = std::to_string( lpLedger->info().seq);
|
||||
jvResult[jss::ledger_hash] = to_string (lpLedger->info().hash);
|
||||
jvResult[jss::ledger_index] = std::to_string(lpLedger->info().seq);
|
||||
|
||||
Json::Value& nodes = (jvResult[jss::state] = Json::arrayValue);
|
||||
auto& map = lpLedger->stateMap();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
auto item = map.peekNextItem (resumePoint);
|
||||
if (!item)
|
||||
break;
|
||||
resumePoint = item->key();
|
||||
|
||||
forEachSLE(*lpLedger, [&] (SLE const& sle) {
|
||||
if (limit-- <= 0)
|
||||
{
|
||||
--resumePoint;
|
||||
jvResult[jss::marker] = to_string (resumePoint);
|
||||
break;
|
||||
auto marker = sle.key();
|
||||
jvResult[jss::marker] = to_string (--marker);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isBinary)
|
||||
{
|
||||
Json::Value& entry = nodes.append (Json::objectValue);
|
||||
entry[jss::data] = strHex (
|
||||
item->peekData().begin(), item->peekData().size());
|
||||
entry[jss::index] = to_string (item->key());
|
||||
entry[jss::data] = serializeHex(sle);
|
||||
entry[jss::index] = to_string (sle.key());
|
||||
}
|
||||
else
|
||||
{
|
||||
SLE sle (SerialIter{item->data(), item->size()}, item->key());
|
||||
Json::Value& entry = nodes.append (sle.getJson (0));
|
||||
entry[jss::index] = to_string (item->key());
|
||||
entry[jss::index] = to_string (sle.key());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace ripple {
|
||||
// }
|
||||
Json::Value doLedgerEntry (RPC::Context& context)
|
||||
{
|
||||
Ledger::pointer lpLedger;
|
||||
std::shared_ptr<ReadView const> lpLedger;
|
||||
auto jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
|
||||
if (!lpLedger)
|
||||
@@ -201,8 +201,7 @@ Json::Value doLedgerEntry (RPC::Context& context)
|
||||
|
||||
if (uNodeIndex.isNonZero ())
|
||||
{
|
||||
auto const sleNode = cachedRead(*lpLedger, uNodeIndex);
|
||||
|
||||
auto const sleNode = lpLedger->read(keylet::unchecked(uNodeIndex));
|
||||
if (context.params.isMember(jss::binary))
|
||||
bNodeBinary = context.params[jss::binary].asBool();
|
||||
|
||||
|
||||
@@ -28,16 +28,14 @@ namespace ripple {
|
||||
// }
|
||||
Json::Value doLedgerHeader (RPC::Context& context)
|
||||
{
|
||||
Ledger::pointer lpLedger;
|
||||
std::shared_ptr<ReadView const> lpLedger;
|
||||
auto jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
Serializer s;
|
||||
|
||||
lpLedger->addRaw (s);
|
||||
|
||||
addRaw (lpLedger->info(), s);
|
||||
jvResult[jss::ledger_data] = strHex (s.peekData ());
|
||||
|
||||
// This information isn't verified: they should only use it if they trust
|
||||
|
||||
@@ -29,14 +29,15 @@ static void fillTransaction (
|
||||
Json::Value& txArray,
|
||||
AccountID const& accountID,
|
||||
std::uint32_t& sequence,
|
||||
Ledger::ref ledger)
|
||||
ReadView const& ledger)
|
||||
{
|
||||
txArray["Sequence"] = Json::UInt (sequence++);
|
||||
txArray["Account"] = getApp().accountIDCache().toBase58 (accountID);
|
||||
// VFALCO Needs audit
|
||||
// Why are we hard-coding 10?
|
||||
auto& fees = ledger.fees();
|
||||
txArray["Fee"] = Json::UInt (getApp().getFeeTrack().scaleFeeLoad(
|
||||
10, ledger->fees().base, ledger->fees().units, false));
|
||||
10, fees.base, fees.units, false));
|
||||
}
|
||||
|
||||
// {
|
||||
@@ -83,7 +84,7 @@ Json::Value doNoRippleCheck (RPC::Context& context)
|
||||
if (params.isMember (jss::transactions))
|
||||
transactions = params["transactions"].asBool();
|
||||
|
||||
Ledger::pointer ledger;
|
||||
std::shared_ptr<ReadView const> ledger;
|
||||
auto result = RPC::lookupLedger (ledger, context);
|
||||
if (! ledger)
|
||||
return result;
|
||||
@@ -103,8 +104,7 @@ Json::Value doNoRippleCheck (RPC::Context& context)
|
||||
return result;
|
||||
}
|
||||
|
||||
auto const sle = cachedRead(*ledger,
|
||||
keylet::account(accountID).key, ltACCOUNT_ROOT);
|
||||
auto const sle = ledger->read(keylet::account(accountID));
|
||||
if (! sle)
|
||||
return rpcError (rpcACT_NOT_FOUND);
|
||||
|
||||
@@ -127,7 +127,7 @@ Json::Value doNoRippleCheck (RPC::Context& context)
|
||||
Json::Value& tx = jvTransactions.append (Json::objectValue);
|
||||
tx["TransactionType"] = "AccountSet";
|
||||
tx["SetFlag"] = 8;
|
||||
fillTransaction (tx, accountID, seq, ledger);
|
||||
fillTransaction (tx, accountID, seq, *ledger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ Json::Value doNoRippleCheck (RPC::Context& context)
|
||||
tx["TransactionType"] = "TrustSet";
|
||||
tx["LimitAmount"] = limitAmount.getJson (0);
|
||||
tx["Flags"] = bNoRipple ? tfClearNoRipple : tfSetNoRipple;
|
||||
fillTransaction(tx, accountID, seq, ledger);
|
||||
fillTransaction(tx, accountID, seq, *ledger);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ripple {
|
||||
|
||||
Json::Value doPathFind (RPC::Context& context)
|
||||
{
|
||||
Ledger::pointer lpLedger = context.ledgerMaster.getClosedLedger();
|
||||
auto lpLedger = context.ledgerMaster.getClosedLedger();
|
||||
|
||||
if (!context.params.isMember (jss::subcommand) ||
|
||||
!context.params[jss::subcommand].isString ())
|
||||
@@ -35,7 +35,7 @@ Json::Value doPathFind (RPC::Context& context)
|
||||
if (!context.infoSub)
|
||||
return rpcError (rpcNO_EVENTS);
|
||||
|
||||
std::string sSubCommand = context.params[jss::subcommand].asString ();
|
||||
auto sSubCommand = context.params[jss::subcommand].asString ();
|
||||
|
||||
if (sSubCommand == "create")
|
||||
{
|
||||
|
||||
@@ -73,7 +73,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
|
||||
context.params.isMember(jss::ledger_hash))
|
||||
{
|
||||
// The caller specified a ledger
|
||||
jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
jvResult = RPC::lookupLedgerDeprecated (lpLedger, context);
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
}
|
||||
|
||||
@@ -292,8 +292,8 @@ Json::Value doSubscribe (RPC::Context& context)
|
||||
if (bSnapshot)
|
||||
{
|
||||
context.loadType = Resource::feeMediumBurdenRPC;
|
||||
auto lpLedger = getApp().getLedgerMaster ().
|
||||
getPublishedLedger ();
|
||||
std::shared_ptr<ReadView const> lpLedger
|
||||
= getApp().getLedgerMaster().getPublishedLedger();
|
||||
if (lpLedger)
|
||||
{
|
||||
const Json::Value jvMarker = Json::Value (Json::nullValue);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ripple {
|
||||
Json::Value doTransactionEntry (RPC::Context& context)
|
||||
{
|
||||
Ledger::pointer lpLedger;
|
||||
Json::Value jvResult = RPC::lookupLedger (lpLedger, context);
|
||||
Json::Value jvResult = RPC::lookupLedgerDeprecated (lpLedger, context);
|
||||
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
@@ -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