mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Refactor out a version of lookupLedger returning Status.
This commit is contained in:
committed by
Vinnie Falco
parent
c72db5fa5f
commit
a360c481c2
@@ -45,10 +45,11 @@ static const int LEDGER_VALIDATED = -3;
|
||||
// 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.
|
||||
Json::Value lookupLedger (
|
||||
Status lookupLedger (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
NetworkOPs& netOps)
|
||||
NetworkOPs& netOps,
|
||||
Json::Value& jsonResult)
|
||||
{
|
||||
using RPC::make_error;
|
||||
ledger.reset();
|
||||
@@ -74,7 +75,7 @@ Json::Value lookupLedger (
|
||||
uint256 ledgerHash;
|
||||
|
||||
if (!jsonHash.isString() || !ledgerHash.SetHex (jsonHash.asString ()))
|
||||
return make_error(rpcINVALID_PARAMS, "ledgerHashMalformed");
|
||||
return {rpcINVALID_PARAMS, "ledgerHashMalformed"};
|
||||
|
||||
std::int32_t ledgerIndex = LEDGER_CURRENT;
|
||||
|
||||
@@ -97,7 +98,7 @@ Json::Value lookupLedger (
|
||||
else if (index == "validated")
|
||||
ledgerIndex = LEDGER_VALIDATED;
|
||||
else
|
||||
return make_error(rpcINVALID_PARAMS, "ledgerIndexMalformed");
|
||||
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -105,7 +106,7 @@ Json::Value lookupLedger (
|
||||
ledger = netOps.getLedgerByHash (ledgerHash);
|
||||
|
||||
if (!ledger)
|
||||
return make_error(rpcLGR_NOT_FOUND, "ledgerNotFound");
|
||||
return {rpcLGR_NOT_FOUND, "ledgerNotFound"};
|
||||
|
||||
ledgerIndex = ledger->getLedgerSeq ();
|
||||
}
|
||||
@@ -128,7 +129,7 @@ Json::Value lookupLedger (
|
||||
break;
|
||||
|
||||
default:
|
||||
return make_error(rpcINVALID_PARAMS, "ledgerIndexMalformed");
|
||||
return {rpcINVALID_PARAMS, "ledgerIndexMalformed"};
|
||||
}
|
||||
|
||||
assert (ledger->isImmutable());
|
||||
@@ -142,10 +143,9 @@ Json::Value lookupLedger (
|
||||
ledger = netOps.getLedgerBySeq (ledgerIndex);
|
||||
|
||||
if (!ledger)
|
||||
return make_error(rpcLGR_NOT_FOUND, "ledgerNotFound");
|
||||
return {rpcLGR_NOT_FOUND, "ledgerNotFound"};
|
||||
}
|
||||
|
||||
Json::Value jsonResult;
|
||||
if (ledger->isClosed ())
|
||||
{
|
||||
if (ledgerHash != zero)
|
||||
@@ -190,7 +190,19 @@ Json::Value lookupLedger (
|
||||
}
|
||||
}
|
||||
|
||||
return jsonResult;
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Json::Value lookupLedger (
|
||||
Json::Value const& params,
|
||||
Ledger::pointer& ledger,
|
||||
NetworkOPs& netOps)
|
||||
{
|
||||
Json::Value value (Json::objectValue);
|
||||
if (auto status = lookupLedger (params, ledger, netOps, value))
|
||||
status.inject (value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
} // RPC
|
||||
|
||||
Reference in New Issue
Block a user