mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Simplify lookupLedger to use an RPC::Context.
This commit is contained in:
committed by
Vinnie Falco
parent
c094772bc0
commit
a0010effbc
@@ -34,15 +34,16 @@ bool isValidatedOld (LedgerMaster& ledgerMaster)
|
||||
Tuning::maxValidatedLedgerAge;
|
||||
}
|
||||
|
||||
Status ledgerFromRequest (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
LedgerMaster& ledgerMaster)
|
||||
Status ledgerFromRequest (Ledger::pointer& 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];
|
||||
auto hashValue = params[jss::ledger_hash];
|
||||
|
||||
@@ -182,36 +183,32 @@ bool isValidated (LedgerMaster& ledgerMaster, Ledger& ledger)
|
||||
// optionally the fields "ledger_hash", "ledger_index" and
|
||||
// "ledger_current_index", if they are defined.
|
||||
Status lookupLedger (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
LedgerMaster& ledgerMaster,
|
||||
Json::Value& jsonResult)
|
||||
Ledger::pointer& ledger, Context& context, Json::Value& result)
|
||||
{
|
||||
if (auto status = ledgerFromRequest (params, ledger, ledgerMaster))
|
||||
if (auto status = ledgerFromRequest (ledger, context))
|
||||
return status;
|
||||
|
||||
if (ledger->isClosed ())
|
||||
{
|
||||
jsonResult[jss::ledger_hash] = to_string (ledger->getHash());
|
||||
jsonResult[jss::ledger_index] = ledger->getLedgerSeq();
|
||||
result[jss::ledger_hash] = to_string (ledger->getHash());
|
||||
result[jss::ledger_index] = ledger->getLedgerSeq();
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonResult[jss::ledger_current_index] = ledger->getLedgerSeq();
|
||||
result[jss::ledger_current_index] = ledger->getLedgerSeq();
|
||||
}
|
||||
jsonResult[jss::validated] = isValidated (ledgerMaster, *ledger);
|
||||
|
||||
result[jss::validated] = isValidated (context.ledgerMaster, *ledger);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Json::Value lookupLedger (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
LedgerMaster& ledgerMaster)
|
||||
Json::Value lookupLedger (Ledger::pointer& ledger, Context& context)
|
||||
{
|
||||
Json::Value value (Json::objectValue);
|
||||
if (auto status = lookupLedger (params, ledger, ledgerMaster, value))
|
||||
status.inject (value);
|
||||
return value;
|
||||
Json::Value result;
|
||||
if (auto status = lookupLedger (ledger, context, result))
|
||||
status.inject (result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // RPC
|
||||
|
||||
@@ -25,26 +25,22 @@
|
||||
namespace ripple {
|
||||
namespace RPC {
|
||||
|
||||
class Context;
|
||||
|
||||
/** Look up a ledger from a request and fill a Json::Result with either
|
||||
an error, or data representing a ledger.
|
||||
|
||||
If there is no error in the return value, then the ledger pointer will have
|
||||
been filled.
|
||||
*/
|
||||
Json::Value lookupLedger (
|
||||
Json::Value const& request,
|
||||
Ledger::pointer&,
|
||||
LedgerMaster&);
|
||||
Json::Value lookupLedger (Ledger::pointer&, 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 (
|
||||
Json::Value const& request,
|
||||
Ledger::pointer&,
|
||||
LedgerMaster&,
|
||||
Json::Value& result);
|
||||
Ledger::pointer&, Context&, Json::Value& result);
|
||||
|
||||
} // RPC
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user