Cleanup ripple::Ledger:

* Convert static member functions to free functions
* Adopt consistent naming convention
* De-inline code
This commit is contained in:
Nik Bougalis
2014-10-17 21:23:41 -07:00
parent 0e1dd92d9b
commit 31110c7fd9
36 changed files with 473 additions and 382 deletions

View File

@@ -2637,6 +2637,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Indexes.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\LedgerFormats.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -2679,6 +2682,8 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\TxFormats.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\protocol\Indexes.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\JsonFields.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\KnownFormats.h">

View File

@@ -3705,6 +3705,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\HashPrefix.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\Indexes.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\protocol\impl\LedgerFormats.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
@@ -3747,6 +3750,9 @@
<ClCompile Include="..\..\src\ripple\protocol\impl\TxFormats.cpp">
<Filter>ripple\protocol\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\protocol\Indexes.h">
<Filter>ripple\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\protocol\JsonFields.h">
<Filter>ripple\protocol</Filter>
</ClInclude>

View File

@@ -70,7 +70,7 @@ public:
Quality const
quality() const noexcept
{
return Quality (Ledger::getQuality (m_dir));
return Quality (getQuality (m_dir));
}
SLE::pointer const&

View File

@@ -25,8 +25,8 @@ namespace core {
BookTip::BookTip (LedgerView& view, BookRef book)
: m_view (view)
, m_valid (false)
, m_book (Ledger::getBookBase (book))
, m_end (Ledger::getQualityNext (m_book))
, m_book (getBookBase (book))
, m_end (getQualityNext (m_book))
{
}

View File

@@ -381,7 +381,7 @@ void Ledger::setAccepted ()
bool Ledger::hasAccount (RippleAddress const& accountID) const
{
return mAccountStateMap->hasItem (Ledger::getAccountRootIndex (accountID));
return mAccountStateMap->hasItem (getAccountRootIndex (accountID));
}
bool Ledger::addSLE (SLE const& sle)
@@ -392,13 +392,13 @@ bool Ledger::addSLE (SLE const& sle)
AccountState::pointer Ledger::getAccountState (RippleAddress const& accountID) const
{
SLE::pointer sle = getSLEi (Ledger::getAccountRootIndex (accountID));
SLE::pointer sle = getSLEi (getAccountRootIndex (accountID));
if (!sle)
{
WriteLog (lsDEBUG, Ledger) << "Ledger:getAccountState:" <<
" not found: " << accountID.humanAccountID () <<
": " << to_string (Ledger::getAccountRootIndex (accountID));
": " << to_string (getAccountRootIndex (accountID));
return AccountState::pointer ();
}
@@ -1351,7 +1351,7 @@ void Ledger::visitAccountItems (
Account const& accountID, std::function<void (SLE::ref)> func) const
{
// Visit each item in this account's owner directory
uint256 rootIndex = Ledger::getOwnerDirIndex (accountID);
uint256 rootIndex = getOwnerDirIndex (accountID);
uint256 currentIndex = rootIndex;
while (1)
@@ -1371,7 +1371,7 @@ void Ledger::visitAccountItems (
if (!uNodeNext)
return;
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
currentIndex = getDirNodeIndex (rootIndex, uNodeNext);
}
}
@@ -1384,7 +1384,7 @@ bool Ledger::visitAccountItems (
std::function <bool (SLE::ref)> func) const
{
// Visit each item in this account's owner directory
uint256 const rootIndex (Ledger::getOwnerDirIndex (accountID));
uint256 const rootIndex (getOwnerDirIndex (accountID));
uint256 currentIndex (rootIndex);
// If startAfter is not zero try jumping to that page using the hint
@@ -1431,7 +1431,7 @@ bool Ledger::visitAccountItems (
if (uNodeNext == 0)
return found;
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
currentIndex = getDirNodeIndex (rootIndex, uNodeNext);
}
}
else
@@ -1454,7 +1454,7 @@ bool Ledger::visitAccountItems (
if (uNodeNext == 0)
return true;
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
currentIndex = getDirNodeIndex (rootIndex, uNodeNext);
}
}
}
@@ -1597,88 +1597,29 @@ SLE::pointer Ledger::getGenerator (Account const& uGeneratorID) const
return getASNodeI (getGeneratorIndex (uGeneratorID), ltGENERATOR_MAP);
}
SLE::pointer Ledger::getOffer (uint256 const& uIndex) const
SLE::pointer
Ledger::getOffer (uint256 const& uIndex) const
{
return getASNodeI (uIndex, ltOFFER);
}
SLE::pointer Ledger::getRippleState (uint256 const& uNode) const
SLE::pointer
Ledger::getOffer (Account const& account, std::uint32_t uSequence) const
{
return getOffer (getOfferIndex (account, uSequence));
}
SLE::pointer
Ledger::getRippleState (uint256 const& uNode) const
{
return getASNodeI (uNode, ltRIPPLE_STATE);
}
// For an entry put in the 64 bit index or quality.
uint256 Ledger::getQualityIndex (
uint256 const& uBase, const std::uint64_t uNodeDir)
SLE::pointer
Ledger::getRippleState (
Account const& a, Account const& b, Currency const& currency) const
{
// 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);
// TODO(tom): there must be a better way.
((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir);
return uNode;
}
// Return the last 64 bits.
std::uint64_t Ledger::getQuality (uint256 const& uBase)
{
return be64toh (((std::uint64_t*) uBase.end ())[-1]);
}
uint256 Ledger::getQualityNext (uint256 const& uBase)
{
static uint256 uNext ("10000000000000000");
return uBase + uNext;
}
uint256 Ledger::getAccountRootIndex (Account const& account)
{
Serializer s (22);
s.add16 (spaceAccount); // 2
s.add160 (account); // 20
return s.getSHA512Half ();
}
uint256 Ledger::getLedgerFeeIndex ()
{
// get the index of the node that holds the fee schedul
Serializer s (2);
s.add16 (spaceFee);
return s.getSHA512Half ();
}
uint256 Ledger::getLedgerAmendmentIndex ()
{
// get the index of the node that holds the enabled amendments
Serializer s (2);
s.add16 (spaceAmendment);
return s.getSHA512Half ();
}
uint256 Ledger::getLedgerHashIndex ()
{
// get the index of the node that holds the last 256 ledgers
Serializer s (2);
s.add16 (spaceSkipList);
return s.getSHA512Half ();
}
uint256 Ledger::getLedgerHashIndex (std::uint32_t desiredLedgerIndex)
{
// Get the index of the node that holds the set of 256 ledgers that includes
// this ledger's hash (or the first ledger after it if it's not a multiple
// of 256).
Serializer s (6);
s.add16 (spaceSkipList);
s.add32 (desiredLedgerIndex >> 16);
return s.getSHA512Half ();
return getRippleState (getRippleStateIndex (a, b, currency));
}
uint256 Ledger::getLedgerHash (std::uint32_t ledgerIndex)
@@ -1786,112 +1727,6 @@ std::vector<uint256> Ledger::getLedgerAmendments () const
return usAmendments;
}
uint256 Ledger::getBookBase (Book const& book)
{
Serializer s (82);
s.add16 (spaceBookDir); // 2
s.add160 (book.in.currency); // 20
s.add160 (book.out.currency); // 20
s.add160 (book.in.account); // 20
s.add160 (book.out.account); // 20
// Return with quality 0.
uint256 uBaseIndex = getQualityIndex (s.getSHA512Half ());
WriteLog (lsTRACE, Ledger)
<< "getBookBase (" << book << ") = " << to_string (uBaseIndex);
assert (isConsistent (book));
return uBaseIndex;
}
uint256 Ledger::getDirNodeIndex (
uint256 const& uDirRoot, const std::uint64_t 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 (Account const& uGeneratorID)
{
Serializer s (22);
s.add16 (spaceGenerator); // 2
s.add160 (uGeneratorID); // 20
return s.getSHA512Half ();
}
uint256 Ledger::getOfferIndex (Account const& account, std::uint32_t uSequence)
{
Serializer s (26);
s.add16 (spaceOffer); // 2
s.add160 (account); // 20
s.add32 (uSequence); // 4
return s.getSHA512Half ();
}
uint256 Ledger::getOwnerDirIndex (Account const& account)
{
Serializer s (22);
s.add16 (spaceOwnerDir); // 2
s.add160 (account); // 20
return s.getSHA512Half ();
}
uint256 Ledger::getRippleStateIndex (
Account const& a, Account const& b, Currency const& currency)
{
Serializer s (62);
s.add16 (spaceRipple); // 2
if (a < b)
{
s.add160 (a); // 20
s.add160 (b); // 20
}
else
{
s.add160 (b); // 20
s.add160 (a); // 20
}
s.add160 (currency); // 20
return s.getSHA512Half ();
}
uint256 Ledger::getTicketIndex (
Account const& account, std::uint32_t uSequence)
{
Serializer s (26);
s.add16 (spaceTicket); // 2
s.add160 (account); // 20
s.add32 (uSequence); // 4
return s.getSHA512Half ();
}
bool Ledger::walkLedger () const
{
std::vector <SHAMapMissingNode> missingNodes1;
@@ -2108,7 +1943,7 @@ void Ledger::updateFees ()
std::int64_t reserveIncrement = getConfig ().FEE_OWNER_RESERVE;
LedgerStateParms p = lepNONE;
auto sle = getASNode (p, Ledger::getLedgerFeeIndex (), ltFEE_SETTINGS);
auto sle = getASNode (p, getLedgerFeeIndex (), ltFEE_SETTINGS);
if (sle)
{
@@ -2209,7 +2044,7 @@ class Ledger_test : public beast::unit_test::suite
"D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000");
// VFALCO NOTE This fails in the original version as well.
expect (6125895493223874560 == Ledger::getQuality (uBig));
expect (6125895493223874560 == getQuality (uBig));
}
public:
void run ()

View File

@@ -330,18 +330,10 @@ public:
uint256 getPrevLedgerIndex (uint256 const& uHash, uint256 const& uBegin) const;
// Ledger hash table function
static uint256 getLedgerHashIndex ();
static uint256 getLedgerHashIndex (std::uint32_t desiredLedgerIndex);
static int getLedgerHashOffset (std::uint32_t desiredLedgerIndex);
static int getLedgerHashOffset (
std::uint32_t desiredLedgerIndex, std::uint32_t currentLedgerIndex);
uint256 getLedgerHash (std::uint32_t ledgerIndex);
typedef std::vector<std::pair<std::uint32_t, uint256>> LedgerHashes;
LedgerHashes getLedgerHashes () const;
static uint256 getLedgerAmendmentIndex ();
static uint256 getLedgerFeeIndex ();
std::vector<uint256> getLedgerAmendments () const;
std::vector<uint256> getNeededTransactionHashes (
@@ -349,60 +341,24 @@ public:
std::vector<uint256> getNeededAccountStateHashes (
int max, SHAMapSyncFilter* filter) const;
// index calculation functions
static uint256 getAccountRootIndex (Account const&);
static uint256 getAccountRootIndex (const RippleAddress & account)
{
return getAccountRootIndex (account.getAccountID ());
}
//
// Generator Map functions
//
SLE::pointer getGenerator (Account const& uGeneratorID) const;
static uint256 getGeneratorIndex (Account const& uGeneratorID);
//
// Order book functions
//
// Order book dirs have a base so we can use next to step through them in
// quality order.
static uint256 getBookBase (Book const&);
//
// Offer functions
//
SLE::pointer getOffer (uint256 const& uIndex) const;
SLE::pointer getOffer (Account const& account, std::uint32_t uSequence) const
{
return getOffer (getOfferIndex (account, uSequence));
}
// The index of an offer.
static uint256 getOfferIndex (
Account const& account, std::uint32_t uSequence);
//
// Owner functions
//
// VFALCO NOTE This is a simple math operation that converts the account ID
// into a 256 bit object (I think....need to research this)
//
// All items controlled by an account are here: offers
static uint256 getOwnerDirIndex (Account const&account);
SLE::pointer getOffer (Account const& account, std::uint32_t uSequence) const;
//
// Directory functions
// Directories are doubly linked lists of nodes.
// Given a directory root and and index compute the index of a node.
static uint256 getDirNodeIndex (
uint256 const& uDirRoot, const std::uint64_t uNodeIndex = 0);
static void ownerDirDescriber (SLE::ref, bool, Account const& owner);
// Return a node: root or normal
@@ -412,48 +368,22 @@ public:
// Quality
//
static uint256 getQualityIndex (
uint256 const& uBase, const std::uint64_t uNodeDir = 0);
static uint256 getQualityNext (uint256 const& uBase);
static std::uint64_t getQuality (uint256 const& uBase);
static void qualityDirDescriber (
SLE::ref, bool,
Currency const& uTakerPaysCurrency, Account const& uTakerPaysIssuer,
Currency const& uTakerGetsCurrency, Account const& uTakerGetsIssuer,
const std::uint64_t & uRate);
//
// Tickets
//
static uint256 getTicketIndex (
Account const& account, std::uint32_t uSequence);
//
// Ripple functions : credit lines
//
//
// Index of node which is the ripple state between two accounts for a
// currency.
//
// VFALCO NOTE Rename these to make it clear they are simple functions that
// don't access global variables. e.g.
// "calculateKeyFromRippleStateAndAddress"
static uint256 getRippleStateIndex (
Account const& a, Account const& b, Currency const& currency);
static uint256 getRippleStateIndex (
Account const& a, Issue const& issue)
{
return getRippleStateIndex (a, issue.account, issue.currency);
}
SLE::pointer getRippleState (uint256 const& uNode) const;
SLE::pointer
getRippleState (uint256 const& uNode) const;
SLE::pointer getRippleState (
Account const& a, Account const& b, Currency const& currency) const
{
return getRippleState (getRippleStateIndex (a, b, currency));
}
SLE::pointer
getRippleState (
Account const& a, Account const& b, Currency const& currency) const;
std::uint32_t getReferenceFeeUnits ()
{

View File

@@ -384,7 +384,7 @@ bool LedgerEntrySet::threadTx (RippleAddress const& threadTo, Ledger::ref ledger
NodeToLedgerEntry& newMods)
{
SLE::pointer sle = getForMod (
Ledger::getAccountRootIndex (threadTo.getAccountID ()), ledger, newMods);
getAccountRootIndex (threadTo.getAccountID ()), ledger, newMods);
#ifdef META_DEBUG
WriteLog (lsTRACE, LedgerEntrySet) << "Thread to " << threadTo.getAccountID ();
@@ -591,7 +591,7 @@ TER LedgerEntrySet::dirCount (uint256 const& uRootIndex, std::uint32_t& uCount)
do
{
SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir));
if (sleNode)
{
@@ -617,7 +617,7 @@ bool LedgerEntrySet::dirIsEmpty (uint256 const& uRootIndex)
{
std::uint64_t uNodeDir = 0;
SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir));
if (!sleNode)
return true;
@@ -665,7 +665,7 @@ TER LedgerEntrySet::dirAdd (
if (uNodeDir)
{
// Try adding to last node.
sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir));
assert (sleNode);
}
@@ -698,7 +698,7 @@ TER LedgerEntrySet::dirAdd (
entryModify (sleRoot);
// Create the new node.
sleNode = entryCreate (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
sleNode = entryCreate (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir));
sleNode->setFieldH256 (sfRootIndex, uRootIndex);
if (uNodeDir != 1)
@@ -734,7 +734,7 @@ TER LedgerEntrySet::dirDelete (
const bool bSoft) // --> True, uNodeDir is not hard and fast (pass uNodeDir=0).
{
std::uint64_t uNodeCur = uNodeDir;
SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeCur));
SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeCur));
if (!sleNode)
{
@@ -836,7 +836,7 @@ TER LedgerEntrySet::dirDelete (
else
{
// Have only a root node and a last node.
SLE::pointer sleLast = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext));
SLE::pointer sleLast = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext));
assert (sleLast);
@@ -858,11 +858,11 @@ TER LedgerEntrySet::dirDelete (
{
// Not root and not last node. Can delete node.
SLE::pointer slePrevious = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodePrevious));
SLE::pointer slePrevious = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodePrevious));
assert (slePrevious);
SLE::pointer sleNext = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext));
SLE::pointer sleNext = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext));
assert (slePrevious);
assert (sleNext);
@@ -962,7 +962,7 @@ bool LedgerEntrySet::dirNext (
}
else
{
SLE::pointer sleNext = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext));
SLE::pointer sleNext = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext));
uDirEntry = 0;
if (!sleNext)
@@ -1046,7 +1046,7 @@ void LedgerEntrySet::incrementOwnerCount (SLE::ref sleAccount)
void LedgerEntrySet::incrementOwnerCount (Account const& owner)
{
incrementOwnerCount(entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (owner)));
getAccountRootIndex (owner)));
}
void LedgerEntrySet::decrementOwnerCount (SLE::ref sleAccount)
@@ -1070,7 +1070,7 @@ void LedgerEntrySet::decrementOwnerCount (SLE::ref sleAccount)
void LedgerEntrySet::decrementOwnerCount (Account const& owner)
{
decrementOwnerCount(entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (owner)));
getAccountRootIndex (owner)));
}
TER LedgerEntrySet::offerDelete (SLE::pointer sleOffer)
@@ -1089,7 +1089,7 @@ TER LedgerEntrySet::offerDelete (SLE::pointer sleOffer)
TER terResult = dirDelete (
false, uOwnerNode,
Ledger::getOwnerDirIndex (owner), offerIndex, false, !bOwnerNode);
getOwnerDirIndex (owner), offerIndex, false, !bOwnerNode);
TER terResult2 = dirDelete (
false, uBookNode, uDirectory, offerIndex, true, false);
@@ -1112,7 +1112,7 @@ STAmount LedgerEntrySet::rippleHolds (
{
STAmount saBalance;
SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (account, issuer, currency));
getRippleStateIndex (account, issuer, currency));
if (!sleRippleState)
{
@@ -1153,7 +1153,7 @@ STAmount LedgerEntrySet::accountHolds (
if (!currency)
{
SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (account));
getAccountRootIndex (account));
std::uint64_t uReserve = mLedger->getReserve (
sleAccount->getFieldU32 (sfOwnerCount));
@@ -1191,7 +1191,7 @@ bool LedgerEntrySet::isGlobalFrozen (Account const& issuer)
if (!enforceFreeze () || isXRP (issuer))
return false;
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer));
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer));
if (sle && sle->isFlag (lsfGlobalFreeze))
return true;
@@ -1208,7 +1208,7 @@ bool LedgerEntrySet::isFrozen(
if (!enforceFreeze () || isXRP (currency))
return false;
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer));
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer));
if (sle && sle->isFlag (lsfGlobalFreeze))
return true;
@@ -1216,7 +1216,7 @@ bool LedgerEntrySet::isFrozen(
{
// Check if the issuer froze the line
sle = entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (account, issuer, currency));
getRippleStateIndex (account, issuer, currency));
if (sle && sle->isFlag ((issuer > account) ? lsfHighFreeze : lsfLowFreeze))
{
return true;
@@ -1320,7 +1320,7 @@ TER LedgerEntrySet::trustCreate (
TER terResult = dirAdd (
uLowNode,
Ledger::getOwnerDirIndex (uLowAccountID),
getOwnerDirIndex (uLowAccountID),
sleRippleState->getIndex (),
std::bind (&Ledger::ownerDirDescriber,
std::placeholders::_1, std::placeholders::_2,
@@ -1330,7 +1330,7 @@ TER LedgerEntrySet::trustCreate (
{
terResult = dirAdd (
uHighNode,
Ledger::getOwnerDirIndex (uHighAccountID),
getOwnerDirIndex (uHighAccountID),
sleRippleState->getIndex (),
std::bind (&Ledger::ownerDirDescriber,
std::placeholders::_1, std::placeholders::_2,
@@ -1402,7 +1402,7 @@ TER LedgerEntrySet::trustDelete (
terResult = dirDelete (
false,
uLowNode,
Ledger::getOwnerDirIndex (uLowAccountID),
getOwnerDirIndex (uLowAccountID),
sleRippleState->getIndex (),
false,
!bLowNode);
@@ -1414,7 +1414,7 @@ TER LedgerEntrySet::trustDelete (
terResult = dirDelete (
false,
uHighNode,
Ledger::getOwnerDirIndex (uHighAccountID),
getOwnerDirIndex (uHighAccountID),
sleRippleState->getIndex (),
false,
!bHighNode);
@@ -1446,7 +1446,7 @@ TER LedgerEntrySet::rippleCredit (
assert (uSenderID != uReceiverID);
bool bSenderHigh = uSenderID > uReceiverID;
uint256 uIndex = Ledger::getRippleStateIndex (
uint256 uIndex = getRippleStateIndex (
uSenderID, uReceiverID, saAmount.getCurrency ());
auto sleRippleState = entryCache (ltRIPPLE_STATE, uIndex);
@@ -1472,7 +1472,7 @@ TER LedgerEntrySet::rippleCredit (
uSenderID,
uReceiverID,
uIndex,
entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)),
entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uReceiverID)),
false,
false,
false,
@@ -1636,10 +1636,10 @@ TER LedgerEntrySet::accountSend (
TER terResult (tesSUCCESS);
SLE::pointer sender = uSenderID != beast::zero
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID))
? entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uSenderID))
: SLE::pointer ();
SLE::pointer receiver = uReceiverID != beast::zero
? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID))
? entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uReceiverID))
: SLE::pointer ();
if (ShouldLog (lsTRACE, LedgerEntrySet))
@@ -1708,7 +1708,7 @@ std::uint32_t
rippleTransferRate (LedgerEntrySet& ledger, Account const& issuer)
{
SLE::pointer sleAccount (ledger.entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer)));
ltACCOUNT_ROOT, getAccountRootIndex (issuer)));
std::uint32_t quality = QUALITY_ONE;

View File

@@ -78,7 +78,7 @@ static void updateHelper (SLE::ref entry,
book.out.account.copyFrom (entry->getFieldH160 (sfTakerGetsIssuer));
book.out.currency.copyFrom (entry->getFieldH160 (sfTakerGetsCurrency));
uint256 index = Ledger::getBookBase (book);
uint256 index = getBookBase (book);
if (seen.insert (index).second)
{
auto orderBook = std::make_shared<OrderBook> (index, book);
@@ -156,7 +156,7 @@ void OrderBookDB::addOrderBook(Book const& book)
}
}
}
uint256 index = Ledger::getBookBase(book);
uint256 index = getBookBase(book);
auto orderBook = std::make_shared<OrderBook> (index, book);
mSourceMap[book.in].push_back (orderBook);

View File

@@ -24,9 +24,9 @@ BookDirIterator::BookDirIterator(
Currency const& currencyIn, Account const& issuerIn,
Currency const& currencyOut, Account const& issuerOut)
{
mBase = Ledger::getBookBase({{currencyIn, issuerIn},
mBase = ripple::getBookBase({{currencyIn, issuerIn},
{currencyOut, issuerOut}});
mEnd = Ledger::getQualityNext(mBase);
mEnd = getQualityNext(mBase);
mIndex = mBase;
}
@@ -94,7 +94,7 @@ DirectoryEntryIterator BookDirIterator::getOfferIterator () const
std::uint64_t BookDirIterator::getRate () const
{
return Ledger::getQuality(mIndex);
return getQuality(mIndex);
}
bool BookDirIterator::addJson (Json::Value& jv) const

View File

@@ -67,7 +67,7 @@ public:
*/
std::uint64_t getCurrentQuality () const
{
return Ledger::getQuality(mIndex);
return getQuality(mIndex);
}
/** Make this iterator refer to the next book

View File

@@ -31,7 +31,7 @@ AccountState::AccountState (RippleAddress const& naAccountID)
mValid = true;
mLedgerEntry = std::make_shared <SerializedLedgerEntry> (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (naAccountID));
ltACCOUNT_ROOT, getAccountRootIndex (naAccountID));
mLedgerEntry->setFieldAccount (sfAccount, naAccountID.getAccountID ());
}

View File

@@ -1143,7 +1143,7 @@ Json::Value NetworkOPsImp::getOwnerInfo (
Ledger::pointer lpLedger, RippleAddress const& naAccount)
{
Json::Value jvObjects (Json::objectValue);
auto uRootIndex = lpLedger->getOwnerDirIndex (naAccount.getAccountID ());
auto uRootIndex = getOwnerDirIndex (naAccount.getAccountID ());
auto sleNode = lpLedger->getDirNode (uRootIndex);
if (sleNode)
@@ -1189,7 +1189,7 @@ Json::Value NetworkOPsImp::getOwnerInfo (
if (uNodeDir)
{
sleNode = lpLedger->getDirNode (
Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
getDirNodeIndex (uRootIndex, uNodeDir));
assert (sleNode);
}
}
@@ -2986,8 +2986,8 @@ void NetworkOPsImp::getBookPage (
(jvResult[jss::offers] = Json::Value (Json::arrayValue));
std::map<Account, STAmount> umBalance;
const uint256 uBookBase = Ledger::getBookBase (book);
const uint256 uBookEnd = Ledger::getQualityNext (uBookBase);
const uint256 uBookBase = getBookBase (book);
const uint256 uBookEnd = getQualityNext (uBookBase);
uint256 uTipIndex = uBookBase;
if (m_journal.trace)
@@ -3036,7 +3036,7 @@ void NetworkOPsImp::getBookPage (
else
{
uTipIndex = sleOfferDir->getIndex ();
saDirRate = amountFromQuality (Ledger::getQuality (uTipIndex));
saDirRate = amountFromQuality (getQuality (uTipIndex));
lesActive.dirFirst (
uTipIndex, sleOfferDir, uBookEntry, offerIndex);

View File

@@ -189,7 +189,7 @@ std::vector<uint256> SerializedLedgerEntry::getOwners ()
auto entry = dynamic_cast<const STAccount*> (peekAtPIndex (i));
if ((entry != nullptr) && entry->getValueH160 (account))
owners.push_back (Ledger::getAccountRootIndex (account));
owners.push_back (getAccountRootIndex (account));
}
if ((fc == sfLowLimit) || (fc == sfHighLimit))
@@ -201,7 +201,7 @@ std::vector<uint256> SerializedLedgerEntry::getOwners ()
auto issuer = entry->getIssuer ();
if (issuer.isNonZero ())
owners.push_back (Ledger::getAccountRootIndex (issuer));
owners.push_back (getAccountRootIndex (issuer));
}
}
}

View File

@@ -30,13 +30,12 @@ STAmount creditLimit (
STAmount result ({currency, account});
auto sleRippleState = ledger.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (account, issuer, currency));
getRippleStateIndex (account, issuer, currency));
if (sleRippleState)
{
result = sleRippleState->getFieldAmount (
account < issuer ? sfLowLimit : sfHighLimit);
result.setIssuer (account);
}
@@ -54,14 +53,13 @@ STAmount creditBalance (
STAmount result ({currency, account});
auto sleRippleState = ledger.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (account, issuer, currency));
getRippleStateIndex (account, issuer, currency));
if (sleRippleState)
{
result = sleRippleState->getFieldAmount (sfBalance);
if (account < issuer)
result.negate ();
result.setIssuer (account);
}

View File

@@ -52,8 +52,8 @@ class NodeDirectory {
if (current != zero)
return false;
current.copyFrom (Ledger::getBookBase (book));
next.copyFrom (Ledger::getQualityNext (current));
current.copyFrom (getBookBase (book));
next.copyFrom (getQualityNext (current));
// TODO(tom): it seems impossible that any actual offers with
// quality == 0 could occur - we should disallow them, and clear

View File

@@ -263,7 +263,7 @@ TER PathState::pushNode (
{
auto sleRippleState = lesEntries.entryCache (
ltRIPPLE_STATE,
Ledger::getRippleStateIndex (
getRippleStateIndex (
backNode.account_,
node.account_,
backNode.issue_.currency));
@@ -290,7 +290,7 @@ TER PathState::pushNode (
auto sleBck = lesEntries.entryCache (
ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (backNode.account_));
getAccountRootIndex (backNode.account_));
// Is the source account the highest numbered account ID?
bool bHigh = backNode.account_ > node.account_;
@@ -623,7 +623,7 @@ void PathState::checkFreeze()
if (nodes_[i].uFlags & STPathElement::typeIssuer)
{
sle = lesEntries.entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (nodes_[i].issue_.account));
getAccountRootIndex (nodes_[i].issue_.account));
if (sle && sle->isFlag (lsfGlobalFreeze))
{
@@ -642,7 +642,7 @@ void PathState::checkFreeze()
if (inAccount != outAccount)
{
sle = lesEntries.entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (outAccount));
getAccountRootIndex (outAccount));
if (sle && sle->isFlag (lsfGlobalFreeze))
{
@@ -651,7 +651,7 @@ void PathState::checkFreeze()
}
sle = lesEntries.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (inAccount,
getRippleStateIndex (inAccount,
outAccount, currencyID));
if (sle && sle->isFlag (
@@ -679,9 +679,9 @@ TER PathState::checkNoRipple (
{
// fetch the ripple lines into and out of this node
SLE::pointer sleIn = lesEntries.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (firstAccount, secondAccount, currency));
getRippleStateIndex (firstAccount, secondAccount, currency));
SLE::pointer sleOut = lesEntries.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (secondAccount, thirdAccount, currency));
getRippleStateIndex (secondAccount, thirdAccount, currency));
if (!sleIn || !sleOut)
{

View File

@@ -248,14 +248,14 @@ bool Pathfinder::findPaths (int searchLevel)
bool bSrcXrp = isXRP (mSrcCurrency);
bool bDstXrp = isXRP (mDstAmount.getCurrency());
if (!mLedger->getSLEi (Ledger::getAccountRootIndex (mSrcAccount)))
if (!mLedger->getSLEi (getAccountRootIndex (mSrcAccount)))
{
// We can't even start without a source account.
WriteLog (lsDEBUG, Pathfinder) << "invalid source account";
return false;
}
if (!mLedger->getSLEi (Ledger::getAccountRootIndex (mDstAccount)))
if (!mLedger->getSLEi (getAccountRootIndex (mDstAccount)))
{
// Can't find the destination account - we must be funding a new
// account.
@@ -637,8 +637,7 @@ int Pathfinder::getPathsOut (
if (!it.second)
return it.first->second;
auto sleAccount
= mLedger->getSLEi (Ledger::getAccountRootIndex (account));
auto sleAccount = mLedger->getSLEi (getAccountRootIndex (account));
if (!sleAccount)
return 0;
@@ -775,8 +774,8 @@ bool Pathfinder::isNoRipple (
Account const& toAccount,
Currency const& currency)
{
SLE::pointer sleRipple = mLedger->getSLEi (
Ledger::getRippleStateIndex (toAccount, fromAccount, currency));
auto sleRipple = mLedger->getSLEi (
getRippleStateIndex (toAccount, fromAccount, currency));
auto const flag ((toAccount > fromAccount)
? lsfHighNoRipple : lsfLowNoRipple);
@@ -849,8 +848,8 @@ void Pathfinder::addLink (
else
{
// search for accounts to add
auto sleEnd = mLedger->getSLEi(
Ledger::getAccountRootIndex (uEndAccount));
auto sleEnd = mLedger->getSLEi(getAccountRootIndex (uEndAccount));
if (sleEnd)
{
bool const bRequireAuth (

View File

@@ -104,7 +104,7 @@ TER PathCursor::advanceNode (bool const bReverse) const
// Our quality changed since last iteration.
// Use the rate from the directory.
node().saOfrRate = amountFromQuality (
Ledger::getQuality (node().directory.current));
getQuality (node().directory.current));
// For correct ratio
node().uEntry = 0;
node().bEntryAdvance = true;

View File

@@ -212,7 +212,7 @@ rippleQuality (
if (destination != source)
{
SLE::pointer sleRippleState (ledger.entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (destination, source, currency)));
getRippleStateIndex (destination, source, currency)));
// we should be able to assert(sleRippleState) here

View File

@@ -67,7 +67,7 @@ public:
}
SLE::pointer sleDst (mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID)));
ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID)));
if (sleDst)
{
@@ -105,7 +105,7 @@ public:
// Create the account.
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (uDstAccountID));
getAccountRootIndex (uDstAccountID));
sleDst->setFieldAccount (sfAccount, uDstAccountID);
sleDst->setFieldU32 (sfSequence, 1);

View File

@@ -62,11 +62,9 @@ public:
return temBAD_SEQUENCE;
}
uint256 const offerIndex (
Ledger::getOfferIndex (mTxnAccountID, uOfferSequence));
uint256 const offerIndex (getOfferIndex (mTxnAccountID, uOfferSequence));
SLE::pointer sleOffer (
mEngine->entryCache (ltOFFER, offerIndex));
SLE::pointer sleOffer (mEngine->entryCache (ltOFFER, offerIndex));
if (sleOffer)
{

View File

@@ -70,7 +70,7 @@ public:
std::uint64_t const hint (sleTicket->getFieldU64 (sfOwnerNode));
TER const result = mEngine->view ().dirDelete (false, hint,
Ledger::getOwnerDirIndex (ticket_owner), ticketId, false, (hint == 0));
getOwnerDirIndex (ticket_owner), ticketId, false, (hint == 0));
mEngine->view ().decrementOwnerCount (mTxnAccount);
mEngine->view ().entryDelete (sleTicket);

View File

@@ -112,14 +112,12 @@ private:
{
uint256 amendment (mTxn.getFieldH256 (sfAmendment));
SLE::pointer amendmentObject (mEngine->entryCache (
ltAMENDMENTS, Ledger::getLedgerAmendmentIndex ()));
auto const index = getLedgerAmendmentIndex ();
SLE::pointer amendmentObject (mEngine->entryCache (ltAMENDMENTS, index));
if (!amendmentObject)
{
amendmentObject = mEngine->entryCreate(
ltAMENDMENTS, Ledger::getLedgerAmendmentIndex());
}
amendmentObject = mEngine->entryCreate(ltAMENDMENTS, index);
STVector256 amendments (amendmentObject->getFieldV256 (sfAmendments));
@@ -143,12 +141,12 @@ private:
TER applyFee ()
{
SLE::pointer feeObject = mEngine->entryCache (
ltFEE_SETTINGS, Ledger::getLedgerFeeIndex ());
auto const index = getLedgerFeeIndex ();
SLE::pointer feeObject = mEngine->entryCache (ltFEE_SETTINGS, index);
if (!feeObject)
feeObject = mEngine->entryCreate (
ltFEE_SETTINGS, Ledger::getLedgerFeeIndex ());
feeObject = mEngine->entryCreate (ltFEE_SETTINGS, index);
m_journal.trace <<
"Previous fee object: " << feeObject->getJson (0);

View File

@@ -43,7 +43,7 @@ private:
assert (!isXRP (issue.currency));
SLE::pointer const issuerAccount = mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issue.account));
ltACCOUNT_ROOT, getAccountRootIndex (issue.account));
if (!issuerAccount)
{
@@ -59,7 +59,7 @@ private:
if (issuerAccount->getFieldU32 (sfFlags) & lsfRequireAuth)
{
SLE::pointer const trustLine (mEngine->entryCache (
ltRIPPLE_STATE, Ledger::getRippleStateIndex (
ltRIPPLE_STATE, getRippleStateIndex (
mTxnAccountID, issue.account, issue.currency)));
if (!trustLine)
@@ -179,7 +179,7 @@ public:
std::uint32_t const uAccountSequenceNext = mTxnAccount->getFieldU32 (sfSequence);
std::uint32_t const uSequence = mTxn.getSequence ();
const uint256 uLedgerIndex = Ledger::getOfferIndex (mTxnAccountID, uSequence);
const uint256 uLedgerIndex = getOfferIndex (mTxnAccountID, uSequence);
if (m_journal.debug)
{
@@ -211,7 +211,7 @@ public:
view.bumpSeq (); // Begin ledger variance.
SLE::pointer sleCreator = mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (mTxnAccountID));
ltACCOUNT_ROOT, getAccountRootIndex (mTxnAccountID));
if (uTxFlags & tfOfferCreateMask)
{
@@ -309,7 +309,7 @@ public:
if ((terResult == tesSUCCESS) && bHaveCancel)
{
uint256 const uCancelIndex (
Ledger::getOfferIndex (mTxnAccountID, uCancelSequence));
getOfferIndex (mTxnAccountID, uCancelSequence));
SLE::pointer sleCancel = mEngine->entryCache (ltOFFER, uCancelIndex);
// It's not an error to not find the offer to cancel: it might have
@@ -485,7 +485,7 @@ public:
// Add offer to owner's directory.
terResult = view.dirAdd (uOwnerNode,
Ledger::getOwnerDirIndex (mTxnAccountID), uLedgerIndex,
getOwnerDirIndex (mTxnAccountID), uLedgerIndex,
std::bind (
&Ledger::ownerDirDescriber, std::placeholders::_1,
std::placeholders::_2, mTxnAccountID));
@@ -495,7 +495,7 @@ public:
// Update owner count.
view.incrementOwnerCount (sleCreator);
uint256 const uBookBase (Ledger::getBookBase (
uint256 const uBookBase (getBookBase (
{{uPaysCurrency, uPaysIssuerID},
{uGetsCurrency, uGetsIssuerID}}));
@@ -507,7 +507,7 @@ public:
"/" << to_string (saTakerGets.getIssuer ());
// We use the original rate to place the offer.
uDirectory = Ledger::getQualityIndex (uBookBase, uRate);
uDirectory = getQualityIndex (uBookBase, uRate);
// Add offer to order book.
terResult = view.dirAdd (uBookNode, uDirectory, uLedgerIndex,

View File

@@ -68,7 +68,7 @@ public:
}
SLE::pointer sleTicket = mEngine->entryCreate (ltTICKET,
Ledger::getTicketIndex (mTxnAccountID, mTxn.getSequence ()));
getTicketIndex (mTxnAccountID, mTxn.getSequence ()));
sleTicket->setFieldAccount (sfAccount, mTxnAccountID);
sleTicket->setFieldU32 (sfSequence, mTxn.getSequence ());
@@ -81,7 +81,7 @@ public:
Account const target_account (mTxn.getFieldAccount160 (sfTarget));
SLE::pointer sleTarget = mEngine->entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (target_account));
getAccountRootIndex (target_account));
// Destination account does not exist.
if (!sleTarget)
@@ -101,7 +101,7 @@ public:
};
TER result = mEngine->view ().dirAdd (
hint,
Ledger::getOwnerDirIndex (mTxnAccountID),
getOwnerDirIndex (mTxnAccountID),
sleTicket->getIndex (),
describer);

View File

@@ -178,7 +178,7 @@ public:
//
// Open a ledger for editing.
auto const index = Ledger::getAccountRootIndex (uDstAccountID);
auto const index = getAccountRootIndex (uDstAccountID);
SLE::pointer sleDst (mEngine->entryCache (ltACCOUNT_ROOT, index));
if (!sleDst)
@@ -220,7 +220,7 @@ public:
}
// Create the account.
auto const newIndex = Ledger::getAccountRootIndex (uDstAccountID);
auto const newIndex = getAccountRootIndex (uDstAccountID);
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT, newIndex);
sleDst->setFieldAccount (sfAccount, uDstAccountID);
sleDst->setFieldU32 (sfSequence, 1);

View File

@@ -83,7 +83,7 @@ public:
if (bSetRequireAuth && !(uFlagsIn & lsfRequireAuth))
{
if (!mEngine->view().dirIsEmpty (Ledger::getOwnerDirIndex (mTxnAccountID)))
if (!mEngine->view().dirIsEmpty (getOwnerDirIndex (mTxnAccountID)))
{
m_journal.trace << "Retry: Owner directory not empty.";

View File

@@ -126,7 +126,7 @@ public:
{
SLE::pointer selDelete (
mEngine->entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (
getRippleStateIndex (
mTxnAccountID, uDstAccountID, currency)));
if (selDelete)
@@ -146,7 +146,7 @@ public:
}
SLE::pointer sleDst (mEngine->entryCache (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID)));
ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID)));
if (!sleDst)
{
@@ -159,7 +159,7 @@ public:
saLimitAllow.setIssuer (mTxnAccountID);
SLE::pointer sleRippleState (mEngine->entryCache (ltRIPPLE_STATE,
Ledger::getRippleStateIndex (mTxnAccountID, uDstAccountID, currency)));
getRippleStateIndex (mTxnAccountID, uDstAccountID, currency)));
if (sleRippleState)
{
@@ -392,7 +392,7 @@ public:
// Zero balance in currency.
STAmount saBalance ({currency, noAccount()});
uint256 index (Ledger::getRippleStateIndex (
uint256 index (getRippleStateIndex (
mTxnAccountID, uDstAccountID, currency));
m_journal.trace <<

View File

@@ -272,7 +272,7 @@ TER Transactor::apply ()
return (terResult);
mTxnAccount = mEngine->entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (mTxnAccountID));
getAccountRootIndex (mTxnAccountID));
calculateFee ();
// Find source account

View File

@@ -139,7 +139,7 @@ TER TransactionEngine::applyTransaction (
mNodes.clear ();
SLE::pointer txnAcct = entryCache (ltACCOUNT_ROOT,
Ledger::getAccountRootIndex (txn.getSourceAccount ()));
getAccountRootIndex (txn.getSourceAccount ()));
if (!txnAcct)
terResult = terNO_ACCOUNT;

View File

@@ -0,0 +1,92 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_PROTOCOL_INDEXES_H_INCLUDED
#define RIPPLE_PROTOCOL_INDEXES_H_INCLUDED
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/types/base_uint.h>
#include <ripple/types/Book.h>
#include <ripple/types/UintTypes.h>
namespace ripple {
// get the index of the node that holds the last 256 ledgers
uint256
getLedgerHashIndex ();
// Get the index of the node that holds the set of 256 ledgers that includes
// this ledger's hash (or the first ledger after it if it's not a multiple
// of 256).
uint256
getLedgerHashIndex (std::uint32_t desiredLedgerIndex);
// get the index of the node that holds the enabled amendments
uint256
getLedgerAmendmentIndex ();
// get the index of the node that holds the fee schedule
uint256
getLedgerFeeIndex ();
uint256
getAccountRootIndex (Account const& account);
uint256
getAccountRootIndex (const RippleAddress & account);
uint256
getGeneratorIndex (Account const& uGeneratorID);
uint256
getBookBase (Book const& book);
uint256
getOfferIndex (Account const& account, std::uint32_t uSequence);
uint256
getOwnerDirIndex (Account const& account);
uint256
getDirNodeIndex (uint256 const& uDirRoot, const std::uint64_t uNodeIndex);
uint256
getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir = 0);
uint256
getQualityNext (uint256 const& uBase);
std::uint64_t
getQuality (uint256 const& uBase);
uint256
getTicketIndex (Account const& account, std::uint32_t uSequence);
uint256
getRippleStateIndex (Account const& a, Account const& b, Currency const& currency);
uint256
getRippleStateIndex (Account const& a, Issue const& issue);
}
#endif

View File

@@ -0,0 +1,228 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/RippleAddress.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/types/base_uint.h>
#include <ripple/types/Book.h>
#include <ripple/types/UintTypes.h>
namespace ripple {
// get the index of the node that holds the last 256 ledgers
uint256
getLedgerHashIndex ()
{
Serializer s (2);
s.add16 (spaceSkipList);
return s.getSHA512Half ();
}
// Get the index of the node that holds the set of 256 ledgers that includes
// this ledger's hash (or the first ledger after it if it's not a multiple
// of 256).
uint256
getLedgerHashIndex (std::uint32_t desiredLedgerIndex)
{
Serializer s (6);
s.add16 (spaceSkipList);
s.add32 (desiredLedgerIndex >> 16);
return s.getSHA512Half ();
}
// get the index of the node that holds the enabled amendments
uint256
getLedgerAmendmentIndex ()
{
Serializer s (2);
s.add16 (spaceAmendment);
return s.getSHA512Half ();
}
// get the index of the node that holds the fee schedule
uint256
getLedgerFeeIndex ()
{
Serializer s (2);
s.add16 (spaceFee);
return s.getSHA512Half ();
}
uint256
getAccountRootIndex (Account const& account)
{
Serializer s (22);
s.add16 (spaceAccount);
s.add160 (account);
return s.getSHA512Half ();
}
uint256
getAccountRootIndex (const RippleAddress & account)
{
return getAccountRootIndex (account.getAccountID ());
}
uint256
getGeneratorIndex (Account const& uGeneratorID)
{
Serializer s (22);
s.add16 (spaceGenerator);
s.add160 (uGeneratorID);
return s.getSHA512Half ();
}
uint256
getBookBase (Book const& book)
{
Serializer s (82);
assert (isConsistent (book));
s.add16 (spaceBookDir);
s.add160 (book.in.currency);
s.add160 (book.out.currency);
s.add160 (book.in.account);
s.add160 (book.out.account);
// Return with quality 0.
return getQualityIndex (s.getSHA512Half ());
}
uint256
getOfferIndex (Account const& account, std::uint32_t uSequence)
{
Serializer s (26);
s.add16 (spaceOffer);
s.add160 (account);
s.add32 (uSequence);
return s.getSHA512Half ();
}
uint256
getOwnerDirIndex (Account const& account)
{
Serializer s (22);
s.add16 (spaceOwnerDir);
s.add160 (account);
return s.getSHA512Half ();
}
uint256
getDirNodeIndex (uint256 const& uDirRoot, const std::uint64_t uNodeIndex)
{
if (uNodeIndex)
{
Serializer s (42);
s.add16 (spaceDirNode);
s.add256 (uDirRoot);
s.add64 (uNodeIndex);
return s.getSHA512Half ();
}
else
{
return uDirRoot;
}
}
uint256
getQualityIndex (uint256 const& uBase, const std::uint64_t 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);
// TODO(tom): there must be a better way.
((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir);
return uNode;
}
uint256
getQualityNext (uint256 const& uBase)
{
static uint256 uNext ("10000000000000000");
return uBase + uNext;
}
std::uint64_t
getQuality (uint256 const& uBase)
{
return be64toh (((std::uint64_t*) uBase.end ())[-1]);
}
uint256
getTicketIndex (Account const& account, std::uint32_t uSequence)
{
Serializer s (26);
s.add16 (spaceTicket);
s.add160 (account);
s.add32 (uSequence);
return s.getSHA512Half ();
}
uint256
getRippleStateIndex (Account const& a, Account const& b, Currency const& currency)
{
Serializer s (62);
s.add16 (spaceRipple);
if (a < b)
{
s.add160 (a);
s.add160 (b);
}
else
{
s.add160 (b);
s.add160 (a);
}
s.add160 (currency);
return s.getSHA512Half ();
}
uint256
getRippleStateIndex (Account const& a, Issue const& issue)
{
return getRippleStateIndex (a, issue.account, issue.currency);
}
}

View File

@@ -56,7 +56,7 @@ Json::Value doLedgerEntry (RPC::Context& context)
else
{
uNodeIndex
= Ledger::getAccountRootIndex (naAccount.getAccountID ());
= getAccountRootIndex (naAccount.getAccountID ());
}
}
else if (context.params.isMember ("directory"))
@@ -82,7 +82,7 @@ Json::Value doLedgerEntry (RPC::Context& context)
uDirRoot.SetHex (context.params["dir_root"].asString ());
uNodeIndex = Ledger::getDirNodeIndex (uDirRoot, uSubIndex);
uNodeIndex = getDirNodeIndex (uDirRoot, uSubIndex);
}
else if (context.params["directory"].isMember ("owner"))
{
@@ -96,9 +96,9 @@ Json::Value doLedgerEntry (RPC::Context& context)
else
{
uint256 uDirRoot
= Ledger::getOwnerDirIndex (
= getOwnerDirIndex (
naOwnerID.getAccountID ());
uNodeIndex = Ledger::getDirNodeIndex (uDirRoot, uSubIndex);
uNodeIndex = getDirNodeIndex (uDirRoot, uSubIndex);
}
}
else
@@ -132,7 +132,7 @@ Json::Value doLedgerEntry (RPC::Context& context)
na0Public.setAccountPublic (naGenerator, 0);
uNodeIndex = Ledger::getGeneratorIndex (na0Public.getAccountID ());
uNodeIndex = getGeneratorIndex (na0Public.getAccountID ());
}
}
else if (context.params.isMember ("offer"))
@@ -156,9 +156,8 @@ Json::Value doLedgerEntry (RPC::Context& context)
}
else
{
auto uSequence = context.params["offer"]["seq"].asUInt ();
uNodeIndex = Ledger::getOfferIndex (
naAccountID.getAccountID (), uSequence);
uNodeIndex = getOfferIndex (naAccountID.getAccountID (),
context.params["offer"]["seq"].asUInt ());
}
}
else if (context.params.isMember ("ripple_state"))
@@ -195,7 +194,7 @@ Json::Value doLedgerEntry (RPC::Context& context)
}
else
{
uNodeIndex = Ledger::getRippleStateIndex (
uNodeIndex = getRippleStateIndex (
naA.getAccountID (), naB.getAccountID (), uCurrency);
}
}

View File

@@ -290,7 +290,7 @@ transactionSign (
if (verify)
{
SLE::pointer sleAccountRoot = netOps.getSLEi (lSnapshot,
Ledger::getAccountRootIndex (raSrcAddressID.getAccountID ()));
getAccountRootIndex (raSrcAddressID.getAccountID ()));
if (!sleAccountRoot)
// XXX Ignore transactions for accounts not created.

View File

@@ -56,6 +56,8 @@
#include <ripple/basics/KeyCache.h>
#include <ripple/basics/TaggedCache.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/app/data/Database.h>
#include <ripple/app/data/DatabaseCon.h>
#include <ripple/app/data/SqliteDatabase.h>
@@ -113,7 +115,7 @@
#include <ripple/app/paths/PathRequest.h>
#include <ripple/app/paths/PathRequests.h>
#include <ripple/app/main/ParameterTable.h>
#include <ripple/app/paths/PathState.h>
#include <ripple/app/paths/RippleCalc.h>
#include <ripple/app/paths/PathState.h>
#include <ripple/app/paths/RippleCalc.h>
#endif

View File

@@ -26,6 +26,7 @@
#include <ripple/protocol/impl/BuildInfo.cpp>
#include <ripple/protocol/impl/SField.cpp>
#include <ripple/protocol/impl/HashPrefix.cpp>
#include <ripple/protocol/impl/Indexes.cpp>
#include <ripple/protocol/impl/LedgerFormats.cpp>
#include <ripple/protocol/impl/RippleAddress.cpp>
#include <ripple/protocol/impl/STInteger.cpp>