Skip to content

Commit

Permalink
Remove implicit Asset cast to Currency/MPT
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Jan 23, 2024
1 parent c3c68fc commit 9ff0841
Show file tree
Hide file tree
Showing 57 changed files with 318 additions and 208 deletions.
2 changes: 1 addition & 1 deletion src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4420,7 +4420,7 @@ NetworkOPsImp::getBookPage(
saOwnerFunds = accountHolds(
view,
uOfferOwnerID,
book.out.asset(),
book.out.getCurrency(),
book.out.account(),
fhZERO_IF_FROZEN,
viewJ);
Expand Down
11 changes: 6 additions & 5 deletions src/ripple/app/misc/impl/AMMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ ammLPHolds(
{
return ammLPHolds(
view,
ammSle[sfAsset].asset(),
ammSle[sfAsset2].asset(),
ammSle[sfAsset].getCurrency(),
ammSle[sfAsset2].getCurrency(),
ammSle[sfAccount],
lpAccount,
j);
Expand Down Expand Up @@ -173,10 +173,11 @@ ammAccountHolds(
if (auto const sle = view.read(keylet::account(ammAccountID)))
return (*sle)[sfBalance];
}
else if (auto const sle = view.read(
keylet::line(ammAccountID, issue.account(), issue.asset()));
else if (auto const sle = view.read(keylet::line(
ammAccountID, issue.account(), issue.getCurrency()));
sle &&
!isFrozen(view, ammAccountID, issue.asset(), issue.account()))
!isFrozen(
view, ammAccountID, issue.getCurrency(), issue.account()))
{
auto amount = (*sle)[sfBalance];
if (ammAccountID > issue.account())
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/paths/AccountCurrencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ accountSourceCurrencies(
// Peer extends credit.
&& ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left.
{
currencies.insert(saBalance.getAsset());
currencies.insert(saBalance.getCurrency());
}
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ accountDestCurrencies(
auto& saBalance = rspEntry.getBalance();

if (saBalance < rspEntry.getLimit()) // Can take more
currencies.insert(saBalance.getAsset());
currencies.insert(saBalance.getCurrency());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/paths/Credit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ creditLimit(
}

assert(result.getIssuer() == account);
assert(result.getAsset() == currency);
assert(result.getCurrency() == currency);
return result;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ creditBalance(
}

assert(result.getIssuer() == account);
assert(result.getAsset() == currency);
assert(result.getCurrency() == currency);
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/ripple/app/paths/Flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ flow(
Issue const srcIssue = [&] {
if (sendMax)
return sendMax->issue();
if (!isXRP(deliver.issue().asset()))
return Issue(deliver.issue().asset(), src);
if (!isXRP(deliver.issue().getCurrency()))
return Issue(deliver.issue().getCurrency(), src);
return xrpIssue();
}();

Expand Down Expand Up @@ -128,8 +128,8 @@ flow(
}
}

const bool srcIsXRP = isXRP(srcIssue.asset());
const bool dstIsXRP = isXRP(dstIssue.asset());
const bool srcIsXRP = isXRP(srcIssue.getCurrency());
const bool dstIsXRP = isXRP(dstIssue.getCurrency());

auto const asDeliver = toAmountSpec(deliver);

Expand Down
18 changes: 9 additions & 9 deletions src/ripple/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ PathRequest::parseJson(Json::Value const& jvParams)

convert_all_ = saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true);

if ((saDstAmount.getAsset().isXRP() &&
if ((isXRP(saDstAmount.getCurrency()) &&
saDstAmount.getIssuer().isNonZero()) ||
(saDstAmount.getAsset() == badCurrency()) ||
(saDstAmount.getCurrency() == badCurrency()) ||
(!convert_all_ && saDstAmount <= beast::zero))
{
jvStatus = rpcError(rpcDST_AMT_MALFORMED);
Expand All @@ -335,9 +335,9 @@ PathRequest::parseJson(Json::Value const& jvParams)

saSendMax.emplace();
if (!amountFromJsonNoThrow(*saSendMax, jvParams[jss::send_max]) ||
(saSendMax->getAsset().isXRP() &&
(isXRP(saSendMax->getCurrency()) &&
saSendMax->getIssuer().isNonZero()) ||
(saSendMax->getAsset() == badCurrency()) ||
(saSendMax->getCurrency() == badCurrency()) ||
(*saSendMax <= beast::zero &&
*saSendMax != STAmount(saSendMax->issue(), 1u, 0, true)))
{
Expand Down Expand Up @@ -396,7 +396,7 @@ PathRequest::parseJson(Json::Value const& jvParams)
if (saSendMax)
{
// If the currencies don't match, ignore the source currency.
if (srcCurrencyID == saSendMax->getAsset())
if (srcCurrencyID == saSendMax->getCurrency())
{
// If neither is the source and they are not equal, then the
// source issuer is illegal.
Expand Down Expand Up @@ -509,7 +509,7 @@ PathRequest::findPaths(
bool const sameAccount = *raSrcAccount == *raDstAccount;
for (auto const& c : currencies)
{
if (!sameAccount || c != saDstAmount.getAsset())
if (!sameAccount || c != saDstAmount.getCurrency())
{
if (sourceCurrencies.size() >= RPC::Tuning::max_auto_src_cur)
return false;
Expand All @@ -532,7 +532,7 @@ PathRequest::findPaths(
auto& pathfinder = getPathFinder(
cache,
currency_map,
issue.asset(),
issue.getCurrency(),
dst_amount,
level,
continueCallback);
Expand All @@ -555,14 +555,14 @@ PathRequest::findPaths(
if (!isXRP(issue.account()))
return issue.account();

if (isXRP(issue.asset()))
if (isXRP(issue.getCurrency()))
return xrpAccount();

return *raSrcAccount;
}();

STAmount saMaxAmount = saSendMax.value_or(
STAmount({issue.asset(), sourceAccount}, 1u, 0, true));
STAmount({issue.getCurrency(), sourceAccount}, 1u, 0, true));

JLOG(m_journal.debug())
<< iIdentifier << " Paths found, calling rippleCalc";
Expand Down
44 changes: 24 additions & 20 deletions src/ripple/app/paths/Pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ Pathfinder::findPaths(
}

if (mSrcAccount == mDstAccount && mDstAccount == mEffectiveDst &&
mSrcCurrency == mDstAmount.getAsset())
mSrcCurrency == mDstAmount.getCurrency())
{
// No need to send to same account with same currency.
JLOG(j_.debug()) << "Tried to send to same issuer";
mLedger.reset();
return false;
}

if (mSrcAccount == mEffectiveDst && mSrcCurrency == mDstAmount.getAsset())
if (mSrcAccount == mEffectiveDst &&
mSrcCurrency == mDstAmount.getCurrency())
{
// Default path might work, but any path would loop
return true;
Expand Down Expand Up @@ -246,7 +247,7 @@ Pathfinder::findPaths(
}

bool bSrcXrp = isXRP(mSrcCurrency);
bool bDstXrp = isXRP(mDstAmount.getAsset());
bool bDstXrp = isXRP(mDstAmount.getCurrency());

if (!mLedger->exists(keylet::account(mSrcAccount)))
{
Expand Down Expand Up @@ -303,7 +304,7 @@ Pathfinder::findPaths(
JLOG(j_.debug()) << "non-XRP to XRP payment";
paymentType = pt_nonXRP_to_XRP;
}
else if (mSrcCurrency == mDstAmount.getAsset())
else if (mSrcCurrency == mDstAmount.getCurrency())
{
// non-XRP -> non-XRP - Same currency
JLOG(j_.debug()) << "non-XRP to non-XRP - same currency";
Expand Down Expand Up @@ -695,8 +696,8 @@ Pathfinder::getBestPaths(
bool
Pathfinder::issueMatchesOrigin(Issue const& issue)
{
bool matchingCurrency = (issue.asset() == mSrcCurrency);
bool matchingAccount = isXRP(issue.asset()) ||
bool matchingCurrency = (issue.getCurrency() == mSrcCurrency);
bool matchingAccount = isXRP(issue.getCurrency()) ||
(mSrcIssuer && issue.account() == mSrcIssuer) ||
issue.account() == mSrcAccount;

Expand Down Expand Up @@ -739,7 +740,7 @@ Pathfinder::getPathsOut(
{
for (auto const& rspEntry : *lines)
{
if (currency != rspEntry.getLimit().getAsset())
if (currency != rspEntry.getLimit().getCurrency())
{
}
else if (
Expand Down Expand Up @@ -976,7 +977,7 @@ Pathfinder::addLink(
bool const bRequireAuth(
sleEnd->getFieldU32(sfFlags) & lsfRequireAuth);
bool const bIsEndCurrency(
uEndCurrency == mDstAmount.getAsset());
uEndCurrency == mDstAmount.getCurrency());
bool const bIsNoRippleOut(isNoRippleOut(currentPath));
bool const bDestOnly(addFlags & afAC_LAST);

Expand Down Expand Up @@ -1010,7 +1011,7 @@ Pathfinder::addLink(
continue;
}

if ((uEndCurrency == rs.getLimit().getAsset()) &&
if ((uEndCurrency == rs.getLimit().getCurrency()) &&
!currentPath.hasSeen(acct, uEndCurrency, acct))
{
// path is for correct currency and has not been
Expand All @@ -1029,7 +1030,7 @@ Pathfinder::addLink(
else if (bToDestination)
{
// destination is always worth trying
if (uEndCurrency == mDstAmount.getAsset())
if (uEndCurrency == mDstAmount.getCurrency())
{
// this is a complete path
if (!currentPath.empty())
Expand Down Expand Up @@ -1141,13 +1142,16 @@ Pathfinder::addLink(
if (continueCallback && !continueCallback())
return;
if (!currentPath.hasSeen(
xrpAccount(), book.out.asset(), book.out.account()) &&
xrpAccount(),
book.out.getCurrency(),
book.out.account()) &&
!issueMatchesOrigin(book.out) &&
(!bDestOnly || (book.out.asset() == mDstAmount.getAsset())))
(!bDestOnly ||
(book.out.getCurrency() == mDstAmount.getCurrency())))
{
STPath newPath(currentPath);

if (book.out.asset().isXRP())
if (isXRP(book.out.getCurrency()))
{ // to XRP

// add the order book itself
Expand All @@ -1157,7 +1161,7 @@ Pathfinder::addLink(
xrpCurrency(),
xrpAccount());

if (mDstAmount.getAsset().isXRP())
if (isXRP(mDstAmount.getCurrency()))
{
// destination is XRP, add account and path is
// complete
Expand All @@ -1171,7 +1175,7 @@ Pathfinder::addLink(
}
else if (!currentPath.hasSeen(
book.out.account(),
book.out.asset(),
book.out.getCurrency(),
book.out.account()))
{
// Don't want the book if we've already seen the issuer
Expand All @@ -1185,7 +1189,7 @@ Pathfinder::addLink(
STPathElement::typeCurrency |
STPathElement::typeIssuer,
xrpAccount(),
book.out.asset(),
book.out.getCurrency(),
book.out.account());
}
else
Expand All @@ -1195,19 +1199,19 @@ Pathfinder::addLink(
STPathElement::typeCurrency |
STPathElement::typeIssuer,
xrpAccount(),
book.out.asset(),
book.out.getCurrency(),
book.out.account());
}

if (hasEffectiveDestination &&
book.out.account() == mDstAccount &&
book.out.asset() == mDstAmount.getAsset())
book.out.getCurrency() == mDstAmount.getCurrency())
{
// We skipped a required issuer
}
else if (
book.out.account() == mEffectiveDst &&
book.out.asset() == mDstAmount.getAsset())
book.out.getCurrency() == mDstAmount.getCurrency())
{ // with the destination account, this path is
// complete
JLOG(j_.trace())
Expand All @@ -1223,7 +1227,7 @@ Pathfinder::addLink(
STPathElement(
STPathElement::typeAccount,
book.out.account(),
book.out.asset(),
book.out.getCurrency(),
book.out.account()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/paths/RippleCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RippleCalc::rippleCalculate(

auto const sendMax = [&]() -> std::optional<STAmount> {
if (saMaxAmountReq >= beast::zero ||
saMaxAmountReq.getAsset() != saDstAmountReq.getAsset() ||
saMaxAmountReq.getCurrency() != saDstAmountReq.getCurrency() ||
saMaxAmountReq.getIssuer() != uSrcAccountID)
{
return saMaxAmountReq;
Expand Down
17 changes: 9 additions & 8 deletions src/ripple/app/paths/impl/BookStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class BookStep : public StepImp<TIn, TOut, BookStep<TIn, TOut, TDerived>>
ostr << name << ": "
<< "\ninIss: " << book_.in.account()
<< "\noutIss: " << book_.out.account()
<< "\ninCur: " << book_.in.asset()
<< "\noutCur: " << book_.out.asset();
<< "\ninCur: " << book_.in.getCurrency()
<< "\noutCur: " << book_.out.getCurrency();
return ostr.str();
}

Expand Down Expand Up @@ -681,7 +681,7 @@ BookStep<TIn, TOut, TDerived>::forEachOffer(

// Make sure offer owner has authorization to own IOUs from issuer.
// An account can always own XRP or their own IOUs.
if (flowCross && (!isXRP(offer.issueIn().asset())) &&
if (flowCross && (!isXRP(offer.issueIn().getCurrency())) &&
(offer.owner() != offer.issueIn().account()))
{
auto const& issuerID = offer.issueIn().account();
Expand All @@ -693,8 +693,8 @@ BookStep<TIn, TOut, TDerived>::forEachOffer(
auto const authFlag =
issuerID > ownerID ? lsfHighAuth : lsfLowAuth;

auto const line = afView.read(
keylet::line(ownerID, issuerID, offer.issueIn().asset()));
auto const line = afView.read(keylet::line(
ownerID, issuerID, offer.issueIn().getCurrency()));

if (!line || (((*line)[sfFlags] & authFlag) == 0))
{
Expand Down Expand Up @@ -1270,7 +1270,8 @@ BookStep<TIn, TOut, TDerived>::check(StrandContext const& ctx) const
auto const& view = ctx.view;
auto const& cur = book_.in.account();

auto sle = view.read(keylet::line(*prev, cur, book_.in.asset()));
auto sle =
view.read(keylet::line(*prev, cur, book_.in.getCurrency()));
if (!sle)
return terNO_LINE;
if ((*sle)[sfFlags] &
Expand Down Expand Up @@ -1299,8 +1300,8 @@ equalHelper(Step const& step, ripple::Book const& book)
bool
bookStepEqual(Step const& step, ripple::Book const& book)
{
bool const inXRP = isXRP(book.in.asset());
bool const outXRP = isXRP(book.out.asset());
bool const inXRP = isXRP(book.in.getCurrency());
bool const outXRP = isXRP(book.out.getCurrency());
if (inXRP && outXRP)
{
assert(0);
Expand Down
Loading

0 comments on commit 9ff0841

Please sign in to comment.