mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
159 lines
3.4 KiB
C++
159 lines
3.4 KiB
C++
|
|
#include "Ledger.h"
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
#include "utils.h"
|
|
#include "Log.h"
|
|
|
|
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SLE::pointer entry)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
bool create = false;
|
|
|
|
if (!mAccountStateMap->hasItem(entry->getIndex()))
|
|
{
|
|
if ((parms & lepCREATE) == 0)
|
|
{
|
|
Log(lsERROR) << "WriteBack non-existent node without create";
|
|
return lepMISSING;
|
|
}
|
|
create = true;
|
|
}
|
|
|
|
SHAMapItem::pointer item = boost::make_shared<SHAMapItem>(entry->getIndex());
|
|
entry->add(item->peekSerializer());
|
|
|
|
if (create)
|
|
{
|
|
assert(!mAccountStateMap->hasItem(entry->getIndex()));
|
|
if(!mAccountStateMap->addGiveItem(item, false))
|
|
{
|
|
assert(false);
|
|
return lepERROR;
|
|
}
|
|
return lepCREATED;
|
|
}
|
|
|
|
if (!mAccountStateMap->updateGiveItem(item, false))
|
|
{
|
|
assert(false);
|
|
return lepERROR;
|
|
}
|
|
return lepOKAY;
|
|
}
|
|
|
|
SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
|
|
LedgerEntryType let )
|
|
{
|
|
SHAMapItem::pointer account = mAccountStateMap->peekItem(nodeID);
|
|
|
|
if (!account)
|
|
{
|
|
if ( (parms & lepCREATE) == 0 )
|
|
{
|
|
parms = lepMISSING;
|
|
return SLE::pointer();
|
|
}
|
|
|
|
parms = parms | lepCREATED | lepOKAY;
|
|
SLE::pointer sle=boost::make_shared<SLE>(let);
|
|
sle->setIndex(nodeID);
|
|
|
|
return sle;
|
|
}
|
|
|
|
SLE::pointer sle =
|
|
boost::make_shared<SLE>(account->peekSerializer(), nodeID);
|
|
|
|
if(sle->getType() != let)
|
|
{ // maybe it's a currency or something
|
|
parms = parms | lepWRONGTYPE;
|
|
return SLE::pointer();
|
|
}
|
|
|
|
parms = parms | lepOKAY;
|
|
|
|
return sle;
|
|
|
|
}
|
|
|
|
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const uint160& accountID)
|
|
{
|
|
uint256 nodeID=getAccountRootIndex(accountID);
|
|
|
|
return getASNode(parms, nodeID, ltACCOUNT_ROOT);
|
|
}
|
|
|
|
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID)
|
|
{
|
|
return getAccountRoot(parms, naAccountID.getAccountID());
|
|
}
|
|
|
|
//
|
|
// Generator Map
|
|
//
|
|
|
|
SLE::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
|
|
return getASNode(parms, getGeneratorIndex(uGeneratorID), ltGENERATOR_MAP);
|
|
}
|
|
|
|
//
|
|
// Nickname
|
|
//
|
|
|
|
SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickname)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
|
|
return getASNode(parms, uNickname, ltNICKNAME);
|
|
}
|
|
|
|
//
|
|
// Ripple State
|
|
//
|
|
|
|
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
|
|
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
|
}
|
|
|
|
//
|
|
// Directory
|
|
//
|
|
|
|
// For a directory entry put in the 64 bit index or quality.
|
|
uint256 Ledger::getDirIndex(const uint256& uBase, const uint64 uNodeDir)
|
|
{
|
|
// Indexes are stored in big endian format: they print as hex as stored.
|
|
// Most significant bytes are first. Least significant bytes repesent adjcent entries.
|
|
// We place uNodeDir in the 8 right most bytes to be adjcent.
|
|
// Want uNodeDir in big endian format so ++ goes to the next entry for indexes.
|
|
uint256 uNode(uBase);
|
|
|
|
((uint64*) uNode.end())[-1] = htobe64(uNodeDir);
|
|
|
|
return uNode;
|
|
}
|
|
|
|
SLE::pointer Ledger::getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
|
|
return getASNode(parms, uRootIndex, ltDIR_ROOT);
|
|
}
|
|
|
|
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
|
{
|
|
ScopedLock l(mAccountStateMap->Lock());
|
|
|
|
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
|
}
|
|
|
|
// vim:ts=4
|