From fff9be79ba17c65cbaa6eee4cf79e4431635ce22 Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Thu, 2 Jan 2025 12:24:00 -0500 Subject: [PATCH] Make currency/account private in Issue and add getters/setters. Change Issue to IOUIssue Change Asset to Issue issueFromJson/assetFromJson refactoring Update ifdef --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- RELEASENOTES.md | 2 +- cmake/RippledCore.cmake | 3 +- include/xrpl/basics/Resolver.h | 6 +- include/xrpl/protocol/AMMCore.h | 24 +- include/xrpl/protocol/AmountConversions.h | 18 +- include/xrpl/protocol/Asset.h | 282 ------------------ include/xrpl/protocol/Book.h | 40 +-- include/xrpl/protocol/Concepts.h | 12 +- include/xrpl/protocol/IOUIssue.h | 159 ++++++++++ include/xrpl/protocol/Indexes.h | 6 +- include/xrpl/protocol/Issue.h | 271 +++++++++++++---- .../protocol/{PathAsset.h => PathIssue.h} | 54 ++-- include/xrpl/protocol/Rate.h | 4 +- include/xrpl/protocol/STAmount.h | 100 +++---- include/xrpl/protocol/STIssue.h | 28 +- include/xrpl/protocol/STPathSet.h | 28 +- include/xrpl/protocol/STXChainBridge.h | 20 +- include/xrpl/protocol/XChainAttestations.h | 2 +- include/xrpl/protocol/XRPIssue.h | 154 ++++++++++ src/libxrpl/protocol/AMMCore.cpp | 29 +- src/libxrpl/protocol/Asset.cpp | 104 ------- src/libxrpl/protocol/IOUIssue.cpp | 152 ++++++++++ src/libxrpl/protocol/Indexes.cpp | 55 ++-- src/libxrpl/protocol/Issue.cpp | 137 +++------ .../protocol/{PathAsset.cpp => PathIssue.cpp} | 6 +- src/libxrpl/protocol/Quality.cpp | 4 +- src/libxrpl/protocol/Rate2.cpp | 9 +- src/libxrpl/protocol/STAmount.cpp | 90 +++--- src/libxrpl/protocol/STIssue.cpp | 18 +- src/libxrpl/protocol/STParsedJSON.cpp | 14 +- src/libxrpl/protocol/STPathSet.cpp | 12 +- src/libxrpl/protocol/STXChainBridge.cpp | 10 +- src/libxrpl/protocol/TER.cpp | 2 +- src/test/app/AMMCalc_test.cpp | 6 +- src/test/app/AMMClawback_test.cpp | 20 +- src/test/app/AMMExtended_test.cpp | 18 +- src/test/app/AMM_test.cpp | 30 +- src/test/app/Check_test.cpp | 4 +- src/test/app/Flow_test.cpp | 6 +- src/test/app/Freeze_test.cpp | 2 +- src/test/app/MPToken_test.cpp | 32 +- src/test/app/Offer_test.cpp | 26 +- src/test/app/Oracle_test.cpp | 8 +- src/test/app/Path_test.cpp | 2 +- src/test/app/PayStrand_test.cpp | 14 +- src/test/app/ReducedOffer_test.cpp | 2 +- src/test/app/SetAuth_test.cpp | 2 +- src/test/app/SetTrust_test.cpp | 3 +- src/test/app/Taker_test.cpp | 26 +- src/test/app/TheoreticalQuality_test.cpp | 2 +- src/test/app/XChain_test.cpp | 10 +- src/test/basics/Number_test.cpp | 2 +- src/test/consensus/Validations_test.cpp | 2 +- src/test/csf/Peer.h | 2 +- src/test/jtx/AMM.h | 38 +-- src/test/jtx/Env.h | 4 +- src/test/jtx/PathSet.h | 16 +- src/test/jtx/TestHelpers.h | 31 +- src/test/jtx/amount.h | 38 +-- src/test/jtx/impl/AMM.cpp | 24 +- src/test/jtx/impl/Env.cpp | 10 +- src/test/jtx/impl/TestHelpers.cpp | 46 ++- src/test/jtx/impl/amount.cpp | 11 +- src/test/jtx/impl/balance.cpp | 2 +- src/test/jtx/impl/paths.cpp | 16 +- src/test/jtx/impl/xchain_bridge.cpp | 10 +- src/test/jtx/paths.h | 6 +- src/test/jtx/xchain_bridge.h | 4 +- src/test/ledger/Invariants_test.cpp | 4 +- src/test/ledger/PaymentSandbox_test.cpp | 151 +++++++--- src/test/protocol/Issue_test.cpp | 176 +++++------ src/test/protocol/Quality_test.cpp | 3 +- src/test/protocol/STAmount_test.cpp | 17 +- src/test/protocol/STIssue_test.cpp | 30 +- src/test/protocol/STNumber_test.cpp | 2 +- src/test/rpc/AMMInfo_test.cpp | 12 +- src/test/rpc/Book_test.cpp | 2 +- src/test/rpc/OwnerInfo_test.cpp | 8 +- src/xrpld/app/ledger/OrderBookDB.cpp | 24 +- src/xrpld/app/ledger/OrderBookDB.h | 10 +- src/xrpld/app/misc/AMMHelpers.h | 4 +- src/xrpld/app/misc/AMMUtils.h | 22 +- src/xrpld/app/misc/MPTUtils.h | 6 +- src/xrpld/app/misc/detail/AMMHelpers.cpp | 4 +- src/xrpld/app/misc/detail/AMMUtils.cpp | 44 +-- src/xrpld/app/misc/detail/MPTUtils.cpp | 8 +- src/xrpld/app/paths/AMMLiquidity.h | 12 +- src/xrpld/app/paths/AMMOffer.h | 4 +- src/xrpld/app/paths/AccountCurrencies.cpp | 4 +- src/xrpld/app/paths/AccountCurrencies.h | 6 +- src/xrpld/app/paths/Credit.cpp | 4 +- src/xrpld/app/paths/Flow.cpp | 14 +- .../paths/{AssetCache.cpp => IssueCache.cpp} | 10 +- .../app/paths/{AssetCache.h => IssueCache.h} | 6 +- src/xrpld/app/paths/PathRequest.cpp | 63 ++-- src/xrpld/app/paths/PathRequest.h | 24 +- src/xrpld/app/paths/PathRequests.cpp | 12 +- src/xrpld/app/paths/PathRequests.h | 8 +- src/xrpld/app/paths/Pathfinder.cpp | 90 +++--- src/xrpld/app/paths/Pathfinder.h | 20 +- src/xrpld/app/paths/detail/AMMLiquidity.cpp | 6 +- src/xrpld/app/paths/detail/AMMOffer.cpp | 4 +- src/xrpld/app/paths/detail/AmountSpec.h | 6 +- src/xrpld/app/paths/detail/BookStep.cpp | 41 ++- src/xrpld/app/paths/detail/DirectStep.cpp | 14 +- src/xrpld/app/paths/detail/PathfinderUtils.h | 2 +- src/xrpld/app/paths/detail/PaySteps.cpp | 80 ++--- src/xrpld/app/paths/detail/Steps.h | 51 ++-- src/xrpld/app/paths/detail/StrandFlow.h | 2 +- .../app/paths/detail/XRPEndpointStep.cpp | 5 +- src/xrpld/app/tx/detail/AMMClawback.cpp | 8 +- src/xrpld/app/tx/detail/AMMCreate.cpp | 8 +- src/xrpld/app/tx/detail/AMMDeposit.cpp | 16 +- src/xrpld/app/tx/detail/AMMDeposit.h | 10 +- src/xrpld/app/tx/detail/AMMWithdraw.cpp | 21 +- src/xrpld/app/tx/detail/AMMWithdraw.h | 12 +- src/xrpld/app/tx/detail/CashCheck.cpp | 16 +- src/xrpld/app/tx/detail/Clawback.cpp | 11 +- src/xrpld/app/tx/detail/CreateCheck.cpp | 10 +- src/xrpld/app/tx/detail/CreateOffer.cpp | 24 +- src/xrpld/app/tx/detail/CreateOffer.h | 2 +- src/xrpld/app/tx/detail/InvariantCheck.cpp | 4 +- src/xrpld/app/tx/detail/Offer.h | 16 +- src/xrpld/app/tx/detail/OfferStream.cpp | 8 +- src/xrpld/app/tx/detail/Payment.cpp | 2 +- src/xrpld/app/tx/detail/SetTrust.cpp | 2 +- src/xrpld/app/tx/detail/Taker.cpp | 24 +- src/xrpld/app/tx/detail/Taker.h | 18 +- src/xrpld/app/tx/detail/XChainBridge.cpp | 9 +- src/xrpld/ledger/View.h | 32 +- src/xrpld/ledger/detail/View.cpp | 81 ++--- src/xrpld/rpc/detail/TransactionSign.cpp | 6 +- src/xrpld/rpc/handlers/AMMInfo.cpp | 14 +- src/xrpld/rpc/handlers/AccountLines.cpp | 2 +- src/xrpld/rpc/handlers/BookOffers.cpp | 16 +- src/xrpld/rpc/handlers/GatewayBalances.cpp | 2 +- src/xrpld/rpc/handlers/LedgerEntry.cpp | 12 +- src/xrpld/rpc/handlers/Subscribe.cpp | 24 +- src/xrpld/rpc/handlers/Unsubscribe.cpp | 22 +- 140 files changed, 2051 insertions(+), 1728 deletions(-) delete mode 100644 include/xrpl/protocol/Asset.h create mode 100644 include/xrpl/protocol/IOUIssue.h rename include/xrpl/protocol/{PathAsset.h => PathIssue.h} (69%) create mode 100644 include/xrpl/protocol/XRPIssue.h delete mode 100644 src/libxrpl/protocol/Asset.cpp create mode 100644 src/libxrpl/protocol/IOUIssue.cpp rename src/libxrpl/protocol/{PathAsset.cpp => PathIssue.cpp} (91%) rename src/xrpld/app/paths/{AssetCache.cpp => IssueCache.cpp} (96%) rename src/xrpld/app/paths/{AssetCache.h => IssueCache.h} (97%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index e2df996005d..2ca88769de0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,7 +8,7 @@ assignees: '' --- -## Issue Description +## IOUIssue Description ## Steps to Reproduce diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c6e8266e348..2a1e4138776 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -881,7 +881,7 @@ On supported platforms, see the [instructions on installing or updating `rippled ### Code Cleanup and Testing -* Replace compare() with the three-way comparison operator in base_uint, Issue and Book by @drlongle in https://github.com/XRPLF/rippled/pull/4411 +* Replace compare() with the three-way comparison operator in base_uint, IOUIssue and Book by @drlongle in https://github.com/XRPLF/rippled/pull/4411 * Rectify the import paths of boost::function_output_iterator by @ckeshava in https://github.com/XRPLF/rippled/pull/4293 * Expand Linux test matrix by @thejohnfreeman in https://github.com/XRPLF/rippled/pull/4454 * Add patched recipe for SOCI by @thejohnfreeman in https://github.com/XRPLF/rippled/pull/4510 diff --git a/cmake/RippledCore.cmake b/cmake/RippledCore.cmake index c37971befdb..ec0c44ce779 100644 --- a/cmake/RippledCore.cmake +++ b/cmake/RippledCore.cmake @@ -159,7 +159,8 @@ target_link_libraries(xrpl.libxrpl ) if(xrpld) - add_executable(rippled) + add_executable(rippled + ../include/xrpl/protocol/Issue.h) if(unity) set_target_properties(rippled PROPERTIES UNITY_BUILD ON) endif() diff --git a/include/xrpl/basics/Resolver.h b/include/xrpl/basics/Resolver.h index 6cba352e0a0..ca613301e63 100644 --- a/include/xrpl/basics/Resolver.h +++ b/include/xrpl/basics/Resolver.h @@ -35,15 +35,15 @@ class Resolver virtual ~Resolver() = 0; - /** Issue an asynchronous stop request. */ + /** IOUIssue an asynchronous stop request. */ virtual void stop_async() = 0; - /** Issue a synchronous stop request. */ + /** IOUIssue a synchronous stop request. */ virtual void stop() = 0; - /** Issue a synchronous start request. */ + /** IOUIssue a synchronous start request. */ virtual void start() = 0; diff --git a/include/xrpl/protocol/AMMCore.h b/include/xrpl/protocol/AMMCore.h index 565316b7429..c17042636ef 100644 --- a/include/xrpl/protocol/AMMCore.h +++ b/include/xrpl/protocol/AMMCore.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -59,14 +59,14 @@ ammAccountID( /** Calculate Liquidity Provider Token (LPT) Currency. */ Currency -ammLPTCurrency(Asset const& asset1, Asset const& asset2); +ammLPTCurrency(Issue const& asset1, Issue const& asset2); -/** Calculate LPT Issue from AMM asset pair. +/** Calculate LPT IOUIssue from AMM asset pair. */ -Issue +IOUIssue ammLPTIssue( - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, AccountID const& ammAccountID); /** Validate the amount. @@ -77,19 +77,19 @@ ammLPTIssue( NotTEC invalidAMMAmount( STAmount const& amount, - std::optional> const& pair = std::nullopt, + std::optional> const& pair = std::nullopt, bool validZero = false); NotTEC invalidAMMAsset( - Asset const& issue, - std::optional> const& pair = std::nullopt); + Issue const& issue, + std::optional> const& pair = std::nullopt); NotTEC invalidAMMAssetPair( - Asset const& issue1, - Asset const& issue2, - std::optional> const& pair = std::nullopt); + Issue const& issue1, + Issue const& issue2, + std::optional> const& pair = std::nullopt); /** Get time slot of the auction slot. */ diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index 5fe84717e1b..3c9f4013fb5 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -30,9 +30,9 @@ namespace ripple { inline STAmount -toSTAmount(IOUAmount const& iou, Asset const& asset) +toSTAmount(IOUAmount const& iou, Issue const& asset) { - XRPL_ASSERT(asset.holds(), "ripple::toSTAmount : is Issue"); + XRPL_ASSERT(asset.holds(), "ripple::toSTAmount : is Issue"); bool const isNeg = iou.signum() < 0; std::uint64_t const umant = isNeg ? -iou.mantissa() : iou.mantissa(); return STAmount(asset, umant, iou.exponent(), isNeg, STAmount::unchecked()); @@ -53,7 +53,7 @@ toSTAmount(XRPAmount const& xrp) } inline STAmount -toSTAmount(XRPAmount const& xrp, Asset const& asset) +toSTAmount(XRPAmount const& xrp, Issue const& asset) { XRPL_ASSERT(isXRP(asset), "ripple::toSTAmount : is XRP"); return toSTAmount(xrp); @@ -66,7 +66,7 @@ toSTAmount(MPTAmount const& mpt) } inline STAmount -toSTAmount(MPTAmount const& mpt, Asset const& asset) +toSTAmount(MPTAmount const& mpt, Issue const& asset) { XRPL_ASSERT(asset.holds(), "ripple::toSTAmount : is MPT"); return STAmount(mpt, asset.get()); @@ -163,7 +163,7 @@ toAmount(MPTAmount const& amt) template T toAmount( - Asset const& asset, + Issue const& asset, Number const& n, Number::rounding_mode mode = Number::getround()) { @@ -192,7 +192,7 @@ toAmount( template T -toMaxAmount(Asset const& asset) +toMaxAmount(Issue const& asset) { if constexpr (std::is_same_v) return IOUAmount(STAmount::cMaxValue, STAmount::cMaxOffset); @@ -204,7 +204,7 @@ toMaxAmount(Asset const& asset) { return std::visit( [](TIss const& issue_) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { if (isXRP(issue_)) return STAmount( @@ -227,7 +227,7 @@ toMaxAmount(Asset const& asset) inline STAmount toSTAmount( - Asset const& asset, + Issue const& asset, Number const& n, Number::rounding_mode mode = Number::getround()) { @@ -235,7 +235,7 @@ toSTAmount( } template -Asset +Issue getAsset(T const& amt) { if constexpr (std::is_same_v) diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h deleted file mode 100644 index c4a528af35b..00000000000 --- a/include/xrpl/protocol/Asset.h +++ /dev/null @@ -1,282 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2024 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef RIPPLE_PROTOCOL_ASSET_H_INCLUDED -#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED - -#include -#include -#include -#include - -namespace ripple { - -template - requires( - std::is_same_v || std::is_same_v || - std::is_same_v) -struct AmountType -{ - using amount_type = T; -}; - -/* 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. Many functions and classes there were first written for Issue - * have been rewritten for Asset. - */ -class Asset -{ -public: - using value_type = std::variant; - -private: - value_type issue_; - -public: - Asset() = default; - - /** Conversions to Asset are implicit and conversions to specific issue - * type are explicit. This design facilitates the use of Asset. - */ - Asset(Issue const& issue) : issue_(issue) - { - } - - Asset(MPTIssue const& mptIssue) : issue_(mptIssue) - { - } - - Asset(MPTID const& issuanceID) : issue_(MPTIssue{issuanceID}) - { - } - - explicit - operator Issue() const; - - explicit - operator MPTIssue() const; - - AccountID const& - getIssuer() const; - - template - constexpr TIss const& - get() const; - - template - TIss& - get(); - - template - constexpr bool - holds() const; - - std::string - getText() const; - - constexpr value_type const& - value() const; - - void - setJson(Json::Value& jv) const; - - bool - native() const - { - return holds() && get().native(); - } - - std::variant< - AmountType, - AmountType, - AmountType> - getAmountType() const; - - friend constexpr bool - operator==(Asset const& lhs, Asset const& rhs); - - friend constexpr std::weak_ordering - operator<=>(Asset const& lhs, Asset const& rhs); - - friend constexpr bool - operator==(Currency const& lhs, Asset const& rhs); - - /** Return true if both assets refer to the same currency (regardless of - * issuer) or MPT issuance. Otherwise return false. - */ - friend constexpr bool - equalTokens(Asset const& lhs, Asset const& rhs); -}; - -template -constexpr bool -Asset::holds() const -{ - return std::holds_alternative(issue_); -} - -template -constexpr TIss const& -Asset::get() const -{ - if (!std::holds_alternative(issue_)) - Throw("Asset is not a requested issue"); - return std::get(issue_); -} - -template -TIss& -Asset::get() -{ - if (!std::holds_alternative(issue_)) - Throw("Asset is not a requested issue"); - return std::get(issue_); -} - -constexpr Asset::value_type const& -Asset::value() const -{ - return issue_; -} - -constexpr bool -operator==(Asset const& lhs, Asset const& rhs) -{ - return std::visit( - [&]( - TLhs const& issLhs, TRhs const& issRhs) { - if constexpr (std::is_same_v) - return issLhs == issRhs; - else - return false; - }, - lhs.issue_, - rhs.issue_); -} - -constexpr std::weak_ordering -operator<=>(Asset const& lhs, Asset const& rhs) -{ - return std::visit( - []( - TLhs const& lhs_, TRhs const& rhs_) { - if constexpr (std::is_same_v) - return std::weak_ordering(lhs_ <=> rhs_); - else if constexpr ( - std::is_same_v && std::is_same_v) - return std::weak_ordering::greater; - else - return std::weak_ordering::less; - }, - lhs.issue_, - rhs.issue_); -} - -constexpr bool -operator==(Currency const& lhs, Asset const& rhs) -{ - return rhs.holds() && rhs.get().currency == lhs; -} - -constexpr bool -equalTokens(Asset const& lhs, Asset const& rhs) -{ - return std::visit( - [&]( - TLhs const& issLhs, TRhs const& issRhs) { - if constexpr ( - std::is_same_v && std::is_same_v) - return issLhs.currency == issRhs.currency; - else if constexpr ( - std::is_same_v && - std::is_same_v) - return issLhs.getMptID() == issRhs.getMptID(); - else - return false; - }, - lhs.issue_, - rhs.issue_); -} - -inline bool -isXRP(Asset const& asset) -{ - return asset.native(); -} - -std::string -to_string(Asset const& asset); - -bool -validJSONAsset(Json::Value const& jv); - -Asset -assetFromJson(Json::Value const& jv); - -Json::Value -to_json(Asset const& asset); - -inline bool -isConsistent(Asset const& issue) -{ - return std::visit( - [&](TIss const& issue_) { - if constexpr (std::is_same_v) - return isConsistent(issue_); - else - return true; - }, - issue.value()); -} - -inline bool -validAsset(Asset const& issue) -{ - return std::visit( - [&](TIss const& issue_) { - if constexpr (std::is_same_v) - return isConsistent(issue_) && issue_.currency != badCurrency(); - else - return true; - }, - issue.value()); -} - -template -void -hash_append(Hasher& h, Asset const& r) -{ - using beast::hash_append; - std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - hash_append(h, issue); - else - hash_append(h, issue); - }, - r.value()); -} - -std::ostream& -operator<<(std::ostream& os, Asset const& x); - -} // namespace ripple - -#endif // RIPPLE_PROTOCOL_ASSET_H_INCLUDED diff --git a/include/xrpl/protocol/Book.h b/include/xrpl/protocol/Book.h index e6b89e5c9b6..56a06689b2f 100644 --- a/include/xrpl/protocol/Book.h +++ b/include/xrpl/protocol/Book.h @@ -21,7 +21,7 @@ #define RIPPLE_PROTOCOL_BOOK_H_INCLUDED #include -#include +#include #include namespace ripple { @@ -33,14 +33,14 @@ namespace ripple { class Book final : public CountedObject { public: - Asset in; - Asset out; + Issue in; + Issue out; Book() { } - Book(Asset const& in_, Asset const& out_) : in(in_), out(out_) + Book(Issue const& in_, Issue const& out_) : in(in_), out(out_) { } }; @@ -92,7 +92,7 @@ operator<=>(Book const& lhs, Book const& rhs) namespace std { template <> -struct hash +struct hash : private boost::base_from_member, 0>, private boost::base_from_member, 1> { @@ -106,15 +106,15 @@ struct hash explicit hash() = default; using value_type = std::size_t; - using argument_type = ripple::Issue; + using argument_type = ripple::IOUIssue; value_type operator()(argument_type const& value) const { - value_type result(currency_hash_type::member(value.currency)); - if (!isXRP(value.currency)) + value_type result(currency_hash_type::member(value.getCurrency())); + if (!isXRP(value.getCurrency())) boost::hash_combine( - result, issuer_hash_type::member(value.account)); + result, issuer_hash_type::member(value.getIssuer())); return result; } }; @@ -141,7 +141,7 @@ struct hash }; template <> -struct hash +struct hash : private boost::base_from_member, 0>, private boost::base_from_member, 1>, private boost::base_from_member, 2> @@ -157,22 +157,22 @@ struct hash explicit hash() = default; using value_type = std::size_t; - using argument_type = ripple::Asset; + using argument_type = ripple::Issue; value_type operator()(argument_type const& issue) const { return std::visit( [&](TIss const& issue_) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { value_type result(currency_hash_type::member( - issue.get().currency)); - if (!isXRP(issue.get().currency)) + issue.get().getCurrency())); + if (!isXRP(issue.get().getCurrency())) boost::hash_combine( result, issuer_hash_type::member( - issue.get().account)); + issue.get().getIssuer())); return result; } else if constexpr (std::is_same_v) @@ -192,7 +192,7 @@ template <> struct hash { private: - using hasher = std::hash; + using hasher = std::hash; hasher m_hasher; @@ -218,11 +218,11 @@ struct hash namespace boost { template <> -struct hash : std::hash +struct hash : std::hash { explicit hash() = default; - using Base = std::hash; + using Base = std::hash; // VFALCO NOTE broken in vs2012 // using Base::Base; // inherit ctors }; @@ -236,11 +236,11 @@ struct hash : std::hash }; template <> -struct hash : std::hash +struct hash : std::hash { explicit hash() = default; - using Base = std::hash; + using Base = std::hash; }; template <> diff --git a/include/xrpl/protocol/Concepts.h b/include/xrpl/protocol/Concepts.h index d7b8cd527f8..ffd537196de 100644 --- a/include/xrpl/protocol/Concepts.h +++ b/include/xrpl/protocol/Concepts.h @@ -27,8 +27,8 @@ namespace ripple { class STAmount; -class Asset; class Issue; +class IOUIssue; class MPTIssue; class IOUAmount; class XRPAmount; @@ -41,18 +41,18 @@ std::is_same_v; template concept ValidIssueType = - std::is_same_v || std::is_same_v; + std::is_same_v || std::is_same_v; template -concept AssetType = std::is_same_v || - std::is_convertible_v || std::is_convertible_v; +concept IssueType = std::is_same_v || + std::is_convertible_v || std::is_convertible_v; template -concept StepAsset = ! +concept StepIssue = ! std::is_same_v; template -concept ValidPathAsset = +concept ValidPathIssue = (std::is_same_v || std::is_same_v); template diff --git a/include/xrpl/protocol/IOUIssue.h b/include/xrpl/protocol/IOUIssue.h new file mode 100644 index 00000000000..853e3a7b31c --- /dev/null +++ b/include/xrpl/protocol/IOUIssue.h @@ -0,0 +1,159 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_PROTOCOL_IOUISSUE_H_INCLUDED +#define RIPPLE_PROTOCOL_IOUISSUE_H_INCLUDED + +#include +#include +#include + +#include +#include + +namespace ripple { + +/** A currency issued by an account. + @see Currency, AccountID, Issue, Book +*/ +class IOUIssue +{ +private: + Currency currency_; + AccountID account_; + +public: + IOUIssue() = default; + + IOUIssue(Currency const& c, AccountID const& a) : currency_(c), account_(a) + { + } + + AccountID const& + getIssuer() const + { + return account_; + } + + void + setIssuer(AccountID const& account) + { + account_ = account; + } + + Currency const& + getCurrency() const + { + return currency_; + } + + void + setCurrency(Currency const& currency) + { + currency_ = currency; + } + + std::string + getText() const; + + void + setJson(Json::Value& jv) const; + + bool + native() const; + + friend constexpr std::weak_ordering + operator<=>(IOUIssue const& lhs, IOUIssue const& rhs); +}; + +bool +isConsistent(IOUIssue const& ac); + +std::string +to_string(IOUIssue const& ac); + +Json::Value +to_json(IOUIssue const& is); + +IOUIssue +iouIssueFromJson(Json::Value const& v); + +std::ostream& +operator<<(std::ostream& os, IOUIssue const& x); + +template +void +hash_append(Hasher& h, IOUIssue const& r) +{ + using beast::hash_append; + hash_append(h, r.getCurrency(), r.getIssuer()); +} + +/** Equality comparison. */ +/** @{ */ +[[nodiscard]] inline constexpr bool +operator==(IOUIssue const& lhs, IOUIssue const& rhs) +{ + return (lhs.getCurrency() == rhs.getCurrency()) && + (isXRP(lhs.getCurrency()) || lhs.getIssuer() == rhs.getIssuer()); +} +/** @} */ + +/** Strict weak ordering. */ +/** @{ */ +[[nodiscard]] constexpr std::weak_ordering +operator<=>(IOUIssue const& lhs, IOUIssue const& rhs) +{ + if (auto const c{lhs.getCurrency() <=> rhs.getCurrency()}; c != 0) + return c; + + if (isXRP(lhs.getCurrency())) + return std::weak_ordering::equivalent; + + return (lhs.getIssuer() <=> rhs.getIssuer()); +} +/** @} */ + +//------------------------------------------------------------------------------ + +/** Returns an asset specifier that represents XRP. */ +inline IOUIssue const& +xrpIssue() +{ + static IOUIssue issue{xrpCurrency(), xrpAccount()}; + return issue; +} + +/** Returns an asset specifier that represents no account and currency. */ +inline IOUIssue const& +noIssue() +{ + static IOUIssue issue{noCurrency(), noAccount()}; + return issue; +} + +inline bool +isXRP(IOUIssue const& issue) +{ + return issue.native(); +} + +} // namespace ripple + +#endif // RIPPLE_PROTOCOL_IOUISSUE_H_INCLUDED diff --git a/include/xrpl/protocol/Indexes.h b/include/xrpl/protocol/Indexes.h index e0bddd023ca..05dc06fa5e7 100644 --- a/include/xrpl/protocol/Indexes.h +++ b/include/xrpl/protocol/Indexes.h @@ -118,9 +118,9 @@ line( Currency const& currency) noexcept; inline Keylet -line(AccountID const& id, Issue const& issue) noexcept +line(AccountID const& id, IOUIssue const& issue) noexcept { - return line(id, issue.account, issue.currency); + return line(id, issue.getIssuer(), issue.getCurrency()); } /** @} */ @@ -274,7 +274,7 @@ nft_sells(uint256 const& id) noexcept; /** AMM entry */ Keylet -amm(Asset const& issue1, Asset const& issue2) noexcept; +amm(Issue const& issue1, Issue const& issue2) noexcept; Keylet amm(uint256 const& amm) noexcept; diff --git a/include/xrpl/protocol/Issue.h b/include/xrpl/protocol/Issue.h index 83ef337c357..a2812006591 100644 --- a/include/xrpl/protocol/Issue.h +++ b/include/xrpl/protocol/Issue.h @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -20,121 +20,266 @@ #ifndef RIPPLE_PROTOCOL_ISSUE_H_INCLUDED #define RIPPLE_PROTOCOL_ISSUE_H_INCLUDED -#include -#include -#include - -#include -#include +#include +#include +#include +#include namespace ripple { -/** A currency issued by an account. - @see Currency, AccountID, Issue, Book -*/ +template + requires( + std::is_same_v || std::is_same_v || + std::is_same_v) +struct AmountType +{ + using amount_type = T; +}; + +/* Issue 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. Many functions and classes there were first written for Issue + * have been rewritten for Issue. + */ class Issue { public: - Currency currency{}; - AccountID account{}; + using value_type = std::variant; +private: + value_type issue_; + +public: Issue() = default; - Issue(Currency const& c, AccountID const& a) : currency(c), account(a) + /** Conversions to Issue are implicit and conversions to specific issue + * type are explicit. This design facilitates the use of Issue. + */ + Issue(IOUIssue const& issue) : issue_(issue) { } - AccountID const& - getIssuer() const + Issue(MPTIssue const& mptIssue) : issue_(mptIssue) { - return account; } + Issue(MPTID const& issuanceID) : issue_(MPTIssue{issuanceID}) + { + } + + explicit + operator IOUIssue() const; + + explicit + operator MPTIssue() const; + + AccountID const& + getIssuer() const; + + template + constexpr TIss const& + get() const; + + template + TIss& + get(); + + template + constexpr bool + holds() const; + std::string getText() const; + constexpr value_type const& + value() const; + void setJson(Json::Value& jv) const; bool - native() const; + native() const + { + return holds() && get().native(); + } + + std::variant< + AmountType, + AmountType, + AmountType> + getAmountType() const; + + friend constexpr bool + operator==(Issue const& lhs, Issue const& rhs); friend constexpr std::weak_ordering operator<=>(Issue const& lhs, Issue const& rhs); -}; -bool -isConsistent(Issue const& ac); + friend constexpr bool + operator==(Currency const& lhs, Issue const& rhs); -std::string -to_string(Issue const& ac); + /** Return true if both assets refer to the same currency (regardless of + * issuer) or MPT issuance. Otherwise return false. + */ + friend constexpr bool + equalTokens(Issue const& lhs, Issue const& rhs); +}; -Json::Value -to_json(Issue const& is); +template +constexpr bool +Issue::holds() const +{ + return std::holds_alternative(issue_); +} -Issue -issueFromJson(Json::Value const& v); +template +constexpr TIss const& +Issue::get() const +{ + if (!std::holds_alternative(issue_)) + Throw("Issue is not a requested issue"); + return std::get(issue_); +} -std::ostream& -operator<<(std::ostream& os, Issue const& x); +template +TIss& +Issue::get() +{ + if (!std::holds_alternative(issue_)) + Throw("Issue is not a requested issue"); + return std::get(issue_); +} -template -void -hash_append(Hasher& h, Issue const& r) +constexpr Issue::value_type const& +Issue::value() const { - using beast::hash_append; - hash_append(h, r.currency, r.account); + return issue_; } -/** Equality comparison. */ -/** @{ */ -[[nodiscard]] inline constexpr bool +constexpr bool operator==(Issue const& lhs, Issue const& rhs) { - return (lhs.currency == rhs.currency) && - (isXRP(lhs.currency) || lhs.account == rhs.account); + return std::visit( + [&]( + TLhs const& issLhs, TRhs const& issRhs) { + if constexpr (std::is_same_v) + return issLhs == issRhs; + else + return false; + }, + lhs.issue_, + rhs.issue_); } -/** @} */ -/** Strict weak ordering. */ -/** @{ */ -[[nodiscard]] constexpr std::weak_ordering +constexpr std::weak_ordering operator<=>(Issue const& lhs, Issue const& rhs) { - if (auto const c{lhs.currency <=> rhs.currency}; c != 0) - return c; - - if (isXRP(lhs.currency)) - return std::weak_ordering::equivalent; + return std::visit( + []( + TLhs const& lhs_, TRhs const& rhs_) { + if constexpr (std::is_same_v) + return std::weak_ordering(lhs_ <=> rhs_); + else if constexpr ( + std::is_same_v && + std::is_same_v) + return std::weak_ordering::greater; + else + return std::weak_ordering::less; + }, + lhs.issue_, + rhs.issue_); +} - return (lhs.account <=> rhs.account); +constexpr bool +operator==(Currency const& lhs, Issue const& rhs) +{ + return rhs.holds() && rhs.get().getCurrency() == lhs; } -/** @} */ -//------------------------------------------------------------------------------ +constexpr bool +equalTokens(Issue const& lhs, Issue const& rhs) +{ + return std::visit( + [&]( + TLhs const& issLhs, TRhs const& issRhs) { + if constexpr ( + std::is_same_v && + std::is_same_v) + return issLhs.getCurrency() == issRhs.getCurrency(); + else if constexpr ( + std::is_same_v && + std::is_same_v) + return issLhs.getMptID() == issRhs.getMptID(); + else + return false; + }, + lhs.issue_, + rhs.issue_); +} -/** Returns an asset specifier that represents XRP. */ -inline Issue const& -xrpIssue() +inline bool +isXRP(Issue const& asset) { - static Issue issue{xrpCurrency(), xrpAccount()}; - return issue; + return asset.native(); } -/** Returns an asset specifier that represents no account and currency. */ -inline Issue const& -noIssue() +std::string +to_string(Issue const& asset); + +bool +validJSONAsset(Json::Value const& jv); + +Issue +issueFromJson(Json::Value const& jv); + +Json::Value +to_json(Issue const& asset); + +inline bool +isConsistent(Issue const& issue) { - static Issue issue{noCurrency(), noAccount()}; - return issue; + return std::visit( + [&](TIss const& issue_) { + if constexpr (std::is_same_v) + return isConsistent(issue_); + else + return true; + }, + issue.value()); } inline bool -isXRP(Issue const& issue) +validAsset(Issue const& issue) +{ + return std::visit( + [&](TIss const& issue_) { + if constexpr (std::is_same_v) + return isConsistent(issue_) && + issue_.getCurrency() != badCurrency(); + else + return true; + }, + issue.value()); +} + +template +void +hash_append(Hasher& h, Issue const& r) { - return issue.native(); + using beast::hash_append; + std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + hash_append(h, issue); + else + hash_append(h, issue); + }, + r.value()); } +std::ostream& +operator<<(std::ostream& os, Issue const& x); + } // namespace ripple -#endif +#endif // RIPPLE_PROTOCOL_ISSUE_H_INCLUDED diff --git a/include/xrpl/protocol/PathAsset.h b/include/xrpl/protocol/PathIssue.h similarity index 69% rename from include/xrpl/protocol/PathAsset.h rename to include/xrpl/protocol/PathIssue.h index 79b1a687136..f4c91895088 100644 --- a/include/xrpl/protocol/PathAsset.h +++ b/include/xrpl/protocol/PathIssue.h @@ -20,37 +20,37 @@ #ifndef RIPPLE_APP_PATHASSET_H_INCLUDED #define RIPPLE_APP_PATHASSET_H_INCLUDED -#include #include +#include namespace ripple { /* Represent STPathElement's asset, which can be Currency or MPTID. */ -class PathAsset +class PathIssue { private: std::variant easset_; public: - PathAsset() = default; - // Enables comparing Asset and PathAsset - PathAsset(Asset const& asset); - PathAsset(Currency const& currency) : easset_(currency) + PathIssue() = default; + // Enables comparing Asset and PathIssue + PathIssue(Issue const& asset); + PathIssue(Currency const& currency) : easset_(currency) { } - PathAsset(MPTID const& mpt) : easset_(mpt) + PathIssue(MPTID const& mpt) : easset_(mpt) { } - template + template constexpr bool holds() const; constexpr bool isXRP() const; - template + template T const& get() const; @@ -58,56 +58,56 @@ class PathAsset value() const; friend constexpr bool - operator==(PathAsset const& lhs, PathAsset const& rhs); + operator==(PathIssue const& lhs, PathIssue const& rhs); }; -inline PathAsset::PathAsset(Asset const& asset) +inline PathIssue::PathIssue(Issue const& asset) { std::visit( [&](TIss const& issue) { - if constexpr (std::is_same_v) - easset_ = issue.currency; + if constexpr (std::is_same_v) + easset_ = issue.getCurrency(); else easset_ = issue.getMptID(); }, asset.value()); } -template +template constexpr bool -PathAsset::holds() const +PathIssue::holds() const { return std::holds_alternative(easset_); } -template +template T const& -PathAsset::get() const +PathIssue::get() const { if (!holds()) - Throw("PathAsset doesn't hold requested asset."); + Throw("PathIssue doesn't hold requested asset."); return std::get(easset_); } constexpr std::variant const& -PathAsset::value() const +PathIssue::value() const { return easset_; } constexpr bool -PathAsset::isXRP() const +PathIssue::isXRP() const { return std::visit( - [&](A const& a) { return ripple::isXRP(a); }, + [&](A const& a) { return ripple::isXRP(a); }, easset_); } constexpr bool -operator==(PathAsset const& lhs, PathAsset const& rhs) +operator==(PathIssue const& lhs, PathIssue const& rhs) { return std::visit( - []( + []( TLhs const& lhs_, TRhs const& rhs_) { if constexpr (std::is_same_v) return lhs_ == rhs_; @@ -120,23 +120,23 @@ operator==(PathAsset const& lhs, PathAsset const& rhs) template void -hash_append(Hasher& h, PathAsset const& pathAsset) +hash_append(Hasher& h, PathIssue const& pathAsset) { std::visit( [&](T const& e) { hash_append(h, e); }, pathAsset.value()); } inline bool -isXRP(PathAsset const& asset) +isXRP(PathIssue const& asset) { return asset.isXRP(); } std::string -to_string(PathAsset const& asset); +to_string(PathIssue const& asset); std::ostream& -operator<<(std::ostream& os, PathAsset const& x); +operator<<(std::ostream& os, PathIssue const& x); } // namespace ripple diff --git a/include/xrpl/protocol/Rate.h b/include/xrpl/protocol/Rate.h index 2872a5809de..3846c18a498 100644 --- a/include/xrpl/protocol/Rate.h +++ b/include/xrpl/protocol/Rate.h @@ -74,7 +74,7 @@ STAmount multiplyRound( STAmount const& amount, Rate const& rate, - Asset const& asset, + Issue const& asset, bool roundUp); STAmount @@ -87,7 +87,7 @@ STAmount divideRound( STAmount const& amount, Rate const& rate, - Asset const& asset, + Issue const& asset, bool roundUp); namespace nft { diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index f0d93ddd6ff..a8fa1922ad2 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -54,7 +54,7 @@ class STAmount final : public STBase, public CountedObject using rep = std::pair; private: - Asset mAsset; + Issue mIssue; mantissa_type mValue; exponent_type mOffset; bool mIsNegative; @@ -88,7 +88,7 @@ class STAmount final : public STBase, public CountedObject }; // Do not call canonicalize - template + template STAmount( SField const& name, A const& asset, @@ -97,7 +97,7 @@ class STAmount final : public STBase, public CountedObject bool negative, unchecked); - template + template STAmount( A const& asset, mantissa_type mantissa, @@ -106,7 +106,7 @@ class STAmount final : public STBase, public CountedObject unchecked); // Call canonicalize - template + template STAmount( SField const& name, A const& asset, @@ -125,13 +125,13 @@ class STAmount final : public STBase, public CountedObject explicit STAmount(SField const& name, STAmount const& amt); - template + template STAmount( A const& asset, std::uint64_t mantissa = 0, int exponent = 0, bool negative = false) - : mAsset(asset) + : mIssue(asset) , mValue(mantissa) , mOffset(exponent) , mIsNegative(negative) @@ -140,21 +140,21 @@ class STAmount final : public STBase, public CountedObject } // VFALCO Is this needed when we have the previous signature? - template + template STAmount( A const& asset, std::uint32_t mantissa, int exponent = 0, bool negative = false); - template + template STAmount(A const& asset, std::int64_t mantissa, int exponent = 0); - template + template STAmount(A const& asset, int mantissa, int exponent = 0); // Legacy support for new-style amounts - STAmount(IOUAmount const& amount, Issue const& issue); + STAmount(IOUAmount const& amount, IOUIssue const& issue); STAmount(XRPAmount const& amount); STAmount(MPTAmount const& amount, MPTIssue const& mptIssue); operator Number() const; @@ -181,14 +181,14 @@ class STAmount final : public STBase, public CountedObject std::uint64_t mantissa() const noexcept; - Asset const& + Issue const& asset() const; template constexpr TIss const& get() const; - Issue const& + IOUIssue const& issue() const; // These three are deprecated @@ -244,14 +244,14 @@ class STAmount final : public STBase, public CountedObject // Zero while copying currency and issuer. void - clear(Asset const& asset); + clear(Issue const& asset); void setIssuer(AccountID const& uIssuer); - /** Set the Issue for this amount. */ + /** Set the IOUIssue for this amount. */ void - setIssue(Asset const& asset); + setIssue(Issue const& asset); //-------------------------------------------------------------------------- // @@ -309,7 +309,7 @@ class STAmount final : public STBase, public CountedObject operator+(STAmount const& v1, STAmount const& v2); }; -template +template STAmount::STAmount( SField const& name, A const& asset, @@ -318,25 +318,25 @@ STAmount::STAmount( bool negative, unchecked) : STBase(name) - , mAsset(asset) + , mIssue(asset) , mValue(mantissa) , mOffset(exponent) , mIsNegative(negative) { } -template +template STAmount::STAmount( A const& asset, mantissa_type mantissa, exponent_type exponent, bool negative, unchecked) - : mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) + : mIssue(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative) { } -template +template STAmount::STAmount( SField const& name, A const& asset, @@ -344,7 +344,7 @@ STAmount::STAmount( int exponent, bool negative) : STBase(name) - , mAsset(asset) + , mIssue(asset) , mValue(mantissa) , mOffset(exponent) , mIsNegative(negative) @@ -357,15 +357,15 @@ STAmount::STAmount( canonicalize(); } -template +template STAmount::STAmount(A const& asset, std::int64_t mantissa, int exponent) - : mAsset(asset), mOffset(exponent) + : mIssue(asset), mOffset(exponent) { set(mantissa); canonicalize(); } -template +template STAmount::STAmount( A const& asset, std::uint32_t mantissa, @@ -375,15 +375,15 @@ STAmount::STAmount( { } -template +template STAmount::STAmount(A const& asset, int mantissa, int exponent) : STAmount(asset, safe_cast(mantissa), exponent) { } // Legacy support for new-style amounts -inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue) - : mAsset(issue) +inline STAmount::STAmount(IOUAmount const& amount, IOUIssue const& issue) + : mIssue(issue) , mOffset(amount.exponent()) , mIsNegative(amount < beast::zero) { @@ -396,7 +396,7 @@ inline STAmount::STAmount(IOUAmount const& amount, Issue const& issue) } inline STAmount::STAmount(MPTAmount const& amount, MPTIssue const& mptIssue) - : mAsset(mptIssue), mOffset(0), mIsNegative(amount < beast::zero) + : mIssue(mptIssue), mOffset(0), mIsNegative(amount < beast::zero) { if (mIsNegative) mValue = unsafe_cast(-amount.value()); @@ -417,7 +417,7 @@ STAmount amountFromQuality(std::uint64_t rate); STAmount -amountFromString(Asset const& issue, std::string const& amount); +amountFromString(Issue const& issue, std::string const& amount); STAmount amountFromJson(SField const& name, Json::Value const& v); @@ -448,14 +448,14 @@ STAmount::exponent() const noexcept inline bool STAmount::native() const noexcept { - return mAsset.native(); + return mIssue.native(); } template constexpr bool STAmount::holds() const noexcept { - return mAsset.holds(); + return mIssue.holds(); } inline bool @@ -470,35 +470,35 @@ STAmount::mantissa() const noexcept return mValue; } -inline Asset const& +inline Issue const& STAmount::asset() const { - return mAsset; + return mIssue; } template constexpr TIss const& STAmount::get() const { - return mAsset.get(); + return mIssue.get(); } -inline Issue const& +inline IOUIssue const& STAmount::issue() const { - return get(); + return get(); } inline Currency const& STAmount::getCurrency() const { - return mAsset.get().currency; + return mIssue.get().getCurrency(); } inline AccountID const& STAmount::getIssuer() const { - return mAsset.getIssuer(); + return mIssue.getIssuer(); } inline int @@ -510,7 +510,7 @@ STAmount::signum() const noexcept inline STAmount STAmount::zeroed() const { - return STAmount(mAsset); + return STAmount(mIssue); } inline STAmount::operator bool() const noexcept @@ -522,7 +522,7 @@ inline STAmount::operator Number() const { if (native()) return xrp(); - if (mAsset.holds()) + if (mIssue.holds()) return mpt(); return iou(); } @@ -559,7 +559,7 @@ STAmount::clear() } inline void -STAmount::clear(Asset const& asset) +STAmount::clear(Issue const& asset) { setIssue(asset); clear(); @@ -568,9 +568,9 @@ STAmount::clear(Asset const& asset) inline void STAmount::setIssuer(AccountID const& uIssuer) { - if (!mAsset.holds()) + if (!mIssue.holds()) Throw("Can't set issuer for non-Issue"); - mAsset.get().account = uIssuer; + mIssue.get().setIssuer(uIssuer); } inline STAmount const& @@ -635,17 +635,17 @@ STAmount operator-(STAmount const& v1, STAmount const& v2); STAmount -divide(STAmount const& v1, STAmount const& v2, Asset const& asset); +divide(STAmount const& v1, STAmount const& v2, Issue const& asset); STAmount -multiply(STAmount const& v1, STAmount const& v2, Asset const& asset); +multiply(STAmount const& v1, STAmount const& v2, Issue const& asset); // multiply rounding result in specified direction STAmount mulRound( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp); // multiply following the rounding directions more precisely. @@ -653,7 +653,7 @@ STAmount mulRoundStrict( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp); // divide rounding result in specified direction @@ -661,7 +661,7 @@ STAmount divRound( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp); // divide following the rounding directions more precisely. @@ -669,7 +669,7 @@ STAmount divRoundStrict( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp); // Someone is offering X for Y, what is the rate? diff --git a/include/xrpl/protocol/STIssue.h b/include/xrpl/protocol/STIssue.h index 08812c15aec..26c75249542 100644 --- a/include/xrpl/protocol/STIssue.h +++ b/include/xrpl/protocol/STIssue.h @@ -21,7 +21,7 @@ #define RIPPLE_PROTOCOL_STISSUE_H_INCLUDED #include -#include +#include #include #include #include @@ -31,16 +31,16 @@ namespace ripple { class STIssue final : public STBase, CountedObject { private: - Asset asset_{xrpIssue()}; + Issue asset_{xrpIssue()}; public: - using value_type = Asset; + using value_type = Issue; STIssue() = default; explicit STIssue(SerialIter& sit, SField const& name); - template + template explicit STIssue(SField const& name, A const& issue); explicit STIssue(SField const& name); @@ -57,7 +57,7 @@ class STIssue final : public STBase, CountedObject value() const noexcept; void - setIssue(Asset const& issue); + setIssue(Issue const& issue); SerializedTypeID getSType() const override; @@ -83,10 +83,10 @@ class STIssue final : public STBase, CountedObject operator<=>(STIssue const& lhs, STIssue const& rhs); friend constexpr bool - operator==(STIssue const& lhs, Asset const& rhs); + operator==(STIssue const& lhs, Issue const& rhs); friend constexpr std::weak_ordering - operator<=>(STIssue const& lhs, Asset const& rhs); + operator<=>(STIssue const& lhs, Issue const& rhs); private: STBase* @@ -97,11 +97,11 @@ class STIssue final : public STBase, CountedObject friend class detail::STVar; }; -template +template STIssue::STIssue(SField const& name, A const& asset) : STBase{name}, asset_{asset} { - if (holds() && !isConsistent(asset_.get())) + if (holds() && !isConsistent(asset_.get())) Throw( "Invalid asset: currency and account native mismatch"); } @@ -121,7 +121,7 @@ TIss const& STIssue::get() const { if (!holds(asset_)) - Throw("Asset doesn't hold the requested issue"); + Throw("Issue doesn't hold the requested issue"); return std::get(asset_); } @@ -132,9 +132,9 @@ STIssue::value() const noexcept } inline void -STIssue::setIssue(Asset const& asset) +STIssue::setIssue(Issue const& asset) { - if (holds() && !isConsistent(asset_.get())) + if (holds() && !isConsistent(asset_.get())) Throw( "Invalid asset: currency and account native mismatch"); @@ -154,13 +154,13 @@ operator<=>(STIssue const& lhs, STIssue const& rhs) } constexpr bool -operator==(STIssue const& lhs, Asset const& rhs) +operator==(STIssue const& lhs, Issue const& rhs) { return lhs.asset_ == rhs; } constexpr std::weak_ordering -operator<=>(STIssue const& lhs, Asset const& rhs) +operator<=>(STIssue const& lhs, Issue const& rhs) { return lhs.asset_ <=> rhs; } diff --git a/include/xrpl/protocol/STPathSet.h b/include/xrpl/protocol/STPathSet.h index d5d474540a1..7acf552d378 100644 --- a/include/xrpl/protocol/STPathSet.h +++ b/include/xrpl/protocol/STPathSet.h @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -37,7 +37,7 @@ class STPathElement final : public CountedObject { unsigned int mType; AccountID mAccountID; - PathAsset mAssetID; + PathIssue mAssetID; AccountID mIssuerID; bool is_offer_; @@ -64,19 +64,19 @@ class STPathElement final : public CountedObject STPathElement( std::optional const& account, - std::optional const& asset, + std::optional const& asset, std::optional const& issuer); STPathElement( AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer, bool forceAsset = false); STPathElement( unsigned int uType, AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer); auto @@ -108,8 +108,8 @@ class STPathElement final : public CountedObject AccountID const& getAccountID() const; - PathAsset const& - getPathAsset() const; + PathIssue const& + getPathIssue() const; Currency const& getCurrency() const; @@ -156,7 +156,7 @@ class STPath final : public CountedObject bool hasSeen( AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer) const; Json::Value getJson(JsonOptions) const; @@ -260,7 +260,7 @@ inline STPathElement::STPathElement() : mType(typeNone), is_offer_(true) inline STPathElement::STPathElement( std::optional const& account, - std::optional const& asset, + std::optional const& asset, std::optional const& issuer) : mType(typeNone) { @@ -298,7 +298,7 @@ inline STPathElement::STPathElement( inline STPathElement::STPathElement( AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer, bool forceAsset) : mType(typeNone) @@ -322,7 +322,7 @@ inline STPathElement::STPathElement( inline STPathElement::STPathElement( unsigned int uType, AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer) : mType(uType) , mAccountID(account) @@ -395,8 +395,8 @@ STPathElement::getAccountID() const return mAccountID; } -inline PathAsset const& -STPathElement::getPathAsset() const +inline PathIssue const& +STPathElement::getPathIssue() const { return mAssetID; } diff --git a/include/xrpl/protocol/STXChainBridge.h b/include/xrpl/protocol/STXChainBridge.h index 813bcc44437..443ab9dbd1b 100644 --- a/include/xrpl/protocol/STXChainBridge.h +++ b/include/xrpl/protocol/STXChainBridge.h @@ -61,9 +61,9 @@ class STXChainBridge final : public STBase, public CountedObject STXChainBridge( AccountID const& srcChainDoor, - Issue const& srcChainIssue, + IOUIssue const& srcChainIssue, AccountID const& dstChainDoor, - Issue const& dstChainIssue); + IOUIssue const& dstChainIssue); explicit STXChainBridge(Json::Value const& v); @@ -83,19 +83,19 @@ class STXChainBridge final : public STBase, public CountedObject AccountID const& lockingChainDoor() const; - Issue const& + IOUIssue const& lockingChainIssue() const; AccountID const& issuingChainDoor() const; - Issue const& + IOUIssue const& issuingChainIssue() const; AccountID const& door(ChainType ct) const; - Issue const& + IOUIssue const& issue(ChainType ct) const; SerializedTypeID @@ -167,10 +167,10 @@ STXChainBridge::lockingChainDoor() const return lockingChainDoor_.value(); }; -inline Issue const& +inline IOUIssue const& STXChainBridge::lockingChainIssue() const { - return lockingChainIssue_.value().get(); + return lockingChainIssue_.value().get(); }; inline AccountID const& @@ -179,10 +179,10 @@ STXChainBridge::issuingChainDoor() const return issuingChainDoor_.value(); }; -inline Issue const& +inline IOUIssue const& STXChainBridge::issuingChainIssue() const { - return issuingChainIssue_.value().get(); + return issuingChainIssue_.value().get(); }; inline STXChainBridge::value_type const& @@ -199,7 +199,7 @@ STXChainBridge::door(ChainType ct) const return issuingChainDoor(); } -inline Issue const& +inline IOUIssue const& STXChainBridge::issue(ChainType ct) const { if (ct == ChainType::locking) diff --git a/include/xrpl/protocol/XChainAttestations.h b/include/xrpl/protocol/XChainAttestations.h index 721950ca9c1..a0d256977de 100644 --- a/include/xrpl/protocol/XChainAttestations.h +++ b/include/xrpl/protocol/XChainAttestations.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/xrpl/protocol/XRPIssue.h b/include/xrpl/protocol/XRPIssue.h new file mode 100644 index 00000000000..fe9c1723fa0 --- /dev/null +++ b/include/xrpl/protocol/XRPIssue.h @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2024 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_PROTOCOL_XRPISSUE_H_INCLUDED +#define RIPPLE_PROTOCOL_XRPISSUE_H_INCLUDED + +#include +#include +#include + +namespace ripple { + +class XRPAmount; + +class XRPIssue +{ +public: + using amount_type = XRPAmount; + static inline AccountID const account = xrpAccount(); + static inline Currency const currency = xrpCurrency(); + XRPIssue() = default; + + AccountID const& + getIssuer() const + { + return account; + } + + std::string + getText() const + { + return to_string(currency); + } + + void + setJson(Json::Value& jv) const + { + jv[jss::currency] = to_string(currency); + } + + bool + native() const + { + return true; + } + + friend constexpr bool + operator==(XRPIssue const& lhs, XRPIssue const& rhs) + { + return true; + } + + friend constexpr std::weak_ordering + operator<=>(XRPIssue const& lhs, XRPIssue const& rhs) + { + return std::weak_ordering::equivalent; + } +}; + +inline bool +isConsistent(XRPIssue const& ac) +{ + return true; +} + +inline Json::Value +to_json(XRPIssue const& is) +{ + Json::Value jv; + jv[jss::currency] = to_string(is.currency); + return jv; +} + +inline std::string +to_string(XRPIssue const& is) +{ + return to_string(is.currency); +} + +inline XRPIssue +xrpIssueFromJson(Json::Value const& v) +{ + if (!v.isObject()) + { + Throw( + "xrpIssueFromJson can only be specified with an 'object' Json " + "value"); + } + + if (v.isMember(jss::account) || v.isMember(jss::mpt_issuance_id)) + { + Throw( + "xrpIssueFromJson, IOUIssue should not have mpt_issuance_id"); + } + + Json::Value const curStr = v[jss::currency]; + if (!curStr.isString()) + { + Throw( + "xrpIssueFromJson currency must be a string Json value"); + } + + auto const currency = to_currency(curStr.asString()); + if (currency == badCurrency() || currency == noCurrency()) + { + Throw( + "xrpIssueFromJson currency must be a valid currency"); + } + + return XRPIssue(); +} + +inline std::ostream& +operator<<(std::ostream& os, XRPIssue const& x) +{ + os << to_string(x.currency); + return os; +} + +template +void +hash_append(Hasher& h, XRPIssue const& r) +{ + using beast::hash_append; + hash_append(h, r.currency, r.account); +} + +/** Returns an asset specifier that represents XRP. */ +inline XRPIssue const& +xrpIssue() +{ + static XRPIssue issue; + return issue; +} + +} // namespace ripple + +#endif // RIPPLE_PROTOCOL_XRPISSUE_H_INCLUDED diff --git a/src/libxrpl/protocol/AMMCore.cpp b/src/libxrpl/protocol/AMMCore.cpp index 1c2f8ff1e76..cbdb5515c97 100644 --- a/src/libxrpl/protocol/AMMCore.cpp +++ b/src/libxrpl/protocol/AMMCore.cpp @@ -39,7 +39,7 @@ ammAccountID( } Currency -ammLPTCurrency(Asset const& asset1, Asset const& asset2) +ammLPTCurrency(Issue const& asset1, Issue const& asset2) { // AMM LPToken is 0x03 plus 19 bytes of the hash std::int32_t constexpr AMMCurrencyCode = 0x03; @@ -47,8 +47,8 @@ ammLPTCurrency(Asset const& asset1, Asset const& asset2) uint256 const hash = std::visit( [](auto&& issue1_, auto&& issue2_) { auto fromIss = [](T const& iss) { - if constexpr (std::is_same_v) - return iss.currency; + if constexpr (std::is_same_v) + return iss.getCurrency(); if constexpr (std::is_same_v) return iss.getMptID(); }; @@ -63,24 +63,25 @@ ammLPTCurrency(Asset const& asset1, Asset const& asset2) return currency; } -Issue +IOUIssue ammLPTIssue( - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, AccountID const& ammAccountID) { - return Issue(ammLPTCurrency(asset1, asset2), ammAccountID); + return IOUIssue(ammLPTCurrency(asset1, asset2), ammAccountID); } NotTEC invalidAMMAsset( - Asset const& issue, - std::optional> const& pair) + Issue const& issue, + std::optional> const& pair) { if (issue.holds() && issue.get().getIssuer() == beast::zero) return temBAD_MPT; - if (issue.holds() && badCurrency() == issue.get().currency) + if (issue.holds() && + badCurrency() == issue.get().getCurrency()) return temBAD_CURRENCY; if (isXRP(issue) && issue.getIssuer().isNonZero()) return temBAD_ISSUER; @@ -91,9 +92,9 @@ invalidAMMAsset( NotTEC invalidAMMAssetPair( - Asset const& asset1, - Asset const& asset2, - std::optional> const& pair) + Issue const& asset1, + Issue const& asset2, + std::optional> const& pair) { if (asset1 == asset2) return temBAD_AMM_TOKENS; @@ -107,7 +108,7 @@ invalidAMMAssetPair( NotTEC invalidAMMAmount( STAmount const& amount, - std::optional> const& pair, + std::optional> const& pair, bool validZero) { if (auto const res = invalidAMMAsset(amount.asset(), pair)) diff --git a/src/libxrpl/protocol/Asset.cpp b/src/libxrpl/protocol/Asset.cpp deleted file mode 100644 index b152c68e38b..00000000000 --- a/src/libxrpl/protocol/Asset.cpp +++ /dev/null @@ -1,104 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2024 Ripple Labs Inc. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include -#include -#include - -namespace ripple { - -AccountID const& -Asset::getIssuer() const -{ - return std::visit( - [&](auto&& issue) -> AccountID const& { return issue.getIssuer(); }, - issue_); -} - -std::string -Asset::getText() const -{ - return std::visit([&](auto&& issue) { return issue.getText(); }, issue_); -} - -void -Asset::setJson(Json::Value& jv) const -{ - std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_); -} - -std:: - variant, AmountType, AmountType> - Asset::getAmountType() const -{ - static AmountType xrp; - static AmountType iou; - static AmountType mpt; - if (holds()) - return mpt; - if (native()) - return xrp; - return iou; -} - -std::string -to_string(Asset const& asset) -{ - return std::visit( - [&](auto const& issue) { return to_string(issue); }, asset.value()); -} - -bool -validJSONAsset(Json::Value const& jv) -{ - if (jv.isMember(jss::mpt_issuance_id)) - return !(jv.isMember(jss::currency) || jv.isMember(jss::issuer)); - return jv.isMember(jss::currency); -} - -Asset -assetFromJson(Json::Value const& v) -{ - if (!v.isMember(jss::currency) && !v.isMember(jss::mpt_issuance_id)) - Throw( - "assetFromJson must contain currency or mpt_issuance_id"); - - if (v.isMember(jss::currency)) - return issueFromJson(v); - return mptIssueFromJson(v); -} - -Json::Value -to_json(Asset const& asset) -{ - return std::visit( - [&](auto const& issue) { return to_json(issue); }, asset.value()); -} - -std::ostream& -operator<<(std::ostream& os, Asset const& x) -{ - if (x.holds()) - os << x.get(); - else - os << x.get(); - return os; -} - -} // namespace ripple diff --git a/src/libxrpl/protocol/IOUIssue.cpp b/src/libxrpl/protocol/IOUIssue.cpp new file mode 100644 index 00000000000..999033bc191 --- /dev/null +++ b/src/libxrpl/protocol/IOUIssue.cpp @@ -0,0 +1,152 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include + +#include +#include +#include +#include + +namespace ripple { + +std::string +IOUIssue::getText() const +{ + std::string ret; + + ret.reserve(64); + ret = to_string(currency_); + + if (!isXRP(currency_)) + { + ret += "/"; + + if (isXRP(account_)) + ret += "0"; + else if (account_ == noAccount()) + ret += "1"; + else + ret += to_string(account_); + } + + return ret; +} + +void +IOUIssue::setJson(Json::Value& jv) const +{ + jv[jss::currency] = to_string(currency_); + if (!isXRP(currency_)) + jv[jss::issuer] = toBase58(account_); +} + +bool +IOUIssue::native() const +{ + return *this == xrpIssue(); +} + +bool +isConsistent(IOUIssue const& ac) +{ + return isXRP(ac.getCurrency()) == isXRP(ac.getIssuer()); +} + +std::string +to_string(IOUIssue const& ac) +{ + if (isXRP(ac.getIssuer())) + return to_string(ac.getCurrency()); + + return to_string(ac.getIssuer()) + "/" + to_string(ac.getCurrency()); +} + +Json::Value +to_json(IOUIssue const& is) +{ + Json::Value jv; + is.setJson(jv); + return jv; +} + +IOUIssue +iouIssueFromJson(Json::Value const& v) +{ + if (!v.isObject()) + { + Throw( + "iouIssueFromJson can only be specified with an 'object' Json " + "value"); + } + + if (v.isMember(jss::mpt_issuance_id)) + { + Throw( + "iouIssueFromJson, IOUIssue should not have mpt_issuance_id"); + } + + Json::Value const curStr = v[jss::currency]; + Json::Value const issStr = v[jss::issuer]; + + if (!curStr.isString()) + { + Throw( + "iouIssueFromJson currency must be a string Json value"); + } + + auto const currency = to_currency(curStr.asString()); + if (currency == badCurrency() || currency == noCurrency()) + { + Throw( + "iouIssueFromJson currency must be a valid currency"); + } + + if (isXRP(currency)) + { + if (!issStr.isNull()) + { + Throw("Issue, XRP should not have issuer"); + } + return xrpIssue(); + } + + if (!issStr.isString()) + { + Throw( + "iouIssueFromJson issuer must be a string Json value"); + } + auto const issuer = parseBase58(issStr.asString()); + + if (!issuer) + { + Throw("iouIssueFromJson issuer must be a valid account"); + } + + return IOUIssue{currency, *issuer}; +} + +std::ostream& +operator<<(std::ostream& os, IOUIssue const& x) +{ + os << to_string(x); + return os; +} + +} // namespace ripple diff --git a/src/libxrpl/protocol/Indexes.cpp b/src/libxrpl/protocol/Indexes.cpp index 499e6c354d9..4f70a9c976a 100644 --- a/src/libxrpl/protocol/Indexes.cpp +++ b/src/libxrpl/protocol/Indexes.cpp @@ -18,8 +18,8 @@ //============================================================================== #include -#include #include +#include #include #include #include @@ -103,27 +103,27 @@ getBookBase(Book const& book) [&]( TIn const& in, TOut const& out) { if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && std::is_same_v) return indexHash( LedgerNameSpace::BOOK_DIR, - in.currency, - out.currency, - in.account, - out.account); + in.getCurrency(), + out.getCurrency(), + in.getIssuer(), + out.getIssuer()); else if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && std::is_same_v) return indexHash( LedgerNameSpace::BOOK_DIR, - in.currency, + in.getCurrency(), out.getMptID(), - in.account); + in.getIssuer()); else if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && std::is_same_v) return indexHash( LedgerNameSpace::BOOK_DIR, in.getMptID(), - out.currency, - out.account); + out.getCurrency(), + out.getIssuer()); else return indexHash( LedgerNameSpace::BOOK_DIR, in.getMptID(), out.getMptID()); @@ -443,34 +443,37 @@ nft_sells(uint256 const& id) noexcept } Keylet -amm(Asset const& asset1, Asset const& asset2) noexcept +amm(Issue const& asset1, Issue const& asset2) noexcept { auto const& [minA, maxA] = std::minmax(asset1, asset2); return std::visit( []( TIss1 const& issue1_, TIss2 const& issue2_) { if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && + std::is_same_v) return amm(indexHash( LedgerNameSpace::AMM, - issue1_.account, - issue1_.currency, - issue2_.account, - issue2_.currency)); + issue1_.getIssuer(), + issue1_.getCurrency(), + issue2_.getIssuer(), + issue2_.getCurrency())); else if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && + std::is_same_v) return amm(indexHash( LedgerNameSpace::AMM, - issue1_.account, - issue1_.currency, + issue1_.getIssuer(), + issue1_.getCurrency(), issue2_.getMptID())); else if constexpr ( - std::is_same_v && std::is_same_v) + std::is_same_v && + std::is_same_v) return amm(indexHash( LedgerNameSpace::AMM, issue1_.getMptID(), - issue2_.account, - issue2_.currency)); + issue2_.getIssuer(), + issue2_.getCurrency())); else if constexpr ( std::is_same_v && std::is_same_v) @@ -499,7 +502,9 @@ bridge(STXChainBridge const& bridge, STXChainBridge::ChainType chainType) return { ltBRIDGE, indexHash( - LedgerNameSpace::BRIDGE, bridge.door(chainType), issue.currency)}; + LedgerNameSpace::BRIDGE, + bridge.door(chainType), + issue.getCurrency())}; } Keylet diff --git a/src/libxrpl/protocol/Issue.cpp b/src/libxrpl/protocol/Issue.cpp index 179cb1eb14a..832adc5dca4 100644 --- a/src/libxrpl/protocol/Issue.cpp +++ b/src/libxrpl/protocol/Issue.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2012, 2013 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -17,132 +17,87 @@ */ //============================================================================== +#include #include - -#include -#include -#include #include namespace ripple { +AccountID const& +Issue::getIssuer() const +{ + return std::visit( + [&](auto&& issue) -> AccountID const& { return issue.getIssuer(); }, + issue_); +} + std::string Issue::getText() const { - std::string ret; - - ret.reserve(64); - ret = to_string(currency); - - if (!isXRP(currency)) - { - ret += "/"; - - if (isXRP(account)) - ret += "0"; - else if (account == noAccount()) - ret += "1"; - else - ret += to_string(account); - } - - return ret; + return std::visit([&](auto&& issue) { return issue.getText(); }, issue_); } void Issue::setJson(Json::Value& jv) const { - jv[jss::currency] = to_string(currency); - if (!isXRP(currency)) - jv[jss::issuer] = toBase58(account); -} - -bool -Issue::native() const -{ - return *this == xrpIssue(); + std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_); } -bool -isConsistent(Issue const& ac) +std:: + variant, AmountType, AmountType> + Issue::getAmountType() const { - return isXRP(ac.currency) == isXRP(ac.account); + static AmountType xrp; + static AmountType iou; + static AmountType mpt; + if (holds()) + return mpt; + if (native()) + return xrp; + return iou; } std::string -to_string(Issue const& ac) +to_string(Issue const& asset) { - if (isXRP(ac.account)) - return to_string(ac.currency); - - return to_string(ac.account) + "/" + to_string(ac.currency); + return std::visit( + [&](auto const& issue) { return to_string(issue); }, asset.value()); } -Json::Value -to_json(Issue const& is) +bool +validJSONAsset(Json::Value const& jv) { - Json::Value jv; - is.setJson(jv); - return jv; + if (jv.isMember(jss::mpt_issuance_id)) + return !(jv.isMember(jss::currency) || jv.isMember(jss::issuer)); + return jv.isMember(jss::currency); } Issue issueFromJson(Json::Value const& v) { - if (!v.isObject()) - { + if (!v.isMember(jss::currency) && !v.isMember(jss::mpt_issuance_id)) Throw( - "issueFromJson can only be specified with an 'object' Json value"); - } - - if (v.isMember(jss::mpt_issuance_id)) - { - Throw( - "issueFromJson, Issue should not have mpt_issuance_id"); - } - - Json::Value const curStr = v[jss::currency]; - Json::Value const issStr = v[jss::issuer]; - - if (!curStr.isString()) - { - Throw( - "issueFromJson currency must be a string Json value"); - } + "issueFromJson must contain currency or mpt_issuance_id"); - auto const currency = to_currency(curStr.asString()); - if (currency == badCurrency() || currency == noCurrency()) - { - Throw("issueFromJson currency must be a valid currency"); - } - - if (isXRP(currency)) - { - if (!issStr.isNull()) - { - Throw("Issue, XRP should not have issuer"); - } - return xrpIssue(); - } - - if (!issStr.isString()) - { - Throw("issueFromJson issuer must be a string Json value"); - } - auto const issuer = parseBase58(issStr.asString()); - - if (!issuer) - { - Throw("issueFromJson issuer must be a valid account"); - } + if (v.isMember(jss::currency)) + return iouIssueFromJson(v); + return mptIssueFromJson(v); +} - return Issue{currency, *issuer}; +Json::Value +to_json(Issue const& asset) +{ + return std::visit( + [&](auto const& issue) { return to_json(issue); }, asset.value()); } std::ostream& operator<<(std::ostream& os, Issue const& x) { - os << to_string(x); + if (x.holds()) + os << x.get(); + else + os << x.get(); return os; } diff --git a/src/libxrpl/protocol/PathAsset.cpp b/src/libxrpl/protocol/PathIssue.cpp similarity index 91% rename from src/libxrpl/protocol/PathAsset.cpp rename to src/libxrpl/protocol/PathIssue.cpp index 77aa6cbfd0a..5215ca45172 100644 --- a/src/libxrpl/protocol/PathAsset.cpp +++ b/src/libxrpl/protocol/PathIssue.cpp @@ -18,19 +18,19 @@ //============================================================================== #include -#include +#include namespace ripple { std::string -to_string(PathAsset const& asset) +to_string(PathIssue const& asset) { return std::visit( [&](auto const& issue) { return to_string(issue); }, asset.value()); } std::ostream& -operator<<(std::ostream& os, PathAsset const& x) +operator<<(std::ostream& os, PathIssue const& x) { os << to_string(x); return os; diff --git a/src/libxrpl/protocol/Quality.cpp b/src/libxrpl/protocol/Quality.cpp index ba669d9bd1f..19afe56c700 100644 --- a/src/libxrpl/protocol/Quality.cpp +++ b/src/libxrpl/protocol/Quality.cpp @@ -67,7 +67,7 @@ Quality::operator--(int) } template + *DivRoundFunc)(STAmount const&, STAmount const&, Issue const&, bool)> static Amounts ceil_in_impl( Amounts const& amount, @@ -108,7 +108,7 @@ Quality::ceil_in_strict( } template + *MulRoundFunc)(STAmount const&, STAmount const&, Issue const&, bool)> static Amounts ceil_out_impl( Amounts const& amount, diff --git a/src/libxrpl/protocol/Rate2.cpp b/src/libxrpl/protocol/Rate2.cpp index 64ac6c46315..362597b0467 100644 --- a/src/libxrpl/protocol/Rate2.cpp +++ b/src/libxrpl/protocol/Rate2.cpp @@ -69,11 +69,12 @@ STAmount multiplyRound( STAmount const& amount, Rate const& rate, - Asset const& asset, + Issue const& asset, bool roundUp) { XRPL_ASSERT( - rate.value, "ripple::nft::multiplyRound(Issue) : nonzero rate input"); + rate.value, + "ripple::nft::multiplyRound(IOUIssue) : nonzero rate input"); if (rate == parityRate) { @@ -109,11 +110,11 @@ STAmount divideRound( STAmount const& amount, Rate const& rate, - Asset const& asset, + Issue const& asset, bool roundUp) { XRPL_ASSERT( - rate.value, "ripple::nft::divideRound(Issue) : nonzero rate input"); + rate.value, "ripple::nft::divideRound(IOUIssue) : nonzero rate input"); if (rate == parityRate) return amount; diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index fc5078a0ebe..9272b1b8ccb 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -99,9 +99,10 @@ getMPTValue(STAmount const& amount) static bool areComparable(STAmount const& v1, STAmount const& v2) { - if (v1.holds() && v2.holds()) + if (v1.holds() && v2.holds()) return v1.native() == v2.native() && - v1.get().currency == v2.get().currency; + v1.get().getCurrency() == + v2.get().getCurrency(); if (v1.holds() && v2.holds()) return v1.get() == v2.get(); return false; @@ -120,11 +121,11 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) mOffset = 0; mIsNegative = (value & cPositive) == 0; mValue = (value << 8) | sit.get8(); - mAsset = sit.get192(); + mIssue = sit.get192(); return; } // else is XRP - mAsset = xrpIssue(); + mIssue = xrpIssue(); // positive if ((value & cPositive) != 0) { @@ -144,15 +145,15 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) return; } - Issue issue; - issue.currency = sit.get160(); + IOUIssue issue; + issue.setCurrency(static_cast(sit.get160())); - if (isXRP(issue.currency)) + if (isXRP(issue.getCurrency())) Throw("invalid native currency"); - issue.account = sit.get160(); + issue.setIssuer(static_cast(sit.get160())); - if (isXRP(issue.account)) + if (isXRP(issue.getIssuer())) Throw("invalid native account"); // 10 bits for the offset, sign and "not native" flag @@ -171,7 +172,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) Throw("invalid currency value"); } - mAsset = issue; + mIssue = issue; mValue = value; mOffset = offset; mIsNegative = isNegative; @@ -182,7 +183,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) if (offset != 512) Throw("invalid currency value"); - mAsset = issue; + mIssue = issue; mValue = 0; mOffset = 0; mIsNegative = false; @@ -190,14 +191,14 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) } STAmount::STAmount(SField const& name, std::int64_t mantissa) - : STBase(name), mAsset(xrpIssue()), mOffset(0) + : STBase(name), mIssue(xrpIssue()), mOffset(0) { set(mantissa); } STAmount::STAmount(SField const& name, std::uint64_t mantissa, bool negative) : STBase(name) - , mAsset(xrpIssue()) + , mIssue(xrpIssue()) , mValue(mantissa) , mOffset(0) , mIsNegative(negative) @@ -210,7 +211,7 @@ STAmount::STAmount(SField const& name, std::uint64_t mantissa, bool negative) STAmount::STAmount(SField const& name, STAmount const& from) : STBase(name) - , mAsset(from.mAsset) + , mIssue(from.mIssue) , mValue(from.mValue) , mOffset(from.mOffset) , mIsNegative(from.mIsNegative) @@ -224,7 +225,7 @@ STAmount::STAmount(SField const& name, STAmount const& from) //------------------------------------------------------------------------------ STAmount::STAmount(std::uint64_t mantissa, bool negative) - : mAsset(xrpIssue()) + : mIssue(xrpIssue()) , mValue(mantissa) , mOffset(0) , mIsNegative(mantissa != 0 && negative) @@ -236,7 +237,7 @@ STAmount::STAmount(std::uint64_t mantissa, bool negative) } STAmount::STAmount(XRPAmount const& amount) - : mAsset(xrpIssue()), mOffset(0), mIsNegative(amount < beast::zero) + : mIssue(xrpIssue()), mOffset(0), mIsNegative(amount < beast::zero) { if (mIsNegative) mValue = unsafe_cast(-amount.drops()); @@ -287,7 +288,7 @@ STAmount::xrp() const IOUAmount STAmount::iou() const { - if (native() || !holds()) + if (native() || !holds()) Throw("Cannot return non-IOU STAmount as IOUAmount"); auto mantissa = static_cast(mValue); @@ -371,7 +372,7 @@ operator+(STAmount const& v1, STAmount const& v2) if (v1.native()) return {v1.getFName(), getSNValue(v1) + getSNValue(v2)}; if (v1.holds()) - return {v1.mAsset, v1.mpt().value() + v2.mpt().value()}; + return {v1.mIssue, v1.mpt().value() + v2.mpt().value()}; if (getSTNumberSwitchover()) { @@ -433,9 +434,9 @@ operator-(STAmount const& v1, STAmount const& v2) std::uint64_t const STAmount::uRateOne = getRate(STAmount(1), STAmount(1)); void -STAmount::setIssue(Asset const& asset) +STAmount::setIssue(Issue const& asset) { - mAsset = asset; + mIssue = asset; } // Convert an offer into an index amount so they sort by rate. @@ -481,7 +482,7 @@ STAmount::setJson(Json::Value& elem) const // It is an error for currency or issuer not to be specified for valid // json. elem[jss::value] = getText(); - mAsset.setJson(elem); + mIssue.setJson(elem); } else { @@ -507,7 +508,7 @@ STAmount::getFullText() const std::string ret; ret.reserve(64); - ret = getText() + "/" + mAsset.getText(); + ret = getText() + "/" + mIssue.getText(); return ret; } @@ -527,7 +528,7 @@ STAmount::getText() const bool const scientific( (mOffset != 0) && ((mOffset < -25) || (mOffset > -5))); - if (native() || mAsset.holds() || scientific) + if (native() || mIssue.holds() || scientific) { ret.append(raw_value); @@ -620,14 +621,14 @@ STAmount::add(Serializer& s) const else s.add64(mValue); } - else if (mAsset.holds()) + else if (mIssue.holds()) { auto u8 = static_cast(cMPToken >> 56); if (!mIsNegative) u8 |= static_cast(cPositive >> 56); s.add8(u8); s.add64(mValue); - s.addBitString(mAsset.get().getMptID()); + s.addBitString(mIssue.get().getMptID()); } else { @@ -642,8 +643,8 @@ STAmount::add(Serializer& s) const mValue | (static_cast(mOffset + 512 + 256 + 97) << (64 - 10))); - s.addBitString(mAsset.get().currency); - s.addBitString(mAsset.get().account); + s.addBitString(mIssue.get().getCurrency()); + s.addBitString(mIssue.get().getIssuer()); } } @@ -681,7 +682,7 @@ STAmount::isDefault() const void STAmount::canonicalize() { - if (native() || mAsset.holds()) + if (native() || mIssue.holds()) { // native and MPT currency amounts should always have an offset of zero // log(2^64,10) ~ 19.2 @@ -700,7 +701,7 @@ STAmount::canonicalize() Throw( "Native currency amount out of range"); // log(maxMPTokenAmount, 10) ~ 18.96 - if (mAsset.holds() && mOffset > 18) + if (mIssue.holds() && mOffset > 18) Throw("MPT amount out of range"); } @@ -831,7 +832,7 @@ amountFromQuality(std::uint64_t rate) } STAmount -amountFromString(Asset const& asset, std::string const& amount) +amountFromString(Issue const& asset, std::string const& amount) { static boost::regex const reNumber( "^" // the beginning of the string @@ -902,7 +903,7 @@ amountFromJson(SField const& name, Json::Value const& v) STAmount::mantissa_type mantissa = 0; STAmount::exponent_type exponent = 0; bool negative = false; - Asset asset; + Issue asset; Json::Value value; Json::Value currencyOrMPTID; @@ -917,7 +918,7 @@ amountFromJson(SField const& name, Json::Value const& v) else if (v.isObject()) { if (!validJSONAsset(v)) - Throw("Invalid Asset's Json specification"); + Throw("Invalid Issue's Json specification"); value = v[jss::value]; if (v.isMember(jss::mpt_issuance_id)) @@ -981,12 +982,13 @@ amountFromJson(SField const& name, Json::Value const& v) } else { - Issue issue; - if (!to_currency(issue.currency, currencyOrMPTID.asString())) + Currency currency; + AccountID account; + if (!to_currency(currency, currencyOrMPTID.asString())) Throw("invalid currency"); - if (!issuer.isString() || - !to_issuer(issue.account, issuer.asString())) + if (!issuer.isString() || !to_issuer(account, issuer.asString())) Throw("invalid issuer"); + IOUIssue issue{currency, account}; if (issue.native()) Throw("invalid issuer"); asset = issue; @@ -1157,7 +1159,7 @@ muldiv_round( } STAmount -divide(STAmount const& num, STAmount const& den, Asset const& asset) +divide(STAmount const& num, STAmount const& den, Issue const& asset) { if (den == beast::zero) Throw("division by zero"); @@ -1202,7 +1204,7 @@ divide(STAmount const& num, STAmount const& den, Asset const& asset) } STAmount -multiply(STAmount const& v1, STAmount const& v2, Asset const& asset) +multiply(STAmount const& v1, STAmount const& v2, Issue const& asset) { if (v1 == beast::zero || v2 == beast::zero) return STAmount(asset); @@ -1405,7 +1407,7 @@ static STAmount mulRoundImpl( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp) { if (v1 == beast::zero || v2 == beast::zero) @@ -1510,7 +1512,7 @@ STAmount mulRound( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp) { return mulRoundImpl( @@ -1521,7 +1523,7 @@ STAmount mulRoundStrict( STAmount const& v1, STAmount const& v2, - Asset const& asset, + Issue const& asset, bool roundUp) { return mulRoundImpl( @@ -1535,7 +1537,7 @@ static STAmount divRoundImpl( STAmount const& num, STAmount const& den, - Asset const& asset, + Issue const& asset, bool roundUp) { if (den == beast::zero) @@ -1617,7 +1619,7 @@ STAmount divRound( STAmount const& num, STAmount const& den, - Asset const& asset, + Issue const& asset, bool roundUp) { return divRoundImpl(num, den, asset, roundUp); @@ -1627,7 +1629,7 @@ STAmount divRoundStrict( STAmount const& num, STAmount const& den, - Asset const& asset, + Issue const& asset, bool roundUp) { return divRoundImpl(num, den, asset, roundUp); diff --git a/src/libxrpl/protocol/STIssue.cpp b/src/libxrpl/protocol/STIssue.cpp index 5a2008cb178..62539af72cf 100644 --- a/src/libxrpl/protocol/STIssue.cpp +++ b/src/libxrpl/protocol/STIssue.cpp @@ -71,9 +71,7 @@ STIssue::STIssue(SerialIter& sit, SField const& name) : STBase{name} } else { - Issue issue; - issue.currency = currencyOrAccount; - issue.account = account; + IOUIssue issue{static_cast(currencyOrAccount), account}; if (!isConsistent(issue)) Throw( "invalid issue: currency and account native mismatch"); @@ -105,12 +103,12 @@ STIssue::getJson(JsonOptions) const void STIssue::add(Serializer& s) const { - if (holds()) + if (holds()) { - auto const& issue = asset_.get(); - s.addBitString(issue.currency); - if (!isXRP(issue.currency)) - s.addBitString(issue.account); + auto const& issue = asset_.get(); + s.addBitString(issue.getCurrency()); + if (!isXRP(issue.getCurrency())) + s.addBitString(issue.getIssuer()); } else { @@ -133,7 +131,7 @@ STIssue::isEquivalent(const STBase& t) const bool STIssue::isDefault() const { - return holds() && asset_.get() == xrpIssue(); + return holds() && asset_.get() == xrpIssue(); } STBase* @@ -151,7 +149,7 @@ STIssue::move(std::size_t n, void* buf) STIssue issueFromJson(SField const& name, Json::Value const& v) { - return STIssue{name, assetFromJson(v)}; + return STIssue{name, issueFromJson(v)}; } } // namespace ripple diff --git a/src/libxrpl/protocol/STParsedJSON.cpp b/src/libxrpl/protocol/STParsedJSON.cpp index cf800dc908b..aafcf4201df 100644 --- a/src/libxrpl/protocol/STParsedJSON.cpp +++ b/src/libxrpl/protocol/STParsedJSON.cpp @@ -646,7 +646,7 @@ parseLeaf( pathEl.isMember(jss::mpt_issuance_id)) { error = RPC::make_error( - rpcINVALID_PARAMS, "Invalid Asset."); + rpcINVALID_PARAMS, "Invalid Issue."); return ret; } @@ -657,9 +657,9 @@ parseLeaf( Json::Value const& account = pathEl[jss::account]; Json::Value const& asset = pathEl[assetName]; Json::Value const& issuer = pathEl[jss::issuer]; - bool hasAsset = false; + bool hasIssue = false; AccountID uAccount, uIssuer; - PathAsset uAsset; + PathIssue uIssue; if (account) { @@ -697,7 +697,7 @@ parseLeaf( return ret; } - hasAsset = true; + hasIssue = true; if (isMPT) { @@ -708,7 +708,7 @@ parseLeaf( element_name, assetName.c_str()); return ret; } - uAsset = u; + uIssue = u; if (getMPTIssuer(u) == beast::zero) { error = invalid_data( @@ -729,7 +729,7 @@ parseLeaf( return ret; } } - uAsset = currency; + uIssue = currency; } } @@ -757,7 +757,7 @@ parseLeaf( } } - p.emplace_back(uAccount, uAsset, uIssuer, hasAsset); + p.emplace_back(uAccount, uIssue, uIssuer, hasIssue); } tail.push_back(p); diff --git a/src/libxrpl/protocol/STPathSet.cpp b/src/libxrpl/protocol/STPathSet.cpp index e3abfcbb593..77969f8c4d2 100644 --- a/src/libxrpl/protocol/STPathSet.cpp +++ b/src/libxrpl/protocol/STPathSet.cpp @@ -43,13 +43,13 @@ STPathElement::get_hash(STPathElement const& element) // Check pathAsset type instead of element's mType // In some cases mType might be account but the asset // is still set to either MPT or currency (see Pathfinder::addLink()) - if (element.getPathAsset().holds()) + if (element.getPathIssue().holds()) { - hash_currency += beast::uhash<>{}(element.getPathAsset().get()); + hash_currency += beast::uhash<>{}(element.getPathIssue().get()); } else { - for (auto const x : element.getPathAsset().get()) + for (auto const x : element.getPathIssue().get()) hash_currency += (hash_currency * 509) ^ x; } @@ -95,7 +95,7 @@ STPathSet::STPathSet(SerialIter& sit, SField const& name) : STBase(name) auto hasMPT = iType & STPathElement::typeMPT; AccountID account; - PathAsset asset; + PathIssue asset; AccountID issuer; if (hasAccount) @@ -167,12 +167,12 @@ STPathSet::isDefault() const bool STPath::hasSeen( AccountID const& account, - PathAsset const& asset, + PathIssue const& asset, AccountID const& issuer) const { for (auto& p : mPath) { - if (p.getAccountID() == account && p.getPathAsset() == asset && + if (p.getAccountID() == account && p.getPathIssue() == asset && p.getIssuerID() == issuer) return true; } diff --git a/src/libxrpl/protocol/STXChainBridge.cpp b/src/libxrpl/protocol/STXChainBridge.cpp index 2347e63379a..81daa806dd9 100644 --- a/src/libxrpl/protocol/STXChainBridge.cpp +++ b/src/libxrpl/protocol/STXChainBridge.cpp @@ -19,8 +19,8 @@ #include +#include #include -#include #include #include #include @@ -45,9 +45,9 @@ STXChainBridge::STXChainBridge(SField const& name) : STBase{name} STXChainBridge::STXChainBridge( AccountID const& srcChainDoor, - Issue const& srcChainIssue, + IOUIssue const& srcChainIssue, AccountID const& dstChainDoor, - Issue const& dstChainIssue) + IOUIssue const& dstChainIssue) : STBase{sfXChainBridge} , lockingChainDoor_{sfLockingChainDoor, srcChainDoor} , lockingChainIssue_{sfLockingChainIssue, srcChainIssue} @@ -130,10 +130,10 @@ STXChainBridge::STXChainBridge(SField const& name, Json::Value const& v) lockingChainDoor_ = STAccount{sfLockingChainDoor, *lockingChainDoor}; lockingChainIssue_ = - STIssue{sfLockingChainIssue, issueFromJson(lockingChainIssue)}; + STIssue{sfLockingChainIssue, iouIssueFromJson(lockingChainIssue)}; issuingChainDoor_ = STAccount{sfIssuingChainDoor, *issuingChainDoor}; issuingChainIssue_ = - STIssue{sfIssuingChainIssue, issueFromJson(issuingChainIssue)}; + STIssue{sfIssuingChainIssue, iouIssueFromJson(issuingChainIssue)}; } STXChainBridge::STXChainBridge(SerialIter& sit, SField const& name) diff --git a/src/libxrpl/protocol/TER.cpp b/src/libxrpl/protocol/TER.cpp index ee7db39424c..5100138ada3 100644 --- a/src/libxrpl/protocol/TER.cpp +++ b/src/libxrpl/protocol/TER.cpp @@ -69,7 +69,7 @@ transResults() MAKE_ERROR(tecNO_AUTH, "Not authorized to hold asset."), MAKE_ERROR(tecNO_LINE, "No such line."), MAKE_ERROR(tecINSUFF_FEE, "Insufficient balance to pay fee."), - MAKE_ERROR(tecFROZEN, "Asset is frozen."), + MAKE_ERROR(tecFROZEN, "Issue is frozen."), MAKE_ERROR(tecNO_TARGET, "Target account does not exist."), MAKE_ERROR(tecNO_PERMISSION, "No permission to perform requested operation."), MAKE_ERROR(tecNO_ENTRY, "No matching entry found."), diff --git a/src/test/app/AMMCalc_test.cpp b/src/test/app/AMMCalc_test.cpp index 9fb578dcec9..99cbc6e6a66 100644 --- a/src/test/app/AMMCalc_test.cpp +++ b/src/test/app/AMMCalc_test.cpp @@ -177,7 +177,7 @@ class AMMCalc_test : public beast::unit_test::suite toString(STAmount const& a) { return std::format( - "{}/{}", a.getText(), to_string(a.get().currency)); + "{}/{}", a.getText(), to_string(a.get().getCurrency())); } STAmount @@ -203,7 +203,7 @@ class AMMCalc_test : public beast::unit_test::suite int limitingStep = vp.size(); STAmount limitStepOut{}; auto trate = [&](STAmount const& amt) { - auto const currency = to_string(amt.get().currency); + auto const currency = to_string(amt.get().getCurrency()); return rates.find(currency) != rates.end() ? rates.at(currency) : QUALITY_ONE; }; @@ -268,7 +268,7 @@ class AMMCalc_test : public beast::unit_test::suite int limitingStep = 0; STAmount limitStepIn{}; auto trate = [&](STAmount const& amt) { - auto const currency = to_string(amt.get().currency); + auto const currency = to_string(amt.get().getCurrency()); return rates.find(currency) != rates.end() ? rates.at(currency) : QUALITY_ONE; }; diff --git a/src/test/app/AMMClawback_test.cpp b/src/test/app/AMMClawback_test.cpp index c547a537bfb..703507d04c0 100644 --- a/src/test/app/AMMClawback_test.cpp +++ b/src/test/app/AMMClawback_test.cpp @@ -122,7 +122,7 @@ class AMMClawback_test : public jtx::AMMTest ter(temMALFORMED)); } - // Test if the Asset field matches the Account field. + // Test if the Issue field matches the Account field. { Env env(*this, features); Account gw{"gateway"}; @@ -143,18 +143,18 @@ class AMMClawback_test : public jtx::AMMTest AMM amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS)); - // The Asset's issuer field is alice, while the Account field is gw. + // The Issue's issuer field is alice, while the Account field is gw. // This should return temMALFORMED because they do not match. env(amm::ammClawback( gw, alice, - Issue{gw["USD"].currency, alice.id()}, + IOUIssue{gw["USD"].currency, alice.id()}, XRP, std::nullopt), ter(temMALFORMED)); } - // Test if the Amount field matches the Asset field. + // Test if the Amount field matches the Issue field. { Env env(*this, features); Account gw{"gateway"}; @@ -175,7 +175,7 @@ class AMMClawback_test : public jtx::AMMTest AMM amm(env, gw, XRP(100), USD(100), ter(tesSUCCESS)); - // The Asset's issuer subfield is gw account and Amount's issuer + // The Issue's issuer subfield is gw account and Amount's issuer // subfield is alice account. Return temBAD_AMOUNT because // they do not match. env(amm::ammClawback( @@ -183,7 +183,7 @@ class AMMClawback_test : public jtx::AMMTest alice, USD, XRP, - STAmount{Issue{gw["USD"].currency, alice.id()}, 1}), + STAmount{IOUIssue{gw["USD"].currency, alice.id()}, 1}), ter(temBAD_AMOUNT)); } @@ -214,7 +214,7 @@ class AMMClawback_test : public jtx::AMMTest alice, USD, XRP, - STAmount{Issue{gw["USD"].currency, gw.id()}, -1}), + STAmount{IOUIssue{gw["USD"].currency, gw.id()}, -1}), ter(temBAD_AMOUNT)); // Return temBAD_AMOUNT if the Amount value is 0. @@ -223,7 +223,7 @@ class AMMClawback_test : public jtx::AMMTest alice, USD, XRP, - STAmount{Issue{gw["USD"].currency, gw.id()}, 0}), + STAmount{IOUIssue{gw["USD"].currency, gw.id()}, 0}), ter(temBAD_AMOUNT)); } @@ -1243,7 +1243,7 @@ class AMMClawback_test : public jtx::AMMTest alice, gw2["USD"], gw["USD"], - STAmount{Issue{gw2["USD"].currency, gw2.id()}, 500}), + STAmount{IOUIssue{gw2["USD"].currency, gw2.id()}, 500}), ter(temMALFORMED)); // gw2 clawback 500 gw2[USD] from alice. @@ -1252,7 +1252,7 @@ class AMMClawback_test : public jtx::AMMTest alice, gw2["USD"], gw["USD"], - STAmount{Issue{gw2["USD"].currency, gw2.id()}, 500}), + STAmount{IOUIssue{gw2["USD"].currency, gw2.id()}, 500}), ter(tesSUCCESS)); env.close(); BEAST_EXPECT(amm.expectBalances( diff --git a/src/test/app/AMMExtended_test.cpp b/src/test/app/AMMExtended_test.cpp index 96053b93b44..610239aaaab 100644 --- a/src/test/app/AMMExtended_test.cpp +++ b/src/test/app/AMMExtended_test.cpp @@ -1351,7 +1351,9 @@ struct AMMExtended_test : public jtx::AMMTest AMM ammAlice(env, alice, USD(1'000), XRP(1'050)); // Set up authorized trust line for AMM. - env(trust(gw, STAmount{Issue{USD.currency, ammAlice.ammAccount()}, 10}), + env(trust( + gw, + STAmount{IOUIssue{USD.currency, ammAlice.ammAccount()}, 10}), txflags(tfSetfAuth)); env.close(); @@ -1424,7 +1426,9 @@ struct AMMExtended_test : public jtx::AMMTest AMM ammAlice(env, alice, USD(1'000), XRP(1'050)); // Set up authorized trust line for AMM. - env(trust(gw, STAmount{Issue{USD.currency, ammAlice.ammAccount()}, 10}), + env(trust( + gw, + STAmount{IOUIssue{USD.currency, ammAlice.ammAccount()}, 10}), txflags(tfSetfAuth)); env.close(); @@ -2112,12 +2116,12 @@ struct AMMExtended_test : public jtx::AMMTest STAmount smax(BTC(61)); PaymentSandbox sb(env.current().get(), tapNONE); STPathSet paths; - auto IPE = [](Issue const& iss) { + auto IPE = [](IOUIssue const& iss) { return STPathElement( STPathElement::typeCurrency | STPathElement::typeIssuer, xrpAccount(), - iss.currency, - iss.account); + iss.getCurrency(), + iss.getIssuer()); }; { // BTC -> USD @@ -3539,7 +3543,7 @@ struct AMMExtended_test : public jtx::AMMTest BEAST_EXPECT( ff[sfHighLimit.fieldName] == bob["USD"](100).value().getJson(JsonOptions::none)); - auto amt = STAmount{Issue{to_currency("USD"), noAccount()}, -15} + auto amt = STAmount{IOUIssue{to_currency("USD"), noAccount()}, -15} .value() .getJson(JsonOptions::none); BEAST_EXPECT(ff[sfBalance.fieldName] == amt); @@ -3798,7 +3802,7 @@ struct AMMExtended_test : public jtx::AMMTest // test: AMM line is frozen auto const a3am = - STAmount{Issue{to_currency("USD"), ammA3.ammAccount()}, 0}; + STAmount{IOUIssue{to_currency("USD"), ammA3.ammAccount()}, 0}; env(trust(G1, a3am, tfSetFreeze)); auto const info = ammA3.ammRpcInfo(); BEAST_EXPECT(info[jss::amm][jss::asset2_frozen].asBool()); diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index c5877dd13cc..e0757481227 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -673,8 +673,8 @@ struct AMM_test : public jtx::AMMTest // Invalid tokens - bogus currency { - auto const iss1 = Issue{Currency(0xabc), gw.id()}; - auto const iss2 = Issue{Currency(0xdef), gw.id()}; + auto const iss1 = IOUIssue{Currency(0xabc), gw.id()}; + auto const iss2 = IOUIssue{Currency(0xdef), gw.id()}; ammAlice.deposit( alice, 1'000, @@ -937,7 +937,7 @@ struct AMM_test : public jtx::AMMTest env(trust( gw, STAmount{ - Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, + IOUIssue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); env.close(); // Can deposit non-frozen token @@ -985,7 +985,7 @@ struct AMM_test : public jtx::AMMTest env(trust( gw, STAmount{ - Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, + IOUIssue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); env.close(); // Cannot deposit non-frozen token @@ -1434,7 +1434,7 @@ struct AMM_test : public jtx::AMMTest }); // Single deposit with EP not exceeding specified: - // 100USD with EP not to exceed 0.1 (AssetIn/TokensOut) + // 100USD with EP not to exceed 0.1 (IssueIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { ammAlice.deposit( carol, USD(1'000), std::nullopt, STAmount{USD, 1, -1}); @@ -1445,7 +1445,7 @@ struct AMM_test : public jtx::AMMTest }); // Single deposit with EP not exceeding specified: - // 100USD with EP not to exceed 0.002004 (AssetIn/TokensOut) + // 100USD with EP not to exceed 0.002004 (IssueIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { ammAlice.deposit( carol, USD(100), std::nullopt, STAmount{USD, 2004, -6}); @@ -1456,7 +1456,7 @@ struct AMM_test : public jtx::AMMTest }); // Single deposit with EP not exceeding specified: - // 0USD with EP not to exceed 0.002004 (AssetIn/TokensOut) + // 0USD with EP not to exceed 0.002004 (IssueIn/TokensOut) testAMM([&](AMM& ammAlice, Env&) { ammAlice.deposit( carol, USD(0), std::nullopt, STAmount{USD, 2004, -6}); @@ -1975,7 +1975,8 @@ struct AMM_test : public jtx::AMMTest // Individually frozen AMM env(trust( gw, - STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, + STAmount{ + IOUIssue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); // Can withdraw non-frozen token ammAlice.withdraw(alice, XRP(100)); @@ -2198,7 +2199,7 @@ struct AMM_test : public jtx::AMMTest env(trust( carol, STAmount{ - Issue{EUR.currency, ammAlice.ammAccount()}, 10'000}), + IOUIssue{EUR.currency, ammAlice.ammAccount()}, 10'000}), ter(tecNO_PERMISSION)); env.close(); ammAlice.withdrawAll(alice); @@ -3478,7 +3479,8 @@ struct AMM_test : public jtx::AMMTest testAMM([&](AMM& ammAlice, Env& env) { env(trust( gw, - STAmount{Issue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, + STAmount{ + IOUIssue{gw["USD"].currency, ammAlice.ammAccount()}, 0}, tfSetFreeze)); env.close(); env(pay(alice, carol, USD(1)), @@ -4662,7 +4664,7 @@ struct AMM_test : public jtx::AMMTest env(pay(A, C, TSTA(10'000))); env(pay(B, C, TSTB(10'000))); AMM amm(env, C, TSTA(5'000), TSTB(5'000)); - auto const ammIss = Issue(TSTA.currency, amm.ammAccount()); + auto const ammIss = IOUIssue(TSTA.currency, amm.ammAccount()); // Can SetTrust only for AMM LP tokens env(trust(D, STAmount{ammIss, 10'000}), ter(tecNO_PERMISSION)); @@ -4787,7 +4789,7 @@ struct AMM_test : public jtx::AMMTest {features}); // Single deposit with EP not exceeding specified: - // 100USD with EP not to exceed 0.1 (AssetIn/TokensOut). 1% fee. + // 100USD with EP not to exceed 0.1 (IssueIn/TokensOut). 1% fee. testAMM( [&](AMM& ammAlice, Env& env) { auto const balance = env.balance(carol, USD); @@ -4809,7 +4811,7 @@ struct AMM_test : public jtx::AMMTest {features}); // Single deposit with EP not exceeding specified: - // 200USD with EP not to exceed 0.002020 (AssetIn/TokensOut). 1% fee + // 200USD with EP not to exceed 0.002020 (IssueIn/TokensOut). 1% fee testAMM( [&](AMM& ammAlice, Env& env) { auto const balance = env.balance(carol, USD); @@ -6976,7 +6978,7 @@ struct AMM_test : public jtx::AMMTest // allowed for clawing back from an AMM account. Please notice the // `issuer` subfield represents the account being clawed back, which // is confusing. - Issue usd(USD.issue().currency, amm.ammAccount()); + IOUIssue usd(USD.issue().getCurrency(), amm.ammAccount()); auto amount = amountFromString(usd, "10"); env(claw(gw, amount), ter(tecAMM_ACCOUNT)); } diff --git a/src/test/app/Check_test.cpp b/src/test/app/Check_test.cpp index 621c20edb15..2165d906680 100644 --- a/src/test/app/Check_test.cpp +++ b/src/test/app/Check_test.cpp @@ -1483,9 +1483,9 @@ class Check_test : public beast::unit_test::suite // Bad currency. if (!amount.native()) { - Issue const badIssue{badCurrency(), amount.getIssuer()}; + IOUIssue const badIssue{badCurrency(), amount.getIssuer()}; STAmount badAmount{amount}; - badAmount.setIssue(Issue{badCurrency(), amount.getIssuer()}); + badAmount.setIssue(IOUIssue{badCurrency(), amount.getIssuer()}); env(check::cash(bob, chkId, badAmount), ter(temBAD_CURRENCY)); env.close(); } diff --git a/src/test/app/Flow_test.cpp b/src/test/app/Flow_test.cpp index 77d0a874533..dfb3d97d37b 100644 --- a/src/test/app/Flow_test.cpp +++ b/src/test/app/Flow_test.cpp @@ -448,12 +448,12 @@ struct Flow_test : public beast::unit_test::suite STAmount smax(BTC(61)); PaymentSandbox sb(env.current().get(), tapNONE); STPathSet paths; - auto IPE = [](Issue const& iss) { + auto IPE = [](IOUIssue const& iss) { return STPathElement( STPathElement::typeCurrency | STPathElement::typeIssuer, xrpAccount(), - iss.currency, - iss.account); + iss.getCurrency(), + iss.getIssuer()); }; { // BTC -> USD diff --git a/src/test/app/Freeze_test.cpp b/src/test/app/Freeze_test.cpp index 1ea9f1b2530..94c19ece371 100644 --- a/src/test/app/Freeze_test.cpp +++ b/src/test/app/Freeze_test.cpp @@ -112,7 +112,7 @@ class Freeze_test : public beast::unit_test::suite BEAST_EXPECT( ff[sfHighLimit.fieldName] == bob["USD"](100).value().getJson(JsonOptions::none)); - auto amt = STAmount{Issue{to_currency("USD"), noAccount()}, -15} + auto amt = STAmount{IOUIssue{to_currency("USD"), noAccount()}, -15} .value() .getJson(JsonOptions::none); BEAST_EXPECT(ff[sfBalance.fieldName] == amt); diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index b1a906dc13a..1943fc3c37b 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -1484,7 +1484,7 @@ class MPToken_test : public beast::unit_test::suite void testMPTInvalidInTx(FeatureBitset features) { - testcase("MPT Issue Invalid in Transaction"); + testcase("MPT IOUIssue Invalid in Transaction"); using namespace test::jtx; // Validate that every transaction with an amount/issue field, @@ -2078,14 +2078,14 @@ class MPToken_test : public beast::unit_test::suite MPTID const mpt1a = makeMptID(1, gw1); MPTID const mpt2 = makeMptID(1, gw2); MPTID const mpt3 = makeMptID(2, gw2); - Asset const assetCur1Gw1{Issue{cur1, gw1}}; - Asset const assetCur1Gw1a{Issue{cur1, gw1}}; - Asset const assetCur2Gw1{Issue{cur2, gw1}}; - Asset const assetCur2Gw2{Issue{cur2, gw2}}; - Asset const assetMpt1Gw1{mpt1}; - Asset const assetMpt1Gw1a{mpt1a}; - Asset const assetMpt1Gw2{mpt2}; - Asset const assetMpt2Gw2{mpt3}; + Issue const assetCur1Gw1{IOUIssue{cur1, gw1}}; + Issue const assetCur1Gw1a{IOUIssue{cur1, gw1}}; + Issue const assetCur2Gw1{IOUIssue{cur2, gw1}}; + Issue const assetCur2Gw2{IOUIssue{cur2, gw2}}; + Issue const assetMpt1Gw1{mpt1}; + Issue const assetMpt1Gw1a{mpt1a}; + Issue const assetMpt1Gw2{mpt2}; + Issue const assetMpt2Gw2{mpt3}; // Assets holding Issue // Currencies are equal regardless of the issuer @@ -2103,7 +2103,7 @@ class MPToken_test : public beast::unit_test::suite BEAST_EXPECT(!equalTokens(assetMpt1Gw1, assetMpt1Gw2)); BEAST_EXPECT(!equalTokens(assetMpt1Gw2, assetMpt2Gw2)); - // Assets holding Issue and MPTIssue + // Assets holding IOUIssue and MPTIssue BEAST_EXPECT(!equalTokens(assetCur1Gw1, assetMpt1Gw1)); BEAST_EXPECT(!equalTokens(assetMpt2Gw2, assetCur2Gw2)); } @@ -2113,9 +2113,9 @@ class MPToken_test : public beast::unit_test::suite { using namespace test::jtx; Account const gw{"gw"}; - Asset const asset1{makeMptID(1, gw)}; - Asset const asset2{makeMptID(2, gw)}; - Asset const asset3{makeMptID(3, gw)}; + Issue const asset1{makeMptID(1, gw)}; + Issue const asset2{makeMptID(2, gw)}; + Issue const asset3{makeMptID(3, gw)}; STAmount const amt1{asset1, 100}; STAmount const amt2{asset2, 100}; STAmount const amt3{asset3, 10'000}; @@ -2179,7 +2179,7 @@ class MPToken_test : public beast::unit_test::suite } { - testcase("Test Asset from/to Json"); + testcase("Test Issue from/to Json"); Json::Value const jv = to_json(asset1); BEAST_EXPECT( jv[jss::mpt_issuance_id] == to_string(asset1.get())); @@ -2187,7 +2187,7 @@ class MPToken_test : public beast::unit_test::suite to_string(jv) == "{\"mpt_issuance_id\":" "\"00000001A407AF5856CCF3C42619DAA925813FC955C72983\"}"); - BEAST_EXPECT(asset1 == assetFromJson(jv)); + BEAST_EXPECT(asset1 == issueFromJson(jv)); } } @@ -2382,7 +2382,7 @@ class MPToken_test : public beast::unit_test::suite void testCrossAssetPayment(FeatureBitset features) { - testcase("Cross Asset Payment"); + testcase("Cross Issue Payment"); using namespace test::jtx; Account const gw = Account("gw"); Account const alice = Account("alice"); diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index b0f9d33da5f..ae348bda227 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -57,15 +57,17 @@ class OfferBaseUtil_test : public beast::unit_test::suite static auto getBookOffers( jtx::Env& env, - Issue const& taker_pays, - Issue const& taker_gets) + IOUIssue const& taker_pays, + IOUIssue const& taker_gets) { Json::Value jvbp; jvbp[jss::ledger_index] = "current"; - jvbp[jss::taker_pays][jss::currency] = to_string(taker_pays.currency); - jvbp[jss::taker_pays][jss::issuer] = to_string(taker_pays.account); - jvbp[jss::taker_gets][jss::currency] = to_string(taker_gets.currency); - jvbp[jss::taker_gets][jss::issuer] = to_string(taker_gets.account); + jvbp[jss::taker_pays][jss::currency] = + to_string(taker_pays.getCurrency()); + jvbp[jss::taker_pays][jss::issuer] = to_string(taker_pays.getIssuer()); + jvbp[jss::taker_gets][jss::currency] = + to_string(taker_gets.getCurrency()); + jvbp[jss::taker_gets][jss::issuer] = to_string(taker_gets.getIssuer()); return env.rpc("json", "book_offers", to_string(jvbp))[jss::result]; } @@ -2215,7 +2217,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite void testGatewayCrossCurrency(FeatureBitset features) { - testcase("Client Issue #535: Gateway Cross Currency"); + testcase("Client IOUIssue #535: Gateway Cross Currency"); using namespace jtx; @@ -2300,14 +2302,14 @@ class OfferBaseUtil_test : public beast::unit_test::suite BEAST_EXPECT(sleTrust); if (sleTrust) { - Issue const issue = expectBalance.value().issue(); - bool const accountLow = account.id() < issue.account; + IOUIssue const issue = expectBalance.value().issue(); + bool const accountLow = account.id() < issue.getIssuer(); STAmount low{issue}; STAmount high{issue}; - low.setIssuer(accountLow ? account.id() : issue.account); - high.setIssuer(accountLow ? issue.account : account.id()); + low.setIssuer(accountLow ? account.id() : issue.getIssuer()); + high.setIssuer(accountLow ? issue.getIssuer() : account.id()); BEAST_EXPECT(sleTrust->getFieldAmount(sfLowLimit) == low); BEAST_EXPECT(sleTrust->getFieldAmount(sfHighLimit) == high); @@ -4489,7 +4491,7 @@ class OfferBaseUtil_test : public beast::unit_test::suite env(trust(coldEU, EUR(0), mm, tfSetfAuth)); env.close(); - // Issue currency from cold wallets to hot and market maker + // IOUIssue currency from cold wallets to hot and market maker env(pay(coldUS, hotUS, USD(5000000))); env(pay(coldEU, hotEU, EUR(5000000))); env(pay(coldUS, mm, USD(5000000))); diff --git a/src/test/app/Oracle_test.cpp b/src/test/app/Oracle_test.cpp index 44eeb1c9f98..2e5026fe21b 100644 --- a/src/test/app/Oracle_test.cpp +++ b/src/test/app/Oracle_test.cpp @@ -153,7 +153,7 @@ struct Oracle_test : public beast::unit_test::suite env.fund(XRP(1'000), owner); Oracle oracle(env, {.owner = owner}, false); - // Asset class or provider not included on create + // Issue class or provider not included on create oracle.set(CreateArg{ .assetClass = std::nullopt, .provider = "provider", @@ -164,7 +164,7 @@ struct Oracle_test : public beast::unit_test::suite .uri = "URI", .err = ter(temMALFORMED)}); - // Asset class or provider are included on update + // Issue class or provider are included on update // and don't match the current values oracle.set(CreateArg{}); BEAST_EXPECT(oracle.exists()); @@ -184,7 +184,7 @@ struct Oracle_test : public beast::unit_test::suite Oracle oracle(env, {.owner = owner}, false); // Fields too long - // Asset class + // Issue class std::string assetClass(17, '0'); oracle.set( CreateArg{.assetClass = assetClass, .err = ter(temMALFORMED)}); @@ -194,7 +194,7 @@ struct Oracle_test : public beast::unit_test::suite // URI oracle.set(CreateArg{.uri = large, .err = ter(temMALFORMED)}); // Empty field - // Asset class + // Issue class oracle.set(CreateArg{.assetClass = "", .err = ter(temMALFORMED)}); // provider oracle.set(CreateArg{.provider = "", .err = ter(temMALFORMED)}); diff --git a/src/test/app/Path_test.cpp b/src/test/app/Path_test.cpp index 1db15388ff0..392c1385ced 100644 --- a/src/test/app/Path_test.cpp +++ b/src/test/app/Path_test.cpp @@ -576,7 +576,7 @@ class Path_test : public beast::unit_test::suite void issues_path_negative_issue() { - testcase("path negative: Issue #5"); + testcase("path negative: IOUIssue #5"); using namespace jtx; Env env = pathTestEnv(); env.fund(XRP(10000), "alice", "bob", "carol", "dan"); diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index 8f1f646eb5f..c02cc68c19a 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -144,15 +144,15 @@ ape(AccountID const& a) STPathElement::typeAccount, a, xrpCurrency(), xrpAccount()); }; -// Issue path element +// IOUIssue path element STPathElement -ipe(Issue const& iss) +ipe(IOUIssue const& iss) { return STPathElement( STPathElement::typeCurrency | STPathElement::typeIssuer, xrpAccount(), - iss.currency, - iss.account); + iss.getCurrency(), + iss.getIssuer()); }; // Issuer path element @@ -642,8 +642,8 @@ struct PayStrand_test : public beast::unit_test::suite auto test = [&, this]( jtx::Env& env, - Issue const& deliver, - std::optional const& sendMaxIssue, + IOUIssue const& deliver, + std::optional const& sendMaxIssue, STPath const& path, TER expTer, auto&&... expSteps) { @@ -1185,7 +1185,7 @@ struct PayStrand_test : public beast::unit_test::suite env.fund(XRP(10000), alice, bob, gw); STAmount sendMax{USD.issue(), 100, 1}; - STAmount noAccountAmount{Issue{USD.currency, noAccount()}, 100, 1}; + STAmount noAccountAmount{IOUIssue{USD.currency, noAccount()}, 100, 1}; STAmount deliver; AccountID const srcAcc = alice.id(); AccountID dstAcc = bob.id(); diff --git a/src/test/app/ReducedOffer_test.cpp b/src/test/app/ReducedOffer_test.cpp index a070051e435..6fdfb07ce39 100644 --- a/src/test/app/ReducedOffer_test.cpp +++ b/src/test/app/ReducedOffer_test.cpp @@ -622,7 +622,7 @@ class ReducedOffer_test : public beast::unit_test::suite void testSellPartialCrossOldXrpIouQChange() { - // This test case was motivated by Issue #4937. It recreates + // This test case was motivated by IOUIssue #4937. It recreates // the specific failure identified in that issue and samples some other // cases in the same vicinity to make sure that the new behavior makes // sense. diff --git a/src/test/app/SetAuth_test.cpp b/src/test/app/SetAuth_test.cpp index 9c6f3ed18de..017aa848d5d 100644 --- a/src/test/app/SetAuth_test.cpp +++ b/src/test/app/SetAuth_test.cpp @@ -38,7 +38,7 @@ struct SetAuth_test : public beast::unit_test::suite using namespace jtx; Json::Value jv; jv[jss::Account] = account.human(); - jv[jss::LimitAmount] = STAmount(Issue{to_currency(currency), dest}) + jv[jss::LimitAmount] = STAmount(IOUIssue{to_currency(currency), dest}) .getJson(JsonOptions::none); jv[jss::TransactionType] = jss::TrustSet; jv[jss::Flags] = tfSetfAuth; diff --git a/src/test/app/SetTrust_test.cpp b/src/test/app/SetTrust_test.cpp index 57e18d712f8..9c6d29b8daf 100644 --- a/src/test/app/SetTrust_test.cpp +++ b/src/test/app/SetTrust_test.cpp @@ -331,7 +331,8 @@ class SetTrust_test : public beast::unit_test::suite // trust amount can't be from invalid issuer env(trust_explicit_amt( - alice, STAmount{Issue{to_currency("USD"), noAccount()}, 100}), + alice, + STAmount{IOUIssue{to_currency("USD"), noAccount()}, 100}), ter(temDST_NEEDED)); // trust cannot be to self diff --git a/src/test/app/Taker_test.cpp b/src/test/app/Taker_test.cpp index b294e9f827b..716e90fabd3 100644 --- a/src/test/app/Taker_test.cpp +++ b/src/test/app/Taker_test.cpp @@ -123,31 +123,31 @@ class Taker_test : public beast::unit_test::suite }; private: - Issue const& + IOUIssue const& usd() const { - static Issue const issue( + static IOUIssue const issue( Currency(0x5553440000000000), AccountID(0x4985601)); return issue; } - Issue const& + IOUIssue const& eur() const { - static Issue const issue( + static IOUIssue const issue( Currency(0x4555520000000000), AccountID(0x4985602)); return issue; } - Issue const& + IOUIssue const& xrp() const { - static Issue const issue(xrpCurrency(), xrpAccount()); + static IOUIssue const issue(xrpCurrency(), xrpAccount()); return issue; } STAmount - parse_amount(std::string const& amount, Issue const& issue) + parse_amount(std::string const& amount, IOUIssue const& issue) { return amountFromString(issue, amount); } @@ -155,9 +155,9 @@ class Taker_test : public beast::unit_test::suite Amounts parse_amounts( std::string const& amount_in, - Issue const& issue_in, + IOUIssue const& issue_in, std::string const& amount_out, - Issue const& issue_out) + IOUIssue const& issue_out) { STAmount const in(parse_amount(amount_in, issue_in)); STAmount const out(parse_amount(amount_out, issue_out)); @@ -180,11 +180,11 @@ class Taker_test : public beast::unit_test::suite std::string format_amount(STAmount const& amount) { - if (amount.holds()) + if (amount.holds()) return std::format( "{}/{}", amount.getText(), - to_string(amount.get().currency)); + to_string(amount.get().getCurrency())); return std::format( "{}/{}", amount.getText(), to_string(amount.get())); } @@ -200,8 +200,8 @@ class Taker_test : public beast::unit_test::suite cross_attempt_offer const cross, std::string const cross_funds, cross_attempt_offer const flow, - Issue const& issue_in, - Issue const& issue_out, + IOUIssue const& issue_in, + IOUIssue const& issue_out, Rate rate_in = parityRate, Rate rate_out = parityRate) { diff --git a/src/test/app/TheoreticalQuality_test.cpp b/src/test/app/TheoreticalQuality_test.cpp index 917d23377bf..9d826f9f70c 100644 --- a/src/test/app/TheoreticalQuality_test.cpp +++ b/src/test/app/TheoreticalQuality_test.cpp @@ -248,7 +248,7 @@ class TheoreticalQuality_test : public beast::unit_test::suite PaymentSandbox sb(closed.get(), tapNONE); AMMContext ammContext(rcp.srcAccount, false); - auto const sendMaxIssue = [&rcp]() -> std::optional { + auto const sendMaxIssue = [&rcp]() -> std::optional { if (rcp.sendMax) return rcp.sendMax->issue(); return std::nullopt; diff --git a/src/test/app/XChain_test.cpp b/src/test/app/XChain_test.cpp index 4f24d17601e..63d02897325 100644 --- a/src/test/app/XChain_test.cpp +++ b/src/test/app/XChain_test.cpp @@ -19,8 +19,8 @@ #include #include +#include #include -#include #include #include #include @@ -126,7 +126,7 @@ struct SEnv } STAmount - balance(jtx::Account const& account, Issue const& issue) const + balance(jtx::Account const& account, IOUIssue const& issue) const { return env_.balance(account, issue).value(); } @@ -356,9 +356,9 @@ struct BalanceTransfer struct BridgeDef { jtx::Account doorA; - Issue issueA; + IOUIssue issueA; jtx::Account doorB; - Issue issueB; + IOUIssue issueB; STAmount reward; STAmount minAccountCreate; uint32_t quorum; @@ -729,7 +729,7 @@ struct XChain_test : public beast::unit_test::suite, // - Issuing chain is XRP with issuing chain is the root account. // --------------------------------------------------------------------- Account a("a"), b("b"); - Issue ia, ib; + IOUIssue ia, ib; std::tuple lcs{ std::make_pair( diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index 8a0a6702a63..645c7e1f100 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -700,7 +700,7 @@ class Number_test : public beast::unit_test::suite test_toSTAmount() { NumberSO stNumberSO{true}; - Issue const issue; + IOUIssue const issue; Number const n{7'518'783'80596, -5}; saveNumberRoundMode const save{Number::setround(Number::to_nearest)}; auto res2 = STAmount{issue, n.mantissa(), n.exponent()}; diff --git a/src/test/consensus/Validations_test.cpp b/src/test/consensus/Validations_test.cpp index 0279d6330cc..9bd42e8cbb4 100644 --- a/src/test/consensus/Validations_test.cpp +++ b/src/test/consensus/Validations_test.cpp @@ -109,7 +109,7 @@ class Validations_test : public beast::unit_test::suite return toNetClock(c_); } - // Issue a new validation with given sequence number and id and + // IOUIssue a new validation with given sequence number and id and // with signing and seen times offset from the common clock Validation validate( diff --git a/src/test/csf/Peer.h b/src/test/csf/Peer.h index 2f3b460e02f..f16546ffc05 100644 --- a/src/test/csf/Peer.h +++ b/src/test/csf/Peer.h @@ -305,7 +305,7 @@ struct Peer scheduler.in(when, std::forward(what)); } - // Issue a new event to the collectors + // IOUIssue a new event to the collectors template void issue(E const& event) diff --git a/src/test/jtx/AMM.h b/src/test/jtx/AMM.h index 470458b4839..ddac5dfd828 100644 --- a/src/test/jtx/AMM.h +++ b/src/test/jtx/AMM.h @@ -51,7 +51,7 @@ class LPToken return tokens_; } STAmount - tokens(Issue const& ammIssue) const + tokens(IOUIssue const& ammIssue) const { return STAmount{tokens_, ammIssue}; } @@ -77,7 +77,7 @@ struct DepositArg std::optional asset2In = std::nullopt; std::optional maxEP = std::nullopt; std::optional flags = std::nullopt; - std::optional> assets = std::nullopt; + std::optional> assets = std::nullopt; std::optional seq = std::nullopt; std::optional tfee = std::nullopt; std::optional err = std::nullopt; @@ -91,7 +91,7 @@ struct WithdrawArg std::optional asset2Out = std::nullopt; std::optional maxEP = std::nullopt; std::optional flags = std::nullopt; - std::optional> assets = std::nullopt; + std::optional> assets = std::nullopt; std::optional seq = std::nullopt; std::optional err = std::nullopt; }; @@ -102,7 +102,7 @@ struct VoteArg std::uint32_t tfee = 0; std::optional flags = std::nullopt; std::optional seq = std::nullopt; - std::optional> assets = std::nullopt; + std::optional> assets = std::nullopt; std::optional err = std::nullopt; }; @@ -113,7 +113,7 @@ struct BidArg std::optional> bidMax = std::nullopt; std::vector authAccounts = {}; std::optional flags = std::nullopt; - std::optional> assets = std::nullopt; + std::optional> assets = std::nullopt; }; /** Convenience class to test AMM functionality. @@ -137,7 +137,7 @@ class AMM // Transaction fee std::uint32_t const fee_; AccountID const ammAccount_; - Issue const lptIssue_; + IOUIssue const lptIssue_; public: AMM(Env& env, @@ -171,8 +171,8 @@ class AMM ammRpcInfo( std::optional const& account = std::nullopt, std::optional const& ledgerIndex = std::nullopt, - std::optional asset1 = std::nullopt, - std::optional asset2 = std::nullopt, + std::optional asset1 = std::nullopt, + std::optional asset2 = std::nullopt, std::optional const& ammAccount = std::nullopt, bool ignoreParams = false, unsigned apiVersion = RPC::apiInvalidVersion) const; @@ -190,8 +190,8 @@ class AMM */ std::tuple balances( - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, std::optional const& account = std::nullopt) const; [[nodiscard]] bool @@ -251,7 +251,7 @@ class AMM std::optional const& asset2In, std::optional const& maxEP, std::optional const& flags, - std::optional> const& assets, + std::optional> const& assets, std::optional const& seq, std::optional const& tfee = std::nullopt, std::optional const& ter = std::nullopt); @@ -297,7 +297,7 @@ class AMM std::optional const& asset2Out, std::optional const& maxEP, std::optional const& flags, - std::optional> const& assets, + std::optional> const& assets, std::optional const& seq, std::optional const& ter = std::nullopt); @@ -310,7 +310,7 @@ class AMM std::uint32_t feeVal, std::optional const& flags = std::nullopt, std::optional const& seq = std::nullopt, - std::optional> const& assets = std::nullopt, + std::optional> const& assets = std::nullopt, std::optional const& ter = std::nullopt); void @@ -325,7 +325,7 @@ class AMM return ammAccount_; } - Issue + IOUIssue lptIssue() const { return lptIssue_; @@ -381,7 +381,7 @@ class AMM void setTokens( Json::Value& jv, - std::optional> const& assets = std::nullopt); + std::optional> const& assets = std::nullopt); private: AccountID @@ -395,7 +395,7 @@ class AMM deposit( std::optional const& account, Json::Value& jv, - std::optional> const& assets = std::nullopt, + std::optional> const& assets = std::nullopt, std::optional const& seq = std::nullopt, std::optional const& ter = std::nullopt); @@ -404,7 +404,7 @@ class AMM std::optional const& account, Json::Value& jv, std::optional const& seq, - std::optional> const& assets = std::nullopt, + std::optional> const& assets = std::nullopt, std::optional const& ter = std::nullopt); void @@ -443,8 +443,8 @@ Json::Value ammClawback( Account const& issuer, Account const& holder, - Asset const& asset, - Asset const& asset2, + Issue const& asset, + Issue const& asset2, std::optional const& amount); } // namespace amm diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index d90d2bc1228..f7aa259b6f9 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -41,8 +41,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -444,7 +444,7 @@ class Env */ // VFALCO NOTE This should return a unit-less amount PrettyAmount - balance(Account const& account, Issue const& issue) const; + balance(Account const& account, IOUIssue const& issue) const; /** Return the number of objects owned by an account. * Returns 0 if the account does not exist. diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index 1d5a300a8e0..c14b3242ddd 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -33,8 +33,8 @@ inline std::size_t countOffers( jtx::Env& env, jtx::Account const& account, - Asset const& takerPays, - Asset const& takerGets) + Issue const& takerPays, + Issue const& takerGets) { size_t count = 0; forEachItem( @@ -83,8 +83,8 @@ inline bool isOffer( jtx::Env& env, jtx::Account const& account, - Asset const& takerPays, - Asset const& takerGets) + Issue const& takerPays, + Issue const& takerGets) { return countOffers(env, account, takerPays, takerGets) > 0; } @@ -108,7 +108,7 @@ class Path addHelper(std::forward(first), std::forward(rest)...); } Path& - push_back(Issue const& iss); + push_back(IOUIssue const& iss); Path& push_back(jtx::Account const& acc); Path& @@ -130,13 +130,13 @@ Path::push_back(STPathElement const& pe) } inline Path& -Path::push_back(Issue const& iss) +Path::push_back(IOUIssue const& iss) { path.emplace_back( STPathElement::typeCurrency | STPathElement::typeIssuer, beast::zero, - iss.currency, - iss.account); + iss.getCurrency(), + iss.getIssuer()); return *this; } diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 67f67a41e2e..b5b990d09d5 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -67,31 +67,8 @@ getAccountLines(Env& env, Account const& acct) return getAccountLines(env, acct.id()); } -template Json::Value -getAccountLines(Env& env, AccountID const& acctId, IOU... ious) -{ - auto const jrr = getAccountLines(env, acctId); - Json::Value res; - for (auto const& line : jrr[jss::lines]) - { - for (auto const& iou : {ious...}) - { - if (line[jss::currency].asString() == to_string(iou.currency)) - { - Json::Value v; - v[jss::currency] = line[jss::currency]; - v[jss::balance] = line[jss::balance]; - v[jss::limit] = line[jss::limit]; - v[jss::account] = line[jss::account]; - res[jss::lines].append(v); - } - } - } - if (!res.isNull()) - return res; - return jrr; -} +getAccountLines(Env& env, AccountID const& acctId, IOUIssue const& issue); [[nodiscard]] bool checkArraySize(Json::Value const& val, unsigned int size); @@ -136,9 +113,9 @@ stpathset_append(STPathSet& st, STPath const& p, Args const&... args) bool equal(STAmount const& sa1, STAmount const& sa2); -// Issue path element +// IOUIssue path element STPathElement -IPE(Issue const& iss); +IPE(IOUIssue const& iss); STPathElement IPE(MPTIssue const& iss); @@ -484,7 +461,7 @@ cpe(Currency const& c); // All path element STPathElement -allpe(AccountID const& a, Issue const& iss); +allpe(AccountID const& a, IOUIssue const& iss); /***************************************************************/ /* Check */ diff --git a/src/test/jtx/amount.h b/src/test/jtx/amount.h index 3491f1de47f..f6b51cc29b8 100644 --- a/src/test/jtx/amount.h +++ b/src/test/jtx/amount.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -56,7 +56,7 @@ struct AnyAmount; // struct None { - Issue issue; + IOUIssue issue; }; //------------------------------------------------------------------------------ @@ -154,9 +154,9 @@ operator<<(std::ostream& os, PrettyAmount const& amount); // Specifies an order book struct BookSpec { - ripple::Asset asset; + ripple::Issue asset; - BookSpec(ripple::Asset const& asset_) : asset(asset_) + BookSpec(ripple::Issue const& asset_) : asset(asset_) { } }; @@ -168,13 +168,13 @@ struct XRP_t /** Implicit conversion to Issue. This allows passing XRP where - an Issue is expected. + an IOUIssue is expected. */ - operator Issue() const + operator IOUIssue() const { return xrpIssue(); } - operator Asset() const + operator Issue() const { return xrpIssue(); } @@ -222,11 +222,11 @@ struct XRP_t friend BookSpec operator~(XRP_t const&) { - return BookSpec(Issue{xrpCurrency(), xrpAccount()}); + return BookSpec(IOUIssue{xrpCurrency(), xrpAccount()}); } }; -/** Converts to XRP Issue or STAmount. +/** Converts to XRP IOUIssue or STAmount. Examples: XRP Converts to the XRP Issue @@ -284,7 +284,7 @@ struct epsilon_t static epsilon_t const epsilon; -/** Converts to IOU Issue or STAmount. +/** Converts to IOU IOUIssue or STAmount. Examples: IOU Converts to the underlying Issue @@ -302,22 +302,22 @@ class IOU { } - Issue + IOUIssue issue() const { return {currency, account.id()}; } - /** Implicit conversion to Issue or Asset. + /** Implicit conversion to IOUIssue or Issue. This allows passing an IOU - value where an Issue or Asset is expected. + value where an IOUIssue or Issue is expected. */ - operator Issue() const + operator IOUIssue() const { return issue(); } - operator Asset() const + operator Issue() const { return issue(); } @@ -352,7 +352,7 @@ class IOU friend BookSpec operator~(IOU const& iou) { - return BookSpec(Issue{iou.currency, iou.account.id()}); + return BookSpec(IOUIssue{iou.currency, iou.account.id()}); } }; @@ -361,7 +361,7 @@ operator<<(std::ostream& os, IOU const& iou); //------------------------------------------------------------------------------ -/** Converts to MPT Issue or STAmount. +/** Converts to MPT IOUIssue or STAmount. Examples: MPT Converts to the underlying Issue @@ -394,7 +394,7 @@ class MPT { return MPTIssue{issuanceID}; } - operator ripple::Asset() const + operator ripple::Issue() const { return mpt(); } @@ -415,7 +415,7 @@ class MPT friend BookSpec operator~(MPT const& mpt) { - return BookSpec{Asset{mpt}}; + return BookSpec{Issue{mpt}}; } }; diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index 7cf06a3768b..6206efeb058 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -158,8 +158,8 @@ Json::Value AMM::ammRpcInfo( std::optional const& account, std::optional const& ledgerIndex, - std::optional asset1, - std::optional asset2, + std::optional asset1, + std::optional asset2, std::optional const& ammAccount, bool ignoreParams, unsigned apiVersion) const @@ -202,8 +202,8 @@ AMM::ammRpcInfo( std::tuple AMM::balances( - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, std::optional const& account) const { if (auto const amm = @@ -368,7 +368,7 @@ AMM::expectAmmInfo( void AMM::setTokens( Json::Value& jv, - std::optional> const& assets) + std::optional> const& assets) { if (assets) { @@ -390,7 +390,7 @@ IOUAmount AMM::deposit( std::optional const& account, Json::Value& jv, - std::optional> const& assets, + std::optional> const& assets, std::optional const& seq, std::optional const& ter) { @@ -458,7 +458,7 @@ AMM::deposit( std::optional const& asset2In, std::optional const& maxEP, std::optional const& flags, - std::optional> const& assets, + std::optional> const& assets, std::optional const& seq, std::optional const& tfee, std::optional const& ter) @@ -518,7 +518,7 @@ AMM::withdraw( std::optional const& account, Json::Value& jv, std::optional const& seq, - std::optional> const& assets, + std::optional> const& assets, std::optional const& ter) { auto const& acct = account ? *account : creatorAccount_; @@ -582,7 +582,7 @@ AMM::withdraw( std::optional const& asset2Out, std::optional const& maxEP, std::optional const& flags, - std::optional> const& assets, + std::optional> const& assets, std::optional const& seq, std::optional const& ter) { @@ -639,7 +639,7 @@ AMM::vote( std::uint32_t feeVal, std::optional const& flags, std::optional const& seq, - std::optional> const& assets, + std::optional> const& assets, std::optional const& ter) { Json::Value jv; @@ -829,8 +829,8 @@ Json::Value ammClawback( Account const& issuer, Account const& holder, - Asset const& asset, - Asset const& asset2, + Issue const& asset, + Issue const& asset2, std::optional const& amount) { Json::Value jv; diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index ef5a2124e24..130059eab03 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -189,18 +189,18 @@ Env::balance(Account const& account) const } PrettyAmount -Env::balance(Account const& account, Issue const& issue) const +Env::balance(Account const& account, IOUIssue const& issue) const { - if (isXRP(issue.currency)) + if (isXRP(issue.getCurrency())) return balance(account); auto const sle = le(keylet::line(account.id(), issue)); if (!sle) return {STAmount(issue, 0), account.name()}; auto amount = sle->getFieldAmount(sfBalance); - amount.setIssuer(issue.account); - if (account.id() > issue.account) + amount.setIssuer(issue.getIssuer()); + if (account.id() > issue.getIssuer()) amount.negate(); - return {amount, lookup(issue.account).name()}; + return {amount, lookup(issue.getIssuer()).name()}; } std::uint32_t diff --git a/src/test/jtx/impl/TestHelpers.cpp b/src/test/jtx/impl/TestHelpers.cpp index 8f08d37acbe..2233bc6c166 100644 --- a/src/test/jtx/impl/TestHelpers.cpp +++ b/src/test/jtx/impl/TestHelpers.cpp @@ -44,6 +44,28 @@ getAccountLines(Env& env, AccountID const& acctId) return env.rpc("json", "account_lines", to_string(jv))[jss::result]; } +Json::Value +getAccountLines(Env& env, AccountID const& acctId, IOUIssue const& issue) +{ + auto const jrr = getAccountLines(env, acctId); + Json::Value res; + for (auto const& line : jrr[jss::lines]) + { + if (line[jss::currency].asString() == to_string(issue.getCurrency())) + { + Json::Value v; + v[jss::currency] = line[jss::currency]; + v[jss::balance] = line[jss::balance]; + v[jss::limit] = line[jss::limit]; + v[jss::account] = line[jss::account]; + res[jss::lines].append(v); + } + } + if (!res.isNull()) + return res; + return jrr; +} + bool checkArraySize(Json::Value const& val, unsigned int size) { @@ -79,15 +101,15 @@ equal(STAmount const& sa1, STAmount const& sa2) return sa1 == sa2 && sa1.getIssuer() == sa2.getIssuer(); } -// Issue path element +// IOUIssue path element STPathElement -IPE(Issue const& iss) +IPE(IOUIssue const& iss) { return STPathElement( STPathElement::typeCurrency | STPathElement::typeIssuer, xrpAccount(), - PathAsset{iss.currency}, - iss.account); + PathIssue{iss.getCurrency()}, + iss.getIssuer()); } STPathElement IPE(MPTIssue const& iss) @@ -95,7 +117,7 @@ IPE(MPTIssue const& iss) return STPathElement( STPathElement::typeMPT | STPathElement::typeIssuer, xrpAccount(), - PathAsset{iss.getMptID()}, + PathIssue{iss.getMptID()}, iss.getIssuer()); } @@ -268,8 +290,8 @@ expectLine( { if (auto const sle = env.le(keylet::line(account, value.issue()))) { - Issue const issue = value.issue(); - bool const accountLow = account < issue.account; + IOUIssue const issue = value.issue(); + bool const accountLow = account < issue.getIssuer(); bool expectDefaultTrustLine = true; if (defaultLimits) @@ -277,8 +299,8 @@ expectLine( STAmount low{issue}; STAmount high{issue}; - low.setIssuer(accountLow ? account : issue.account); - high.setIssuer(accountLow ? issue.account : account); + low.setIssuer(accountLow ? account : issue.getIssuer()); + high.setIssuer(accountLow ? issue.getIssuer() : account); expectDefaultTrustLine = sle->getFieldAmount(sfLowLimit) == low && sle->getFieldAmount(sfHighLimit) == high; @@ -536,14 +558,14 @@ cpe(Currency const& c) // All path element STPathElement -allpe(AccountID const& a, Issue const& iss) +allpe(AccountID const& a, IOUIssue const& iss) { return STPathElement( STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer, a, - iss.currency, - iss.account); + iss.getCurrency(), + iss.getIssuer()); }; } // namespace jtx diff --git a/src/test/jtx/impl/amount.cpp b/src/test/jtx/impl/amount.cpp index 450f4d7b634..89c741c8955 100644 --- a/src/test/jtx/impl/amount.cpp +++ b/src/test/jtx/impl/amount.cpp @@ -35,12 +35,12 @@ operator<<(std::ostream&& os, if (amount.is_any) { os << amount.value.getText() << "/" << - to_string(amount.value.issue().currency) << + to_string(amount.value.issue().getCurrency()) << "*"; return os; } os << amount.value.getText() << "/" << - to_string(amount.value.issue().currency) << + to_string(amount.value.issue().getCurrency()) << "(" << amount.name() << ")"; return os; } @@ -90,10 +90,10 @@ operator<<(std::ostream& os, PrettyAmount const& amount) os << to_places(d, 6) << " XRP"; } - else if (amount.value().holds()) + else if (amount.value().holds()) { os << amount.value().getText() << "/" - << to_string(amount.value().get().currency) << "(" + << to_string(amount.value().get().getCurrency()) << "(" << amount.name() << ")"; } else @@ -125,7 +125,8 @@ IOU::operator()(detail::epsilon_multiple m) const std::ostream& operator<<(std::ostream& os, IOU const& iou) { - os << to_string(iou.issue().currency) << "(" << iou.account.name() << ")"; + os << to_string(iou.issue().getCurrency()) << "(" << iou.account.name() + << ")"; return os; } diff --git a/src/test/jtx/impl/balance.cpp b/src/test/jtx/impl/balance.cpp index afc6acfb18e..3106ccce67d 100644 --- a/src/test/jtx/impl/balance.cpp +++ b/src/test/jtx/impl/balance.cpp @@ -38,7 +38,7 @@ balance::operator()(Env& env) const env.test.expect(sle->getFieldAmount(sfBalance) == value_); } } - else if (value_.holds()) + else if (value_.holds()) { auto const sle = env.le(keylet::line(account_.id(), value_.issue())); if (none_) diff --git a/src/test/jtx/impl/paths.cpp b/src/test/jtx/impl/paths.cpp index 4608a6cde98..411933db26b 100644 --- a/src/test/jtx/impl/paths.cpp +++ b/src/test/jtx/impl/paths.cpp @@ -33,12 +33,12 @@ paths::operator()(Env& env, JTx& jt) const auto const to = env.lookup(jv[jss::Destination].asString()); auto const amount = amountFromJson(sfAmount, jv[jss::Amount]); Pathfinder pf( - std::make_shared( - env.current(), env.app().journal("AssetCache")), + std::make_shared( + env.current(), env.app().journal("IssueCache")), from, to, - in_.currency, - in_.account, + in_.getCurrency(), + in_.getIssuer(), amount, std::nullopt, env.app()); @@ -47,7 +47,7 @@ paths::operator()(Env& env, JTx& jt) const STPath fp; pf.computePathRanks(limit_); - auto const found = pf.getBestPaths(limit_, fp, {}, in_.account); + auto const found = pf.getBestPaths(limit_, fp, {}, in_.getIssuer()); // VFALCO TODO API to allow caller to examine the STPathSet // VFALCO isDefault should be renamed to empty() @@ -80,8 +80,8 @@ void path::append_one(IOU const& iou) { auto& jv = create(); - jv["currency"] = to_string(iou.issue().currency); - jv["account"] = toBase58(iou.issue().account); + jv["currency"] = to_string(iou.issue().getCurrency()); + jv["account"] = toBase58(iou.issue().getIssuer()); } void @@ -92,7 +92,7 @@ path::append_one(BookSpec const& book) jv["mpt_issuance_id"] = to_string(book.asset); else { - jv["currency"] = to_string(book.asset.get().currency); + jv["currency"] = to_string(book.asset.get().getCurrency()); jv["issuer"] = toBase58(book.asset.getIssuer()); } } diff --git a/src/test/jtx/impl/xchain_bridge.cpp b/src/test/jtx/impl/xchain_bridge.cpp index 43b0e7c2f96..27c3bef4856 100644 --- a/src/test/jtx/impl/xchain_bridge.cpp +++ b/src/test/jtx/impl/xchain_bridge.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -39,9 +39,9 @@ namespace jtx { Json::Value bridge( Account const& lockingChainDoor, - Issue const& lockingChainIssue, + IOUIssue const& lockingChainIssue, Account const& issuingChainDoor, - Issue const& issuingChainIssue) + IOUIssue const& issuingChainIssue) { Json::Value jv; jv[sfLockingChainDoor.getJsonName()] = lockingChainDoor.human(); @@ -55,9 +55,9 @@ bridge( Json::Value bridge_rpc( Account const& lockingChainDoor, - Issue const& lockingChainIssue, + IOUIssue const& lockingChainIssue, Account const& issuingChainDoor, - Issue const& issuingChainIssue) + IOUIssue const& issuingChainIssue) { Json::Value jv; jv[sfLockingChainDoor.getJsonName()] = lockingChainDoor.human(); diff --git a/src/test/jtx/paths.h b/src/test/jtx/paths.h index cc9caf3af72..6260e36c6a9 100644 --- a/src/test/jtx/paths.h +++ b/src/test/jtx/paths.h @@ -21,7 +21,7 @@ #define RIPPLE_TEST_JTX_PATHS_H_INCLUDED #include -#include +#include #include namespace ripple { @@ -32,12 +32,12 @@ namespace jtx { class paths { private: - Issue in_; + IOUIssue in_; int depth_; unsigned int limit_; public: - paths(Issue const& in, int depth = 7, unsigned int limit = 4) + paths(IOUIssue const& in, int depth = 7, unsigned int limit = 4) : in_(in), depth_(depth), limit_(limit) { } diff --git a/src/test/jtx/xchain_bridge.h b/src/test/jtx/xchain_bridge.h index 9968317c8de..52b86d4e460 100644 --- a/src/test/jtx/xchain_bridge.h +++ b/src/test/jtx/xchain_bridge.h @@ -39,9 +39,9 @@ constexpr std::size_t UT_XCHAIN_DEFAULT_QUORUM = 4; Json::Value bridge( Account const& lockingChainDoor, - Issue const& lockingChainIssue, + IOUIssue const& lockingChainIssue, Account const& issuingChainDoor, - Issue const& issuingChainIssue); + IOUIssue const& issuingChainIssue); Json::Value bridge_create( diff --git a/src/test/ledger/Invariants_test.cpp b/src/test/ledger/Invariants_test.cpp index 8d7b08fa1ab..964b6cd1260 100644 --- a/src/test/ledger/Invariants_test.cpp +++ b/src/test/ledger/Invariants_test.cpp @@ -259,7 +259,7 @@ class Invariants_test : public beast::unit_test::suite // AMM special cases AccountID ammAcctID; uint256 ammKey; - Issue ammIssue; + IOUIssue ammIssue; doInvariantCheck( {{"account deletion left behind a DirectoryNode object"}}, [&](Account const& A1, Account const& A2, ApplyContext& ac) { @@ -402,7 +402,7 @@ class Invariants_test : public beast::unit_test::suite [](Account const& A1, Account const& A2, ApplyContext& ac) { // create simple trust SLE with xrp currency auto const sleNew = std::make_shared( - keylet::line(A1, A2, xrpIssue().currency)); + keylet::line(A1, A2, xrpIssue().getCurrency())); ac.view().insert(sleNew); return true; }); diff --git a/src/test/ledger/PaymentSandbox_test.cpp b/src/test/ledger/PaymentSandbox_test.cpp index dd9b5c5d88b..997953865bc 100644 --- a/src/test/ledger/PaymentSandbox_test.cpp +++ b/src/test/ledger/PaymentSandbox_test.cpp @@ -124,23 +124,36 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); { auto r = accountSend(av, gw1, alice, toCredit, j); BEAST_EXPECT(r == tesSUCCESS); } BEAST_EXPECT( accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount + toCredit); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount + toCredit); { auto r = accountSend(av, alice, gw1, toDebit, j); BEAST_EXPECT(r == tesSUCCESS); } BEAST_EXPECT( accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount + toCredit - toDebit); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount + toCredit - toDebit); } { @@ -149,19 +162,32 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); rippleCredit(av, gw1, alice, toCredit, true, j); BEAST_EXPECT( accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount + toCredit); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount + toCredit); rippleCredit(av, alice, gw1, toDebit, true, j); BEAST_EXPECT( accountHolds( - av, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount + toCredit - toDebit); + av, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount + toCredit - toDebit); } { @@ -171,7 +197,12 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); { auto r = accountSend(pv, gw1, alice, toCredit, j); @@ -179,8 +210,12 @@ class PaymentSandbox_test : public beast::unit_test::suite } BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount); { auto r = accountSend(pv, alice, gw1, toDebit, j); @@ -188,8 +223,12 @@ class PaymentSandbox_test : public beast::unit_test::suite } BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount - toDebit); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount - toDebit); } { @@ -199,13 +238,22 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); rippleCredit(pv, gw1, alice, toCredit, true, j); BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount); } { @@ -215,13 +263,22 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); BEAST_EXPECT(redeemIOU(pv, alice, toDebit, iss, j) == tesSUCCESS); BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount - toDebit); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount - toDebit); } { @@ -231,13 +288,22 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); BEAST_EXPECT(issueIOU(pv, alice, toCredit, iss, j) == tesSUCCESS); BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount); } { @@ -247,7 +313,12 @@ class PaymentSandbox_test : public beast::unit_test::suite auto const iss = USD_gw1.issue(); auto const startingAmount = accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j); { auto r = accountSend(pv, gw1, alice, toCredit, j); @@ -255,8 +326,12 @@ class PaymentSandbox_test : public beast::unit_test::suite } BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount); { PaymentSandbox pv2(&pv); @@ -264,8 +339,8 @@ class PaymentSandbox_test : public beast::unit_test::suite accountHolds( pv2, alice, - iss.currency, - iss.account, + iss.getCurrency(), + iss.getIssuer(), fhIGNORE_FREEZE, j) == startingAmount); { @@ -276,8 +351,8 @@ class PaymentSandbox_test : public beast::unit_test::suite accountHolds( pv2, alice, - iss.currency, - iss.account, + iss.getCurrency(), + iss.getIssuer(), fhIGNORE_FREEZE, j) == startingAmount); } @@ -288,8 +363,12 @@ class PaymentSandbox_test : public beast::unit_test::suite } BEAST_EXPECT( accountHolds( - pv, alice, iss.currency, iss.account, fhIGNORE_FREEZE, j) == - startingAmount - toDebit); + pv, + alice, + iss.getCurrency(), + iss.getIssuer(), + fhIGNORE_FREEZE, + j) == startingAmount - toDebit); } } @@ -394,8 +473,8 @@ class PaymentSandbox_test : public beast::unit_test::suite // The currency we pass for the last argument mimics the currency that // is typically passed to creditHook, since it comes from a trust line. - Issue tlIssue = noIssue(); - tlIssue.currency = USD.issue().currency; + IOUIssue tlIssue = noIssue(); + tlIssue.setCurrency(USD.issue().getCurrency()); sb.creditHook(gw.id(), alice.id(), {USD, 400}, {tlIssue, 600}); sb.creditHook(gw.id(), alice.id(), {USD, 100}, {tlIssue, 600}); @@ -403,7 +482,7 @@ class PaymentSandbox_test : public beast::unit_test::suite // Expect that the STAmount issuer returned by balanceHook() is correct. STAmount const balance = sb.balanceHook(gw.id(), alice.id(), {USD, 600}); - BEAST_EXPECT(balance.getIssuer() == USD.issue().account); + BEAST_EXPECT(balance.getIssuer() == USD.issue().getIssuer()); } public: diff --git a/src/test/protocol/Issue_test.cpp b/src/test/protocol/Issue_test.cpp index 7ec1507e04b..3ce575b3ed5 100644 --- a/src/test/protocol/Issue_test.cpp +++ b/src/test/protocol/Issue_test.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -76,7 +76,7 @@ class Issue_test : public beast::unit_test::suite //-------------------------------------------------------------------------- // Comparison, hash tests for Issue - template + template void testIssue() { @@ -87,42 +87,42 @@ class Issue_test : public beast::unit_test::suite Currency const c3(3); AccountID const i3(3); - BEAST_EXPECT(Issue(c1, i1) != Issue(c2, i1)); - BEAST_EXPECT(Issue(c1, i1) < Issue(c2, i1)); - BEAST_EXPECT(Issue(c1, i1) <= Issue(c2, i1)); - BEAST_EXPECT(Issue(c2, i1) <= Issue(c2, i1)); - BEAST_EXPECT(Issue(c2, i1) == Issue(c2, i1)); - BEAST_EXPECT(Issue(c2, i1) >= Issue(c2, i1)); - BEAST_EXPECT(Issue(c3, i1) >= Issue(c2, i1)); - BEAST_EXPECT(Issue(c3, i1) > Issue(c2, i1)); - BEAST_EXPECT(Issue(c1, i1) != Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i1) < Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i1) <= Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i2) <= Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i2) == Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i2) >= Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i3) >= Issue(c1, i2)); - BEAST_EXPECT(Issue(c1, i3) > Issue(c1, i2)); - - std::hash hash; - - BEAST_EXPECT(hash(Issue(c1, i1)) == hash(Issue(c1, i1))); - BEAST_EXPECT(hash(Issue(c1, i2)) == hash(Issue(c1, i2))); - BEAST_EXPECT(hash(Issue(c1, i3)) == hash(Issue(c1, i3))); - BEAST_EXPECT(hash(Issue(c2, i1)) == hash(Issue(c2, i1))); - BEAST_EXPECT(hash(Issue(c2, i2)) == hash(Issue(c2, i2))); - BEAST_EXPECT(hash(Issue(c2, i3)) == hash(Issue(c2, i3))); - BEAST_EXPECT(hash(Issue(c3, i1)) == hash(Issue(c3, i1))); - BEAST_EXPECT(hash(Issue(c3, i2)) == hash(Issue(c3, i2))); - BEAST_EXPECT(hash(Issue(c3, i3)) == hash(Issue(c3, i3))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c1, i2))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c1, i3))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c2, i1))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c2, i2))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c2, i3))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c3, i1))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c3, i2))); - BEAST_EXPECT(hash(Issue(c1, i1)) != hash(Issue(c3, i3))); + BEAST_EXPECT(IOUIssue(c1, i1) != IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c1, i1) < IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c1, i1) <= IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c2, i1) <= IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c2, i1) == IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c2, i1) >= IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c3, i1) >= IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c3, i1) > IOUIssue(c2, i1)); + BEAST_EXPECT(IOUIssue(c1, i1) != IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i1) < IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i1) <= IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i2) <= IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i2) == IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i2) >= IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i3) >= IOUIssue(c1, i2)); + BEAST_EXPECT(IOUIssue(c1, i3) > IOUIssue(c1, i2)); + + std::hash hash; + + BEAST_EXPECT(hash(IOUIssue(c1, i1)) == hash(IOUIssue(c1, i1))); + BEAST_EXPECT(hash(IOUIssue(c1, i2)) == hash(IOUIssue(c1, i2))); + BEAST_EXPECT(hash(IOUIssue(c1, i3)) == hash(IOUIssue(c1, i3))); + BEAST_EXPECT(hash(IOUIssue(c2, i1)) == hash(IOUIssue(c2, i1))); + BEAST_EXPECT(hash(IOUIssue(c2, i2)) == hash(IOUIssue(c2, i2))); + BEAST_EXPECT(hash(IOUIssue(c2, i3)) == hash(IOUIssue(c2, i3))); + BEAST_EXPECT(hash(IOUIssue(c3, i1)) == hash(IOUIssue(c3, i1))); + BEAST_EXPECT(hash(IOUIssue(c3, i2)) == hash(IOUIssue(c3, i2))); + BEAST_EXPECT(hash(IOUIssue(c3, i3)) == hash(IOUIssue(c3, i3))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c1, i2))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c1, i3))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c2, i1))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c2, i2))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c2, i3))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c3, i1))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c3, i2))); + BEAST_EXPECT(hash(IOUIssue(c1, i1)) != hash(IOUIssue(c3, i3))); } template @@ -133,8 +133,8 @@ class Issue_test : public beast::unit_test::suite AccountID const i1(1); Currency const c2(2); AccountID const i2(2); - Issue const a1(c1, i1); - Issue const a2(c2, i2); + IOUIssue const a1(c1, i1); + IOUIssue const a2(c2, i2); { Set c; @@ -146,11 +146,11 @@ class Issue_test : public beast::unit_test::suite if (!BEAST_EXPECT(c.size() == 2)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i2)) == 0)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i2)) == 0)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i1)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i1)) == 1)) return; - if (!BEAST_EXPECT(c.erase(Issue(c2, i2)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c2, i2)) == 1)) return; if (!BEAST_EXPECT(c.empty())) return; @@ -166,11 +166,11 @@ class Issue_test : public beast::unit_test::suite if (!BEAST_EXPECT(c.size() == 2)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i2)) == 0)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i2)) == 0)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i1)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i1)) == 1)) return; - if (!BEAST_EXPECT(c.erase(Issue(c2, i2)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c2, i2)) == 1)) return; if (!BEAST_EXPECT(c.empty())) return; @@ -194,8 +194,8 @@ class Issue_test : public beast::unit_test::suite AccountID const i1(1); Currency const c2(2); AccountID const i2(2); - Issue const a1(c1, i1); - Issue const a2(c2, i2); + IOUIssue const a1(c1, i1); + IOUIssue const a2(c2, i2); { Map c; @@ -207,11 +207,11 @@ class Issue_test : public beast::unit_test::suite if (!BEAST_EXPECT(c.size() == 2)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i2)) == 0)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i2)) == 0)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i1)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i1)) == 1)) return; - if (!BEAST_EXPECT(c.erase(Issue(c2, i2)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c2, i2)) == 1)) return; if (!BEAST_EXPECT(c.empty())) return; @@ -227,11 +227,11 @@ class Issue_test : public beast::unit_test::suite if (!BEAST_EXPECT(c.size() == 2)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i2)) == 0)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i2)) == 0)) return; - if (!BEAST_EXPECT(c.erase(Issue(c1, i1)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c1, i1)) == 1)) return; - if (!BEAST_EXPECT(c.erase(Issue(c2, i2)) == 1)) + if (!BEAST_EXPECT(c.erase(IOUIssue(c2, i2)) == 1)) return; if (!BEAST_EXPECT(c.empty())) return; @@ -241,48 +241,48 @@ class Issue_test : public beast::unit_test::suite void testIssueSets() { - testcase("std::set "); - testIssueSet>(); + testcase("std::set "); + testIssueSet>(); - testcase("std::set "); - testIssueSet>(); + testcase("std::set "); + testIssueSet>(); #if RIPPLE_ASSETS_ENABLE_STD_HASH - testcase("std::unordered_set "); - testIssueSet>(); + testcase("std::unordered_set "); + testIssueSet>(); - testcase("std::unordered_set "); - testIssueSet>(); + testcase("std::unordered_set "); + testIssueSet>(); #endif - testcase("hash_set "); - testIssueSet>(); + testcase("hash_set "); + testIssueSet>(); - testcase("hash_set "); - testIssueSet>(); + testcase("hash_set "); + testIssueSet>(); } void testIssueMaps() { - testcase("std::map "); - testIssueMap>(); + testcase("std::map "); + testIssueMap>(); - testcase("std::map "); - testIssueMap>(); + testcase("std::map "); + testIssueMap>(); #if RIPPLE_ASSETS_ENABLE_STD_HASH - testcase("std::unordered_map "); - testIssueMap>(); + testcase("std::unordered_map "); + testIssueMap>(); - testcase("std::unordered_map "); - testIssueMap>(); + testcase("std::unordered_map "); + testIssueMap>(); - testcase("hash_map "); - testIssueMap>(); + testcase("hash_map "); + testIssueMap>(); - testcase("hash_map "); - testIssueMap>(); + testcase("hash_map "); + testIssueMap>(); #endif } @@ -301,10 +301,10 @@ class Issue_test : public beast::unit_test::suite Currency const c3(3); AccountID const i3(3); - Issue a1(c1, i1); - Issue a2(c1, i2); - Issue a3(c2, i2); - Issue a4(c3, i2); + IOUIssue a1(c1, i1); + IOUIssue a2(c1, i2); + IOUIssue a3(c2, i2); + IOUIssue a4(c3, i2); BEAST_EXPECT(Book(a1, a2) != Book(a2, a3)); BEAST_EXPECT(Book(a1, a2) < Book(a2, a3)); @@ -359,8 +359,8 @@ class Issue_test : public beast::unit_test::suite AccountID const i1(1); Currency const c2(2); AccountID const i2(2); - Issue const a1(c1, i1); - Issue const a2(c2, i2); + IOUIssue const a1(c1, i1); + IOUIssue const a2(c2, i2); Book const b1(a1, a2); Book const b2(a2, a1); @@ -422,8 +422,8 @@ class Issue_test : public beast::unit_test::suite AccountID const i1(1); Currency const c2(2); AccountID const i2(2); - Issue const a1(c1, i1); - Issue const a2(c2, i2); + IOUIssue const a1(c1, i1); + IOUIssue const a2(c2, i2); Book const b1(a1, a2); Book const b2(a2, a1); @@ -537,10 +537,10 @@ class Issue_test : public beast::unit_test::suite // --- testcase("Issue"); - testIssue(); + testIssue(); testcase("Issue"); - testIssue(); + testIssue(); testIssueSets(); testIssueMaps(); diff --git a/src/test/protocol/Quality_test.cpp b/src/test/protocol/Quality_test.cpp index 64cf0c71b3a..b77875f5552 100644 --- a/src/test/protocol/Quality_test.cpp +++ b/src/test/protocol/Quality_test.cpp @@ -29,7 +29,8 @@ class Quality_test : public beast::unit_test::suite // Create a raw, non-integral amount from mantissa and exponent STAmount static raw(std::uint64_t mantissa, int exponent) { - return STAmount(Issue{Currency(3), AccountID(3)}, mantissa, exponent); + return STAmount( + IOUIssue{Currency(3), AccountID(3)}, mantissa, exponent); } template diff --git a/src/test/protocol/STAmount_test.cpp b/src/test/protocol/STAmount_test.cpp index b512c42a643..863b7392cc7 100644 --- a/src/test/protocol/STAmount_test.cpp +++ b/src/test/protocol/STAmount_test.cpp @@ -104,7 +104,7 @@ class STAmount_test : public beast::unit_test::suite BEAST_EXPECT(!cmp.native()); - BEAST_EXPECT(cmp.issue().currency == res.issue().currency); + BEAST_EXPECT(cmp.issue().getCurrency() == res.issue().getCurrency()); if (res != cmp) { @@ -143,7 +143,7 @@ class STAmount_test : public beast::unit_test::suite void testSetValue( std::string const& value, - Issue const& issue, + IOUIssue const& issue, bool success = true) { try @@ -163,7 +163,7 @@ class STAmount_test : public beast::unit_test::suite { testcase("set value (native)"); - Issue const xrp(xrpIssue()); + IOUIssue const xrp(xrpIssue()); // fractional XRP (i.e. drops) testSetValue("1", xrp); @@ -196,7 +196,8 @@ class STAmount_test : public beast::unit_test::suite { testcase("set value (iou)"); - Issue const usd(Currency(0x5553440000000000), AccountID(0x4985601)); + IOUIssue const usd( + Currency(0x5553440000000000), AccountID(0x4985601)); testSetValue("1", usd); testSetValue("10", usd); @@ -608,8 +609,8 @@ class STAmount_test : public beast::unit_test::suite { testcase("STAmount to XRPAmount conversions"); - Issue const usd{Currency(0x5553440000000000), AccountID(0x4985601)}; - Issue const xrp{xrpIssue()}; + IOUIssue const usd{Currency(0x5553440000000000), AccountID(0x4985601)}; + IOUIssue const xrp{xrpIssue()}; for (std::uint64_t drops = 100000000000000000; drops != 1; drops = drops / 10) @@ -641,8 +642,8 @@ class STAmount_test : public beast::unit_test::suite { testcase("STAmount to IOUAmount conversions"); - Issue const usd{Currency(0x5553440000000000), AccountID(0x4985601)}; - Issue const xrp{xrpIssue()}; + IOUIssue const usd{Currency(0x5553440000000000), AccountID(0x4985601)}; + IOUIssue const xrp{xrpIssue()}; for (std::uint64_t dollars = 10000000000; dollars != 1; dollars = dollars / 10) diff --git a/src/test/protocol/STIssue_test.cpp b/src/test/protocol/STIssue_test.cpp index 4c9eeb0ba1b..c4e2fd59365 100644 --- a/src/test/protocol/STIssue_test.cpp +++ b/src/test/protocol/STIssue_test.cpp @@ -34,14 +34,14 @@ class STIssue_test : public beast::unit_test::suite using namespace jtx; Account const alice{"alice"}; auto const USD = alice["USD"]; - Issue issue; + IOUIssue issue; try { issue = xrpIssue(); - issue.account = alice; - STIssue stissue(sfAsset, Asset{issue}); - fail("Inconsistent XRP Issue doesn't fail"); + issue.setIssuer(alice); + STIssue stissue(sfAsset, Issue{issue}); + fail("Inconsistent XRP IOUIssue doesn't fail"); } catch (...) { @@ -51,9 +51,9 @@ class STIssue_test : public beast::unit_test::suite try { issue = USD; - issue.account = xrpAccount(); - STIssue stissue(sfAsset, Asset{issue}); - fail("Inconsistent IOU Issue doesn't fail"); + issue.setIssuer(xrpAccount()); + STIssue stissue(sfAsset, Issue{issue}); + fail("Inconsistent IOU IOUIssue doesn't fail"); } catch (...) { @@ -70,7 +70,7 @@ class STIssue_test : public beast::unit_test::suite (void)uint.parseHex(data); SerialIter iter(Slice(uint.data(), uint.size())); STIssue stissue(iter, sfAsset); - fail("Inconsistent IOU Issue doesn't fail on serializer"); + fail("Inconsistent IOU IOUIssue doesn't fail on serializer"); } catch (...) { @@ -79,7 +79,7 @@ class STIssue_test : public beast::unit_test::suite try { - STIssue stissue(sfAsset, Asset{xrpIssue()}); + STIssue stissue(sfAsset, Issue{xrpIssue()}); } catch (...) { @@ -88,7 +88,7 @@ class STIssue_test : public beast::unit_test::suite try { - STIssue stissue(sfAsset, Asset{USD}); + STIssue stissue(sfAsset, Issue{USD}); } catch (...) { @@ -108,7 +108,7 @@ class STIssue_test : public beast::unit_test::suite } catch (...) { - fail("USD Issue fails on serializer"); + fail("USD IOUIssue fails on serializer"); } try @@ -122,7 +122,7 @@ class STIssue_test : public beast::unit_test::suite } catch (...) { - fail("XRP Issue fails on serializer"); + fail("XRP IOUIssue fails on serializer"); } } @@ -133,9 +133,9 @@ class STIssue_test : public beast::unit_test::suite using namespace jtx; Account const alice{"alice"}; auto const USD = alice["USD"]; - Asset const asset1{xrpIssue()}; - Asset const asset2{USD}; - Asset const asset3{MPTID{2}}; + Issue const asset1{xrpIssue()}; + Issue const asset2{USD}; + Issue const asset3{MPTID{2}}; BEAST_EXPECT(STIssue(sfAsset, asset1) != asset2); BEAST_EXPECT(STIssue(sfAsset, asset1) != asset3); diff --git a/src/test/protocol/STNumber_test.cpp b/src/test/protocol/STNumber_test.cpp index ed255e32f1c..9f61ed007bf 100644 --- a/src/test/protocol/STNumber_test.cpp +++ b/src/test/protocol/STNumber_test.cpp @@ -18,7 +18,7 @@ //============================================================================== #include -#include +#include #include #include diff --git a/src/test/rpc/AMMInfo_test.cpp b/src/test/rpc/AMMInfo_test.cpp index f03bf18434e..9d9743b61a1 100644 --- a/src/test/rpc/AMMInfo_test.cpp +++ b/src/test/rpc/AMMInfo_test.cpp @@ -66,8 +66,8 @@ class AMMInfo_test : public jtx::AMMTestBase }); std::vector, - std::optional, + std::optional, + std::optional, TestAccount, bool>> const invalidParams = { {xrpIssue(), std::nullopt, None, false}, @@ -135,8 +135,8 @@ class AMMInfo_test : public jtx::AMMTestBase }); std::vector, - std::optional, + std::optional, + std::optional, TestAccount, bool>> const invalidParamsBadAccount = { {xrpIssue(), std::nullopt, None, false}, @@ -310,9 +310,9 @@ class AMMInfo_test : public jtx::AMMTestBase auctionSlot[jss::price][jss::value].asString() == "5600" && auctionSlot[jss::price][jss::currency].asString() == - to_string(ammAlice.lptIssue().currency) && + to_string(ammAlice.lptIssue().getCurrency()) && auctionSlot[jss::price][jss::issuer].asString() == - to_string(ammAlice.lptIssue().account)); + to_string(ammAlice.lptIssue().getIssuer())); } catch (std::exception const& e) { diff --git a/src/test/rpc/Book_test.cpp b/src/test/rpc/Book_test.cpp index 6bcc0c20809..e41780f4155 100644 --- a/src/test/rpc/Book_test.cpp +++ b/src/test/rpc/Book_test.cpp @@ -28,7 +28,7 @@ namespace test { class Book_test : public beast::unit_test::suite { std::string - getBookDir(jtx::Env& env, Issue const& in, Issue const& out) + getBookDir(jtx::Env& env, IOUIssue const& in, IOUIssue const& out) { std::string dir; auto uBookBase = getBookBase({in, out}); diff --git a/src/test/rpc/OwnerInfo_test.cpp b/src/test/rpc/OwnerInfo_test.cpp index 606f2274b88..6a131d086e1 100644 --- a/src/test/rpc/OwnerInfo_test.cpp +++ b/src/test/rpc/OwnerInfo_test.cpp @@ -124,7 +124,7 @@ class OwnerInfo_test : public beast::unit_test::suite BEAST_EXPECT( lines[0u][sfBalance.fieldName] == - (STAmount{Issue{to_currency("CNY"), noAccount()}, 0} + (STAmount{IOUIssue{to_currency("CNY"), noAccount()}, 0} .value() .getJson(JsonOptions::none))); BEAST_EXPECT( @@ -136,7 +136,7 @@ class OwnerInfo_test : public beast::unit_test::suite BEAST_EXPECT( lines[1u][sfBalance.fieldName] == - (STAmount{Issue{to_currency("USD"), noAccount()}, 0} + (STAmount{IOUIssue{to_currency("USD"), noAccount()}, 0} .value() .getJson(JsonOptions::none))); BEAST_EXPECT( @@ -169,7 +169,7 @@ class OwnerInfo_test : public beast::unit_test::suite BEAST_EXPECT( lines[0u][sfBalance.fieldName] == - (STAmount{Issue{to_currency("CNY"), noAccount()}, -50} + (STAmount{IOUIssue{to_currency("CNY"), noAccount()}, -50} .value() .getJson(JsonOptions::none))); BEAST_EXPECT( @@ -181,7 +181,7 @@ class OwnerInfo_test : public beast::unit_test::suite BEAST_EXPECT( lines[1u][sfBalance.fieldName] == - (STAmount{Issue{to_currency("USD"), noAccount()}, -50} + (STAmount{IOUIssue{to_currency("USD"), noAccount()}, -50} .value() .getJson(JsonOptions::none))); BEAST_EXPECT( diff --git a/src/xrpld/app/ledger/OrderBookDB.cpp b/src/xrpld/app/ledger/OrderBookDB.cpp index 720dea6f93b..f14b1d72985 100644 --- a/src/xrpld/app/ledger/OrderBookDB.cpp +++ b/src/xrpld/app/ledger/OrderBookDB.cpp @@ -117,9 +117,11 @@ OrderBookDB::update(std::shared_ptr const& ledger) if (sle->isFieldPresent(sfTakerPaysCurrency)) { - Issue iss; - iss.currency = sle->getFieldH160(sfTakerPaysCurrency); - iss.account = sle->getFieldH160(sfTakerPaysIssuer); + IOUIssue iss; + iss.setCurrency(static_cast( + sle->getFieldH160(sfTakerPaysCurrency))); + iss.setIssuer(static_cast( + sle->getFieldH160(sfTakerPaysIssuer))); book.in = iss; } else @@ -128,9 +130,11 @@ OrderBookDB::update(std::shared_ptr const& ledger) } if (sle->isFieldPresent(sfTakerGetsCurrency)) { - Issue iss; - iss.currency = sle->getFieldH160(sfTakerGetsCurrency); - iss.account = sle->getFieldH160(sfTakerGetsIssuer); + IOUIssue iss; + iss.setCurrency(static_cast( + sle->getFieldH160(sfTakerGetsCurrency))); + iss.setIssuer(static_cast( + sle->getFieldH160(sfTakerGetsIssuer))); book.out = iss; } else @@ -149,7 +153,7 @@ OrderBookDB::update(std::shared_ptr const& ledger) { auto const asset1 = (*sle)[sfAsset]; auto const asset2 = (*sle)[sfAsset2]; - auto addBook = [&](Asset const& in, Asset const& out) { + auto addBook = [&](Issue const& in, Issue const& out) { allBooks[in].insert(out); if (isXRP(out)) @@ -197,7 +201,7 @@ OrderBookDB::addOrderBook(Book const& book) // return list of all orderbooks that want this issuerID and currencyID std::vector -OrderBookDB::getBooksByTakerPays(Asset const& asset) +OrderBookDB::getBooksByTakerPays(Issue const& asset) { std::vector ret; @@ -217,7 +221,7 @@ OrderBookDB::getBooksByTakerPays(Asset const& asset) } int -OrderBookDB::getBookSize(Asset const& asset) +OrderBookDB::getBookSize(Issue const& asset) { std::lock_guard sl(mLock); if (auto it = allBooks_.find(asset); it != allBooks_.end()) @@ -226,7 +230,7 @@ OrderBookDB::getBookSize(Asset const& asset) } bool -OrderBookDB::isBookToXRP(Asset const& asset) +OrderBookDB::isBookToXRP(Issue const& asset) { std::lock_guard sl(mLock); return xrpBooks_.count(asset) > 0; diff --git a/src/xrpld/app/ledger/OrderBookDB.h b/src/xrpld/app/ledger/OrderBookDB.h index cbff92613bc..ce0d9f0fafe 100644 --- a/src/xrpld/app/ledger/OrderBookDB.h +++ b/src/xrpld/app/ledger/OrderBookDB.h @@ -45,15 +45,15 @@ class OrderBookDB /** @return a list of all orderbooks that want this issuerID and currencyID. */ std::vector - getBooksByTakerPays(Asset const&); + getBooksByTakerPays(Issue const&); /** @return a count of all orderbooks that want this issuerID and currencyID. */ int - getBookSize(Asset const&); + getBookSize(Issue const&); bool - isBookToXRP(Asset const&); + isBookToXRP(Issue const&); BookListeners::pointer getBookListeners(Book const&); @@ -71,10 +71,10 @@ class OrderBookDB Application& app_; // Maps order books by "issue in" to "issue out": - hardened_hash_map> allBooks_; + hardened_hash_map> allBooks_; // does an order book to XRP exist - hash_set xrpBooks_; + hash_set xrpBooks_; std::recursive_mutex mLock; diff --git a/src/xrpld/app/misc/AMMHelpers.h b/src/xrpld/app/misc/AMMHelpers.h index dd393bb74fa..ba770330526 100644 --- a/src/xrpld/app/misc/AMMHelpers.h +++ b/src/xrpld/app/misc/AMMHelpers.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -60,7 +60,7 @@ STAmount ammLPTokens( STAmount const& asset1, STAmount const& asset2, - Issue const& lptIssue); + IOUIssue const& lptIssue); /** Calculate LP Tokens given asset's deposit amount. * @param asset1Balance current AMM asset1 balance diff --git a/src/xrpld/app/misc/AMMUtils.h b/src/xrpld/app/misc/AMMUtils.h index d82dd390643..07f31203cba 100644 --- a/src/xrpld/app/misc/AMMUtils.h +++ b/src/xrpld/app/misc/AMMUtils.h @@ -39,8 +39,8 @@ std::pair ammPoolHolds( ReadView const& view, AccountID const& ammAccountID, - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal const j); @@ -53,8 +53,8 @@ Expected, TER> ammHolds( ReadView const& view, SLE const& ammSle, - std::optional const& optAsset1, - std::optional const& optAsset2, + std::optional const& optAsset1, + std::optional const& optAsset2, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal const j); @@ -64,8 +64,8 @@ ammHolds( STAmount ammLPHolds( ReadView const& view, - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, AccountID const& ammAccount, AccountID const& lpAccount, beast::Journal const j); @@ -93,7 +93,7 @@ STAmount ammAccountHolds( ReadView const& view, AccountID const& ammAccountID, - Asset const& asset); + Issue const& asset); /** Delete trustlines to AMM. If all trustlines are deleted then * AMM object and account are deleted. Otherwise tecIMPCOMPLETE is returned. @@ -101,8 +101,8 @@ ammAccountHolds( TER deleteAMMAccount( Sandbox& view, - Asset const& asset, - Asset const& asset2, + Issue const& asset, + Issue const& asset2, beast::Journal j); /** Initialize Auction and Voting slots and set the trading/discounted fee. @@ -112,7 +112,7 @@ initializeFeeAuctionVote( ApplyView& view, std::shared_ptr& ammSle, AccountID const& account, - Issue const& lptIssue, + IOUIssue const& lptIssue, std::uint16_t tfee); /** Return true if the Liquidity Provider is the only AMM provider, false @@ -122,7 +122,7 @@ initializeFeeAuctionVote( Expected isOnlyLiquidityProvider( ReadView const& view, - Issue const& ammIssue, + IOUIssue const& ammIssue, AccountID const& lpAccount); } // namespace ripple diff --git a/src/xrpld/app/misc/MPTUtils.h b/src/xrpld/app/misc/MPTUtils.h index b9fa33da38b..df1324d4c02 100644 --- a/src/xrpld/app/misc/MPTUtils.h +++ b/src/xrpld/app/misc/MPTUtils.h @@ -26,7 +26,7 @@ namespace ripple { -class Asset; +class Issue; class ReadView; /* Return true if a transaction is allowed for the specified MPT/account. The @@ -37,13 +37,13 @@ TER isMPTTxAllowed( ReadView const& v, TxType tx, - Asset const& asset, + Issue const& asset, AccountID const& accountID); TER isMPTDEXAllowed( ReadView const& view, - Asset const& issuanceID, + Issue const& issuanceID, AccountID const& srcAccount, AccountID const& destAccount); diff --git a/src/xrpld/app/misc/detail/AMMHelpers.cpp b/src/xrpld/app/misc/detail/AMMHelpers.cpp index 0181dc7361b..fe492c70551 100644 --- a/src/xrpld/app/misc/detail/AMMHelpers.cpp +++ b/src/xrpld/app/misc/detail/AMMHelpers.cpp @@ -25,7 +25,7 @@ STAmount ammLPTokens( STAmount const& asset1, STAmount const& asset2, - Issue const& lptIssue) + IOUIssue const& lptIssue) { auto const tokens = root2(asset1 * asset2); return toSTAmount(lptIssue, tokens); @@ -49,7 +49,7 @@ lpTokensIn( Number const r = asset1Deposit / asset1Balance; auto const c = root2(f2 * f2 + r / f1) - f2; auto const t = lptAMMBalance * (r - c) / (1 + c); - return toSTAmount(lptAMMBalance.get(), t); + return toSTAmount(lptAMMBalance.get(), t); } /* Equation 4 solves equation 3 for b: diff --git a/src/xrpld/app/misc/detail/AMMUtils.cpp b/src/xrpld/app/misc/detail/AMMUtils.cpp index 90603735fd2..15f1b64884a 100644 --- a/src/xrpld/app/misc/detail/AMMUtils.cpp +++ b/src/xrpld/app/misc/detail/AMMUtils.cpp @@ -29,8 +29,8 @@ std::pair ammPoolHolds( ReadView const& view, AccountID const& ammAccountID, - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal const j) @@ -46,13 +46,13 @@ Expected, TER> ammHolds( ReadView const& view, SLE const& ammSle, - std::optional const& optAsset1, - std::optional const& optAsset2, + std::optional const& optAsset1, + std::optional const& optAsset2, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal const j) { - auto const issues = [&]() -> std::optional> { + auto const issues = [&]() -> std::optional> { auto const issue1 = ammSle[sfAsset]; auto const issue2 = ammSle[sfAsset2]; if (optAsset1 && optAsset2) @@ -73,8 +73,8 @@ ammHolds( } auto const singleIssue = [&issue1, &issue2, &j]( - Asset checkIssue, - const char* label) -> std::optional> { + Issue checkIssue, + const char* label) -> std::optional> { if (checkIssue == issue1) return std::make_optional(std::make_pair(issue1, issue2)); else if (checkIssue == issue2) @@ -113,8 +113,8 @@ ammHolds( STAmount ammLPHolds( ReadView const& view, - Asset const& asset1, - Asset const& asset2, + Issue const& asset1, + Issue const& asset2, AccountID const& ammAccount, AccountID const& lpAccount, beast::Journal const j) @@ -180,7 +180,7 @@ STAmount ammAccountHolds( ReadView const& view, AccountID const& ammAccountID, - Asset const& asset) + Issue const& asset) { if (asset.holds()) return accountHolds( @@ -190,7 +190,7 @@ ammAccountHolds( FreezeHandling::fhIGNORE_FREEZE, AuthHandling::ahIGNORE_AUTH, beast::Journal(beast::Journal::getNullSink())); - // Should be accountHolds for Asset for both? + // Should be accountHolds for Issue for both? if (isXRP(asset)) { if (auto const sle = view.read(keylet::account(ammAccountID))) @@ -198,19 +198,19 @@ ammAccountHolds( } else if (auto const sle = view.read(keylet::line( ammAccountID, - asset.get().account, - asset.get().currency)); + asset.get().getIssuer(), + asset.get().getCurrency())); sle && !isFrozen( view, ammAccountID, - asset.get().currency, - asset.get().account)) + asset.get().getCurrency(), + asset.get().getIssuer())) { auto amount = (*sle)[sfBalance]; - if (ammAccountID > asset.get().account) + if (ammAccountID > asset.get().getIssuer()) amount.negate(); - amount.setIssuer(asset.get().account); + amount.setIssuer(asset.get().getIssuer()); return amount; } @@ -272,8 +272,8 @@ deleteAMMObjects( TER deleteAMMAccount( Sandbox& sb, - Asset const& asset, - Asset const& asset2, + Issue const& asset, + Issue const& asset2, beast::Journal j) { auto ammSle = sb.peek(keylet::amm(asset, asset2)); @@ -331,7 +331,7 @@ initializeFeeAuctionVote( ApplyView& view, std::shared_ptr& ammSle, AccountID const& account, - Issue const& lptIssue, + IOUIssue const& lptIssue, std::uint16_t tfee) { auto const& rules = view.rules(); @@ -376,7 +376,7 @@ initializeFeeAuctionVote( Expected isOnlyLiquidityProvider( ReadView const& view, - Issue const& ammIssue, + IOUIssue const& ammIssue, AccountID const& lpAccount) { // Liquidity Provider (LP) must have one LPToken trustline @@ -396,7 +396,7 @@ isOnlyLiquidityProvider( // there are more than one LP. Ten pages should be sufficient to include // five objects. std::uint8_t limit = 10; - auto const root = keylet::ownerDir(ammIssue.account); + auto const root = keylet::ownerDir(ammIssue.getIssuer()); auto currentIndex = root; // Iterate over AMM owner directory objects. diff --git a/src/xrpld/app/misc/detail/MPTUtils.cpp b/src/xrpld/app/misc/detail/MPTUtils.cpp index 22e808352f3..b925d06b9bb 100644 --- a/src/xrpld/app/misc/detail/MPTUtils.cpp +++ b/src/xrpld/app/misc/detail/MPTUtils.cpp @@ -19,8 +19,8 @@ #include #include -#include #include +#include namespace ripple { @@ -28,7 +28,7 @@ static TER isMPTAllowed( ReadView const& view, TxType txType, - Asset const& asset, + Issue const& asset, AccountID const& accountID, std::optional const& destAccount) { @@ -83,7 +83,7 @@ TER isMPTTxAllowed( ReadView const& view, TxType txType, - Asset const& asset, + Issue const& asset, AccountID const& accountID) { // use isDEXAllowed for payment/offer crossing @@ -94,7 +94,7 @@ isMPTTxAllowed( TER isMPTDEXAllowed( ReadView const& view, - Asset const& asset, + Issue const& asset, AccountID const& accountID, AccountID const& dest) { diff --git a/src/xrpld/app/paths/AMMLiquidity.h b/src/xrpld/app/paths/AMMLiquidity.h index 9c4a4ca4675..1c57c250a38 100644 --- a/src/xrpld/app/paths/AMMLiquidity.h +++ b/src/xrpld/app/paths/AMMLiquidity.h @@ -57,8 +57,8 @@ class AMMLiquidity AMMContext& ammContext_; AccountID const ammAccountID_; std::uint32_t const tradingFee_; - Asset const assetIn_; - Asset const assetOut_; + Issue const assetIn_; + Issue const assetOut_; // Initial AMM pool balances TAmounts const initialBalances_; beast::Journal const j_; @@ -68,8 +68,8 @@ class AMMLiquidity ReadView const& view, AccountID const& ammAccountID, std::uint32_t tradingFee, - Asset const& in, - Asset const& out, + Issue const& in, + Issue const& out, AMMContext& ammContext, beast::Journal j); ~AMMLiquidity() = default; @@ -110,13 +110,13 @@ class AMMLiquidity return ammContext_; } - Asset const& + Issue const& assetIn() const { return assetIn_; } - Asset const& + Issue const& assetOut() const { return assetOut_; diff --git a/src/xrpld/app/paths/AMMOffer.h b/src/xrpld/app/paths/AMMOffer.h index f6de0ccd9f0..3e12244133d 100644 --- a/src/xrpld/app/paths/AMMOffer.h +++ b/src/xrpld/app/paths/AMMOffer.h @@ -72,10 +72,10 @@ class AMMOffer return quality_; } - Asset const& + Issue const& assetIn() const; - Asset const& + Issue const& assetOut() const; AccountID const& diff --git a/src/xrpld/app/paths/AccountCurrencies.cpp b/src/xrpld/app/paths/AccountCurrencies.cpp index 434c0421c2c..f2212b425dd 100644 --- a/src/xrpld/app/paths/AccountCurrencies.cpp +++ b/src/xrpld/app/paths/AccountCurrencies.cpp @@ -24,7 +24,7 @@ namespace ripple { hash_set accountSourceCurrencies( AccountID const& account, - std::shared_ptr const& lrCache, + std::shared_ptr const& lrCache, bool includeXRP) { hash_set currencies; @@ -60,7 +60,7 @@ accountSourceCurrencies( hash_set accountDestCurrencies( AccountID const& account, - std::shared_ptr const& lrCache, + std::shared_ptr const& lrCache, bool includeXRP) { hash_set currencies; diff --git a/src/xrpld/app/paths/AccountCurrencies.h b/src/xrpld/app/paths/AccountCurrencies.h index debc9bf6a94..0ea62bb31d8 100644 --- a/src/xrpld/app/paths/AccountCurrencies.h +++ b/src/xrpld/app/paths/AccountCurrencies.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_APP_PATHS_ACCOUNTCURRENCIES_H_INCLUDED #define RIPPLE_APP_PATHS_ACCOUNTCURRENCIES_H_INCLUDED -#include +#include #include namespace ripple { @@ -28,13 +28,13 @@ namespace ripple { hash_set accountDestCurrencies( AccountID const& account, - std::shared_ptr const& cache, + std::shared_ptr const& cache, bool includeXRP); hash_set accountSourceCurrencies( AccountID const& account, - std::shared_ptr const& lrLedger, + std::shared_ptr const& lrLedger, bool includeXRP); } // namespace ripple diff --git a/src/xrpld/app/paths/Credit.cpp b/src/xrpld/app/paths/Credit.cpp index e027949e761..6293d1c6fd5 100644 --- a/src/xrpld/app/paths/Credit.cpp +++ b/src/xrpld/app/paths/Credit.cpp @@ -31,7 +31,7 @@ creditLimit( AccountID const& issuer, Currency const& currency) { - STAmount result(Issue{currency, account}); + STAmount result(IOUIssue{currency, account}); auto sleRippleState = view.read(keylet::line(account, issuer, currency)); @@ -68,7 +68,7 @@ creditBalance( AccountID const& issuer, Currency const& currency) { - STAmount result(Issue{currency, account}); + STAmount result(IOUIssue{currency, account}); auto sleRippleState = view.read(keylet::line(account, issuer, currency)); diff --git a/src/xrpld/app/paths/Flow.cpp b/src/xrpld/app/paths/Flow.cpp index 02472bda247..81bd6a71322 100644 --- a/src/xrpld/app/paths/Flow.cpp +++ b/src/xrpld/app/paths/Flow.cpp @@ -38,8 +38,8 @@ template static auto finishFlow( PaymentSandbox& sb, - Asset const& srcAsset, - Asset const& dstAsset, + Issue const& srcAsset, + Issue const& dstAsset, FlowResult&& f) { path::RippleCalc::Output result; @@ -71,19 +71,19 @@ flow( beast::Journal j, path::detail::FlowDebugInfo* flowDebugInfo) { - Asset const srcAsset = [&]() -> Asset { + Issue const srcAsset = [&]() -> Issue { if (sendMax) return sendMax->asset(); if (isXRP(deliver)) return xrpIssue(); - if (deliver.holds()) - return Issue(deliver.get().currency, src); + if (deliver.holds()) + return IOUIssue(deliver.get().getCurrency(), src); return deliver.asset(); }(); - Asset const dstAsset = deliver.asset(); + Issue const dstAsset = deliver.asset(); - std::optional sendMaxAsset; + std::optional sendMaxAsset; if (sendMax) sendMaxAsset = sendMax->asset(); diff --git a/src/xrpld/app/paths/AssetCache.cpp b/src/xrpld/app/paths/IssueCache.cpp similarity index 96% rename from src/xrpld/app/paths/AssetCache.cpp rename to src/xrpld/app/paths/IssueCache.cpp index 99082d39782..5d1d194238e 100644 --- a/src/xrpld/app/paths/AssetCache.cpp +++ b/src/xrpld/app/paths/IssueCache.cpp @@ -17,13 +17,13 @@ */ //============================================================================== -#include +#include #include #include namespace ripple { -AssetCache::AssetCache( +IssueCache::IssueCache( std::shared_ptr const& ledger, beast::Journal j) : ledger_(ledger), journal_(j) @@ -31,7 +31,7 @@ AssetCache::AssetCache( JLOG(journal_.debug()) << "created for ledger " << ledger_->info().seq; } -AssetCache::~AssetCache() +IssueCache::~IssueCache() { JLOG(journal_.debug()) << "destroyed for ledger " << ledger_->info().seq << " with " << lines_.size() << " accounts and " @@ -39,7 +39,7 @@ AssetCache::~AssetCache() } std::shared_ptr> -AssetCache::getRippleLines(AccountID const& accountID, LineDirection direction) +IssueCache::getRippleLines(AccountID const& accountID, LineDirection direction) { auto const hash = hasher_(accountID); AccountKey key(accountID, direction, hash); @@ -130,7 +130,7 @@ AssetCache::getRippleLines(AccountID const& accountID, LineDirection direction) } std::shared_ptr> const& -AssetCache::getMPTs(const ripple::AccountID& account) +IssueCache::getMPTs(const ripple::AccountID& account) { std::lock_guard sl(mLock); diff --git a/src/xrpld/app/paths/AssetCache.h b/src/xrpld/app/paths/IssueCache.h similarity index 97% rename from src/xrpld/app/paths/AssetCache.h rename to src/xrpld/app/paths/IssueCache.h index 056bdc52afd..340a5dd7628 100644 --- a/src/xrpld/app/paths/AssetCache.h +++ b/src/xrpld/app/paths/IssueCache.h @@ -33,13 +33,13 @@ namespace ripple { // Used by Pathfinder -class AssetCache final : public CountedObject +class IssueCache final : public CountedObject { public: - explicit AssetCache( + explicit IssueCache( std::shared_ptr const& l, beast::Journal j); - ~AssetCache(); + ~IssueCache(); std::shared_ptr const& getLedger() const diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/app/paths/PathRequest.cpp index d08b3febd39..08502516705 100644 --- a/src/xrpld/app/paths/PathRequest.cpp +++ b/src/xrpld/app/paths/PathRequest.cpp @@ -170,7 +170,7 @@ PathRequest::updateComplete() } bool -PathRequest::isValid(std::shared_ptr const& crCache) +PathRequest::isValid(std::shared_ptr const& crCache) { if (!raSrcAccount || !raDstAccount) return false; @@ -250,7 +250,7 @@ PathRequest::isValid(std::shared_ptr const& crCache) */ std::pair PathRequest::doCreate( - std::shared_ptr const& cache, + std::shared_ptr const& cache, Json::Value const& value) { bool valid = false; @@ -371,7 +371,7 @@ PathRequest::parseJson(Json::Value const& jvParams) return PFR_PJ_INVALID; } - PathAsset srcPathAsset; + PathIssue srcPathIssue; if (c.isMember(jss::currency)) { Currency currency; @@ -381,7 +381,7 @@ PathRequest::parseJson(Json::Value const& jvParams) jvStatus = rpcError(rpcSRC_CUR_MALFORMED); return PFR_PJ_INVALID; } - srcPathAsset = currency; + srcPathIssue = currency; } else { @@ -392,7 +392,7 @@ PathRequest::parseJson(Json::Value const& jvParams) jvStatus = rpcError(rpcSRC_CUR_MALFORMED); return PFR_PJ_INVALID; } - srcPathAsset = u; + srcPathIssue = u; } // Optional issuer @@ -406,9 +406,9 @@ PathRequest::parseJson(Json::Value const& jvParams) return PFR_PJ_INVALID; } - if (srcPathAsset.holds()) + if (srcPathIssue.holds()) { - if (srcPathAsset.get().isZero()) + if (srcPathIssue.get().isZero()) { if (srcIssuerID.isNonZero()) { @@ -425,7 +425,7 @@ PathRequest::parseJson(Json::Value const& jvParams) if (saSendMax) { // If the assets don't match, ignore the source asset. - if (srcPathAsset == saSendMax->asset()) + if (srcPathIssue == saSendMax->asset()) { // If neither is the source and they are not equal, then the // source issuer is illegal. @@ -439,37 +439,37 @@ PathRequest::parseJson(Json::Value const& jvParams) // If both are the source, use the source. // Otherwise, use the one that's not the source. - if (srcPathAsset.holds()) + if (srcPathIssue.holds()) { if (srcIssuerID != *raSrcAccount) { - sciSourceAssets.insert(Issue{ - srcPathAsset.get(), srcIssuerID}); + sciSourceAssets.insert(IOUIssue{ + srcPathIssue.get(), srcIssuerID}); } else if (saSendMax->getIssuer() != *raSrcAccount) { - sciSourceAssets.insert(Issue{ - srcPathAsset.get(), + sciSourceAssets.insert(IOUIssue{ + srcPathIssue.get(), saSendMax->getIssuer()}); } else { - sciSourceAssets.insert(Issue{ - srcPathAsset.get(), *raSrcAccount}); + sciSourceAssets.insert(IOUIssue{ + srcPathIssue.get(), *raSrcAccount}); } } else - sciSourceAssets.insert(srcPathAsset.get()); + sciSourceAssets.insert(srcPathIssue.get()); } } - else if (srcPathAsset.holds()) + else if (srcPathIssue.holds()) { sciSourceAssets.insert( - Issue{srcPathAsset.get(), srcIssuerID}); + IOUIssue{srcPathIssue.get(), srcIssuerID}); } else { - sciSourceAssets.insert(MPTIssue{srcPathAsset.get()}); + sciSourceAssets.insert(MPTIssue{srcPathIssue.get()}); } } } @@ -505,9 +505,9 @@ PathRequest::doAborting() const std::unique_ptr const& PathRequest::getPathFinder( - std::shared_ptr const& cache, - hash_map>& pathasset_map, - PathAsset const& asset, + std::shared_ptr const& cache, + hash_map>& pathasset_map, + PathIssue const& asset, STAmount const& dst_amount, int const level, std::function const& continueCallback) @@ -533,7 +533,7 @@ PathRequest::getPathFinder( bool PathRequest::findPaths( - std::shared_ptr const& cache, + std::shared_ptr const& cache, int const level, Json::Value& jvArray, std::function const& continueCallback) @@ -550,13 +550,13 @@ PathRequest::findPaths( for (auto const& c : currencies) { if (!sameAccount || - (saDstAmount.holds() && - c != saDstAmount.get().currency)) + (saDstAmount.holds() && + c != saDstAmount.get().getCurrency())) { if (sourceAssets.size() >= RPC::Tuning::max_auto_src_cur) return false; sourceAssets.insert( - Issue{c, c.isZero() ? xrpAccount() : *raSrcAccount}); + IOUIssue{c, c.isZero() ? xrpAccount() : *raSrcAccount}); } } if (auto mpts = cache->getMPTs(*raSrcAccount)) @@ -569,7 +569,7 @@ PathRequest::findPaths( } auto const dst_amount = convertAmount(saDstAmount, convert_all_); - hash_map> pathasset_map; + hash_map> pathasset_map; for (auto const& asset : sourceAssets) { if (continueCallback && !continueCallback()) @@ -608,9 +608,10 @@ PathRequest::findPaths( STAmount saMaxAmount = [&]() { if (saSendMax) return *saSendMax; - if (asset.holds()) + if (asset.holds()) return STAmount( - Issue{asset.get().currency, sourceAccount}, + IOUIssue{ + asset.get().getCurrency(), sourceAccount}, 1u, 0, true); @@ -673,7 +674,7 @@ PathRequest::findPaths( { Json::Value jvEntry(Json::objectValue); // TODO MPT - if (rc.actualAmountIn.holds()) + if (rc.actualAmountIn.holds()) rc.actualAmountIn.setIssuer(sourceAccount); jvEntry[jss::source_amount] = rc.actualAmountIn.getJson(JsonOptions::none); @@ -709,7 +710,7 @@ PathRequest::findPaths( Json::Value PathRequest::doUpdate( - std::shared_ptr const& cache, + std::shared_ptr const& cache, bool fast, std::function const& continueCallback) { diff --git a/src/xrpld/app/paths/PathRequest.h b/src/xrpld/app/paths/PathRequest.h index 534b1392946..6c631429473 100644 --- a/src/xrpld/app/paths/PathRequest.h +++ b/src/xrpld/app/paths/PathRequest.h @@ -21,11 +21,11 @@ #define RIPPLE_APP_PATHS_PATHREQUEST_H_INCLUDED #include -#include +#include #include #include #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ namespace ripple { // A pathfinding request submitted by a client // The request issuer must maintain a strong pointer -class AssetCache; +class IssueCache; class PathRequests; // Return values from parseJson <0 = invalid, >0 = valid @@ -87,7 +87,7 @@ class PathRequest final : public InfoSubRequest, updateComplete(); std::pair - doCreate(std::shared_ptr const&, Json::Value const&); + doCreate(std::shared_ptr const&, Json::Value const&); Json::Value doClose() override; @@ -99,7 +99,7 @@ class PathRequest final : public InfoSubRequest, // update jvStatus Json::Value doUpdate( - std::shared_ptr const&, + std::shared_ptr const&, bool fast, std::function const& continueCallback = {}); InfoSub::pointer @@ -109,13 +109,13 @@ class PathRequest final : public InfoSubRequest, private: bool - isValid(std::shared_ptr const& crCache); + isValid(std::shared_ptr const& crCache); std::unique_ptr const& getPathFinder( - std::shared_ptr const&, - hash_map>&, - PathAsset const&, + std::shared_ptr const&, + hash_map>&, + PathIssue const&, STAmount const&, int const, std::function const&); @@ -125,7 +125,7 @@ class PathRequest final : public InfoSubRequest, */ bool findPaths( - std::shared_ptr const&, + std::shared_ptr const&, int const, Json::Value&, std::function const&); @@ -153,8 +153,8 @@ class PathRequest final : public InfoSubRequest, STAmount saDstAmount; std::optional saSendMax; - std::set sciSourceAssets; - std::map mContext; + std::set sciSourceAssets; + std::map mContext; bool convert_all_; diff --git a/src/xrpld/app/paths/PathRequests.cpp b/src/xrpld/app/paths/PathRequests.cpp index 8888096ff04..3a7b6152ad3 100644 --- a/src/xrpld/app/paths/PathRequests.cpp +++ b/src/xrpld/app/paths/PathRequests.cpp @@ -30,10 +30,10 @@ namespace ripple { -/** Get the current AssetCache, updating it if necessary. +/** Get the current IssueCache, updating it if necessary. Get the correct ledger to use. */ -std::shared_ptr +std::shared_ptr PathRequests::getAssetCache( std::shared_ptr const& ledger, bool authoritative) @@ -60,7 +60,7 @@ PathRequests::getAssetCache( // weak_ptr, and will immediately discard it if there are no other // references. assetCache_ = assetCache = - std::make_shared(ledger, app_.journal("AssetCache")); + std::make_shared(ledger, app_.journal("IssueCache")); } return assetCache; } @@ -72,7 +72,7 @@ PathRequests::updateAll(std::shared_ptr const& inLedger) app_.getJobQueue().makeLoadEvent(jtPATH_FIND, "PathRequest::updateAll"); std::vector requests; - std::shared_ptr cache; + std::shared_ptr cache; // Get the ledger and cache we should be using { @@ -203,7 +203,7 @@ PathRequests::updateAll(std::shared_ptr const& inLedger) // Hold on to the line cache until after the lock is released, so it can // be destroyed outside of the lock - std::shared_ptr lastCache; + std::shared_ptr lastCache; { // Get the latest requests, cache, and ledger for next pass std::lock_guard sl(mLock); @@ -309,7 +309,7 @@ PathRequests::doLegacyPathRequest( Json::Value const& request) { auto cache = - std::make_shared(inLedger, app_.journal("AssetCache")); + std::make_shared(inLedger, app_.journal("IssueCache")); auto req = std::make_shared( app_, [] {}, consumer, ++mLastIdentifier, *this, mJournal); diff --git a/src/xrpld/app/paths/PathRequests.h b/src/xrpld/app/paths/PathRequests.h index e5760d64ea2..226938aed23 100644 --- a/src/xrpld/app/paths/PathRequests.h +++ b/src/xrpld/app/paths/PathRequests.h @@ -21,7 +21,7 @@ #define RIPPLE_APP_PATHS_PATHREQUESTS_H_INCLUDED #include -#include +#include #include #include #include @@ -54,7 +54,7 @@ class PathRequests bool requestsPending() const; - std::shared_ptr + std::shared_ptr getAssetCache( std::shared_ptr const& ledger, bool authoritative); @@ -111,8 +111,8 @@ class PathRequests // Track all requests std::vector requests_; - // Use a AssetCache - std::weak_ptr assetCache_; + // Use a IssueCache + std::weak_ptr assetCache_; std::atomic mLastIdentifier; diff --git a/src/xrpld/app/paths/Pathfinder.cpp b/src/xrpld/app/paths/Pathfinder.cpp index cfe47ce3daa..6cc408530e8 100644 --- a/src/xrpld/app/paths/Pathfinder.cpp +++ b/src/xrpld/app/paths/Pathfinder.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -158,18 +158,18 @@ smallestUsefulAmount(STAmount const& amount, int maxPaths) } STAmount -amountFromPathAsset( - PathAsset const& pathAsset, +amountFromPathIssue( + PathIssue const& pathAsset, std::optional const& srcIssuer, AccountID const& srcAccount) { return std::visit( - [&](T const& el) { + [&](T const& el) { if constexpr (std::is_same_v) { auto const account = srcIssuer.value_or(isXRP(el) ? xrpAccount() : srcAccount); - return STAmount(Issue{el, account}, 1u, 0, true); + return STAmount(IOUIssue{el, account}, 1u, 0, true); } else return STAmount(el, 1u, 0, true); @@ -177,15 +177,15 @@ amountFromPathAsset( pathAsset.value()); } -Asset -assetFromPathAsset(PathAsset const& pathAsset, AccountID const& account) +Issue +assetFromPathIssue(PathIssue const& pathAsset, AccountID const& account) { return std::visit( - [&](T const& el) { + [&](T const& el) { if constexpr (std::is_same_v) - return Asset{Issue{el, account}}; + return Issue{IOUIssue{el, account}}; else - return Asset{el}; + return Issue{el}; }, pathAsset.value()); } @@ -193,10 +193,10 @@ assetFromPathAsset(PathAsset const& pathAsset, AccountID const& account) } // namespace Pathfinder::Pathfinder( - std::shared_ptr const& cache, + std::shared_ptr const& cache, AccountID const& uSrcAccount, AccountID const& uDstAccount, - PathAsset const& uSrcPathAsset, + PathIssue const& uSrcPathIssue, std::optional const& uSrcIssuer, STAmount const& saDstAmount, std::optional const& srcAmount, @@ -207,9 +207,9 @@ Pathfinder::Pathfinder( isXRP(saDstAmount.getIssuer()) ? uDstAccount : saDstAmount.getIssuer()) , mDstAmount(saDstAmount) - , mSrcPathAsset(uSrcPathAsset) + , mSrcPathIssue(uSrcPathIssue) , mSrcIssuer(uSrcIssuer) - , mSrcAmount(amountFromPathAsset(uSrcPathAsset, uSrcIssuer, uSrcAccount)) + , mSrcAmount(amountFromPathIssue(uSrcPathIssue, uSrcIssuer, uSrcAccount)) , convert_all_(convertAllCheck(mDstAmount)) , mLedger(cache->getLedger()) , mAssetCache(cache) @@ -217,7 +217,7 @@ Pathfinder::Pathfinder( , j_(app.journal("Pathfinder")) { XRPL_ASSERT( - !uSrcIssuer || uSrcPathAsset.isXRP() == isXRP(uSrcIssuer.value()), + !uSrcIssuer || uSrcPathIssue.isXRP() == isXRP(uSrcIssuer.value()), "ripple::Pathfinder::Pathfinder : valid inputs"); } @@ -239,7 +239,7 @@ Pathfinder::findPaths( } if (mSrcAccount == mDstAccount && mDstAccount == mEffectiveDst && - mSrcPathAsset == mDstAmount.asset()) + mSrcPathIssue == mDstAmount.asset()) { // No need to send to same account with same currency. JLOG(j_.debug()) << "Tried to send to same issuer"; @@ -247,26 +247,26 @@ Pathfinder::findPaths( return false; } - if (mSrcAccount == mEffectiveDst && mSrcPathAsset == mDstAmount.asset()) + if (mSrcAccount == mEffectiveDst && mSrcPathIssue == mDstAmount.asset()) { // Default path might work, but any path would loop return true; } m_loadEvent = app_.getJobQueue().makeLoadEvent(jtPATH_FIND, "FindPath"); - auto currencyIsXRP = isXRP(mSrcPathAsset); + auto currencyIsXRP = isXRP(mSrcPathIssue); bool useIssuerAccount = mSrcIssuer && !currencyIsXRP && !isXRP(*mSrcIssuer); auto& account = useIssuerAccount ? *mSrcIssuer : mSrcAccount; auto issuer = currencyIsXRP ? AccountID() : account; - mSource = STPathElement(account, mSrcPathAsset, issuer); + mSource = STPathElement(account, mSrcPathIssue, issuer); auto issuerString = mSrcIssuer ? to_string(*mSrcIssuer) : std::string("none"); JLOG(j_.trace()) << "findPaths>" << " mSrcAccount=" << mSrcAccount << " mDstAccount=" << mDstAccount << " mDstAmount=" << mDstAmount.getFullText() - << " mSrcPathAsset=" << mSrcPathAsset + << " mSrcPathIssue=" << mSrcPathIssue << " mSrcIssuer=" << issuerString; if (!mLedger) @@ -275,7 +275,7 @@ Pathfinder::findPaths( return false; } - bool bSrcXrp = isXRP(mSrcPathAsset); + bool bSrcXrp = isXRP(mSrcPathIssue); bool bDstXrp = isXRP(mDstAmount.asset()); if (!mLedger->exists(keylet::account(mSrcAccount))) @@ -333,7 +333,7 @@ Pathfinder::findPaths( JLOG(j_.debug()) << "non-XRP to XRP payment"; paymentType = pt_nonXRP_to_XRP; } - else if (mSrcPathAsset == mDstAmount.asset()) + else if (mSrcPathIssue == mDstAmount.asset()) { // non-XRP -> non-XRP - Same currency JLOG(j_.debug()) << "non-XRP to non-XRP - same currency"; @@ -610,7 +610,7 @@ Pathfinder::getBestPaths( fullLiquidityPath.empty(), "ripple::Pathfinder::getBestPaths : first empty path result"); const bool issuerIsSender = - isXRP(mSrcPathAsset) || (srcIssuer == mSrcAccount); + isXRP(mSrcPathIssue) || (srcIssuer == mSrcAccount); std::vector extraPathRanks; rankPaths(maxPaths, extraPaths, extraPathRanks, continueCallback); @@ -727,9 +727,9 @@ Pathfinder::getBestPaths( } bool -Pathfinder::issueMatchesOrigin(Asset const& asset) +Pathfinder::issueMatchesOrigin(Issue const& asset) { - bool matchingAsset = asset == mSrcPathAsset; + bool matchingAsset = asset == mSrcPathIssue; bool matchingAccount = isXRP(asset) || (mSrcIssuer && asset.getIssuer() == mSrcIssuer) || asset.getIssuer() == mSrcAccount; @@ -739,14 +739,14 @@ Pathfinder::issueMatchesOrigin(Asset const& asset) int Pathfinder::getPathsOut( - PathAsset const& pathAsset, + PathIssue const& pathAsset, AccountID const& account, std::optional direction, bool isDstAsset, AccountID const& dstAccount, std::function const& continueCallback) { - Asset const asset = assetFromPathAsset(pathAsset, account); + Issue const asset = assetFromPathIssue(pathAsset, account); auto [it, inserted] = mPathsOutCountMap.emplace(asset, 0); @@ -778,7 +778,7 @@ Pathfinder::getPathsOut( { count = app_.getOrderBookDB().getBookSize(asset); - if (asset.holds()) + if (asset.holds()) { assert(direction); if (auto const lines = @@ -1016,10 +1016,10 @@ Pathfinder::addLink( std::function const& continueCallback) { auto const& pathEnd = currentPath.empty() ? mSource : currentPath.back(); - auto const& uEndPathAsset = pathEnd.getPathAsset(); + auto const& uEndPathIssue = pathEnd.getPathIssue(); auto const& uEndIssuer = pathEnd.getIssuerID(); auto const& uEndAccount = pathEnd.getAccountID(); - bool const bOnXRP = isXRP(uEndPathAsset); + bool const bOnXRP = isXRP(uEndPathIssue); // Does pathfinding really need to get this to // a gateway (the issuer of the destination amount) @@ -1051,20 +1051,20 @@ Pathfinder::addLink( { bool const bRequireAuth( sleEnd->getFieldU32(sfFlags) & lsfRequireAuth); - bool const bIsEndAsset(uEndPathAsset == mDstAmount.asset()); + bool const bIsEndAsset(uEndPathIssue == mDstAmount.asset()); bool const bIsNoRippleOut(isNoRippleOut(currentPath)); bool const bDestOnly(addFlags & afAC_LAST); AccountCandidates candidates; - auto forAssets = [&]( - AssetType const& assets) { + auto forAssets = [&]( + IssueType const& assets) { candidates.reserve(assets.size()); static bool constexpr isLine = std:: - is_same_v>; + is_same_v>; static bool constexpr isMPT = - std::is_same_v>; + std::is_same_v>; for (auto const& asset : assets) { @@ -1098,10 +1098,10 @@ Pathfinder::addLink( auto const correctAsset = [&]() { if constexpr (isLine) - return uEndPathAsset.get() == + return uEndPathIssue.get() == asset.getLimit().getCurrency(); if constexpr (isMPT) - return uEndPathAsset.get() == asset; + return uEndPathIssue.get() == asset; }(); auto checkLine = [&]() { if constexpr (isLine) @@ -1119,7 +1119,7 @@ Pathfinder::addLink( }; if (correctAsset && - !currentPath.hasSeen(acct, uEndPathAsset, acct)) + !currentPath.hasSeen(acct, uEndPathIssue, acct)) { // path is for correct currency and has not been // seen @@ -1130,7 +1130,7 @@ Pathfinder::addLink( else if (bToDestination) { // destination is always worth trying - if (uEndPathAsset == mDstAmount.asset()) + if (uEndPathIssue == mDstAmount.asset()) { // this is a complete path if (!currentPath.empty()) @@ -1158,7 +1158,7 @@ Pathfinder::addLink( { // save this candidate int out = getPathsOut( - uEndPathAsset, + uEndPathIssue, acct, direction, bIsEndAsset, @@ -1171,7 +1171,7 @@ Pathfinder::addLink( } }; - if (uEndPathAsset.holds()) + if (uEndPathIssue.holds()) { if (auto const lines = mAssetCache->getRippleLines( uEndAccount, @@ -1213,7 +1213,7 @@ Pathfinder::addLink( STPathElement pathElement( STPathElement::typeAccount, it->account, - uEndPathAsset, + uEndPathIssue, it->account); incompletePaths.assembleAdd(currentPath, pathElement); ++it; @@ -1234,7 +1234,7 @@ Pathfinder::addLink( // to XRP only if (!bOnXRP && app_.getOrderBookDB().isBookToXRP( - assetFromPathAsset(uEndPathAsset, uEndIssuer))) + assetFromPathIssue(uEndPathIssue, uEndIssuer))) { STPathElement pathElement( STPathElement::typeCurrency, @@ -1248,7 +1248,7 @@ Pathfinder::addLink( { bool bDestOnly = (addFlags & afOB_LAST) != 0; auto books = app_.getOrderBookDB().getBooksByTakerPays( - assetFromPathAsset(uEndPathAsset, uEndIssuer)); + assetFromPathIssue(uEndPathIssue, uEndIssuer)); JLOG(j_.trace()) << books.size() << " books found from this currency/issuer"; @@ -1290,7 +1290,7 @@ Pathfinder::addLink( book.out, book.out.getIssuer())) { - auto const assetType = book.out.holds() + auto const assetType = book.out.holds() ? STPathElement::typeCurrency : STPathElement::typeMPT; // Don't want the book if we've already seen the issuer diff --git a/src/xrpld/app/paths/Pathfinder.h b/src/xrpld/app/paths/Pathfinder.h index 882c95b32ed..3ac4877391a 100644 --- a/src/xrpld/app/paths/Pathfinder.h +++ b/src/xrpld/app/paths/Pathfinder.h @@ -21,10 +21,10 @@ #define RIPPLE_APP_PATHS_PATHFINDER_H_INCLUDED #include -#include +#include #include #include -#include +#include #include #include @@ -41,10 +41,10 @@ class Pathfinder : public CountedObject public: /** Construct a pathfinder without an issuer.*/ Pathfinder( - std::shared_ptr const& cache, + std::shared_ptr const& cache, AccountID const& srcAccount, AccountID const& dstAccount, - PathAsset const& uSrcPathAsset, + PathIssue const& uSrcPathIssue, std::optional const& uSrcIssuer, STAmount const& dstAmount, std::optional const& srcAmount, @@ -139,14 +139,14 @@ class Pathfinder : public CountedObject std::function const& continueCallback); bool - issueMatchesOrigin(Asset const&); + issueMatchesOrigin(Issue const&); int getPathsOut( - PathAsset const& pathAsset, + PathIssue const& pathAsset, AccountID const& account, std::optional direction, - bool isDestPathAsset, + bool isDestPathIssue, AccountID const& dest, std::function const& continueCallback); @@ -198,7 +198,7 @@ class Pathfinder : public CountedObject AccountID mDstAccount; AccountID mEffectiveDst; // The account the paths need to end at STAmount mDstAmount; - PathAsset mSrcPathAsset; + PathIssue mSrcPathIssue; std::optional mSrcIssuer; STAmount mSrcAmount; /** The amount remaining from mSrcAccount after the default liquidity has @@ -208,14 +208,14 @@ class Pathfinder : public CountedObject std::shared_ptr mLedger; std::unique_ptr m_loadEvent; - std::shared_ptr mAssetCache; + std::shared_ptr mAssetCache; STPathElement mSource; STPathSet mCompletePaths; std::vector mPathRanks; std::map mPaths; - hash_map mPathsOutCountMap; + hash_map mPathsOutCountMap; Application& app_; beast::Journal const j_; diff --git a/src/xrpld/app/paths/detail/AMMLiquidity.cpp b/src/xrpld/app/paths/detail/AMMLiquidity.cpp index d0e1193b5ee..add279e3a8a 100644 --- a/src/xrpld/app/paths/detail/AMMLiquidity.cpp +++ b/src/xrpld/app/paths/detail/AMMLiquidity.cpp @@ -27,8 +27,8 @@ AMMLiquidity::AMMLiquidity( ReadView const& view, AccountID const& ammAccountID, std::uint32_t tradingFee, - Asset const& in, - Asset const& out, + Issue const& in, + Issue const& out, AMMContext& ammContext, beast::Journal j) : ammContext_(ammContext) @@ -112,7 +112,7 @@ maxAmount() template T -maxOut(T const& out, Asset const& asset) +maxOut(T const& out, Issue const& asset) { Number const res = out * Number{99, -2}; return toAmount(asset, res, Number::rounding_mode::downward); diff --git a/src/xrpld/app/paths/detail/AMMOffer.cpp b/src/xrpld/app/paths/detail/AMMOffer.cpp index 6de969a51e0..d783a31270a 100644 --- a/src/xrpld/app/paths/detail/AMMOffer.cpp +++ b/src/xrpld/app/paths/detail/AMMOffer.cpp @@ -38,14 +38,14 @@ AMMOffer::AMMOffer( } template -Asset const& +Issue const& AMMOffer::assetIn() const { return ammLiquidity_.assetIn(); } template -Asset const& +Issue const& AMMOffer::assetOut() const { return ammLiquidity_.assetOut(); diff --git a/src/xrpld/app/paths/detail/AmountSpec.h b/src/xrpld/app/paths/detail/AmountSpec.h index a58174994db..4eee129133a 100644 --- a/src/xrpld/app/paths/detail/AmountSpec.h +++ b/src/xrpld/app/paths/detail/AmountSpec.h @@ -261,8 +261,8 @@ toAmountSpec(STAmount const& amt) else { result.amount = IOUAmount(sMant, amt.exponent()); - result.issuer = amt.get().account; - result.currency = amt.get().currency; + result.issuer = amt.get().getIssuer(); + result.currency = amt.get().getCurrency(); } return result; @@ -273,7 +273,7 @@ toEitherAmount(STAmount const& amt) { if (isXRP(amt)) return EitherAmount{amt.xrp()}; - else if (amt.holds()) + else if (amt.holds()) return EitherAmount{amt.iou()}; return EitherAmount(amt.mpt()); } diff --git a/src/xrpld/app/paths/detail/BookStep.cpp b/src/xrpld/app/paths/detail/BookStep.cpp index e92b28d8f90..85014de7782 100644 --- a/src/xrpld/app/paths/detail/BookStep.cpp +++ b/src/xrpld/app/paths/detail/BookStep.cpp @@ -91,7 +91,7 @@ class BookStep : public StepImp> } public: - BookStep(StrandContext const& ctx, Asset const& in, Asset const& out) + BookStep(StrandContext const& ctx, Issue const& in, Issue const& out) : maxOffersToConsume_(getMaxOffersToConsume(ctx)) , book_(in, out) , strandSrc_(ctx.strandSrc) @@ -199,7 +199,7 @@ class BookStep : public StepImp> } Rate - rate(ReadView const& view, Asset const& asset, AccountID const& dstAccount) + rate(ReadView const& view, Issue const& asset, AccountID const& dstAccount) const; private: @@ -392,8 +392,8 @@ class BookOfferCrossingStep public: BookOfferCrossingStep( StrandContext const& ctx, - Asset const& in, - Asset const& out) + Issue const& in, + Issue const& out) : BookStep>(ctx, in, out) , defaultPath_(ctx.isDefaultPath) , qualityThreshold_(getQuality(ctx.limitQuality)) @@ -1340,7 +1340,7 @@ BookStep::check(StrandContext const& ctx) const return temBAD_PATH_LOOP; } - auto issuerExists = [](ReadView const& view, Asset const& iss) -> bool { + auto issuerExists = [](ReadView const& view, Issue const& iss) -> bool { return isXRP(iss.getIssuer()) || view.read(keylet::account(iss.getIssuer())); }; @@ -1358,10 +1358,10 @@ BookStep::check(StrandContext const& ctx) const auto const& view = ctx.view; auto const& cur = book_.in.getIssuer(); - if (book_.in.holds()) + if (book_.in.holds()) { - auto sle = view.read( - keylet::line(*prev, cur, book_.in.get().currency)); + auto sle = view.read(keylet::line( + *prev, cur, book_.in.get().getCurrency())); if (!sle) return terNO_LINE; if ((*sle)[sfFlags] & @@ -1393,12 +1393,12 @@ template Rate BookStep::rate( ReadView const& view, - Asset const& asset, + Issue const& asset, AccountID const& dstAccount) const { if (isXRP(asset) || asset.getIssuer() == dstAccount) return parityRate; - if (asset.holds()) + if (asset.holds()) return transferRate(view, asset.getIssuer()); return transferRate(view, asset.get().getMptID()); }; @@ -1441,7 +1441,7 @@ bookStepEqual(Step const& step, ripple::Book const& book) template static std::pair> -make_BookStepHelper(StrandContext const& ctx, Asset const& in, Asset const& out) +make_BookStepHelper(StrandContext const& ctx, Issue const& in, Issue const& out) { TER ter = tefINTERNAL; std::unique_ptr r; @@ -1466,19 +1466,22 @@ make_BookStepHelper(StrandContext const& ctx, Asset const& in, Asset const& out) } std::pair> -make_BookStepII(StrandContext const& ctx, Issue const& in, Issue const& out) +make_BookStepII( + StrandContext const& ctx, + IOUIssue const& in, + IOUIssue const& out) { return make_BookStepHelper(ctx, in, out); } std::pair> -make_BookStepIX(StrandContext const& ctx, Issue const& in) +make_BookStepIX(StrandContext const& ctx, IOUIssue const& in) { return make_BookStepHelper(ctx, in, xrpIssue()); } std::pair> -make_BookStepXI(StrandContext const& ctx, Issue const& out) +make_BookStepXI(StrandContext const& ctx, IOUIssue const& out) { return make_BookStepHelper(ctx, xrpIssue(), out); } @@ -1494,13 +1497,19 @@ make_BookStepMM( } std::pair> -make_BookStepMI(StrandContext const& ctx, MPTIssue const& in, Issue const& out) +make_BookStepMI( + StrandContext const& ctx, + MPTIssue const& in, + IOUIssue const& out) { return make_BookStepHelper(ctx, in, out); } std::pair> -make_BookStepIM(StrandContext const& ctx, Issue const& in, MPTIssue const& out) +make_BookStepIM( + StrandContext const& ctx, + IOUIssue const& in, + MPTIssue const& out) { return make_BookStepHelper(ctx, in, out); } diff --git a/src/xrpld/app/paths/detail/DirectStep.cpp b/src/xrpld/app/paths/detail/DirectStep.cpp index 00832972062..38f0db8afca 100644 --- a/src/xrpld/app/paths/detail/DirectStep.cpp +++ b/src/xrpld/app/paths/detail/DirectStep.cpp @@ -518,7 +518,7 @@ DirectStepI::revImp( static_cast(this)->verifyDstQualityIn(dstQIn), "ripple::DirectStepI : valid destination quality"); - Issue const srcToDstIss(currency_, redeems(srcDebtDir) ? dst_ : src_); + IOUIssue const srcToDstIss(currency_, redeems(srcDebtDir) ? dst_ : src_); JLOG(j_.trace()) << "DirectStepI::rev" << " srcRedeems: " << redeems(srcDebtDir) @@ -643,7 +643,7 @@ DirectStepI::fwdImp( auto const [srcQOut, dstQIn] = qualities(sb, srcDebtDir, StrandDirection::forward); - Issue const srcToDstIss(currency_, redeems(srcDebtDir) ? dst_ : src_); + IOUIssue const srcToDstIss(currency_, redeems(srcDebtDir) ? dst_ : src_); JLOG(j_.trace()) << "DirectStepI::fwd" << " srcRedeems: " << redeems(srcDebtDir) @@ -855,7 +855,7 @@ DirectStepI::qualityUpperBound( if (isLast_ && dstQIn > QUALITY_ONE) dstQIn = QUALITY_ONE; - Issue const iss{currency_, src_}; + IOUIssue const iss{currency_, src_}; return { Quality(getRate(STAmount(iss, srcQOut), STAmount(iss, dstQIn))), dir}; @@ -865,7 +865,7 @@ DirectStepI::qualityUpperBound( ? qualitiesSrcRedeems(v) : qualitiesSrcIssues(v, prevStepDir); - Issue const iss{currency_, src_}; + IOUIssue const iss{currency_, src_}; // Be careful not to switch the parameters to `getRate`. The // `getRate(offerOut, offerIn)` function is usually used for offers. It // returns offerIn/offerOut. For a direct step, the rate is srcQOut/dstQIn @@ -923,8 +923,8 @@ DirectStepI::check(StrandContext const& ctx) const } } { - Issue const srcIssue{currency_, src_}; - Issue const dstIssue{currency_, dst_}; + IOUIssue const srcIssue{currency_, src_}; + IOUIssue const dstIssue{currency_, dst_}; if (ctx.seenBookOuts.count(srcIssue)) { @@ -940,7 +940,7 @@ DirectStepI::check(StrandContext const& ctx) const // issue if (auto book = ctx.prevStep->bookStepBook()) { - if (book->out.get() != srcIssue) + if (book->out.get() != srcIssue) return temBAD_PATH_LOOP; } } diff --git a/src/xrpld/app/paths/detail/PathfinderUtils.h b/src/xrpld/app/paths/detail/PathfinderUtils.h index 5010555868e..634ca08d732 100644 --- a/src/xrpld/app/paths/detail/PathfinderUtils.h +++ b/src/xrpld/app/paths/detail/PathfinderUtils.h @@ -30,7 +30,7 @@ largestAmount(STAmount const& amt) if (amt.native()) return INITIAL_XRP; - if (amt.holds()) + if (amt.holds()) return STAmount(amt.asset(), STAmount::cMaxValue, STAmount::cMaxOffset); return STAmount(amt.asset(), maxMPTokenAmount, 0); } diff --git a/src/xrpld/app/paths/detail/PaySteps.cpp b/src/xrpld/app/paths/detail/PaySteps.cpp index b642fa18b3e..ca59042fc9d 100644 --- a/src/xrpld/app/paths/detail/PaySteps.cpp +++ b/src/xrpld/app/paths/detail/PaySteps.cpp @@ -70,13 +70,13 @@ toStep( StrandContext const& ctx, STPathElement const* e1, STPathElement const* e2, - Asset const& curAsset) + Issue const& curAsset) { auto& j = ctx.j; if (ctx.isFirst && e1->isAccount() && (e1->getNodeType() & STPathElement::typeCurrency) && - e1->getPathAsset().isXRP()) + e1->getPathIssue().isXRP()) { return make_XRPEndpointStep(ctx, e1->getAccountID()); } @@ -111,7 +111,7 @@ toStep( ctx, e1->getAccountID(), e2->getAccountID(), - curAsset.get().currency); + curAsset.get().getCurrency()); } if (e1->isOffer() && e2->isAccount()) @@ -128,7 +128,7 @@ toStep( (e2->getNodeType() & STPathElement::typeIssuer), "ripple::toStep : currency or issuer"); auto const outAsset = e2->getNodeType() & STPathElement::typeAsset - ? e2->getPathAsset() + ? e2->getPathIssue() : curAsset; auto const outIssuer = e2->getNodeType() & STPathElement::typeIssuer ? e2->getIssuerID() @@ -146,7 +146,7 @@ toStep( { if (curAsset.holds()) return make_BookStepMX(ctx, curAsset.get()); - return make_BookStepIX(ctx, curAsset.get()); + return make_BookStepIX(ctx, curAsset.get()); } if (isXRP(curAsset)) @@ -161,15 +161,15 @@ toStep( ctx, curAsset.get(), {outAsset.get(), outIssuer}); - if (curAsset.holds() && outAsset.holds()) + if (curAsset.holds() && outAsset.holds()) return make_BookStepIM( - ctx, curAsset.get(), outAsset.get()); + ctx, curAsset.get(), outAsset.get()); if (curAsset.holds()) return make_BookStepMM( ctx, curAsset.get(), outAsset.get()); return make_BookStepII( - ctx, curAsset.get(), {outAsset.get(), outIssuer}); + ctx, curAsset.get(), {outAsset.get(), outIssuer}); } std::pair @@ -177,9 +177,9 @@ toStrand( ReadView const& view, AccountID const& src, AccountID const& dst, - Asset const& deliver, + Issue const& deliver, std::optional const& limitQuality, - std::optional const& sendMaxAsset, + std::optional const& sendMaxAsset, STPath const& path, bool ownerPaysTransferFee, OfferCrossing offerCrossing, @@ -246,14 +246,14 @@ toStrand( return {temBAD_PATH, Strand{}}; } - Asset curAsset = [&]() -> Asset { + Issue curAsset = [&]() -> Issue { auto const& asset = sendMaxAsset ? *sendMaxAsset : deliver; if (isXRP(asset)) return xrpIssue(); if (asset.holds()) return asset; // First step ripples from the source to the issuer. - return Issue{asset.get().currency, src}; + return IOUIssue{asset.get().getCurrency(), src}; }(); // Currency or MPT @@ -267,7 +267,7 @@ toStrand( normPath.reserve(4 + path.size()); { // The first step of a path is always implied to be the sender of the - // transaction, as defined by the transaction's Account field. The Asset + // transaction, as defined by the transaction's Account field. The Issue // is either SendMax or Deliver. auto const t = [&]() { auto const t = @@ -301,7 +301,7 @@ toStrand( // that MPTIssue can't change the account. STPathElement const& lastAsset = *std::find_if(normPath.rbegin(), normPath.rend(), hasAsset); - if (lastAsset.getPathAsset() != deliver || + if (lastAsset.getPathIssue() != deliver || (offerCrossing && lastAsset.getIssuerID() != deliver.getIssuer())) { @@ -347,9 +347,9 @@ toStrand( at most twice: once as a src and once as a dst (hence the two element array). The strandSrc and strandDst will only show up once each. */ - std::array, 2> seenDirectAssets; + std::array, 2> seenDirectAssets; // A strand may not include the same offer book more than once - boost::container::flat_set seenBookOuts; + boost::container::flat_set seenBookOuts; seenDirectAssets[0].reserve(normPath.size()); seenDirectAssets[1].reserve(normPath.size()); seenBookOuts.reserve(normPath.size()); @@ -386,38 +386,39 @@ toStrand( // Switch over from MPT to Currency. if (curAsset.holds() && cur->hasCurrency()) - curAsset = Issue{}; + curAsset = IOUIssue{}; - // Can only update the account for Issue since MPTIssue's account + // Can only update the account for IOUIssue since MPTIssue's account // is immutable as it is part of MPTID - if (curAsset.holds()) + if (curAsset.holds()) { if (cur->isAccount()) - curAsset.get().account = cur->getAccountID(); + curAsset.get().setIssuer(cur->getAccountID()); else if (cur->hasIssuer()) - curAsset.get().account = cur->getIssuerID(); + curAsset.get().setIssuer(cur->getIssuerID()); } if (cur->hasCurrency()) { - curAsset = Issue{cur->getCurrency(), curAsset.getIssuer()}; + curAsset = IOUIssue{cur->getCurrency(), curAsset.getIssuer()}; if (isXRP(curAsset)) - curAsset.get().account = xrpAccount(); + curAsset.get().setIssuer( + xrpAccount()); // TODO XRPIssue } else if (cur->hasMPT()) - curAsset = cur->getPathAsset().get(); + curAsset = cur->getPathIssue().get(); auto getImpliedStep = [&](AccountID const& src_, AccountID const& dst_, - Asset const& asset_) -> std::pair> { + Issue const& asset_) -> std::pair> { if (asset_.holds()) { JLOG(j.error()) << "MPT is invalid with rippling"; return {temBAD_PATH, nullptr}; } return make_DirectStepI( - ctx(), src_, dst_, asset_.get().currency); + ctx(), src_, dst_, asset_.get().getCurrency()); }; if (cur->isAccount() && next->isAccount()) @@ -508,7 +509,7 @@ toStrand( } if (!next->isOffer() && next->hasAsset() && - next->getPathAsset() != curAsset) + next->getPathIssue() != curAsset) { // Should never happen UNREACHABLE("ripple::toStrand : offer currency mismatch"); @@ -538,13 +539,13 @@ toStrand( }; auto curAcc = src; - auto curAsset = [&]() -> Asset { + auto curAsset = [&]() -> Issue { auto const& asset = sendMaxAsset ? *sendMaxAsset : deliver; if (isXRP(asset)) return xrpIssue(); if (asset.holds()) return asset; - return Issue{asset.get().currency, src}; + return IOUIssue{asset.get().getCurrency(), src}; }(); for (auto const& s : result) @@ -559,18 +560,19 @@ toStrand( return false; curAsset = b->out; } - else if (curAsset.holds()) + else if (curAsset.holds()) { - curAsset.get().account = accts.second; + curAsset.get().setIssuer(accts.second); } curAcc = accts.second; } if (curAcc != dst) return false; - if (curAsset.holds() != deliver.holds() || - (curAsset.holds() && - curAsset.get().currency != deliver.get().currency) || + if (curAsset.holds() != deliver.holds() || + (curAsset.holds() && + curAsset.get().getCurrency() != + deliver.get().getCurrency()) || (curAsset.holds() && curAsset.get() != deliver.get())) return false; @@ -595,9 +597,9 @@ toStrands( ReadView const& view, AccountID const& src, AccountID const& dst, - Asset const& deliver, + Issue const& deliver, std::optional const& limitQuality, - std::optional const& sendMax, + std::optional const& sendMax, STPathSet const& paths, bool addDefaultPath, bool ownerPaysTransferFee, @@ -710,14 +712,14 @@ StrandContext::StrandContext( // replicates the source or destination. AccountID const& strandSrc_, AccountID const& strandDst_, - Asset const& strandDeliver_, + Issue const& strandDeliver_, std::optional const& limitQuality_, bool isLast_, bool ownerPaysTransferFee_, OfferCrossing offerCrossing_, bool isDefaultPath_, - std::array, 2>& seenDirectAssets_, - boost::container::flat_set& seenBookOuts_, + std::array, 2>& seenDirectAssets_, + boost::container::flat_set& seenBookOuts_, AMMContext& ammContext_, beast::Journal j_) : view(view_) diff --git a/src/xrpld/app/paths/detail/Steps.h b/src/xrpld/app/paths/detail/Steps.h index 931a9479b95..59cfc0e2363 100644 --- a/src/xrpld/app/paths/detail/Steps.h +++ b/src/xrpld/app/paths/detail/Steps.h @@ -352,7 +352,7 @@ operator==(Strand const& lhs, Strand const& rhs) @param src Account that is sending assets @param dst Account that is receiving assets - @param deliver Asset the dst account will receive + @param deliver Issue the dst account will receive (if issuer of deliver == dst, then accept any issuer) @param sendMax Optional asset to send. @param path Liquidity sources to use for this strand of the payment. The path @@ -364,8 +364,8 @@ std::pair normalizePath( AccountID const& src, AccountID const& dst, - Asset const& deliver, - std::optional const& sendMaxAsset, + Issue const& deliver, + std::optional const& sendMaxAsset, STPath const& path); /** @@ -374,7 +374,7 @@ normalizePath( @param sb view for trust lines, balances, and attributes like auth and freeze @param src Account that is sending assets @param dst Account that is receiving assets - @param deliver Asset the dst account will receive + @param deliver Issue the dst account will receive (if issuer of deliver == dst, then accept any issuer) @param limitQuality Offer crossing BookSteps use this value in an optimization. If, during direct offer crossing, the @@ -396,9 +396,9 @@ toStrand( ReadView const& sb, AccountID const& src, AccountID const& dst, - Asset const& deliver, + Issue const& deliver, std::optional const& limitQuality, - std::optional const& sendMaxAsset, + std::optional const& sendMaxAsset, STPath const& path, bool ownerPaysTransferFee, OfferCrossing offerCrossing, @@ -412,7 +412,7 @@ toStrand( @param sb View for trust lines, balances, and attributes like auth and freeze @param src Account that is sending assets @param dst Account that is receiving assets - @param deliver Asset the dst account will receive + @param deliver Issue the dst account will receive (if issuer of deliver == dst, then accept any issuer) @param limitQuality Offer crossing BookSteps use this value in an optimization. If, during direct offer crossing, the @@ -435,9 +435,9 @@ toStrands( ReadView const& sb, AccountID const& src, AccountID const& dst, - Asset const& deliver, + Issue const& deliver, std::optional const& limitQuality, - std::optional const& sendMax, + std::optional const& sendMax, STPathSet const& paths, bool addDefaultPath, bool ownerPaysTransferFee, @@ -446,7 +446,7 @@ toStrands( beast::Journal j); /// @cond INTERNAL -template +template struct StepImp : public Step { explicit StepImp() = default; @@ -534,7 +534,7 @@ struct StrandContext ReadView const& view; ///< Current ReadView AccountID const strandSrc; ///< Strand source account AccountID const strandDst; ///< Strand destination account - Asset const strandDeliver; ///< Asset strand delivers + Issue const strandDeliver; ///< Issue strand delivers std::optional const limitQuality; ///< Worst accepted quality bool const isFirst; ///< true if Step is first in Strand bool const isLast = false; ///< true if Step is last in Strand @@ -552,11 +552,11 @@ struct StrandContext at most twice: once as a src and once as a dst (hence the two element array). The strandSrc and strandDst will only show up once each. */ - std::array, 2>& seenDirectAssets; + std::array, 2>& seenDirectAssets; /** A strand may not include an offer that output the same issue more than once */ - boost::container::flat_set& seenBookOuts; + boost::container::flat_set& seenBookOuts; AMMContext& ammContext; beast::Journal const j; @@ -568,15 +568,15 @@ struct StrandContext // replicates the source or destination. AccountID const& strandSrc_, AccountID const& strandDst_, - Asset const& strandDeliver_, + Issue const& strandDeliver_, std::optional const& limitQuality_, bool isLast_, bool ownerPaysTransferFee_, OfferCrossing offerCrossing_, bool isDefaultPath_, - std::array, 2>& + std::array, 2>& seenDirectAssets_, ///< For detecting currency loops - boost::container::flat_set& + boost::container::flat_set& seenBookOuts_, ///< For detecting book loops AMMContext& ammContext_, beast::Journal j_); ///< Journal for logging @@ -614,13 +614,16 @@ make_MPTEndpointStep( MPTID const& a); std::pair> -make_BookStepII(StrandContext const& ctx, Issue const& in, Issue const& out); +make_BookStepII( + StrandContext const& ctx, + IOUIssue const& in, + IOUIssue const& out); std::pair> -make_BookStepIX(StrandContext const& ctx, Issue const& in); +make_BookStepIX(StrandContext const& ctx, IOUIssue const& in); std::pair> -make_BookStepXI(StrandContext const& ctx, Issue const& out); +make_BookStepXI(StrandContext const& ctx, IOUIssue const& out); std::pair> make_XRPEndpointStep(StrandContext const& ctx, AccountID const& acc); @@ -638,10 +641,16 @@ std::pair> make_BookStepXM(StrandContext const& ctx, MPTIssue const& out); std::pair> -make_BookStepMI(StrandContext const& ctx, MPTIssue const& in, Issue const& out); +make_BookStepMI( + StrandContext const& ctx, + MPTIssue const& in, + IOUIssue const& out); std::pair> -make_BookStepIM(StrandContext const& ctx, Issue const& in, MPTIssue const& out); +make_BookStepIM( + StrandContext const& ctx, + IOUIssue const& in, + MPTIssue const& out); template bool diff --git a/src/xrpld/app/paths/detail/StrandFlow.h b/src/xrpld/app/paths/detail/StrandFlow.h index 4e1d830827a..50449e2eb9a 100644 --- a/src/xrpld/app/paths/detail/StrandFlow.h +++ b/src/xrpld/app/paths/detail/StrandFlow.h @@ -559,7 +559,7 @@ class ActiveStrands @return Actual amount in and out from the strands, errors, and payment sandbox */ -template +template FlowResult flow( PaymentSandbox const& baseView, diff --git a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp b/src/xrpld/app/paths/detail/XRPEndpointStep.cpp index 80220d2e1dd..42bbfd86e02 100644 --- a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp +++ b/src/xrpld/app/paths/detail/XRPEndpointStep.cpp @@ -201,8 +201,9 @@ class XRPEndpointOfferCrossingStep static std::int32_t computeReserveReduction(StrandContext const& ctx, AccountID const& acc) { - if (ctx.isFirst && ctx.strandDeliver.holds() && - !ctx.view.read(keylet::line(acc, ctx.strandDeliver.get()))) + if (ctx.isFirst && ctx.strandDeliver.holds() && + !ctx.view.read( + keylet::line(acc, ctx.strandDeliver.get()))) return -1; return 0; } diff --git a/src/xrpld/app/tx/detail/AMMClawback.cpp b/src/xrpld/app/tx/detail/AMMClawback.cpp index bba09a80040..b4893489227 100644 --- a/src/xrpld/app/tx/detail/AMMClawback.cpp +++ b/src/xrpld/app/tx/detail/AMMClawback.cpp @@ -78,7 +78,7 @@ AMMClawback::preflight(PreflightContext const& ctx) if (asset.getIssuer() != issuer) { - JLOG(ctx.j.trace()) << "AMMClawback: Asset's account does not " + JLOG(ctx.j.trace()) << "AMMClawback: Issue's account does not " "match Account field."; return temMALFORMED; } @@ -86,7 +86,7 @@ AMMClawback::preflight(PreflightContext const& ctx) if (clawAmount && clawAmount->issue() != asset) { JLOG(ctx.j.trace()) << "AMMClawback: Amount's issuer/currency subfield " - "does not match Asset field"; + "does not match Issue field"; return temBAD_AMOUNT; } @@ -144,8 +144,8 @@ AMMClawback::applyGuts(Sandbox& sb) std::optional const clawAmount = ctx_.tx[~sfAmount]; AccountID const issuer = ctx_.tx[sfAccount]; AccountID const holder = ctx_.tx[sfHolder]; - Asset const asset = ctx_.tx[sfAsset]; - Asset const asset2 = ctx_.tx[sfAsset2]; + Issue const asset = ctx_.tx[sfAsset]; + Issue const asset2 = ctx_.tx[sfAsset2]; auto ammSle = sb.peek(keylet::amm(asset, asset2)); if (!ammSle) diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 34ca7187013..64f98a1ebcc 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -130,7 +130,7 @@ AMMCreate::preclaim(PreclaimContext const& ctx) return tecFROZEN; } - auto noDefaultRipple = [](ReadView const& view, Asset const& asset) { + auto noDefaultRipple = [](ReadView const& view, Issue const& asset) { if (asset.holds() || isXRP(asset)) return false; @@ -198,7 +198,7 @@ AMMCreate::preclaim(PreclaimContext const& ctx) // Disallow AMM if the issuer has clawback enabled when featureAMMClawback // is not enabled - auto clawbackDisabled = [&](Asset const& asset) -> TER { + auto clawbackDisabled = [&](Issue const& asset) -> TER { if (isXRP(asset)) return tesSUCCESS; if (asset.holds()) @@ -382,7 +382,7 @@ applyCreate( return res; // Set AMM flag on AMM trustline - if (amount.holds() && !isXRP(amount)) + if (amount.holds() && !isXRP(amount)) { if (SLE::pointer sleRippleState = sb.peek(keylet::line(*ammAccount, amount.issue())); @@ -419,7 +419,7 @@ applyCreate( << ammKeylet.key << " " << lpTokens << " " << amount << " " << amount2; auto addOrderBook = - [&](Asset const& assetIn, Asset const& assetOut, std::uint64_t uRate) { + [&](Issue const& assetIn, Issue const& assetOut, std::uint64_t uRate) { Book const book{assetIn, assetOut}; auto const dir = keylet::quality(keylet::book(book), uRate); if (auto const bookExisted = static_cast(sb.read(dir)); diff --git a/src/xrpld/app/tx/detail/AMMDeposit.cpp b/src/xrpld/app/tx/detail/AMMDeposit.cpp index 416bb4cc2d5..246c26fee58 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.cpp +++ b/src/xrpld/app/tx/detail/AMMDeposit.cpp @@ -234,8 +234,8 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) { auto const lpIssue = (*ammSle)[sfLPTokenBalance].issue(); // Adjust the reserve if LP doesn't have LPToken trustline - auto const sle = ctx.view.read( - keylet::line(accountID, lpIssue.account, lpIssue.currency)); + auto const sle = ctx.view.read(keylet::line( + accountID, lpIssue.getIssuer(), lpIssue.getCurrency())); if (xrpLiquid(ctx.view, accountID, !sle, ctx.j) >= deposit) return TER(tesSUCCESS); if (sle) @@ -258,7 +258,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) { // Check if either of the assets is frozen, AMMDeposit is not allowed // if either asset is frozen - auto checkAsset = [&](Asset const& asset) -> TER { + auto checkAsset = [&](Issue const& asset) -> TER { if (auto const ter = requireAuth( ctx.view, asset, accountID, MPTAuthType::WeakAuth)) { @@ -402,8 +402,8 @@ AMMDeposit::applyGuts(Sandbox& sb) auto const expected = ammHolds( sb, *ammSle, - amount ? amount->asset() : std::optional{}, - amount2 ? amount2->asset() : std::optional{}, + amount ? amount->asset() : std::optional{}, + amount2 ? amount2->asset() : std::optional{}, FreezeHandling::fhZERO_IF_FROZEN, AuthHandling::ahIGNORE_AUTH, ctx_.journal); @@ -540,8 +540,8 @@ AMMDeposit::deposit( { auto const& lpIssue = lpTokensDeposit.issue(); // Adjust the reserve if LP doesn't have LPToken trustline - auto const sle = view.read( - keylet::line(account_, lpIssue.account, lpIssue.currency)); + auto const sle = view.read(keylet::line( + account_, lpIssue.getIssuer(), lpIssue.getCurrency())); if (xrpLiquid(view, account_, !sle, j_) >= depositAmount) return tesSUCCESS; } @@ -949,7 +949,7 @@ AMMDeposit::equalDepositInEmptyState( AccountID const& ammAccount, STAmount const& amount, STAmount const& amount2, - Issue const& lptIssue, + IOUIssue const& lptIssue, std::uint16_t tfee) { return deposit( diff --git a/src/xrpld/app/tx/detail/AMMDeposit.h b/src/xrpld/app/tx/detail/AMMDeposit.h index 0acb1dd9ab3..6f1a601d0c3 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.h +++ b/src/xrpld/app/tx/detail/AMMDeposit.h @@ -135,7 +135,7 @@ class AMMDeposit : public Transactor std::optional const& deposit2Min, std::uint16_t tfee); - /** Equal asset deposit (Asset1In, Asset2In) with the constraint on + /** Equal asset deposit (Issue1In, Asset2In) with the constraint on * the maximum amount of both assets that the trader is willing to deposit. * The trading fee is not charged. * @param view @@ -161,7 +161,7 @@ class AMMDeposit : public Transactor std::optional const& lpTokensDepositMin, std::uint16_t tfee); - /** Single asset deposit (Asset1In) by the amount. + /** Single asset deposit (Issue1In) by the amount. * The trading fee is charged. * @param view * @param ammAccount @@ -182,7 +182,7 @@ class AMMDeposit : public Transactor std::optional const& lpTokensDepositMin, std::uint16_t tfee); - /** Single asset deposit (Asset1In, LPTokens) by the tokens. + /** Single asset deposit (Issue1In, LPTokens) by the tokens. * The trading fee is charged. * @param view * @param ammAccount @@ -203,7 +203,7 @@ class AMMDeposit : public Transactor STAmount const& lpTokensDeposit, std::uint16_t tfee); - /** Single asset deposit (Asset1In, EPrice) with two constraints. + /** Single asset deposit (Issue1In, EPrice) with two constraints. * The trading fee is charged. * @param view * @param ammAccount @@ -238,7 +238,7 @@ class AMMDeposit : public Transactor AccountID const& ammAccount, STAmount const& amount, STAmount const& amount2, - Issue const& lptIssue, + IOUIssue const& lptIssue, std::uint16_t tfee); }; diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.cpp b/src/xrpld/app/tx/detail/AMMWithdraw.cpp index c6a3a967885..5355552fa4d 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.cpp +++ b/src/xrpld/app/tx/detail/AMMWithdraw.cpp @@ -195,8 +195,8 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) auto const expected = ammHolds( ctx.view, *ammSle, - amount ? amount->asset() : std::optional{}, - amount2 ? amount2->asset() : std::optional{}, + amount ? amount->asset() : std::optional{}, + amount2 ? amount2->asset() : std::optional{}, FreezeHandling::fhIGNORE_FREEZE, AuthHandling::ahIGNORE_AUTH, ctx.j); @@ -361,8 +361,8 @@ AMMWithdraw::applyGuts(Sandbox& sb) auto const expected = ammHolds( sb, *ammSle, - amount ? amount->asset() : std::optional{}, - amount2 ? amount2->asset() : std::optional{}, + amount ? amount->asset() : std::optional{}, + amount2 ? amount2->asset() : std::optional{}, FreezeHandling::fhZERO_IF_FROZEN, AuthHandling::ahIGNORE_AUTH, ctx_.journal); @@ -620,14 +620,15 @@ AMMWithdraw::withdraw( // If seated after a call to sufficientReserve() then MPToken must be // authorized std::optional mptokenKey; - auto sufficientReserve = [&](Asset const& asset) -> TER { + auto sufficientReserve = [&](Issue const& asset) -> TER { mptokenKey = std::nullopt; if (!enabledFixAMMv1_2 || isXRP(asset)) return tesSUCCESS; - bool const isIssue = asset.holds(); + bool const isIssue = asset.holds(); bool const checkReserve = [&] { if (isIssue) - return !view.exists(keylet::line(account, asset.get())); + return !view.exists( + keylet::line(account, asset.get())); auto const issuanceKey = keylet::mptIssuance(asset.get()); mptokenKey = keylet::mptoken(issuanceKey.key, account); if (!view.exists(keylet::mptoken(issuanceKey.key, account))) @@ -665,7 +666,7 @@ AMMWithdraw::withdraw( // Create MPToken if doesn't exist // TODO make a library, AMMCreate, AMMAuthorize use almost identical code - auto createMPToken = [&](Asset const& asset) -> TER { + auto createMPToken = [&](Issue const& asset) -> TER { // If mptoken is seated then must authorize if (mptokenKey) { @@ -802,8 +803,8 @@ AMMWithdraw::deleteAMMAccountIfEmpty( Sandbox& sb, std::shared_ptr const ammSle, STAmount const& lpTokenBalance, - Asset const& issue1, - Asset const& issue2, + Issue const& issue1, + Issue const& issue2, beast::Journal const& journal) { TER ter; diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.h b/src/xrpld/app/tx/detail/AMMWithdraw.h index 2636aa26912..08142bc9209 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.h +++ b/src/xrpld/app/tx/detail/AMMWithdraw.h @@ -154,8 +154,8 @@ class AMMWithdraw : public Transactor Sandbox& sb, std::shared_ptr const ammSle, STAmount const& lpTokenBalance, - Asset const& issue1, - Asset const& issue2, + Issue const& issue1, + Issue const& issue2, beast::Journal const& journal); private: @@ -211,7 +211,7 @@ class AMMWithdraw : public Transactor STAmount const& lpTokensWithdraw, std::uint16_t tfee); - /** Withdraw both assets (Asset1Out, Asset2Out) with the constraints + /** Withdraw both assets (Issue1Out, Asset2Out) with the constraints * on the maximum amount of each asset that the trader is willing * to withdraw. The trading fee is not charged. * @param view @@ -236,7 +236,7 @@ class AMMWithdraw : public Transactor STAmount const& amount2, std::uint16_t tfee); - /** Single asset withdrawal (Asset1Out) equivalent to the amount specified + /** Single asset withdrawal (Issue1Out) equivalent to the amount specified * in Asset1Out. The trading fee is charged. * @param view * @param ammAccount @@ -256,7 +256,7 @@ class AMMWithdraw : public Transactor STAmount const& amount, std::uint16_t tfee); - /** Single asset withdrawal (Asset1Out, LPTokens) proportional + /** Single asset withdrawal (Issue1Out, LPTokens) proportional * to the share specified by tokens. The trading fee is charged. * @param view * @param ammAccount @@ -278,7 +278,7 @@ class AMMWithdraw : public Transactor STAmount const& lpTokensWithdraw, std::uint16_t tfee); - /** Withdraw single asset (Asset1Out, EPrice) with two constraints. + /** Withdraw single asset (Issue1Out, EPrice) with two constraints. * The trading fee is charged. * @param view * @param ammAccount diff --git a/src/xrpld/app/tx/detail/CashCheck.cpp b/src/xrpld/app/tx/detail/CashCheck.cpp index 8ba46c2723e..bd04d234ee7 100644 --- a/src/xrpld/app/tx/detail/CashCheck.cpp +++ b/src/xrpld/app/tx/detail/CashCheck.cpp @@ -195,9 +195,9 @@ CashCheck::preclaim(PreclaimContext const& ctx) // An issuer can always accept their own currency. if (!value.native() && (value.getIssuer() != dstId)) { - if (value.holds()) + if (value.holds()) { - Currency const currency{value.get().currency}; + Currency const currency{value.get().getCurrency()}; auto const sleTrustLine = ctx.view.read(keylet::line(dstId, issuerId, currency)); @@ -389,7 +389,7 @@ CashCheck::doApply() // transfer rate to account for. Since the transfer rate cannot // exceed 200%, we use 1/2 maxValue as our limit. auto const maxDeliverMin = [&]() { - if (optDeliverMin->holds()) + if (optDeliverMin->holds()) return STAmount( optDeliverMin->asset(), STAmount::cMaxValue / 2, @@ -406,10 +406,10 @@ CashCheck::doApply() std::optional trustLineKey; STAmount savedLimit; bool destLow = false; - if (flowDeliver.holds()) + if (flowDeliver.holds()) { // If a trust line does not exist yet create one. - Issue const& trustLineIssue = flowDeliver.get(); + IOUIssue const& trustLineIssue = flowDeliver.get(); AccountID const issuer = flowDeliver.getIssuer(); AccountID const truster = issuer == account_ ? srcId : account_; trustLineKey = keylet::line(truster, trustLineIssue); @@ -441,7 +441,7 @@ CashCheck::doApply() } Currency const currency = - flowDeliver.asset().get().currency; + flowDeliver.asset().get().getCurrency(); STAmount initialBalance(flowDeliver.asset()); initialBalance.setIssuer(noAccount()); @@ -457,7 +457,7 @@ CashCheck::doApply() (sleDst->getFlags() & lsfDefaultRipple) == 0, false, // freeze trust line initialBalance, // zero initial balance - Issue(currency, account_), // limit of zero + IOUIssue(currency, account_), // limit of zero 0, // quality in 0, // quality out viewJ); // journal @@ -564,7 +564,7 @@ CashCheck::doApply() return tecPATH_PARTIAL; } if (doFix1623 && !checkCashMakesTrustLine && - optDeliverMin->holds()) + optDeliverMin->holds()) // Set the delivered_amount metadata. ctx_.deliver(result.actualAmountOut); } diff --git a/src/xrpld/app/tx/detail/Clawback.cpp b/src/xrpld/app/tx/detail/Clawback.cpp index d60acf9fd73..928c781487e 100644 --- a/src/xrpld/app/tx/detail/Clawback.cpp +++ b/src/xrpld/app/tx/detail/Clawback.cpp @@ -34,7 +34,7 @@ preflightHelper(PreflightContext const& ctx); template <> NotTEC -preflightHelper(PreflightContext const& ctx) +preflightHelper(PreflightContext const& ctx) { if (ctx.tx.isFieldPresent(sfHolder)) return temMALFORMED; @@ -107,7 +107,7 @@ preclaimHelper( template <> TER -preclaimHelper( +preclaimHelper( PreclaimContext const& ctx, SLE const& sleIssuer, AccountID const& issuer, @@ -199,8 +199,9 @@ Clawback::preclaim(PreclaimContext const& ctx) { AccountID const issuer = ctx.tx[sfAccount]; auto const clawAmount = ctx.tx[sfAmount]; - AccountID const holder = - clawAmount.holds() ? clawAmount.getIssuer() : ctx.tx[sfHolder]; + AccountID const holder = clawAmount.holds() + ? clawAmount.getIssuer() + : ctx.tx[sfHolder]; auto const sleIssuer = ctx.view.read(keylet::account(issuer)); auto const sleHolder = ctx.view.read(keylet::account(holder)); @@ -224,7 +225,7 @@ applyHelper(ApplyContext& ctx); template <> TER -applyHelper(ApplyContext& ctx) +applyHelper(ApplyContext& ctx) { AccountID const issuer = ctx.tx[sfAccount]; STAmount clawAmount = ctx.tx[sfAmount]; diff --git a/src/xrpld/app/tx/detail/CreateCheck.cpp b/src/xrpld/app/tx/detail/CreateCheck.cpp index 5449787242c..e29ad7a61a8 100644 --- a/src/xrpld/app/tx/detail/CreateCheck.cpp +++ b/src/xrpld/app/tx/detail/CreateCheck.cpp @@ -125,7 +125,7 @@ CreateCheck::preclaim(PreclaimContext const& ctx) JLOG(ctx.j.warn()) << "Creating a check for frozen asset"; return tecFROZEN; } - if (sendMax.holds()) + if (sendMax.holds()) { // If this account has a trustline for the currency, that // trustline may not be frozen. @@ -137,7 +137,9 @@ CreateCheck::preclaim(PreclaimContext const& ctx) { // Check if the issuer froze the line auto const sleTrust = ctx.view.read(keylet::line( - srcId, issuerId, sendMax.get().currency)); + srcId, + issuerId, + sendMax.get().getCurrency())); if (sleTrust && sleTrust->isFlag( (issuerId > srcId) ? lsfHighFreeze : lsfLowFreeze)) @@ -151,7 +153,9 @@ CreateCheck::preclaim(PreclaimContext const& ctx) { // Check if dst froze the line. auto const sleTrust = ctx.view.read(keylet::line( - issuerId, dstId, sendMax.get().currency)); + issuerId, + dstId, + sendMax.get().getCurrency())); if (sleTrust && sleTrust->isFlag( (dstId > issuerId) ? lsfHighFreeze : lsfLowFreeze)) diff --git a/src/xrpld/app/tx/detail/CreateOffer.cpp b/src/xrpld/app/tx/detail/CreateOffer.cpp index d0ba6303828..8b879d2c1c1 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -223,7 +223,7 @@ CreateOffer::checkAcceptAsset( ApplyFlags const flags, AccountID const id, beast::Journal const j, - Asset const& asset) + Issue const& asset) { // Only valid for custom currencies XRPL_ASSERT( @@ -249,12 +249,12 @@ CreateOffer::checkAcceptAsset( // An account can always accept its own issuance. return tesSUCCESS; - if (asset.holds()) + if (asset.holds()) { if ((*issuerAccount)[sfFlags] & lsfRequireAuth) { auto const trustLine = view.read(keylet::line( - id, asset.getIssuer(), asset.get().currency)); + id, asset.getIssuer(), asset.get().getCurrency())); if (!trustLine) { @@ -316,7 +316,7 @@ CreateOffer::flowCross( if (!sendMax.native() && (account_ != sendMax.getIssuer())) { gatewayXferRate = [&]() { - if (sendMax.holds()) + if (sendMax.holds()) return transferRate(psb, sendMax.getIssuer()); else return transferRate( @@ -516,8 +516,8 @@ CreateOffer::format_amount(STAmount const& amount) { std::string txt = amount.getText(); txt += "/"; - if (amount.holds()) - txt += to_string(amount.get().currency); + if (amount.holds()) + txt += to_string(amount.get().getCurrency()); else txt += to_string(amount.get()); return txt; @@ -805,24 +805,24 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) bool const bookExisted = static_cast(sb.peek(dir)); auto const bookNode = sb.dirAppend(dir, offer_index, [&](SLE::ref sle) { - if (saTakerPays.holds()) + if (saTakerPays.holds()) { sle->setFieldH160( - sfTakerPaysCurrency, saTakerPays.get().currency); + sfTakerPaysCurrency, saTakerPays.get().getCurrency()); sle->setFieldH160( - sfTakerPaysIssuer, saTakerPays.get().account); + sfTakerPaysIssuer, saTakerPays.get().getIssuer()); } else { sle->setFieldH192( sfTakerPaysMPT, saTakerPays.get().getMptID()); } - if (saTakerGets.holds()) + if (saTakerGets.holds()) { sle->setFieldH160( - sfTakerGetsCurrency, saTakerGets.get().currency); + sfTakerGetsCurrency, saTakerGets.get().getCurrency()); sle->setFieldH160( - sfTakerGetsIssuer, saTakerGets.get().account); + sfTakerGetsIssuer, saTakerGets.get().getIssuer()); } else { diff --git a/src/xrpld/app/tx/detail/CreateOffer.h b/src/xrpld/app/tx/detail/CreateOffer.h index 5f130c29785..7c16f5430e0 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.h +++ b/src/xrpld/app/tx/detail/CreateOffer.h @@ -66,7 +66,7 @@ class CreateOffer : public Transactor ApplyFlags const flags, AccountID const id, beast::Journal const j, - Asset const& asset); + Issue const& asset); // Use the payment flow code to perform offer crossing. std::pair diff --git a/src/xrpld/app/tx/detail/InvariantCheck.cpp b/src/xrpld/app/tx/detail/InvariantCheck.cpp index c1d7a38853f..ae246b85d68 100644 --- a/src/xrpld/app/tx/detail/InvariantCheck.cpp +++ b/src/xrpld/app/tx/detail/InvariantCheck.cpp @@ -927,11 +927,11 @@ ValidClawback::finalize( STAmount const& amount = tx.getFieldAmount(sfAmount); AccountID const& holder = amount.getIssuer(); STAmount const holderBalance = [&]() { - if (amount.holds()) + if (amount.holds()) return accountHolds( view, holder, - amount.get().currency, + amount.get().getCurrency(), issuer, fhIGNORE_FREEZE, j); diff --git a/src/xrpld/app/tx/detail/Offer.h b/src/xrpld/app/tx/detail/Offer.h index 38eb36b1804..467b2a7a5d9 100644 --- a/src/xrpld/app/tx/detail/Offer.h +++ b/src/xrpld/app/tx/detail/Offer.h @@ -35,8 +35,8 @@ template class TOfferBase { protected: - Asset assetIn_; - Asset assetOut_; + Issue assetIn_; + Issue assetOut_; }; template <> @@ -132,9 +132,9 @@ class TOffer : private TOfferBase return m_entry->key(); } - Asset const& + Issue const& assetIn() const; - Asset const& + Issue const& assetOut() const; TAmounts @@ -268,28 +268,28 @@ TOffer::send(Args&&... args) } template -Asset const& +Issue const& TOffer::assetIn() const { return this->assetIn_; } template <> -inline Asset const& +inline Issue const& TOffer::assetIn() const { return m_amounts.in.asset(); } template -Asset const& +Issue const& TOffer::assetOut() const { return this->assetOut_; } template <> -inline Asset const& +inline Issue const& TOffer::assetOut() const { return m_amounts.out.asset(); diff --git a/src/xrpld/app/tx/detail/OfferStream.cpp b/src/xrpld/app/tx/detail/OfferStream.cpp index 9e53a5fc862..d08927e823e 100644 --- a/src/xrpld/app/tx/detail/OfferStream.cpp +++ b/src/xrpld/app/tx/detail/OfferStream.cpp @@ -27,7 +27,7 @@ namespace { bool checkIssuers(ReadView const& view, Book const& book) { - auto issuerExists = [](ReadView const& view, Asset const& asset) -> bool { + auto issuerExists = [](ReadView const& view, Issue const& asset) -> bool { return isXRP(asset.getIssuer()) || view.read(keylet::account(asset.getIssuer())); }; @@ -98,7 +98,7 @@ accountFundsHelper( ReadView const& view, AccountID const& id, STAmount const& saDefault, - Asset const&, + Issue const&, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal j) @@ -113,7 +113,7 @@ accountFundsHelper( ReadView const& view, AccountID const& id, T const& amtDefault, - Asset const& asset, + Issue const& asset, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal j) @@ -131,7 +131,7 @@ accountFundsHelper( ReadView const& view, AccountID const& id, XRPAmount const& amtDefault, - Asset const& asset, + Issue const& asset, FreezeHandling freezeHandling, AuthHandling authHandling, beast::Journal j) diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index 2df669d98d2..82983c9b5f6 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -57,7 +57,7 @@ getMaxSourceAmount( return dstAmount; else return STAmount( - Issue{dstAmount.get().currency, account}, + IOUIssue{dstAmount.get().getCurrency(), account}, dstAmount.mantissa(), dstAmount.exponent(), dstAmount < beast::zero); diff --git a/src/xrpld/app/tx/detail/SetTrust.cpp b/src/xrpld/app/tx/detail/SetTrust.cpp index 954fc6543f1..c67f69146c4 100644 --- a/src/xrpld/app/tx/detail/SetTrust.cpp +++ b/src/xrpld/app/tx/detail/SetTrust.cpp @@ -537,7 +537,7 @@ SetTrust::doApply() else { // Zero balance in currency. - STAmount saBalance(Issue{currency, noAccount()}); + STAmount saBalance(IOUIssue{currency, noAccount()}); auto const k = keylet::line(account_, uDstAccountID, currency); diff --git a/src/xrpld/app/tx/detail/Taker.cpp b/src/xrpld/app/tx/detail/Taker.cpp index 9f7b660c726..635feef72a7 100644 --- a/src/xrpld/app/tx/detail/Taker.cpp +++ b/src/xrpld/app/tx/detail/Taker.cpp @@ -26,9 +26,11 @@ namespace ripple { static std::string format_amount(STAmount const& amount) { - if (amount.holds()) + if (amount.holds()) return std::format( - "{}/{}", amount.getText(), to_string(amount.get().currency)); + "{}/{}", + amount.getText(), + to_string(amount.get().getCurrency())); return std::format( "{}/{}", amount.getText(), to_string(amount.get())); } @@ -93,15 +95,15 @@ BasicTaker::BasicTaker( Rate BasicTaker::effective_rate( Rate const& rate, - Issue const& issue, + IOUIssue const& issue, AccountID const& from, AccountID const& to) { // If there's a transfer rate, the issuer is not involved // and the sender isn't the same as the recipient, return // the actual transfer rate. - if (rate != parityRate && from != to && from != issue.account && - to != issue.account) + if (rate != parityRate && from != to && from != issue.getIssuer() && + to != issue.getIssuer()) { return rate; } @@ -598,13 +600,13 @@ Taker::Taker( stream << " Offer in: " << format_amount(offer.in); else stream << " Offer in: " << format_amount(offer.in) - << " (issuer: " << issue_in().account << ")"; + << " (issuer: " << issue_in().getIssuer() << ")"; if (isXRP(issue_out())) stream << " Offer out: " << format_amount(offer.out); else stream << " Offer out: " << format_amount(offer.out) - << " (issuer: " << issue_out().account << ")"; + << " (issuer: " << issue_out().getIssuer() << ")"; stream << " Balance: " << format_amount(get_funds(account, offer.in)); @@ -662,12 +664,12 @@ TER Taker::redeemIOU( AccountID const& account, STAmount const& amount, - Issue const& issue) + IOUIssue const& issue) { if (isXRP(amount)) Throw("Using redeemIOU with XRP"); - if (account == issue.account) + if (account == issue.getIssuer()) return tesSUCCESS; // Transferring zero is equivalent to not doing a transfer @@ -691,12 +693,12 @@ TER Taker::issueIOU( AccountID const& account, STAmount const& amount, - Issue const& issue) + IOUIssue const& issue) { if (isXRP(amount)) Throw("Using issueIOU with XRP"); - if (account == issue.account) + if (account == issue.getIssuer()) return tesSUCCESS; // Transferring zero is equivalent to not doing a transfer diff --git a/src/xrpld/app/tx/detail/Taker.h b/src/xrpld/app/tx/detail/Taker.h index 3e64c59b542..e0ac846bce6 100644 --- a/src/xrpld/app/tx/detail/Taker.h +++ b/src/xrpld/app/tx/detail/Taker.h @@ -52,8 +52,8 @@ class BasicTaker Amounts remaining_; // The issuers for the input and output - Issue const& issue_in_; - Issue const& issue_out_; + IOUIssue const& issue_in_; + IOUIssue const& issue_out_; // The rates that will be paid when the input and output currencies are // transfered and the currency issuer isn't involved: @@ -120,7 +120,7 @@ class BasicTaker static Rate effective_rate( Rate const& rate, - Issue const& issue, + IOUIssue const& issue, AccountID const& from, AccountID const& to); @@ -188,15 +188,15 @@ class BasicTaker return cross_type_; } - /** Returns the Issue associated with the input of the offer */ - Issue const& + /** Returns the IOUIssue associated with the input of the offer */ + IOUIssue const& issue_in() const { return issue_in_; } - /** Returns the Issue associated with the output of the offer */ - Issue const& + /** Returns the IOUIssue associated with the output of the offer */ + IOUIssue const& issue_out() const { return issue_out_; @@ -315,13 +315,13 @@ class Taker : public BasicTaker redeemIOU( AccountID const& account, STAmount const& amount, - Issue const& issue); + IOUIssue const& issue); TER issueIOU( AccountID const& account, STAmount const& amount, - Issue const& issue); + IOUIssue const& issue); private: // The underlying ledger entry we are dealing with diff --git a/src/xrpld/app/tx/detail/XChainBridge.cpp b/src/xrpld/app/tx/detail/XChainBridge.cpp index 0c6be61040c..79fa0fbc3f9 100644 --- a/src/xrpld/app/tx/detail/XChainBridge.cpp +++ b/src/xrpld/app/tx/detail/XChainBridge.cpp @@ -1443,13 +1443,14 @@ XChainCreateBridge::preflight(PreflightContext const& ctx) // Issuing account must be the issuer for non-XRP. This is done so the // issuing account can't "run out" of wrapped tokens. if (bridgeSpec.issuingChainDoor() != - bridgeSpec.issuingChainIssue().account) + bridgeSpec.issuingChainIssue().getIssuer()) { return temXCHAIN_BRIDGE_BAD_ISSUES; } } - if (bridgeSpec.lockingChainDoor() == bridgeSpec.lockingChainIssue().account) + if (bridgeSpec.lockingChainDoor() == + bridgeSpec.lockingChainIssue().getIssuer()) { // If the locking chain door is locking their own asset, in some sense // nothing is being locked. Disallow this. @@ -1481,8 +1482,8 @@ XChainCreateBridge::preclaim(PreclaimContext const& ctx) if (!isXRP(bridgeSpec.issue(chainType))) { - auto const sleIssuer = - ctx.view.read(keylet::account(bridgeSpec.issue(chainType).account)); + auto const sleIssuer = ctx.view.read( + keylet::account(bridgeSpec.issue(chainType).getIssuer())); if (!sleIssuer) return tecNO_ISSUER; diff --git a/src/xrpld/ledger/View.h b/src/xrpld/ledger/View.h index d22e74a1405..9d24a31e6b5 100644 --- a/src/xrpld/ledger/View.h +++ b/src/xrpld/ledger/View.h @@ -89,7 +89,7 @@ isGlobalFrozen(ReadView const& view, AccountID const& issuer); isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue); [[nodiscard]] bool -isGlobalFrozen(ReadView const& view, Asset const& asset); +isGlobalFrozen(ReadView const& view, Issue const& asset); [[nodiscard]] bool isIndividualFrozen( @@ -102,9 +102,10 @@ isIndividualFrozen( isIndividualFrozen( ReadView const& view, AccountID const& account, - Issue const& issue) + IOUIssue const& issue) { - return isIndividualFrozen(view, account, issue.currency, issue.account); + return isIndividualFrozen( + view, account, issue.getCurrency(), issue.getIssuer()); } [[nodiscard]] bool @@ -117,7 +118,7 @@ isIndividualFrozen( isIndividualFrozen( ReadView const& view, AccountID const& account, - Asset const& asset) + Issue const& asset) { return std::visit( [&](auto const& issue) { @@ -134,9 +135,9 @@ isFrozen( AccountID const& issuer); [[nodiscard]] inline bool -isFrozen(ReadView const& view, AccountID const& account, Issue const& issue) +isFrozen(ReadView const& view, AccountID const& account, IOUIssue const& issue) { - return isFrozen(view, account, issue.currency, issue.account); + return isFrozen(view, account, issue.getCurrency(), issue.getIssuer()); } [[nodiscard]] bool @@ -146,7 +147,7 @@ isFrozen( MPTIssue const& mptIssue); [[nodiscard]] inline bool -isFrozen(ReadView const& view, AccountID const& account, Asset const& asset) +isFrozen(ReadView const& view, AccountID const& account, Issue const& asset) { return std::visit( [&](auto const& issue) { return isFrozen(view, account, issue); }, @@ -169,7 +170,7 @@ accountHolds( accountHolds( ReadView const& view, AccountID const& account, - Issue const& issue, + IOUIssue const& issue, FreezeHandling zeroIfFrozen, beast::Journal j); @@ -186,7 +187,7 @@ accountHolds( accountHolds( ReadView const& view, AccountID const& account, - Asset const& issue, + Issue const& issue, FreezeHandling zeroIfFrozen, AuthHandling zeroIfUnauthorized, beast::Journal j); @@ -523,7 +524,7 @@ issueIOU( ApplyView& view, AccountID const& account, STAmount const& amount, - Issue const& issue, + IOUIssue const& issue, beast::Journal j); [[nodiscard]] TER @@ -531,7 +532,7 @@ redeemIOU( ApplyView& view, AccountID const& account, STAmount const& amount, - Issue const& issue, + IOUIssue const& issue, beast::Journal j); [[nodiscard]] TER @@ -553,7 +554,10 @@ enum class MPTAuthType : bool { StrongAuth = true, WeakAuth = false }; * and tesSUCCESS otherwise. */ [[nodiscard]] TER -requireAuth(ReadView const& view, Issue const& issue, AccountID const& account); +requireAuth( + ReadView const& view, + IOUIssue const& issue, + AccountID const& account); /* If StrongAuth then return tecNO_AUTH if MPToken doesn't exist or * lsfMPTRequireAuth is set and MPToken is not authorized. If WeakAuth then * return tecNO_AUTH if lsfMPTRequireAuth is set and MPToken doesn't exist or is @@ -567,13 +571,13 @@ requireAuth( MPTAuthType authType = MPTAuthType::StrongAuth); [[nodiscard]] TER inline requireAuth( ReadView const& view, - Asset const& asset, + Issue const& asset, AccountID const& account, MPTAuthType authType = MPTAuthType::StrongAuth) { return std::visit( [&](TIss const& issue_) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return requireAuth(view, issue_, account); else return requireAuth(view, issue_, account, authType); diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index ffb1dadf255..9ece9808468 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -188,11 +188,11 @@ isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue) } bool -isGlobalFrozen(ReadView const& view, Asset const& asset) +isGlobalFrozen(ReadView const& view, Issue const& asset) { return std::visit( [&](TIss const& issue) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return isGlobalFrozen(view, issue.getIssuer()); else return isGlobalFrozen(view, issue); @@ -286,13 +286,13 @@ accountHolds( auto const sle = view.read(keylet::line(account, issuer, currency)); if (!sle) { - amount.clear(Issue{currency, issuer}); + amount.clear(IOUIssue{currency, issuer}); } else if ( (zeroIfFrozen == fhZERO_IF_FROZEN) && isFrozen(view, account, currency, issuer)) { - amount.clear(Issue{currency, issuer}); + amount.clear(IOUIssue{currency, issuer}); } else { @@ -314,12 +314,12 @@ STAmount accountHolds( ReadView const& view, AccountID const& account, - Issue const& issue, + IOUIssue const& issue, FreezeHandling zeroIfFrozen, beast::Journal j) { return accountHolds( - view, account, issue.currency, issue.account, zeroIfFrozen, j); + view, account, issue.getCurrency(), issue.getIssuer(), zeroIfFrozen, j); } STAmount @@ -366,14 +366,14 @@ STAmount accountHolds( ReadView const& view, AccountID const& account, - Asset const& issue, + Issue const& issue, FreezeHandling zeroIfFrozen, AuthHandling zeroIfUnauthorized, beast::Journal j) { return std::visit( [&](TIss const& issue_) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return accountHolds(view, account, issue_, zeroIfFrozen, j); else return accountHolds( @@ -957,7 +957,7 @@ trustCreate( bSetHigh ? sfHighLimit : sfLowLimit, saLimit); sleRippleState->setFieldAmount( bSetHigh ? sfLowLimit : sfHighLimit, - STAmount(Issue{ + STAmount(IOUIssue{ saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID})); if (uQualityIn) @@ -1199,7 +1199,7 @@ rippleCreditIOU( return tesSUCCESS; } - STAmount const saReceiverLimit(Issue{currency, uReceiverID}); + STAmount const saReceiverLimit(IOUIssue{currency, uReceiverID}); STAmount saBalance{saAmount}; saBalance.setIssuer(noAccount()); @@ -1569,7 +1569,7 @@ accountSend( { return std::visit( [&](TIss const& issue) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) return accountSendIOU( view, uSenderID, uReceiverID, saAmount, j, waiveFee); else @@ -1637,11 +1637,11 @@ issueIOU( ApplyView& view, AccountID const& account, STAmount const& amount, - Issue const& issue, + IOUIssue const& issue, beast::Journal j) { XRPL_ASSERT( - !isXRP(account) && !isXRP(issue.account), + !isXRP(account) && !isXRP(issue.getIssuer()), "ripple::issueIOU : neither account nor issuer is XRP"); // Consistency check @@ -1649,14 +1649,15 @@ issueIOU( // Can't send to self! XRPL_ASSERT( - issue.account != account, "ripple::issueIOU : not issuer account"); + issue.getIssuer() != account, "ripple::issueIOU : not issuer account"); JLOG(j.trace()) << "issueIOU: " << to_string(account) << ": " << amount.getFullText(); - bool bSenderHigh = issue.account > account; + bool bSenderHigh = issue.getIssuer() > account; - auto const index = keylet::line(issue.account, account, issue.currency); + auto const index = + keylet::line(issue.getIssuer(), account, issue.getCurrency()); if (auto state = view.peek(index)) { @@ -1673,12 +1674,12 @@ issueIOU( view, state, bSenderHigh, - issue.account, + issue.getIssuer(), start_balance, final_balance, j); - view.creditHook(issue.account, account, amount, start_balance); + view.creditHook(issue.getIssuer(), account, amount, start_balance); if (bSenderHigh) final_balance.negate(); @@ -1691,8 +1692,8 @@ issueIOU( return trustDelete( view, state, - bSenderHigh ? account : issue.account, - bSenderHigh ? issue.account : account, + bSenderHigh ? account : issue.getIssuer(), + bSenderHigh ? issue.getIssuer() : account, j); view.update(state); @@ -1703,7 +1704,7 @@ issueIOU( // NIKB TODO: The limit uses the receiver's account as the issuer and // this is unnecessarily inefficient as copying which could be avoided // is now required. Consider available options. - STAmount const limit(Issue{issue.currency, account}); + STAmount const limit(IOUIssue{issue.getCurrency(), account}); STAmount final_balance = amount; final_balance.setIssuer(noAccount()); @@ -1717,7 +1718,7 @@ issueIOU( return trustCreate( view, bSenderHigh, - issue.account, + issue.getIssuer(), account, index.key, receiverAccount, @@ -1736,11 +1737,11 @@ redeemIOU( ApplyView& view, AccountID const& account, STAmount const& amount, - Issue const& issue, + IOUIssue const& issue, beast::Journal j) { XRPL_ASSERT( - !isXRP(account) && !isXRP(issue.account), + !isXRP(account) && !isXRP(issue.getIssuer()), "ripple::redeemIOU : neither account nor issuer is XRP"); // Consistency check @@ -1748,15 +1749,15 @@ redeemIOU( // Can't send to self! XRPL_ASSERT( - issue.account != account, "ripple::redeemIOU : not issuer account"); + issue.getIssuer() != account, "ripple::redeemIOU : not issuer account"); JLOG(j.trace()) << "redeemIOU: " << to_string(account) << ": " << amount.getFullText(); - bool bSenderHigh = account > issue.account; + bool bSenderHigh = account > issue.getIssuer(); - if (auto state = - view.peek(keylet::line(account, issue.account, issue.currency))) + if (auto state = view.peek( + keylet::line(account, issue.getIssuer(), issue.getCurrency()))) { STAmount final_balance = state->getFieldAmount(sfBalance); @@ -1770,7 +1771,7 @@ redeemIOU( auto const must_delete = updateTrustLine( view, state, bSenderHigh, account, start_balance, final_balance, j); - view.creditHook(account, issue.account, amount, start_balance); + view.creditHook(account, issue.getIssuer(), amount, start_balance); if (bSenderHigh) final_balance.negate(); @@ -1785,8 +1786,8 @@ redeemIOU( return trustDelete( view, state, - bSenderHigh ? issue.account : account, - bSenderHigh ? account : issue.account, + bSenderHigh ? issue.getIssuer() : account, + bSenderHigh ? account : issue.getIssuer(), j); } @@ -1848,17 +1849,21 @@ transferXRP( } TER -requireAuth(ReadView const& view, Issue const& issue, AccountID const& account) +requireAuth( + ReadView const& view, + IOUIssue const& issue, + AccountID const& account) { - if (isXRP(issue) || issue.account == account) + if (isXRP(issue) || issue.getIssuer() == account) return tesSUCCESS; - if (auto const issuerAccount = view.read(keylet::account(issue.account)); + if (auto const issuerAccount = + view.read(keylet::account(issue.getIssuer())); issuerAccount && (*issuerAccount)[sfFlags] & lsfRequireAuth) { - if (auto const trustLine = - view.read(keylet::line(account, issue.account, issue.currency))) + if (auto const trustLine = view.read( + keylet::line(account, issue.getIssuer(), issue.getCurrency()))) return ((*trustLine)[sfFlags] & - ((account > issue.account) ? lsfLowAuth : lsfHighAuth)) + ((account > issue.getIssuer()) ? lsfLowAuth : lsfHighAuth)) ? tesSUCCESS : TER{tecNO_AUTH}; return TER{tecNO_LINE}; @@ -2078,7 +2083,7 @@ rippleCredit( { return std::visit( [&](TIss const& issue) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v) { return rippleCreditIOU( view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j); diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index f10751ae854..6cad7adca7e 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -239,7 +239,7 @@ checkPayment( { // If no SendMax, default to Amount with sender as issuer if Issue. sendMax = amount; - if (sendMax.holds()) + if (sendMax.holds()) sendMax.setIssuer(srcAddressID); } @@ -257,8 +257,8 @@ checkPayment( if (auto ledger = app.openLedger().current()) { Pathfinder pf( - std::make_shared( - ledger, app.journal("AssetCache")), + std::make_shared( + ledger, app.journal("IssueCache")), srcAddressID, *dstAccountID, sendMax.asset(), diff --git a/src/xrpld/rpc/handlers/AMMInfo.cpp b/src/xrpld/rpc/handlers/AMMInfo.cpp index 44bbd3a6676..232c55c1149 100644 --- a/src/xrpld/rpc/handlers/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/AMMInfo.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -45,12 +45,12 @@ getAccount(Json::Value const& v, Json::Value& result) return std::optional(accountID); } -Expected +Expected getAsset(Json::Value const& v, beast::Journal j) { try { - return assetFromJson(v); + return issueFromJson(v); } catch (std::runtime_error const& ex) { @@ -84,16 +84,16 @@ doAMMInfo(RPC::JsonContext& context) struct ValuesFromContextParams { std::optional accountID; - Asset asset1; - Asset asset2; + Issue asset1; + Issue asset2; std::shared_ptr amm; }; auto getValuesFromContextParams = [&]() -> Expected { std::optional accountID; - std::optional asset1; - std::optional asset2; + std::optional asset1; + std::optional asset2; std::optional ammID; constexpr auto invalid = [](Json::Value const& params) -> bool { diff --git a/src/xrpld/rpc/handlers/AccountLines.cpp b/src/xrpld/rpc/handlers/AccountLines.cpp index 7222788d6cd..24ddf9f4954 100644 --- a/src/xrpld/rpc/handlers/AccountLines.cpp +++ b/src/xrpld/rpc/handlers/AccountLines.cpp @@ -45,7 +45,7 @@ addLine(Json::Value& jsonLines, RPCTrustLine const& line) // Amount reported is negative if other account holds current // account's IOUs. jPeer[jss::balance] = saBalance.getText(); - jPeer[jss::currency] = to_string(saBalance.get().currency); + jPeer[jss::currency] = to_string(saBalance.get().getCurrency()); jPeer[jss::limit] = saLimit.getText(); jPeer[jss::limit_peer] = saLimitPeer.getText(); jPeer[jss::quality_in] = line.getQualityIn().value; diff --git a/src/xrpld/rpc/handlers/BookOffers.cpp b/src/xrpld/rpc/handlers/BookOffers.cpp index dcdbb97c437..77093246f94 100644 --- a/src/xrpld/rpc/handlers/BookOffers.cpp +++ b/src/xrpld/rpc/handlers/BookOffers.cpp @@ -105,7 +105,7 @@ doBookOffers(RPC::JsonContext& context) rpcSRC_CUR_MALFORMED, "Invalid field 'taker_pays.currency', bad currency."); } - book.in.get().currency = pay_currency; + book.in.get().setCurrency(pay_currency); } if (taker_gets.isMember(jss::currency)) @@ -119,7 +119,7 @@ doBookOffers(RPC::JsonContext& context) rpcDST_AMT_MALFORMED, "Invalid field 'taker_gets.currency', bad currency."); } - book.out.get().currency = get_currency; + book.out.get().setCurrency(get_currency); } if (taker_pays.isMember(jss::currency)) @@ -147,15 +147,15 @@ doBookOffers(RPC::JsonContext& context) pay_issuer = xrpAccount(); } - book.in.get().account = pay_issuer; + book.in.get().setIssuer(pay_issuer); - if (isXRP(book.in.get().currency) && !isXRP(pay_issuer)) + if (isXRP(book.in.get().getCurrency()) && !isXRP(pay_issuer)) return RPC::make_error( rpcSRC_ISR_MALFORMED, "Unneeded field 'taker_pays.issuer' for " "XRP currency specification."); - if (!isXRP(book.in.get().currency) && isXRP(pay_issuer)) + if (!isXRP(book.in.get().getCurrency()) && isXRP(pay_issuer)) return RPC::make_error( rpcSRC_ISR_MALFORMED, "Invalid field 'taker_pays.issuer', expected non-XRP issuer."); @@ -195,15 +195,15 @@ doBookOffers(RPC::JsonContext& context) get_issuer = xrpAccount(); } - book.out.get().account = get_issuer; + book.out.get().setIssuer(get_issuer); - if (isXRP(book.out.get().currency) && !isXRP(get_issuer)) + if (isXRP(book.out.get().getCurrency()) && !isXRP(get_issuer)) return RPC::make_error( rpcDST_ISR_MALFORMED, "Unneeded field 'taker_gets.issuer' for " "XRP currency specification."); - if (!isXRP(book.out.get().currency) && isXRP(get_issuer)) + if (!isXRP(book.out.get().getCurrency()) && isXRP(get_issuer)) return RPC::make_error( rpcDST_ISR_MALFORMED, "Invalid field 'taker_gets.issuer', expected non-XRP issuer."); diff --git a/src/xrpld/rpc/handlers/GatewayBalances.cpp b/src/xrpld/rpc/handlers/GatewayBalances.cpp index 8fd13d472cc..2f27b95722f 100644 --- a/src/xrpld/rpc/handlers/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/GatewayBalances.cpp @@ -232,7 +232,7 @@ doGatewayBalances(RPC::JsonContext& context) { Json::Value entry; entry[jss::currency] = - to_string(balance.issue().currency); + to_string(balance.issue().getCurrency()); entry[jss::value] = balance.getText(); balanceArray.append(std::move(entry)); } diff --git a/src/xrpld/rpc/handlers/LedgerEntry.cpp b/src/xrpld/rpc/handlers/LedgerEntry.cpp index 4401b4dacd0..e7d9bf3a962 100644 --- a/src/xrpld/rpc/handlers/LedgerEntry.cpp +++ b/src/xrpld/rpc/handlers/LedgerEntry.cpp @@ -520,7 +520,7 @@ parseXChainOwnedClaimID(Json::Value const& claim_id, Json::Value& jvResult) claim_id[sfLockingChainDoor.getJsonName()].asString()); auto const issuingChainDoor = parseBase58( claim_id[sfIssuingChainDoor.getJsonName()].asString()); - Issue lockingChainIssue, issuingChainIssue; + IOUIssue lockingChainIssue, issuingChainIssue; bool valid = lockingChainDoor && issuingChainDoor; if (valid) @@ -528,9 +528,9 @@ parseXChainOwnedClaimID(Json::Value const& claim_id, Json::Value& jvResult) try { lockingChainIssue = - issueFromJson(claim_id[sfLockingChainIssue.getJsonName()]); + iouIssueFromJson(claim_id[sfLockingChainIssue.getJsonName()]); issuingChainIssue = - issueFromJson(claim_id[sfIssuingChainIssue.getJsonName()]); + iouIssueFromJson(claim_id[sfIssuingChainIssue.getJsonName()]); } catch (std::runtime_error const& ex) { @@ -596,16 +596,16 @@ parseXChainOwnedCreateAccountClaimID( claim_id[sfLockingChainDoor.getJsonName()].asString()); auto const issuingChainDoor = parseBase58( claim_id[sfIssuingChainDoor.getJsonName()].asString()); - Issue lockingChainIssue, issuingChainIssue; + IOUIssue lockingChainIssue, issuingChainIssue; bool valid = lockingChainDoor && issuingChainDoor; if (valid) { try { lockingChainIssue = - issueFromJson(claim_id[sfLockingChainIssue.getJsonName()]); + iouIssueFromJson(claim_id[sfLockingChainIssue.getJsonName()]); issuingChainIssue = - issueFromJson(claim_id[sfIssuingChainIssue.getJsonName()]); + iouIssueFromJson(claim_id[sfIssuingChainIssue.getJsonName()]); } catch (std::runtime_error const& ex) { diff --git a/src/xrpld/rpc/handlers/Subscribe.cpp b/src/xrpld/rpc/handlers/Subscribe.cpp index 92d72560a48..115cbe8e410 100644 --- a/src/xrpld/rpc/handlers/Subscribe.cpp +++ b/src/xrpld/rpc/handlers/Subscribe.cpp @@ -246,11 +246,12 @@ doSubscribe(RPC::JsonContext& context) if (taker_pays.isMember(jss::currency)) { - Issue issue = xrpIssue(); + Currency currency; + AccountID account = xrpAccount(); // Parse mandatory currency. if (!taker_pays.isMember(jss::currency) || !to_currency( - issue.currency, taker_pays[jss::currency].asString())) + currency, taker_pays[jss::currency].asString())) { JLOG(context.j.info()) << "Bad taker_pays currency."; return rpcError(rpcSRC_CUR_MALFORMED); @@ -259,15 +260,14 @@ doSubscribe(RPC::JsonContext& context) // Parse optional issuer. if (((taker_pays.isMember(jss::issuer)) && (!taker_pays[jss::issuer].isString() || - !to_issuer( - issue.account, taker_pays[jss::issuer].asString()))) + !to_issuer(account, taker_pays[jss::issuer].asString()))) // Don't allow illegal issuers. - || (!issue.currency != !issue.account) || - noAccount() == issue.account) + || (!currency != !account) || noAccount() == account) { JLOG(context.j.info()) << "Bad taker_pays issuer."; return rpcError(rpcSRC_ISR_MALFORMED); } + IOUIssue issue{currency, account}; book.in = issue; } else if (taker_pays.isMember(jss::mpt_issuance_id)) @@ -287,11 +287,12 @@ doSubscribe(RPC::JsonContext& context) if (taker_gets.isMember(jss::currency)) { - Issue issue; + Currency currency; + AccountID account = xrpAccount(); // Parse mandatory currency. if (!taker_gets.isMember(jss::currency) || !to_currency( - issue.currency, taker_gets[jss::currency].asString())) + currency, taker_gets[jss::currency].asString())) { JLOG(context.j.info()) << "Bad taker_gets currency."; return rpcError(rpcDST_AMT_MALFORMED); @@ -300,15 +301,14 @@ doSubscribe(RPC::JsonContext& context) // Parse optional issuer. if (((taker_gets.isMember(jss::issuer)) && (!taker_gets[jss::issuer].isString() || - !to_issuer( - issue.account, taker_gets[jss::issuer].asString()))) + !to_issuer(account, taker_gets[jss::issuer].asString()))) // Don't allow illegal issuers. - || (!issue.currency != !issue.account) || - noAccount() == issue.account) + || (!currency != !account) || noAccount() == account) { JLOG(context.j.info()) << "Bad taker_gets issuer."; return rpcError(rpcDST_ISR_MALFORMED); } + IOUIssue issue{currency, account}; book.out = issue; } else if (taker_gets.isMember(jss::mpt_issuance_id)) diff --git a/src/xrpld/rpc/handlers/Unsubscribe.cpp b/src/xrpld/rpc/handlers/Unsubscribe.cpp index 49d9e99ee2b..80947448fca 100644 --- a/src/xrpld/rpc/handlers/Unsubscribe.cpp +++ b/src/xrpld/rpc/handlers/Unsubscribe.cpp @@ -180,11 +180,12 @@ doUnsubscribe(RPC::JsonContext& context) if (taker_pays.isMember(jss::currency)) { - Issue issue; + Currency currency; + AccountID account; // Parse mandatory currency. if (!taker_pays.isMember(jss::currency) || !to_currency( - issue.currency, taker_pays[jss::currency].asString())) + currency, taker_pays[jss::currency].asString())) { JLOG(context.j.info()) << "Bad taker_pays currency."; return rpcError(rpcSRC_CUR_MALFORMED); @@ -193,15 +194,15 @@ doUnsubscribe(RPC::JsonContext& context) else if ( ((taker_pays.isMember(jss::issuer)) && (!taker_pays[jss::issuer].isString() || - !to_issuer( - issue.account, taker_pays[jss::issuer].asString()))) + !to_issuer(account, taker_pays[jss::issuer].asString()))) // Don't allow illegal issuers. - || !isConsistent(book.in) || noAccount() == issue.account) + || !isConsistent(book.in) || noAccount() == account) { JLOG(context.j.info()) << "Bad taker_pays issuer."; return rpcError(rpcSRC_ISR_MALFORMED); } + IOUIssue issue{currency, account}; book.in = issue; } else if (taker_pays.isMember(jss::mpt_issuance_id)) @@ -221,11 +222,12 @@ doUnsubscribe(RPC::JsonContext& context) if (taker_gets.isMember(jss::currency)) { - Issue issue; + Currency currency; + AccountID account; // Parse mandatory currency. if (!taker_gets.isMember(jss::currency) || !to_currency( - issue.currency, taker_gets[jss::currency].asString())) + currency, taker_gets[jss::currency].asString())) { JLOG(context.j.info()) << "Bad taker_gets currency."; @@ -235,15 +237,15 @@ doUnsubscribe(RPC::JsonContext& context) else if ( ((taker_gets.isMember(jss::issuer)) && (!taker_gets[jss::issuer].isString() || - !to_issuer( - issue.account, taker_gets[jss::issuer].asString()))) + !to_issuer(account, taker_gets[jss::issuer].asString()))) // Don't allow illegal issuers. - || !isConsistent(book.out) || noAccount() == issue.account) + || !isConsistent(book.out) || noAccount() == account) { JLOG(context.j.info()) << "Bad taker_gets issuer."; return rpcError(rpcDST_ISR_MALFORMED); } + IOUIssue issue{currency, account}; book.out = issue; } else if (taker_gets.isMember(jss::mpt_issuance_id))