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