moved all Ledger:: functions to the same .cpp file

This commit is contained in:
jed
2012-08-20 09:51:10 -07:00
parent 336a1c27fc
commit 3dc0646ed8
6 changed files with 4 additions and 356 deletions

View File

@@ -114,9 +114,7 @@
<ClCompile Include="src\LedgerEntrySet.cpp" />
<ClCompile Include="src\LedgerFormats.cpp" />
<ClCompile Include="src\LedgerHistory.cpp" />
<ClCompile Include="src\LedgerIndex.cpp" />
<ClCompile Include="src\LedgerMaster.cpp" />
<ClCompile Include="src\LedgerNode.cpp" />
<ClCompile Include="src\LedgerProposal.cpp" />
<ClCompile Include="src\LedgerTiming.cpp" />
<ClCompile Include="src\Log.cpp" />

View File

@@ -93,15 +93,9 @@
<ClCompile Include="src\LedgerHistory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\LedgerIndex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\LedgerMaster.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\LedgerNode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@@ -505,8 +505,7 @@ void Ledger::setCloseTime(boost::posix_time::ptime ptm)
}
// XXX Use shared locks where possible?
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SLE::pointer entry)
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, const SLE::pointer& entry)
{
ScopedLock l(mAccountStateMap->Lock());
bool create = false;
@@ -696,4 +695,5 @@ SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNod
}
// vim:ts=4

View File

@@ -1,144 +0,0 @@
#include "Ledger.h"
// For an entry put in the 64 bit index or quality.
uint256 Ledger::getQualityIndex(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 represent adjacent entries.
// We place uNodeDir in the 8 right most bytes to be adjacent.
// 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;
}
// Return the last 64 bits.
uint64 Ledger::getQuality(const uint256& uBase)
{
return be64toh(((uint64*) uBase.end())[-1]);
}
uint256 Ledger::getQualityNext(const uint256& uBase)
{
static uint256 uNext("10000000000000000");
uint256 uResult = uBase;
uResult += uNext;
return uResult;
}
uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
{
Serializer s(22);
s.add16(spaceAccount); // 2
s.add160(uAccountID); // 20
return s.getSHA512Half();
}
uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
{
bool bInNative = uTakerPaysCurrency.isZero();
bool bOutNative = uTakerGetsCurrency.isZero();
assert(!bInNative || !bOutNative); // Stamps to stamps not allowed.
assert(bInNative == uTakerPaysIssuerID.isZero()); // Make sure issuer is specified as needed.
assert(bOutNative == uTakerGetsIssuerID.isZero()); // Make sure issuer is specified as needed.
assert(uTakerPaysCurrency != uTakerGetsCurrency || uTakerPaysIssuerID != uTakerGetsIssuerID); // Currencies or accounts must differ.
Serializer s(82);
s.add16(spaceBookDir); // 2
s.add160(uTakerPaysCurrency); // 20
s.add160(uTakerGetsCurrency); // 20
s.add160(uTakerPaysIssuerID); // 20
s.add160(uTakerGetsIssuerID); // 20
return getQualityIndex(s.getSHA512Half()); // Return with quality 0.
}
uint256 Ledger::getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex)
{
if (uNodeIndex)
{
Serializer s(42);
s.add16(spaceDirNode); // 2
s.add256(uDirRoot); // 32
s.add64(uNodeIndex); // 8
return s.getSHA512Half();
}
else
{
return uDirRoot;
}
}
uint256 Ledger::getGeneratorIndex(const uint160& uGeneratorID)
{
Serializer s(22);
s.add16(spaceGenerator); // 2
s.add160(uGeneratorID); // 20
return s.getSHA512Half();
}
// What is important:
// --> uNickname: is a Sha256
// <-- SHA512/2: for consistency and speed in generating indexes.
uint256 Ledger::getNicknameIndex(const uint256& uNickname)
{
Serializer s(34);
s.add16(spaceNickname); // 2
s.add256(uNickname); // 32
return s.getSHA512Half();
}
uint256 Ledger::getOfferIndex(const uint160& uAccountID, uint32 uSequence)
{
Serializer s(26);
s.add16(spaceOffer); // 2
s.add160(uAccountID); // 20
s.add32(uSequence); // 4
return s.getSHA512Half();
}
uint256 Ledger::getOwnerDirIndex(const uint160& uAccountID)
{
Serializer s(22);
s.add16(spaceOwnerDir); // 2
s.add160(uAccountID); // 20
return s.getSHA512Half();
}
uint256 Ledger::getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
{
uint160 uAID = naA.getAccountID();
uint160 uBID = naB.getAccountID();
bool bAltB = uAID < uBID;
Serializer s(62);
s.add16(spaceRipple); // 2
s.add160(bAltB ? uAID : uBID); // 20
s.add160(bAltB ? uBID : uAID); // 20
s.add160(uCurrency); // 20
return s.getSHA512Half();
}
// vim:ts=4

View File

@@ -1,200 +0,0 @@
#include "Ledger.h"
#include <boost/make_shared.hpp>
#include "utils.h"
#include "Log.h"
// XXX Use shared locks where possible?
LedgerStateParms Ledger::writeBack(LedgerStateParms parms, const 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, false)) // FIXME: TX metadata
{
assert(false);
return lepERROR;
}
return lepCREATED;
}
if (!mAccountStateMap->updateGiveItem(item, false, false)) // FIXME: TX metadata
{
assert(false);
return lepERROR;
}
return lepOKAY;
}
SLE::pointer Ledger::getSLE(const uint256& uHash)
{
SHAMapItem::pointer node = mAccountStateMap->peekItem(uHash);
if (!node)
return SLE::pointer();
return boost::make_shared<SLE>(node->peekSerializer(), node->getTag());
}
uint256 Ledger::getFirstLedgerIndex()
{
SHAMapItem::pointer node = mAccountStateMap->peekFirstItem();
return node ? node->getTag() : uint256();
}
uint256 Ledger::getLastLedgerIndex()
{
SHAMapItem::pointer node = mAccountStateMap->peekLastItem();
return node ? node->getTag() : uint256();
}
uint256 Ledger::getNextLedgerIndex(const uint256& uHash)
{
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
return node ? node->getTag() : uint256();
}
uint256 Ledger::getNextLedgerIndex(const uint256& uHash, const uint256& uEnd)
{
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
if ((!node) || (node->getTag() > uEnd))
return uint256();
return node->getTag();
}
uint256 Ledger::getPrevLedgerIndex(const uint256& uHash)
{
SHAMapItem::pointer node = mAccountStateMap->peekPrevItem(uHash);
return node ? node->getTag() : uint256();
}
uint256 Ledger::getPrevLedgerIndex(const uint256& uHash, const uint256& uBegin)
{
SHAMapItem::pointer node = mAccountStateMap->peekNextItem(uHash);
if ((!node) || (node->getTag() < uBegin))
return uint256();
return node->getTag();
}
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(const uint160& accountID)
{
LedgerStateParms qry = lepNONE;
return getASNode(qry, getAccountRootIndex(accountID), ltACCOUNT_ROOT);
}
SLE::pointer Ledger::getAccountRoot(const NewcoinAddress& naAccountID)
{
LedgerStateParms qry = lepNONE;
return getASNode(qry, getAccountRootIndex(naAccountID.getAccountID()), ltACCOUNT_ROOT);
}
//
// Directory
//
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
{
ScopedLock l(mAccountStateMap->Lock());
return getASNode(parms, uNodeIndex, ltDIR_NODE);
}
//
// 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);
}
//
// Offer
//
SLE::pointer Ledger::getOffer(LedgerStateParms& parms, const uint256& uIndex)
{
ScopedLock l(mAccountStateMap->Lock());
return getASNode(parms, uIndex, ltOFFER);
}
//
// Ripple State
//
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
{
ScopedLock l(mAccountStateMap->Lock());
return getASNode(parms, uNode, ltRIPPLE_STATE);
}
// vim:ts=4

View File

@@ -47,8 +47,8 @@ public:
STAmount getLimit() const { return mViewLowest ? mLowLimit : mHighLimit; }
STAmount getLimitPeer() const { return mViewLowest ? mHighLimit : mLowLimit; }
uint32 getQualityIn() const { return mViewLowest ? mLowQualityIn : mHighQualityIn; }
uint32 getQualityOut() const { return mViewLowest ? mLowQualityOut : mHighQualityOut; }
uint32 getQualityIn() const { return((uint32) (mViewLowest ? mLowQualityIn : mHighQualityIn)); }
uint32 getQualityOut() const { return((uint32) (mViewLowest ? mLowQualityOut : mHighQualityOut)); }
SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; }
const SerializedLedgerEntry& peekSLE() const { return *mLedgerEntry; }