mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 03:55:53 +00:00
Make directory nodes self-descriptive.
Callers pass in a "describer" function that stamps new directory entries.
This commit is contained in:
@@ -1180,4 +1180,22 @@ void Ledger::decPendingSaves()
|
||||
--sPendingSaves;
|
||||
}
|
||||
|
||||
void Ledger::ownerDirDescriber(SLE::ref sle, const uint160& owner)
|
||||
{
|
||||
sle->setFieldH160(sfOwner, owner);
|
||||
}
|
||||
|
||||
void Ledger::qualityDirDescriber(SLE::ref sle,
|
||||
const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer,
|
||||
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer,
|
||||
const uint64& uRate)
|
||||
{
|
||||
sle->setFieldH160(sfTakerPaysCurrency, uTakerPaysCurrency);
|
||||
sle->setFieldH160(sfTakerPaysIssuer, uTakerPaysIssuer);
|
||||
sle->setFieldH160(sfTakerGetsCurrency, uTakerGetsCurrency);
|
||||
sle->setFieldH160(sfTakerGetsIssuer, uTakerGetsIssuer);
|
||||
sle->setFieldU64(sfExchangeRate, uRate);
|
||||
}
|
||||
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -263,6 +263,7 @@ public:
|
||||
|
||||
// Given a directory root and and index compute the index of a node.
|
||||
static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex = 0);
|
||||
static void ownerDirDescriber(SLE::ref, const uint160& owner);
|
||||
|
||||
// Return a node: root or normal
|
||||
SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex);
|
||||
@@ -274,6 +275,10 @@ public:
|
||||
static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir = 0);
|
||||
static uint256 getQualityNext(const uint256& uBase);
|
||||
static uint64 getQuality(const uint256& uBase);
|
||||
static void qualityDirDescriber(SLE::ref,
|
||||
const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer,
|
||||
const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer,
|
||||
const uint64& uRate);
|
||||
|
||||
//
|
||||
// Ripple functions : credit lines
|
||||
|
||||
@@ -494,7 +494,8 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result, uint32 index)
|
||||
TER LedgerEntrySet::dirAdd(
|
||||
uint64& uNodeDir,
|
||||
const uint256& uRootIndex,
|
||||
const uint256& uLedgerIndex)
|
||||
const uint256& uLedgerIndex,
|
||||
boost::function<void (SLE::ref)> fDescriber)
|
||||
{
|
||||
SLE::pointer sleNode;
|
||||
STVector256 svIndexes;
|
||||
@@ -505,6 +506,7 @@ TER LedgerEntrySet::dirAdd(
|
||||
// No root, make it.
|
||||
sleRoot = entryCreate(ltDIR_NODE, uRootIndex);
|
||||
sleRoot->setFieldH256(sfRootIndex, uRootIndex);
|
||||
fDescriber(sleRoot);
|
||||
|
||||
sleNode = sleRoot;
|
||||
uNodeDir = 0;
|
||||
@@ -566,6 +568,8 @@ TER LedgerEntrySet::dirAdd(
|
||||
// Create the new node.
|
||||
sleNode = entryCreate(ltDIR_NODE, Ledger::getDirNodeIndex(uRootIndex, uNodeDir));
|
||||
sleNode->setFieldH256(sfRootIndex, uRootIndex);
|
||||
fDescriber(sleNode);
|
||||
|
||||
svIndexes = STVector256();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define __LEDGERENTRYSET__
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include "SerializedLedger.h"
|
||||
#include "TransactionMeta.h"
|
||||
@@ -88,7 +89,8 @@ public:
|
||||
TER dirAdd(
|
||||
uint64& uNodeDir, // Node of entry.
|
||||
const uint256& uRootIndex,
|
||||
const uint256& uLedgerIndex);
|
||||
const uint256& uLedgerIndex,
|
||||
boost::function<void (SLE::ref)> fDescriber);
|
||||
|
||||
TER dirDelete(
|
||||
const bool bKeepRoot,
|
||||
|
||||
@@ -51,7 +51,7 @@ static bool LEFInit()
|
||||
<< SOElement(sfTakerPaysIssuer, SOE_OPTIONAL) // for order book directories
|
||||
<< SOElement(sfTakerGetsCurrency, SOE_OPTIONAL) // for order book directories
|
||||
<< SOElement(sfTakerGetsIssuer, SOE_OPTIONAL) // for order book directories
|
||||
<< SOElement(sfExhangeRate, SOE_OPTIONAL) // for order book directories
|
||||
<< SOElement(sfExchangeRate, SOE_OPTIONAL) // for order book directories
|
||||
<< SOElement(sfIndexes, SOE_REQUIRED)
|
||||
<< SOElement(sfRootIndex, SOE_REQUIRED)
|
||||
<< SOElement(sfIndexNext, SOE_OPTIONAL)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "OfferCreateTransactor.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
// Take as much as possible. Adjusts account balances. Charges fees on top to taker.
|
||||
// --> uBookBase: The order book to take against.
|
||||
@@ -387,7 +389,9 @@ TER OfferCreateTransactor::doApply()
|
||||
% saTakerGets.getFullText());
|
||||
|
||||
// Add offer to owner's directory.
|
||||
terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex);
|
||||
terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex,
|
||||
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
{
|
||||
@@ -403,7 +407,9 @@ TER OfferCreateTransactor::doApply()
|
||||
uDirectory = Ledger::getQualityIndex(uBookBase, uRate); // Use original rate.
|
||||
|
||||
// Add offer to order book.
|
||||
terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex);
|
||||
terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex,
|
||||
boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID,
|
||||
saTakerGets.getCurrency(), uGetsIssuerID, uRate));
|
||||
}
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "TrustSetTransactor.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
TER TrustSetTransactor::doApply()
|
||||
{
|
||||
TER terResult = tesSUCCESS;
|
||||
@@ -135,10 +137,18 @@ TER TrustSetTransactor::doApply()
|
||||
|
||||
uint64 uSrcRef; // Ignored, dirs never delete.
|
||||
|
||||
terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(mTxnAccountID), sleRippleState->getIndex());
|
||||
terResult = mEngine->getNodes().dirAdd(
|
||||
uSrcRef,
|
||||
Ledger::getOwnerDirIndex(mTxnAccountID),
|
||||
sleRippleState->getIndex(),
|
||||
boost::bind(&Ledger::ownerDirDescriber, _1, mTxnAccountID));
|
||||
|
||||
if (tesSUCCESS == terResult)
|
||||
terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(uDstAccountID), sleRippleState->getIndex());
|
||||
terResult = mEngine->getNodes().dirAdd(
|
||||
uSrcRef,
|
||||
Ledger::getOwnerDirIndex(uDstAccountID),
|
||||
sleRippleState->getIndex(),
|
||||
boost::bind(&Ledger::ownerDirDescriber, _1, uDstAccountID));
|
||||
}
|
||||
|
||||
Log(lsINFO) << "doTrustSet<";
|
||||
|
||||
Reference in New Issue
Block a user