mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Complete the basic API for LedgerEntrySet's.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "LedgerEntrySet.h"
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
LedgerEntrySet LedgerEntrySet::duplicate()
|
||||
{
|
||||
return LedgerEntrySet(mEntries, mSeq + 1);
|
||||
@@ -17,5 +19,73 @@ void LedgerEntrySet::swapWith(LedgerEntrySet& e)
|
||||
mEntries.swap(e.mEntries);
|
||||
}
|
||||
|
||||
SLE::pointer LedgerEntrySet::getEntry(const uint256& index, LedgerEntryAction& action)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(index);
|
||||
if (it == mEntries.end())
|
||||
{
|
||||
action = taaNONE;
|
||||
return SLE::pointer();
|
||||
}
|
||||
if (it->second.mSeq != mSeq)
|
||||
{
|
||||
it->second.mEntry = boost::make_shared<SerializedLedgerEntry>(*it->second.mEntry);
|
||||
it->second.mSeq = mSeq;
|
||||
}
|
||||
action = it->second.mAction;
|
||||
return it->second.mEntry;
|
||||
}
|
||||
|
||||
LedgerEntryAction LedgerEntrySet::hasEntry(const uint256& index) const
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator it = mEntries.find(index);
|
||||
if (it == mEntries.end())
|
||||
return taaNONE;
|
||||
return it->second.mAction;
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryCache(SLE::pointer sle)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
|
||||
if (it == mEntries.end())
|
||||
mEntries.insert(std::make_pair(sle->getIndex(), LedgerEntrySetEntry(sle, taaCACHED, mSeq)));
|
||||
else if (it->second.mAction == taaCACHED)
|
||||
{
|
||||
it->second.mSeq = mSeq;
|
||||
it->second.mEntry = sle;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Cache after modify/delete");
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryCreate(SLE::pointer sle)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
|
||||
if (it == mEntries.end())
|
||||
mEntries.insert(std::make_pair(sle->getIndex(), LedgerEntrySetEntry(sle, taaDELETE, mSeq)));
|
||||
else if (it->second.mAction == taaDELETE)
|
||||
throw std::runtime_error("Create after delete");
|
||||
else if (it->second.mAction == taaMODIFY)
|
||||
throw std::runtime_error("Create after modify");
|
||||
else
|
||||
{
|
||||
it->second.mSeq = mSeq;
|
||||
it->second.mEntry = sle;
|
||||
it->second.mAction = taaDELETE;
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryModify(SLE::pointer sle)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
|
||||
if (it == mEntries.end())
|
||||
mEntries.insert(std::make_pair(sle->getIndex(), LedgerEntrySetEntry(sle, taaMODIFY, mSeq)));
|
||||
else if (it->second.mAction == taaDELETE)
|
||||
throw std::runtime_error("Modify after delete");
|
||||
else
|
||||
{
|
||||
it->second.mSeq = mSeq;
|
||||
it->second.mEntry = sle;
|
||||
it->second.mAction = (it->second.mAction == taaCREATE) ? taaCREATE : taaDELETE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
SLE::pointer mEntry;
|
||||
LedgerEntryAction mAction;
|
||||
int mSeq;
|
||||
|
||||
LedgerEntrySetEntry(SLE::pointer e, LedgerEntryAction a, int s) : mEntry(e), mAction(a), mSeq(s) { ; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user