mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
107 lines
3.0 KiB
C++
107 lines
3.0 KiB
C++
#include "LedgerEntrySet.h"
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
LedgerEntrySet LedgerEntrySet::duplicate()
|
|
{
|
|
return LedgerEntrySet(mEntries, mSeq + 1);
|
|
}
|
|
|
|
void LedgerEntrySet::setTo(LedgerEntrySet& e)
|
|
{
|
|
mEntries = e.mEntries;
|
|
mSeq = e.mSeq;
|
|
}
|
|
|
|
void LedgerEntrySet::swapWith(LedgerEntrySet& e)
|
|
{
|
|
std::swap(mSeq, e.mSeq);
|
|
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"); // We could make this a modify
|
|
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;
|
|
}
|
|
}
|
|
|
|
void LedgerEntrySet::entryDelete(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 == taaCREATE) // We support delete after create
|
|
mEntries.erase(it);
|
|
else
|
|
{
|
|
it->second.mSeq = mSeq;
|
|
it->second.mEntry = sle;
|
|
it->second.mAction = taaDELETE;
|
|
}
|
|
}
|