Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Mar 7, 2024
1 parent 1dd4b5b commit d31d8ab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/ripple/app/paths/PathRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,7 @@ PathRequest::parseJson(Json::Value const& jvParams)
for (auto const& c : jvSrcCurrencies)
{
// Mandatory currency or MPT
if ((!c.isMember(jss::currency) &&
!c.isMember(jss::mpt_issuance_id)) ||
(c.isMember(jss::currency) &&
c.isMember(jss::mpt_issuance_id)) ||
!c.isObject())
if (!validJSONAsset(c) || !c.isObject())
{
jvStatus = rpcError(rpcSRC_CUR_MALFORMED);
return PFR_PJ_INVALID;
Expand Down
11 changes: 8 additions & 3 deletions src/ripple/app/paths/impl/PaySteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ toStrand(
(deliver.account() == noAccount()))
return {temBAD_PATH, Strand{}};

if ((deliver.isMPT() && deliver.account() == beast::zero) ||
(sendMaxAsset && sendMaxAsset->isMPT() &&
sendMaxAsset->account() == beast::zero))
return {temBAD_PATH, Strand{}};

for (auto const& pe : path)
{
auto const t = pe.getNodeType();
Expand Down Expand Up @@ -230,6 +235,7 @@ toStrand(
return Issue{asset.issue().currency, src};
}();

// Currency or MPT
auto hasAsset = [](STPathElement const pe) {
return pe.getNodeType() & STPathElement::typeAsset;
};
Expand Down Expand Up @@ -266,11 +272,10 @@ toStrand(

{
// Note that for offer crossing (only) we do use an offer book
// even if all that is changing is the Issue.account.
// even if all that is changing is the Issue/MPTIssue.account.
STPathElement const& lastAsset =
*std::find_if(normPath.rbegin(), normPath.rend(), hasAsset);
if (lastAsset.hasCurrency() != deliver.isIssue() ||
lastAsset.getPathAsset() != deliver ||
if (lastAsset.getPathAsset() != deliver ||
(offerCrossing && lastAsset.getIssuerID() != deliver.account()))
{
normPath.emplace_back(std::nullopt, deliver, deliver.account());
Expand Down
3 changes: 1 addition & 2 deletions src/ripple/protocol/impl/Asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ Asset
assetFromJson(Json::Value const& jv)
{
Asset asset;
if ((!jv.isMember(jss::currency) && !jv.isMember(jss::mpt_issuance_id)) ||
(jv.isMember(jss::currency) && jv.isMember(jss::mpt_issuance_id)))
if (!validJSONAsset(jv))
Throw<std::runtime_error>("invalid Asset");

if (jv.isMember(jss::mpt_issuance_id))
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/rpc/handlers/BookOffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class AssetHelper
!takerField_.isMember(jss::mpt_issuance_id))
return RPC::missing_field_error(currencyName);

if (takerField_.isMember(jss::currency) &&
takerField_.isMember(jss::mpt_issuance_id))
if ((takerField_.isMember(jss::currency) &&
takerField_.isMember(jss::mpt_issuance_id)) ||
(takerField_.isMember(jss::mpt_issuance_id) &&
takerField_.isMember(jss::issuer)))
return RPC::invalid_field_error(currencyName);

auto const assetField = [&]() {
Expand Down

0 comments on commit d31d8ab

Please sign in to comment.