Skip to content

Commit

Permalink
Address reviewer's feedback
Browse files Browse the repository at this point in the history
* Add assetFromJson, mptIssueFromJson
* Minor refactoring
  • Loading branch information
gregtatcam committed Oct 18, 2024
1 parent fe6fa60 commit f4bc120
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ to_string(Asset const& asset);
bool
validJSONAsset(Json::Value const& jv);

Asset
assetFromJson(Json::Value const& jv);

} // namespace ripple

#endif // RIPPLE_PROTOCOL_ASSET_H_INCLUDED
3 changes: 3 additions & 0 deletions include/xrpl/protocol/MPTIssue.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ to_json(MPTIssue const& mptIssue);
std::string
to_string(MPTIssue const& mptIssue);

MPTIssue
mptIssueFromJson(Json::Value const& jv);

} // namespace ripple

#endif // RIPPLE_PROTOCOL_MPTISSUE_H_INCLUDED
2 changes: 1 addition & 1 deletion include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ TRANSACTION(ttMPTOKEN_ISSUANCE_DESTROY, 55, MPTokenIssuanceDestroy, ({
{sfMPTokenIssuanceID, soeREQUIRED},
}))

/** This transaction type sets a MPTokensIssuance instance */
/** This transaction type sets flags on a MPTokensIssuance instance */
TRANSACTION(ttMPTOKEN_ISSUANCE_SET, 56, MPTokenIssuanceSet, ({
{sfMPTokenIssuanceID, soeREQUIRED},
{sfMPTokenHolder, soeOPTIONAL},
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ JSS(AssetPrice); // in: Oracle
JSS(AuthAccount); // in: AMM Auction Slot
JSS(AuthAccounts); // in: AMM Auction Slot
JSS(BaseAsset); // in: Oracle
JSS(BidMax); // in: AMM Bid
JSS(BidMin); // in: AMM Bid
JSS(Bridge); // ledger type.
JSS(Check); // ledger type.
JSS(ClearFlag); // field.
Expand All @@ -76,8 +78,6 @@ JSS(LastLedgerSequence); // in: TransactionSign; field
JSS(LastUpdateTime); // field.
JSS(LedgerHashes); // ledger type.
JSS(LimitAmount); // field.
JSS(BidMax); // in: AMM Bid
JSS(BidMin); // in: AMM Bid
JSS(MPToken); // ledger type.
JSS(MPTokenIssuance); // ledger type.
JSS(NetworkID); // field.
Expand Down
12 changes: 12 additions & 0 deletions src/libxrpl/protocol/Asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ validJSONAsset(Json::Value const& jv)
return jv.isMember(jss::currency);
}

Asset
assetFromJson(Json::Value const& v)

Check warning on line 62 in src/libxrpl/protocol/Asset.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/Asset.cpp#L62

Added line #L62 was not covered by tests
{
if (!v.isMember(jss::currency) && !v.isMember(jss::mpt_issuance_id))
Throw<std::runtime_error>(

Check warning on line 65 in src/libxrpl/protocol/Asset.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/Asset.cpp#L65

Added line #L65 was not covered by tests
"assetFromJson must contain currency or mpt_issuance_id");

if (v.isMember(jss::currency))
return issueFromJson(v);
return mptIssueFromJson(v);

Check warning on line 70 in src/libxrpl/protocol/Asset.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/Asset.cpp#L69-L70

Added lines #L69 - L70 were not covered by tests
}

} // namespace ripple
6 changes: 6 additions & 0 deletions src/libxrpl/protocol/Issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ issueFromJson(Json::Value const& v)
"issueFromJson can only be specified with an 'object' Json value");
}

if (v.isMember(jss::mpt_issuance_id))
{
Throw<std::runtime_error>(

Check warning on line 100 in src/libxrpl/protocol/Issue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/Issue.cpp#L100

Added line #L100 was not covered by tests
"issueFromJson, Issue should not have mpt_issuance_id");
}

Json::Value const curStr = v[jss::currency];
Json::Value const issStr = v[jss::issuer];

Expand Down
35 changes: 34 additions & 1 deletion src/libxrpl/protocol/MPTIssue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
//==============================================================================

#include <xrpl/protocol/Indexes.h>
#include <xrpl/json/json_errors.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/jss.h>

Expand Down Expand Up @@ -71,4 +71,37 @@ to_string(MPTIssue const& mptIssue)
return to_string(mptIssue.getMptID());
}

MPTIssue
mptIssueFromJson(Json::Value const& v)

Check warning on line 75 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L75

Added line #L75 was not covered by tests
{
if (!v.isObject())
{
Throw<std::runtime_error>(

Check warning on line 79 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L79

Added line #L79 was not covered by tests
"mptIssueFromJson can only be specified with an 'object' Json "
"value");
}

if (v.isMember(jss::currency) || v.isMember(jss::issuer))
{
Throw<std::runtime_error>(

Check warning on line 86 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L86

Added line #L86 was not covered by tests
"mptIssueFromJson, MPTIssue should not have currency or issuer");
}

Json::Value const idStr = v[jss::mpt_issuance_id];

if (!idStr.isString())
{
Throw<Json::error>(

Check warning on line 94 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L94

Added line #L94 was not covered by tests
"mptIssueFromJson MPTID must be a string Json value");
}

MPTID id;

Check warning on line 98 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L98

Added line #L98 was not covered by tests
if (!id.parseHex(idStr.asString()))
{
Throw<Json::error>("mptIssueFromJson MPTID is invalid");

Check warning on line 101 in src/libxrpl/protocol/MPTIssue.cpp

View check run for this annotation

Codecov / codecov/patch

src/libxrpl/protocol/MPTIssue.cpp#L101

Added line #L101 was not covered by tests
}

return MPTIssue{id};
}

} // namespace ripple

0 comments on commit f4bc120

Please sign in to comment.