mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-03 17:35:51 +00:00
Add MPTIssue to STIssue (#5200)
Replace Issue in STIssue with Asset. STIssue with MPTIssue is only used in MPT tests. Will be used in Vault and in transactions with STIssue fields once MPT is integrated into DEX.
This commit is contained in:
committed by
GitHub
parent
eabca8439f
commit
5cd72f2431
@@ -21,7 +21,7 @@
|
||||
#define RIPPLE_PROTOCOL_STISSUE_H_INCLUDED
|
||||
|
||||
#include <xrpl/basics/CountedObject.h>
|
||||
#include <xrpl/protocol/Issue.h>
|
||||
#include <xrpl/protocol/Asset.h>
|
||||
#include <xrpl/protocol/SField.h>
|
||||
#include <xrpl/protocol/STBase.h>
|
||||
#include <xrpl/protocol/Serializer.h>
|
||||
@@ -31,31 +31,40 @@ namespace ripple {
|
||||
class STIssue final : public STBase, CountedObject<STIssue>
|
||||
{
|
||||
private:
|
||||
Issue issue_{xrpIssue()};
|
||||
Asset asset_{xrpIssue()};
|
||||
|
||||
public:
|
||||
using value_type = Issue;
|
||||
using value_type = Asset;
|
||||
|
||||
STIssue() = default;
|
||||
|
||||
explicit STIssue(SerialIter& sit, SField const& name);
|
||||
|
||||
explicit STIssue(SField const& name, Issue const& issue);
|
||||
template <AssetType A>
|
||||
explicit STIssue(SField const& name, A const& issue);
|
||||
|
||||
explicit STIssue(SField const& name);
|
||||
|
||||
Issue const&
|
||||
issue() const;
|
||||
template <ValidIssueType TIss>
|
||||
TIss const&
|
||||
get() const;
|
||||
|
||||
Issue const&
|
||||
template <ValidIssueType TIss>
|
||||
bool
|
||||
holds() const;
|
||||
|
||||
value_type const&
|
||||
value() const noexcept;
|
||||
|
||||
void
|
||||
setIssue(Issue const& issue);
|
||||
setIssue(Asset const& issue);
|
||||
|
||||
SerializedTypeID
|
||||
getSType() const override;
|
||||
|
||||
std::string
|
||||
getText() const override;
|
||||
|
||||
Json::Value getJson(JsonOptions) const override;
|
||||
|
||||
void
|
||||
@@ -67,6 +76,18 @@ public:
|
||||
bool
|
||||
isDefault() const override;
|
||||
|
||||
friend constexpr bool
|
||||
operator==(STIssue const& lhs, STIssue const& rhs);
|
||||
|
||||
friend constexpr std::weak_ordering
|
||||
operator<=>(STIssue const& lhs, STIssue const& rhs);
|
||||
|
||||
friend constexpr bool
|
||||
operator==(STIssue const& lhs, Asset const& rhs);
|
||||
|
||||
friend constexpr std::weak_ordering
|
||||
operator<=>(STIssue const& lhs, Asset const& rhs);
|
||||
|
||||
private:
|
||||
STBase*
|
||||
copy(std::size_t n, void* buf) const override;
|
||||
@@ -76,59 +97,72 @@ private:
|
||||
friend class detail::STVar;
|
||||
};
|
||||
|
||||
template <AssetType A>
|
||||
STIssue::STIssue(SField const& name, A const& asset)
|
||||
: STBase{name}, asset_{asset}
|
||||
{
|
||||
if (holds<Issue>() && !isConsistent(asset_.get<Issue>()))
|
||||
Throw<std::runtime_error>(
|
||||
"Invalid asset: currency and account native mismatch");
|
||||
}
|
||||
|
||||
STIssue
|
||||
issueFromJson(SField const& name, Json::Value const& v);
|
||||
|
||||
inline Issue const&
|
||||
STIssue::issue() const
|
||||
template <ValidIssueType TIss>
|
||||
bool
|
||||
STIssue::holds() const
|
||||
{
|
||||
return issue_;
|
||||
return asset_.holds<TIss>();
|
||||
}
|
||||
|
||||
inline Issue const&
|
||||
template <ValidIssueType TIss>
|
||||
TIss const&
|
||||
STIssue::get() const
|
||||
{
|
||||
if (!holds<TIss>(asset_))
|
||||
Throw<std::runtime_error>("Asset doesn't hold the requested issue");
|
||||
return std::get<TIss>(asset_);
|
||||
}
|
||||
|
||||
inline STIssue::value_type const&
|
||||
STIssue::value() const noexcept
|
||||
{
|
||||
return issue_;
|
||||
return asset_;
|
||||
}
|
||||
|
||||
inline void
|
||||
STIssue::setIssue(Issue const& issue)
|
||||
STIssue::setIssue(Asset const& asset)
|
||||
{
|
||||
if (isXRP(issue_.currency) != isXRP(issue_.account))
|
||||
if (holds<Issue>() && !isConsistent(asset_.get<Issue>()))
|
||||
Throw<std::runtime_error>(
|
||||
"invalid issue: currency and account native mismatch");
|
||||
"Invalid asset: currency and account native mismatch");
|
||||
|
||||
issue_ = issue;
|
||||
asset_ = asset;
|
||||
}
|
||||
|
||||
inline bool
|
||||
constexpr bool
|
||||
operator==(STIssue const& lhs, STIssue const& rhs)
|
||||
{
|
||||
return lhs.issue() == rhs.issue();
|
||||
return lhs.asset_ == rhs.asset_;
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(STIssue const& lhs, STIssue const& rhs)
|
||||
constexpr std::weak_ordering
|
||||
operator<=>(STIssue const& lhs, STIssue const& rhs)
|
||||
{
|
||||
return !operator==(lhs, rhs);
|
||||
return lhs.asset_ <=> rhs.asset_;
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator<(STIssue const& lhs, STIssue const& rhs)
|
||||
constexpr bool
|
||||
operator==(STIssue const& lhs, Asset const& rhs)
|
||||
{
|
||||
return lhs.issue() < rhs.issue();
|
||||
return lhs.asset_ == rhs;
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator==(STIssue const& lhs, Issue const& rhs)
|
||||
constexpr std::weak_ordering
|
||||
operator<=>(STIssue const& lhs, Asset const& rhs)
|
||||
{
|
||||
return lhs.issue() == rhs;
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator<(STIssue const& lhs, Issue const& rhs)
|
||||
{
|
||||
return lhs.issue() < rhs;
|
||||
return lhs.asset_ <=> rhs;
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user