mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 05:25:55 +00:00
Cleanups and surface reduction:
* Don't use friendship unless needed * Trim down interfaces * Make classes feel more like std containers
This commit is contained in:
@@ -1719,7 +1719,7 @@ uint256 Ledger::getLedgerHash (std::uint32_t ledgerIndex)
|
||||
STVector256 vec = hashIndex->getFieldV256 (sfHashes);
|
||||
|
||||
if (vec.size () >= diff)
|
||||
return vec.at (vec.size () - diff);
|
||||
return vec[vec.size () - diff];
|
||||
|
||||
WriteLog (lsWARNING, Ledger)
|
||||
<< "Ledger " << mLedgerSeq
|
||||
@@ -1754,7 +1754,7 @@ uint256 Ledger::getLedgerHash (std::uint32_t ledgerIndex)
|
||||
STVector256 vec = hashIndex->getFieldV256 (sfHashes);
|
||||
|
||||
if (vec.size () > sDiff)
|
||||
return vec.at (vec.size () - sDiff - 1);
|
||||
return vec[vec.size () - sDiff - 1];
|
||||
}
|
||||
|
||||
WriteLog (lsWARNING, Ledger) << "Can't get seq " << ledgerIndex
|
||||
@@ -1775,7 +1775,7 @@ Ledger::LedgerHashes Ledger::getLedgerHashes () const
|
||||
auto seq = hashIndex->getFieldU32 (sfLastLedgerSequence) - size;
|
||||
|
||||
for (int i = 0; i < size; ++i)
|
||||
ret.push_back (std::make_pair (++seq, vec.at (i)));
|
||||
ret.push_back (std::make_pair (++seq, vec[i]));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -431,9 +431,7 @@ AmendmentTableImpl::doValidation (Ledger::ref lastClosedLedger,
|
||||
|
||||
STVector256 vAmendments (sfAmendments);
|
||||
for (auto const& uAmendment : lAmendments)
|
||||
{
|
||||
vAmendments.addValue (uAmendment);
|
||||
}
|
||||
vAmendments.push_back (uAmendment);
|
||||
vAmendments.sort ();
|
||||
baseValidation.setFieldV256 (sfAmendments, vAmendments);
|
||||
}
|
||||
|
||||
@@ -1230,10 +1230,7 @@ Json::Value NetworkOPsImp::getOwnerInfo (
|
||||
|
||||
do
|
||||
{
|
||||
STVector256 svIndexes = sleNode->getFieldV256 (sfIndexes);
|
||||
const std::vector<uint256>& vuiIndexes = svIndexes.peekValue ();
|
||||
|
||||
BOOST_FOREACH (uint256 const& uDirEntry, vuiIndexes)
|
||||
for (auto const& uDirEntry : sleNode->getFieldV256 (sfIndexes))
|
||||
{
|
||||
auto sleCur = lpLedger->getSLEi (uDirEntry);
|
||||
|
||||
@@ -1265,7 +1262,7 @@ Json::Value NetworkOPsImp::getOwnerInfo (
|
||||
}
|
||||
}
|
||||
|
||||
uNodeDir = sleNode->getFieldU64 (sfIndexNext);
|
||||
uNodeDir = sleNode->getFieldU64 (sfIndexNext);
|
||||
|
||||
if (uNodeDir)
|
||||
{
|
||||
|
||||
@@ -464,7 +464,7 @@ Json::Value PathRequest::doUpdate (RippleLineCache::ref cache, bool fast)
|
||||
{
|
||||
m_journal.debug
|
||||
<< iIdentifier << " Trying with an extra path element";
|
||||
spsPaths.addPath(extraPath);
|
||||
spsPaths.push_back (extraPath);
|
||||
rc = path::RippleCalc::rippleCalculate (lesSandbox,
|
||||
saMaxAmount,
|
||||
saDstAmount,
|
||||
|
||||
@@ -470,7 +470,7 @@ TER PathState::expandPath (
|
||||
|
||||
// Figure out next node properties for implied node.
|
||||
const auto uNxtCurrencyID = spSourcePath.size ()
|
||||
? Currency(spSourcePath.getElement (0).getCurrency ())
|
||||
? Currency(spSourcePath.front ().getCurrency ())
|
||||
// Use next node.
|
||||
: currencyOutID;
|
||||
// Use send.
|
||||
@@ -478,7 +478,7 @@ TER PathState::expandPath (
|
||||
// TODO(tom): complexify this next logic further in case someone
|
||||
// understands it.
|
||||
const auto nextAccountID = spSourcePath.size ()
|
||||
? Account(spSourcePath.getElement (0).getAccountID ())
|
||||
? Account(spSourcePath. front ().getAccountID ())
|
||||
: !isXRP(currencyOutID)
|
||||
? (issuerOutID == uReceiverID)
|
||||
? Account(uReceiverID)
|
||||
|
||||
@@ -231,7 +231,7 @@ bool Pathfinder::findPaths (
|
||||
for (auto const& path : pathsOut)
|
||||
{ // make sure no paths were lost
|
||||
bool found = false;
|
||||
if (!path.isEmpty ())
|
||||
if (!path.empty ())
|
||||
{
|
||||
for (auto const& ePath : mCompletePaths)
|
||||
{
|
||||
@@ -242,7 +242,7 @@ bool Pathfinder::findPaths (
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
mCompletePaths.addPath(path);
|
||||
mCompletePaths.push_back (path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ TER Pathfinder::checkPath (
|
||||
uint64_t& qualityOut) const // The returned initial quality
|
||||
{
|
||||
STPathSet pathSet;
|
||||
pathSet.addPath (path);
|
||||
pathSet.push_back (path);
|
||||
|
||||
// We only want to look at this path
|
||||
path::RippleCalc::Input rcInput;
|
||||
@@ -388,7 +388,7 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
|
||||
": " << currentPath.getJson (0);
|
||||
|
||||
vMap.push_back (path_LQ_t (
|
||||
uQuality, currentPath.mPath.size (), actualOut, i));
|
||||
uQuality, currentPath.size (), actualOut, i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,7 +399,6 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
|
||||
// Lower is better and should be first.
|
||||
std::sort (vMap.begin (), vMap.end (), bQualityCmp);
|
||||
|
||||
|
||||
for (int i = 0, iPathsLeft = iMaxPaths;
|
||||
(iPathsLeft > 0 || extraPath.empty()) && i < vMap.size (); ++i)
|
||||
{
|
||||
@@ -411,7 +410,7 @@ STPathSet Pathfinder::filterPaths(int iMaxPaths, STPath& extraPath)
|
||||
// last path must fill
|
||||
--iPathsLeft;
|
||||
remaining -= std::get<2> (lqt);
|
||||
spsDst.addPath (mCompletePaths[std::get<3> (lqt)]);
|
||||
spsDst.push_back (mCompletePaths[std::get<3> (lqt)]);
|
||||
}
|
||||
else if (iPathsLeft == 0 && std::get<2>(lqt) >= mDstAmount &&
|
||||
extraPath.empty())
|
||||
@@ -588,7 +587,7 @@ void Pathfinder::addLink(
|
||||
|
||||
STPathSet& Pathfinder::getPaths(PathType_t const& type, bool addComplete)
|
||||
{
|
||||
std::map< PathType_t, STPathSet >::iterator it = mPaths.find(type);
|
||||
auto it = mPaths.find(type);
|
||||
|
||||
// We already have these paths
|
||||
if (it != mPaths.end())
|
||||
@@ -614,37 +613,33 @@ STPathSet& Pathfinder::getPaths(PathType_t const& type, bool addComplete)
|
||||
|
||||
switch (toAdd)
|
||||
{
|
||||
|
||||
case nt_SOURCE:
|
||||
|
||||
{ // source is an empty path
|
||||
assert(pathsOut.isEmpty());
|
||||
pathsOut.addPath(STPath());
|
||||
}
|
||||
case nt_SOURCE:
|
||||
// source is an empty path
|
||||
assert(pathsOut.empty());
|
||||
pathsOut.push_back (STPath());
|
||||
break;
|
||||
|
||||
case nt_ACCOUNTS:
|
||||
addLink(pathsIn, pathsOut, afADD_ACCOUNTS);
|
||||
break;
|
||||
case nt_ACCOUNTS:
|
||||
addLink(pathsIn, pathsOut, afADD_ACCOUNTS);
|
||||
break;
|
||||
|
||||
case nt_BOOKS:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS);
|
||||
break;
|
||||
case nt_BOOKS:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS);
|
||||
break;
|
||||
|
||||
case nt_XRP_BOOK:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS | afOB_XRP);
|
||||
break;
|
||||
case nt_XRP_BOOK:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS | afOB_XRP);
|
||||
break;
|
||||
|
||||
case nt_DEST_BOOK:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS | afOB_LAST);
|
||||
break;
|
||||
|
||||
case nt_DESTINATION:
|
||||
// FIXME: What if a different issuer was specified on the
|
||||
// destination amount?
|
||||
addLink(pathsIn, pathsOut, afADD_ACCOUNTS | afAC_LAST);
|
||||
break;
|
||||
case nt_DEST_BOOK:
|
||||
addLink(pathsIn, pathsOut, afADD_BOOKS | afOB_LAST);
|
||||
break;
|
||||
|
||||
case nt_DESTINATION:
|
||||
// FIXME: What if a different issuer was specified on the
|
||||
// destination amount?
|
||||
addLink(pathsIn, pathsOut, afADD_ACCOUNTS | afAC_LAST);
|
||||
break;
|
||||
}
|
||||
|
||||
CondLog (mCompletePaths.size() != cp, lsDEBUG, Pathfinder)
|
||||
@@ -680,12 +675,12 @@ bool Pathfinder::isNoRippleOut (STPath const& currentPath)
|
||||
return false;
|
||||
|
||||
// What account are we leaving?
|
||||
auto const& fromAccount =
|
||||
(currentPath.size() == 1) ? mSrcAccountID : (currentPath.end() - 2)->
|
||||
mAccountID;
|
||||
auto const& fromAccount = (currentPath.size() == 1)
|
||||
? mSrcAccountID
|
||||
: (currentPath.end() - 2)->getAccountID ();
|
||||
|
||||
return isNoRipple (
|
||||
endElement.mAccountID, fromAccount, endElement.mCurrencyID);
|
||||
endElement.getAccountID (), fromAccount, endElement.getCurrency ());
|
||||
}
|
||||
|
||||
void Pathfinder::addLink(
|
||||
@@ -693,26 +688,37 @@ void Pathfinder::addLink(
|
||||
STPathSet& incompletePaths, // The set of partial paths we add to
|
||||
int addFlags)
|
||||
{
|
||||
auto const& pathEnd = currentPath.isEmpty() ?
|
||||
mSource : currentPath.mPath.back ();
|
||||
auto const& uEndCurrency = pathEnd.mCurrencyID;
|
||||
auto const& uEndIssuer = pathEnd.mIssuerID;
|
||||
auto const& uEndAccount = pathEnd.mAccountID;
|
||||
auto const& pathEnd = currentPath.empty()
|
||||
? mSource
|
||||
: currentPath.back ();
|
||||
auto const& uEndCurrency = pathEnd.getCurrency ();
|
||||
auto const& uEndIssuer = pathEnd.getIssuerID ();
|
||||
auto const& uEndAccount = pathEnd.getAccountID ();
|
||||
bool const bOnXRP = uEndCurrency.isZero();
|
||||
|
||||
WriteLog (lsTRACE, Pathfinder) << "addLink< flags="
|
||||
<< addFlags << " onXRP=" << bOnXRP;
|
||||
WriteLog (lsTRACE, Pathfinder) << currentPath.getJson(0);
|
||||
|
||||
auto add_unique_path = [](STPathSet& path_set, STPath const& path)
|
||||
{
|
||||
for (auto const& p : path_set)
|
||||
{
|
||||
if (p == path)
|
||||
return;
|
||||
}
|
||||
path_set.push_back (path);
|
||||
};
|
||||
|
||||
if (addFlags & afADD_ACCOUNTS)
|
||||
{ // add accounts
|
||||
if (bOnXRP)
|
||||
{
|
||||
if (mDstAmount.isNative() && !currentPath.isEmpty())
|
||||
if (mDstAmount.isNative() && !currentPath.empty())
|
||||
{ // non-default path to XRP destination
|
||||
WriteLog (lsTRACE, Pathfinder)
|
||||
<< "complete path found ax: " << currentPath.getJson(0);
|
||||
mCompletePaths.addUniquePath(currentPath);
|
||||
add_unique_path (mCompletePaths, currentPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -773,12 +779,12 @@ void Pathfinder::addLink(
|
||||
if (uEndCurrency == mDstAmount.getCurrency())
|
||||
{
|
||||
// this is a complete path
|
||||
if (!currentPath.isEmpty())
|
||||
if (!currentPath.empty())
|
||||
{
|
||||
WriteLog (lsTRACE, Pathfinder)
|
||||
<< "complete path found ae: "
|
||||
<< currentPath.getJson(0);
|
||||
mCompletePaths.addUniquePath(currentPath);
|
||||
add_unique_path (mCompletePaths, currentPath);
|
||||
}
|
||||
}
|
||||
else if (!bDestOnly)
|
||||
@@ -873,11 +879,8 @@ void Pathfinder::addLink(
|
||||
{ // to XRP
|
||||
|
||||
// add the order book itself
|
||||
newPath.addElement(STPathElement(
|
||||
STPathElement::typeCurrency,
|
||||
xrpAccount(),
|
||||
xrpCurrency(),
|
||||
xrpAccount()));
|
||||
newPath.emplace_back (STPathElement::typeCurrency,
|
||||
xrpAccount(), xrpCurrency(), xrpAccount());
|
||||
|
||||
if (mDstAmount.getCurrency().isZero())
|
||||
{
|
||||
@@ -886,10 +889,10 @@ void Pathfinder::addLink(
|
||||
WriteLog (lsTRACE, Pathfinder)
|
||||
<< "complete path found bx: "
|
||||
<< currentPath.getJson(0);
|
||||
mCompletePaths.addUniquePath(newPath);
|
||||
add_unique_path (mCompletePaths, newPath);
|
||||
}
|
||||
else
|
||||
incompletePaths.addPath(newPath);
|
||||
incompletePaths.push_back (newPath);
|
||||
}
|
||||
else if (!currentPath.hasSeen(
|
||||
book->getIssuerOut(),
|
||||
@@ -897,12 +900,10 @@ void Pathfinder::addLink(
|
||||
book->getIssuerOut()))
|
||||
{ // Don't want the book if we've already seen the issuer
|
||||
// add the order book itself
|
||||
newPath.addElement(
|
||||
STPathElement(STPathElement::typeCurrency |
|
||||
STPathElement::typeIssuer,
|
||||
xrpAccount(),
|
||||
book->getCurrencyOut(), book->
|
||||
getIssuerOut()));
|
||||
newPath.emplace_back(
|
||||
STPathElement::typeCurrency | STPathElement::typeIssuer,
|
||||
xrpAccount(), book->getCurrencyOut(),
|
||||
book->getIssuerOut());
|
||||
|
||||
if (book->getIssuerOut() == mDstAccountID &&
|
||||
book->getCurrencyOut() == mDstAmount.getCurrency())
|
||||
@@ -910,7 +911,7 @@ void Pathfinder::addLink(
|
||||
WriteLog (lsTRACE, Pathfinder)
|
||||
<< "complete path found ba: "
|
||||
<< currentPath.getJson(0);
|
||||
mCompletePaths.addUniquePath(newPath);
|
||||
add_unique_path (mCompletePaths, newPath);
|
||||
}
|
||||
else
|
||||
{ // add issuer's account, path still incomplete
|
||||
|
||||
@@ -159,7 +159,7 @@ TER RippleCalc::rippleCalculate ()
|
||||
if (!addPathState (STPath(), resultCode))
|
||||
return resultCode;
|
||||
}
|
||||
else if (spsPaths_.isEmpty ())
|
||||
else if (spsPaths_.empty ())
|
||||
{
|
||||
WriteLog (lsDEBUG, RippleCalc)
|
||||
<< "rippleCalc: Invalid transaction:"
|
||||
@@ -210,7 +210,7 @@ TER RippleCalc::rippleCalculate ()
|
||||
bool multiQuality = false;
|
||||
|
||||
// Find the best path.
|
||||
for (auto pathState: pathStateList_)
|
||||
for (auto pathState : pathStateList_)
|
||||
{
|
||||
if (pathState->quality())
|
||||
// Only do active paths.
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
|
||||
TER preCheck () override
|
||||
{
|
||||
mTxnAccountID = mTxn.getSourceAccount ().getAccountID ();
|
||||
mTxnAccountID = mTxn.getSourceAccount ().getAccountID ();
|
||||
|
||||
if (mTxnAccountID.isNonZero ())
|
||||
{
|
||||
@@ -121,10 +121,13 @@ private:
|
||||
|
||||
STVector256 amendments (amendmentObject->getFieldV256 (sfAmendments));
|
||||
|
||||
if (amendments.hasValue (amendment))
|
||||
if (std::find (amendments.begin(), amendments.end(),
|
||||
amendment) != amendments.end ())
|
||||
{
|
||||
return tefALREADY;
|
||||
}
|
||||
|
||||
amendments.addValue (amendment);
|
||||
amendments.push_back (amendment);
|
||||
amendmentObject->setFieldV256 (sfAmendments, amendments);
|
||||
mEngine->entryModify (amendmentObject);
|
||||
|
||||
@@ -138,7 +141,6 @@ private:
|
||||
|
||||
TER applyFee ()
|
||||
{
|
||||
|
||||
SLE::pointer feeObject = mEngine->entryCache (
|
||||
ltFEE_SETTINGS, Ledger::getLedgerFeeIndex ());
|
||||
|
||||
|
||||
@@ -744,13 +744,13 @@ const STArray& STObject::getFieldArray (SField::ref field) const
|
||||
|
||||
STPathSet const& STObject::getFieldPathSet (SField::ref field) const
|
||||
{
|
||||
static STPathSet const empty;
|
||||
static STPathSet const empty{};
|
||||
return getFieldByConstRef <STPathSet> (field, empty);
|
||||
}
|
||||
|
||||
const STVector256& STObject::getFieldV256 (SField::ref field) const
|
||||
{
|
||||
static STVector256 const empty;
|
||||
static STVector256 const empty{};
|
||||
return getFieldByConstRef <STVector256> (field, empty);
|
||||
}
|
||||
|
||||
@@ -897,16 +897,6 @@ bool STObject::operator== (const STObject& obj) const
|
||||
return true;
|
||||
}
|
||||
|
||||
Json::Value STVector256::getJson (int options) const
|
||||
{
|
||||
Json::Value ret (Json::arrayValue);
|
||||
|
||||
for (auto const& vEntry : mValue)
|
||||
ret.append (to_string (vEntry));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SerializedObject_test : public beast::unit_test::suite
|
||||
|
||||
@@ -444,7 +444,7 @@ bool STParsedJSON::parse (std::string const& json_name,
|
||||
{
|
||||
uint256 s;
|
||||
s.SetHex (value[i].asString ());
|
||||
tail->addValue (s);
|
||||
tail->push_back (s);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
@@ -581,10 +581,10 @@ bool STParsedJSON::parse (std::string const& json_name,
|
||||
}
|
||||
}
|
||||
|
||||
p.addElement (STPathElement (uAccount, uCurrency, uIssuer, hasCurrency));
|
||||
p.emplace_back (uAccount, uCurrency, uIssuer, hasCurrency);
|
||||
}
|
||||
|
||||
tail->addPath (p);
|
||||
tail->push_back (p);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
|
||||
@@ -149,15 +149,14 @@ bool STVector256::isEquivalent (const SerializedType& t) const
|
||||
return v && (mValue == v->mValue);
|
||||
}
|
||||
|
||||
bool STVector256::hasValue (uint256 const& v) const
|
||||
Json::Value STVector256::getJson (int) const
|
||||
{
|
||||
BOOST_FOREACH (uint256 const& hash, mValue)
|
||||
{
|
||||
if (hash == v)
|
||||
return true;
|
||||
}
|
||||
Json::Value ret (Json::arrayValue);
|
||||
|
||||
return false;
|
||||
for (auto const& vEntry : mValue)
|
||||
ret.append (to_string (vEntry));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -329,59 +328,20 @@ Json::Value STPathSet::getJson (int options) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::string STPath::getText () const
|
||||
{
|
||||
std::string ret ("[");
|
||||
bool first = true;
|
||||
|
||||
BOOST_FOREACH (const STPathElement & it, mPath)
|
||||
{
|
||||
if (!first) ret += ", ";
|
||||
|
||||
switch (it.getNodeType ())
|
||||
{
|
||||
case STPathElement::typeAccount:
|
||||
{
|
||||
ret += to_string (it.getNode ());
|
||||
break;
|
||||
}
|
||||
|
||||
case STPathElement::typeOffer:
|
||||
{
|
||||
ret += "Offer(";
|
||||
ret += it.getNode ().GetHex ();
|
||||
ret += ")";
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw std::runtime_error ("Unknown path element");
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
return ret + "]";
|
||||
}
|
||||
#endif
|
||||
|
||||
void STPathSet::add (Serializer& s) const
|
||||
{
|
||||
assert (fName->isBinary ());
|
||||
assert (fName->fieldType == STI_PATHSET);
|
||||
bool bFirst = true;
|
||||
bool first = true;
|
||||
|
||||
BOOST_FOREACH (const STPath & spPath, value)
|
||||
for (auto const& spPath : value)
|
||||
{
|
||||
if (!bFirst)
|
||||
{
|
||||
if (!first)
|
||||
s.add8 (STPathElement::typeBoundary);
|
||||
}
|
||||
|
||||
BOOST_FOREACH (const STPathElement & speElement, spPath)
|
||||
for (auto const& speElement : spPath)
|
||||
{
|
||||
int iType = speElement.getNodeType ();
|
||||
int iType = speElement.getNodeType ();
|
||||
|
||||
s.add8 (iType);
|
||||
|
||||
@@ -395,8 +355,9 @@ void STPathSet::add (Serializer& s) const
|
||||
s.add160 (speElement.getIssuerID ());
|
||||
}
|
||||
|
||||
bFirst = false;
|
||||
first = false;
|
||||
}
|
||||
|
||||
s.add8 (STPathElement::typeNone);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,12 +174,6 @@ private:
|
||||
|
||||
class STPathElement
|
||||
{
|
||||
private:
|
||||
// VFALCO Remove these friend declarations
|
||||
friend class STPathSet;
|
||||
friend class STPath;
|
||||
friend class Pathfinder;
|
||||
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
@@ -283,65 +277,48 @@ private:
|
||||
class STPath
|
||||
{
|
||||
public:
|
||||
STPath ()
|
||||
{
|
||||
;
|
||||
}
|
||||
STPath (const std::vector<STPathElement>& p) : mPath (p)
|
||||
{
|
||||
;
|
||||
}
|
||||
STPath () = default;
|
||||
|
||||
int size () const
|
||||
STPath (std::vector<STPathElement> const& p)
|
||||
: mPath (p)
|
||||
{ }
|
||||
|
||||
std::vector<STPathElement>::size_type
|
||||
size () const
|
||||
{
|
||||
return mPath.size ();
|
||||
}
|
||||
void reserve (size_t n)
|
||||
{
|
||||
mPath.reserve(n);
|
||||
}
|
||||
bool isEmpty () const
|
||||
{
|
||||
return mPath.empty ();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return mPath.empty ();
|
||||
}
|
||||
|
||||
const STPathElement& getElement (int offset) const
|
||||
{
|
||||
return mPath[offset];
|
||||
}
|
||||
const STPathElement& getElement (int offset)
|
||||
{
|
||||
return mPath[offset];
|
||||
}
|
||||
void addElement (const STPathElement& e)
|
||||
void
|
||||
push_back (STPathElement const& e)
|
||||
{
|
||||
mPath.push_back (e);
|
||||
}
|
||||
void clear ()
|
||||
|
||||
template <typename ...Args>
|
||||
void
|
||||
emplace_back (Args&&... args)
|
||||
{
|
||||
mPath.clear ();
|
||||
mPath.emplace_back (std::forward<Args> (args)...);
|
||||
}
|
||||
|
||||
bool hasSeen (Account const& account, Currency const& currency,
|
||||
Account const& issuer) const;
|
||||
Json::Value getJson (int) const;
|
||||
|
||||
std::vector<STPathElement>::iterator begin ()
|
||||
std::vector<STPathElement>::const_iterator
|
||||
begin () const
|
||||
{
|
||||
return mPath.begin ();
|
||||
}
|
||||
std::vector<STPathElement>::iterator end ()
|
||||
{
|
||||
return mPath.end ();
|
||||
}
|
||||
std::vector<STPathElement>::const_iterator begin () const
|
||||
{
|
||||
return mPath.begin ();
|
||||
}
|
||||
std::vector<STPathElement>::const_iterator end () const
|
||||
|
||||
std::vector<STPathElement>::const_iterator
|
||||
end () const
|
||||
{
|
||||
return mPath.end ();
|
||||
}
|
||||
@@ -351,12 +328,19 @@ public:
|
||||
return mPath == t.mPath;
|
||||
}
|
||||
|
||||
void setCanonical (STPath const& spExpanded);
|
||||
std::vector<STPathElement>::const_reference
|
||||
back () const
|
||||
{
|
||||
return mPath.back ();
|
||||
}
|
||||
|
||||
std::vector<STPathElement>::const_reference
|
||||
front () const
|
||||
{
|
||||
return mPath.front ();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class STPathSet;
|
||||
friend class Pathfinder;
|
||||
|
||||
std::vector<STPathElement> mPath;
|
||||
};
|
||||
|
||||
@@ -366,32 +350,19 @@ private:
|
||||
class STPathSet : public SerializedType
|
||||
{
|
||||
public:
|
||||
STPathSet ()
|
||||
{
|
||||
;
|
||||
}
|
||||
STPathSet () = default;
|
||||
|
||||
explicit STPathSet (SField::ref n) : SerializedType (n)
|
||||
{
|
||||
;
|
||||
}
|
||||
STPathSet (SField::ref n)
|
||||
: SerializedType (n)
|
||||
{ }
|
||||
|
||||
explicit STPathSet (const std::vector<STPath>& v) : value (v)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
STPathSet (SField::ref n, const std::vector<STPath>& v) : SerializedType (n), value (v)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
static std::unique_ptr<SerializedType> deserialize (SerializerIterator& sit, SField::ref name)
|
||||
static
|
||||
std::unique_ptr<SerializedType>
|
||||
deserialize (SerializerIterator& sit, SField::ref name)
|
||||
{
|
||||
return std::unique_ptr<SerializedType> (construct (sit, name));
|
||||
}
|
||||
|
||||
// std::string getText() const;
|
||||
void add (Serializer& s) const;
|
||||
virtual Json::Value getJson (int) const;
|
||||
|
||||
@@ -399,41 +370,19 @@ public:
|
||||
{
|
||||
return STI_PATHSET;
|
||||
}
|
||||
int size () const
|
||||
std::vector<STPath>::size_type
|
||||
size () const
|
||||
{
|
||||
return value.size ();
|
||||
}
|
||||
void reserve (size_t n)
|
||||
{
|
||||
value.reserve(n);
|
||||
}
|
||||
STPath const& getPath (int off) const
|
||||
{
|
||||
return value[off];
|
||||
}
|
||||
STPath& peekPath (int off)
|
||||
{
|
||||
return value[off];
|
||||
}
|
||||
bool isEmpty () const
|
||||
|
||||
bool empty () const
|
||||
{
|
||||
return value.empty ();
|
||||
}
|
||||
void clear ()
|
||||
|
||||
void push_back (STPath const& e)
|
||||
{
|
||||
value.clear ();
|
||||
}
|
||||
void addPath (STPath const& e)
|
||||
{
|
||||
value.push_back (e);
|
||||
}
|
||||
void addUniquePath (STPath const& e)
|
||||
{
|
||||
for (auto const& p: value)
|
||||
{
|
||||
if (p == e)
|
||||
return;
|
||||
}
|
||||
value.push_back (e);
|
||||
}
|
||||
|
||||
@@ -444,11 +393,11 @@ public:
|
||||
std::vector<STPath>::reverse_iterator it = value.rbegin ();
|
||||
|
||||
STPath& newPath = *it;
|
||||
newPath.mPath.push_back (tail);
|
||||
newPath.push_back (tail);
|
||||
|
||||
while (++it != value.rend ())
|
||||
{
|
||||
if (it->mPath == newPath.mPath)
|
||||
if (*it == newPath)
|
||||
{
|
||||
value.pop_back ();
|
||||
return false;
|
||||
@@ -463,27 +412,17 @@ public:
|
||||
return value.empty ();
|
||||
}
|
||||
|
||||
STPath& operator[](size_t n)
|
||||
{
|
||||
return value[n];
|
||||
}
|
||||
STPath const& operator[](size_t n) const
|
||||
std::vector<STPath>::const_reference
|
||||
operator[] (std::vector<STPath>::size_type n) const
|
||||
{
|
||||
return value[n];
|
||||
}
|
||||
|
||||
std::vector<STPath>::iterator begin ()
|
||||
{
|
||||
return value.begin ();
|
||||
}
|
||||
std::vector<STPath>::iterator end ()
|
||||
{
|
||||
return value.end ();
|
||||
}
|
||||
std::vector<STPath>::const_iterator begin () const
|
||||
{
|
||||
return value.begin ();
|
||||
}
|
||||
|
||||
std::vector<STPath>::const_iterator end () const
|
||||
{
|
||||
return value.end ();
|
||||
@@ -492,11 +431,18 @@ public:
|
||||
private:
|
||||
std::vector<STPath> value;
|
||||
|
||||
STPathSet (SField::ref n, const std::vector<STPath>& v)
|
||||
: SerializedType (n), value (v)
|
||||
{ }
|
||||
|
||||
STPathSet* duplicate () const
|
||||
{
|
||||
return new STPathSet (*this);
|
||||
}
|
||||
static STPathSet* construct (SerializerIterator&, SField::ref);
|
||||
|
||||
static
|
||||
STPathSet*
|
||||
construct (SerializerIterator&, SField::ref);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -504,22 +450,13 @@ private:
|
||||
class STVector256 : public SerializedType
|
||||
{
|
||||
public:
|
||||
STVector256 ()
|
||||
{
|
||||
;
|
||||
}
|
||||
STVector256 (SField::ref n) : SerializedType (n)
|
||||
{
|
||||
;
|
||||
}
|
||||
STVector256 (SField::ref n, const std::vector<uint256>& v) : SerializedType (n), mValue (v)
|
||||
{
|
||||
;
|
||||
}
|
||||
STVector256 (const std::vector<uint256>& vector) : mValue (vector)
|
||||
{
|
||||
;
|
||||
}
|
||||
STVector256 () = default;
|
||||
explicit STVector256 (SField::ref n)
|
||||
: SerializedType (n)
|
||||
{ }
|
||||
explicit STVector256 (std::vector<uint256> const& vector)
|
||||
: mValue (vector)
|
||||
{ }
|
||||
|
||||
SerializedTypeID getSType () const
|
||||
{
|
||||
@@ -527,62 +464,57 @@ public:
|
||||
}
|
||||
void add (Serializer& s) const;
|
||||
|
||||
static std::unique_ptr<SerializedType> deserialize (SerializerIterator& sit, SField::ref name)
|
||||
static
|
||||
std::unique_ptr<SerializedType>
|
||||
deserialize (SerializerIterator& sit, SField::ref name)
|
||||
{
|
||||
return std::unique_ptr<SerializedType> (construct (sit, name));
|
||||
}
|
||||
|
||||
const std::vector<uint256>& peekValue () const
|
||||
const std::vector<uint256>&
|
||||
peekValue () const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
std::vector<uint256>& peekValue ()
|
||||
|
||||
std::vector<uint256>&
|
||||
peekValue ()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
virtual bool isEquivalent (const SerializedType& t) const;
|
||||
virtual bool isDefault () const
|
||||
{
|
||||
return mValue.empty ();
|
||||
}
|
||||
|
||||
std::vector<uint256> getValue () const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
int size () const
|
||||
std::vector<uint256>::size_type
|
||||
size () const
|
||||
{
|
||||
return mValue.size ();
|
||||
}
|
||||
bool isEmpty () const
|
||||
bool empty () const
|
||||
{
|
||||
return mValue.empty ();
|
||||
}
|
||||
|
||||
uint256 const& at (int i) const
|
||||
std::vector<uint256>::const_reference
|
||||
operator[] (std::vector<uint256>::size_type n) const
|
||||
{
|
||||
assert ((i >= 0) && (i < size ()));
|
||||
return mValue.at (i);
|
||||
}
|
||||
uint256& at (int i)
|
||||
{
|
||||
assert ((i >= 0) && (i < size ()));
|
||||
return mValue.at (i);
|
||||
return mValue[n];
|
||||
}
|
||||
|
||||
void setValue (const STVector256& v)
|
||||
{
|
||||
mValue = v.mValue;
|
||||
}
|
||||
void setValue (const std::vector<uint256>& v)
|
||||
{
|
||||
mValue = v;
|
||||
}
|
||||
void addValue (uint256 const& v)
|
||||
|
||||
void push_back (uint256 const& v)
|
||||
{
|
||||
mValue.push_back (v);
|
||||
}
|
||||
bool hasValue (uint256 const& v) const;
|
||||
|
||||
void sort ()
|
||||
{
|
||||
std::sort (mValue.begin (), mValue.end ());
|
||||
@@ -590,11 +522,13 @@ public:
|
||||
|
||||
Json::Value getJson (int) const;
|
||||
|
||||
std::vector<uint256>::const_iterator begin() const
|
||||
std::vector<uint256>::const_iterator
|
||||
begin() const
|
||||
{
|
||||
return mValue.begin ();
|
||||
}
|
||||
std::vector<uint256>::const_iterator end() const
|
||||
std::vector<uint256>::const_iterator
|
||||
end() const
|
||||
{
|
||||
return mValue.end ();
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
|
||||
WriteLog (lsDEBUG, PathRequest)
|
||||
<< "Trying with an extra path element";
|
||||
|
||||
spsComputed.addPath(extraPath);
|
||||
spsComputed.push_back (extraPath);
|
||||
lesSandbox.clear ();
|
||||
rc = path::RippleCalc::rippleCalculate (
|
||||
lesSandbox,
|
||||
|
||||
@@ -177,7 +177,7 @@ static Json::Value signPayment(
|
||||
<< "transactionSign: build_path: "
|
||||
<< spsPaths.getJson (0);
|
||||
|
||||
if (!spsPaths.isEmpty ())
|
||||
if (!spsPaths.empty ())
|
||||
tx_json["Paths"] = spsPaths.getJson (0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user