Skip to content

Commit

Permalink
Merge branch 'develop' into feature/stissue/mpt-v1-var-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Oct 30, 2024
2 parents cb8b7f4 + 0d887ad commit 6b9ff1d
Show file tree
Hide file tree
Showing 38 changed files with 781 additions and 196 deletions.
2 changes: 1 addition & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ If you operate an XRP Ledger server, upgrade to version 2.0.0 by January 22, 202

- Switched to Unity builds to speed up Windows CI. [#4780](https://github.com/XRPLF/rippled/pull/4780)

- Clarified what makes concensus healthy in `FeeEscalation.md`. [#4729](https://github.com/XRPLF/rippled/pull/4729)
- Clarified what makes consensus healthy in `FeeEscalation.md`. [#4729](https://github.com/XRPLF/rippled/pull/4729)

- Removed a dependency on the <ranges> header for unit tests. [#4788](https://github.com/XRPLF/rippled/pull/4788)

Expand Down
2 changes: 1 addition & 1 deletion docs/build/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ direction.

```
apt update
apt install --yes curl git libssl-dev python3.10-dev python3-pip make g++-11
apt install --yes curl git libssl-dev python3.10-dev python3-pip make g++-11 libprotobuf-dev protobuf-compiler
curl --location --remote-name \
"https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1.tar.gz"
Expand Down
7 changes: 5 additions & 2 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ concept AssetType =

/* Asset is an abstraction of three different issue types: XRP, IOU, MPT.
* For historical reasons, two issue types XRP and IOU are wrapped in Issue
* type. Asset replaces Issue where any issue type is expected. For instance,
* STAmount replaces Issue with Asset to represent any issue amount.
* type. Many functions and classes there were first written for Issue
* have been rewritten for Asset.
*/
class Asset
{
Expand Down Expand Up @@ -194,6 +194,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
5 changes: 5 additions & 0 deletions include/xrpl/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@

namespace ripple {

template <typename A>
concept AssetType =
std::is_same_v<A, Asset> || std::is_convertible_v<A, Issue> ||
std::is_convertible_v<A, MPTIssue> || std::is_convertible_v<A, MPTID>;

// Internal form:
// 1: If amount is zero, then value is zero and offset is -100
// 2: Otherwise:
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ enum TEMcodes : TERUnderlyingType {
temARRAY_EMPTY,
temARRAY_TOO_LARGE,

temBAD_TRANSFER_FEE
temBAD_TRANSFER_FEE,
};

//------------------------------------------------------------------------------
Expand Down
22 changes: 8 additions & 14 deletions include/xrpl/protocol/TxFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,27 @@ constexpr std::uint32_t const tfTrustLine = 0x00000004;
constexpr std::uint32_t const tfTransferable = 0x00000008;

// MPTokenIssuanceCreate flags:
// NOTE - there is intentionally no flag here for lsfMPTLocked, which this transaction cannot mutate.
// NOTE - there is intentionally no flag here for lsfMPTLocked, which this transaction cannot mutate.
constexpr std::uint32_t const tfMPTCanLock = lsfMPTCanLock;
constexpr std::uint32_t const tfMPTRequireAuth = lsfMPTRequireAuth;
constexpr std::uint32_t const tfMPTCanEscrow = lsfMPTCanEscrow;
constexpr std::uint32_t const tfMPTCanTrade = lsfMPTCanTrade;
constexpr std::uint32_t const tfMPTCanTransfer = lsfMPTCanTransfer;
constexpr std::uint32_t const tfMPTCanClawback = lsfMPTCanClawback;
constexpr std::uint32_t const tfMPTokenIssuanceCreateMask =
~(tfUniversal | tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade | tfMPTCanTransfer | tfMPTCanClawback);

// MPTokenAuthorize flags:
constexpr std::uint32_t const tfMPTUnauthorize = 0x00000001;
constexpr std::uint32_t const tfMPTokenAuthorizeMask = ~(tfUniversal | tfMPTUnauthorize);

// MPTokenIssuanceSet flags:
constexpr std::uint32_t const tfMPTLock = 0x00000001;
constexpr std::uint32_t const tfMPTUnlock = 0x00000002;
constexpr std::uint32_t const tfMPTokenIssuanceSetMask = ~(tfUniversal | tfMPTLock | tfMPTUnlock);

// MPTokenIssuanceDestroy flags:
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask = ~tfUniversal;

// Prior to fixRemoveNFTokenAutoTrustLine, transfer of an NFToken between
// accounts allowed a TrustLine to be added to the issuer of that token
Expand Down Expand Up @@ -203,19 +210,6 @@ constexpr std::uint32_t tfDepositMask = ~(tfUniversal | tfDepositSubTx);
// BridgeModify flags:
constexpr std::uint32_t tfClearAccountCreateAmount = 0x00010000;
constexpr std::uint32_t tfBridgeModifyMask = ~(tfUniversal | tfClearAccountCreateAmount);

// MPTokenIssuanceCreate flags:
constexpr std::uint32_t const tfMPTokenIssuanceCreateMask =
~(tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow | tfMPTCanTrade | tfMPTCanTransfer | tfMPTCanClawback | tfUniversal);

// MPTokenIssuanceDestroy flags:
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask = ~tfUniversal;

// MPTokenAuthorize flags:
constexpr std::uint32_t const tfMPTokenAuthorizeMask = ~(tfMPTUnauthorize | tfUniversal);

// MPTokenIssuanceSet flags:
constexpr std::uint32_t const tfMPTokenIssuanceSetMask = ~(tfMPTLock | tfMPTUnlock | tfUniversal);
// clang-format on

} // namespace ripple
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (NFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (InnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (EnforceNFTokenTrustline, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ TYPED_SFIELD(sfUnauthorize, ACCOUNT, 6)
TYPED_SFIELD(sfRegularKey, ACCOUNT, 8)
TYPED_SFIELD(sfNFTokenMinter, ACCOUNT, 9)
TYPED_SFIELD(sfEmitCallback, ACCOUNT, 10)
TYPED_SFIELD(sfMPTokenHolder, ACCOUNT, 11)
TYPED_SFIELD(sfHolder, ACCOUNT, 11)

// account (uncommon)
TYPED_SFIELD(sfHookAccount, ACCOUNT, 16)
Expand Down
8 changes: 4 additions & 4 deletions include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ TRANSACTION(ttNFTOKEN_ACCEPT_OFFER, 29, NFTokenAcceptOffer, ({
/** This transaction claws back issued tokens. */
TRANSACTION(ttCLAWBACK, 30, Clawback, ({
{sfAmount, soeREQUIRED, soeMPTSupported},
{sfMPTokenHolder, soeOPTIONAL},
{sfHolder, soeOPTIONAL},
}))

/** This transaction type creates an AMM instance */
Expand Down Expand Up @@ -400,16 +400,16 @@ TRANSACTION(ttMPTOKEN_ISSUANCE_DESTROY, 55, MPTokenIssuanceDestroy, ({
{sfMPTokenIssuanceID, soeREQUIRED},
}))

/** This transaction type sets a MPTokensIssuance instance */
/** This transaction type sets flags on a MPTokensIssuance or MPToken instance */
TRANSACTION(ttMPTOKEN_ISSUANCE_SET, 56, MPTokenIssuanceSet, ({
{sfMPTokenIssuanceID, soeREQUIRED},
{sfMPTokenHolder, soeOPTIONAL},
{sfHolder, soeOPTIONAL},
}))

/** This transaction type authorizes a MPToken instance */
TRANSACTION(ttMPTOKEN_AUTHORIZE, 57, MPTokenAuthorize, ({
{sfMPTokenIssuanceID, soeREQUIRED},
{sfMPTokenHolder, soeOPTIONAL},
{sfHolder, soeOPTIONAL},
}))

/** This system-generated transaction type is used to update the status of the various amendments.
Expand Down
2 changes: 2 additions & 0 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 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)
{
if (!v.isMember(jss::currency) && !v.isMember(jss::mpt_issuance_id))
Throw<std::runtime_error>(
"assetFromJson must contain currency or mpt_issuance_id");

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

} // 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>(
"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)
{
if (!v.isObject())
{
Throw<std::runtime_error>(
"mptIssueFromJson can only be specified with an 'object' Json "
"value");
}

if (v.isMember(jss::currency) || v.isMember(jss::issuer))
{
Throw<std::runtime_error>(
"mptIssueFromJson, MPTIssue should not have currency or issuer");
}

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

if (!idStr.isString())
{
Throw<Json::error>(
"mptIssueFromJson MPTID must be a string Json value");
}

MPTID id;
if (!id.parseHex(idStr.asString()))
{
Throw<Json::error>("mptIssueFromJson MPTID is invalid");
}

return MPTIssue{id};
}

} // namespace ripple
2 changes: 1 addition & 1 deletion src/libxrpl/protocol/STAmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ IOUAmount
STAmount::iou() const
{
if (native() || !holds<Issue>())
Throw<std::logic_error>("Cannot return native STAmount as IOUAmount");
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");

auto mantissa = static_cast<std::int64_t>(mValue);
auto exponent = mOffset;
Expand Down
Loading

0 comments on commit 6b9ff1d

Please sign in to comment.