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
@@ -91,7 +91,7 @@ public:
|
||||
// Used for ledgers loaded from JSON files
|
||||
Ledger (uint256 const& parentHash, uint256 const& transHash,
|
||||
uint256 const& accountHash,
|
||||
std::uint64_t totCoins, std::uint32_t closeTime,
|
||||
std::uint64_t totDrops, std::uint32_t closeTime,
|
||||
std::uint32_t parentCloseTime, int closeFlags, int closeResolution,
|
||||
std::uint32_t ledgerSeq, bool & loaded);
|
||||
|
||||
@@ -242,7 +242,7 @@ public:
|
||||
uint256 const&
|
||||
getHash();
|
||||
|
||||
void setTotalCoins (std::uint64_t totDrops)
|
||||
void setTotalDrops (std::uint64_t totDrops)
|
||||
{
|
||||
info_.drops = totDrops;
|
||||
}
|
||||
|
||||
@@ -81,6 +81,8 @@ public:
|
||||
// This is the last ledger we published to clients and can lag the validated ledger
|
||||
virtual Ledger::ref getPublishedLedger () = 0;
|
||||
|
||||
virtual bool isValidLedger(LedgerInfo const&) = 0;
|
||||
|
||||
virtual int getPublishedLedgerAge () = 0;
|
||||
virtual int getValidatedLedgerAge () = 0;
|
||||
virtual bool isCaughtUp(std::string& reason) = 0;
|
||||
|
||||
@@ -73,8 +73,8 @@ Blob serializeBlob(Object const& o)
|
||||
}
|
||||
|
||||
/** Serialize an object to a hex string. */
|
||||
template <class Object>
|
||||
std::string serializeHex(Object const& o)
|
||||
inline
|
||||
std::string serializeHex(STObject const& o)
|
||||
{
|
||||
return strHex(serializeBlob(o));
|
||||
}
|
||||
|
||||
@@ -1264,6 +1264,36 @@ public:
|
||||
return mPubLedger;
|
||||
}
|
||||
|
||||
bool isValidLedger(LedgerInfo const& info) override
|
||||
{
|
||||
if (info.validated)
|
||||
return true;
|
||||
|
||||
if (info.open)
|
||||
return false;
|
||||
|
||||
auto seq = info.seq;
|
||||
try
|
||||
{
|
||||
// Use the skip list in the last validated ledger to see if ledger
|
||||
// comes before the last validated ledger (and thus has been
|
||||
// validated).
|
||||
auto hash = walkHashBySeq (seq);
|
||||
if (info.hash != hash)
|
||||
return false;
|
||||
}
|
||||
catch (SHAMapMissingNode const&)
|
||||
{
|
||||
WriteLog (lsWARNING, RPCHandler)
|
||||
<< "Missing SHANode " << std::to_string (seq);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mark ledger as validated to save time if we see it again.
|
||||
info.validated = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int getMinValidations ()
|
||||
{
|
||||
return mMinValidations;
|
||||
|
||||
@@ -90,32 +90,29 @@ void fillJsonTx (Object& json, LedgerFill const& fill)
|
||||
|
||||
try
|
||||
{
|
||||
using value_type = ReadView::txs_type::value_type;
|
||||
forEachTx(fill.ledger, [&] (value_type const& i) {
|
||||
for (auto& i: fill.ledger.txs)
|
||||
{
|
||||
count.yield();
|
||||
|
||||
if (! bExpanded)
|
||||
{
|
||||
txns.append(to_string(i.first->getTransactionID()));
|
||||
return true;
|
||||
}
|
||||
|
||||
auto&& txJson = appendObject (txns);
|
||||
|
||||
if (bBinary)
|
||||
else if (bBinary)
|
||||
{
|
||||
auto&& txJson = appendObject (txns);
|
||||
txJson[jss::tx_blob] = serializeHex(*i.first);
|
||||
if (i.second)
|
||||
txJson[jss::meta] = serializeHex(*i.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto&& txJson = appendObject (txns);
|
||||
copyFrom(txJson, i.first->getJson(0));
|
||||
if (i.second)
|
||||
txJson[jss::metaData] = i.second->getJson(0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
@@ -1164,7 +1164,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
std::uint32_t closeTime = getApp().getOPs().getCloseTimeNC ();
|
||||
std::uint32_t closeTimeResolution = 30;
|
||||
bool closeTimeEstimated = false;
|
||||
std::uint64_t totalCoins = 0;
|
||||
std::uint64_t totalDrops = 0;
|
||||
|
||||
if (ledger.get().isMember ("accountState"))
|
||||
{
|
||||
@@ -1188,7 +1188,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
}
|
||||
if (ledger.get().isMember ("total_coins"))
|
||||
{
|
||||
totalCoins =
|
||||
totalDrops =
|
||||
beast::lexicalCastThrow<std::uint64_t>
|
||||
(ledger.get()["total_coins"].asString());
|
||||
}
|
||||
@@ -1201,7 +1201,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
else
|
||||
{
|
||||
loadLedger = std::make_shared<Ledger> (seq, closeTime);
|
||||
loadLedger->setTotalCoins(totalCoins);
|
||||
loadLedger->setTotalDrops(totalDrops);
|
||||
|
||||
for (Json::UInt index = 0; index < ledger.get().size(); ++index)
|
||||
{
|
||||
|
||||
@@ -217,9 +217,11 @@ public:
|
||||
// Book functions.
|
||||
//
|
||||
|
||||
void getBookPage (bool bAdmin, Ledger::pointer lpLedger, Book const&,
|
||||
AccountID const& uTakerID, const bool bProof, const unsigned int iLimit,
|
||||
Json::Value const& jvMarker, Json::Value& jvResult) override;
|
||||
void getBookPage (bool bAdmin, std::shared_ptr<ReadView const>& lpLedger,
|
||||
Book const&, AccountID const& uTakerID, const bool bProof,
|
||||
const unsigned int iLimit,
|
||||
Json::Value const& jvMarker, Json::Value& jvResult)
|
||||
override;
|
||||
|
||||
// Ledger proposal/close functions.
|
||||
void processTrustedProposal (
|
||||
@@ -2640,7 +2642,7 @@ InfoSub::pointer NetworkOPsImp::addRpcSub (
|
||||
// FIXME : support iLimit.
|
||||
void NetworkOPsImp::getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
std::shared_ptr<ReadView const>& lpLedger,
|
||||
Book const& book,
|
||||
AccountID const& uTakerID,
|
||||
bool const bProof,
|
||||
@@ -2864,7 +2866,7 @@ void NetworkOPsImp::getBookPage (
|
||||
// FIXME : support iLimit.
|
||||
void NetworkOPsImp::getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
std::shared_ptr<ReadView const> lpLedger,
|
||||
Book const& book,
|
||||
AccountID const& uTakerID,
|
||||
bool const bProof,
|
||||
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
|
||||
virtual void getBookPage (
|
||||
bool bAdmin,
|
||||
Ledger::pointer lpLedger,
|
||||
std::shared_ptr<ReadView const>& lpLedger,
|
||||
Book const& book,
|
||||
AccountID const& uTakerID,
|
||||
bool const bProof,
|
||||
|
||||
Reference in New Issue
Block a user