diff --git a/include/xrpl/protocol/AmountConversions.h b/include/xrpl/protocol/AmountConversions.h index 270d009b916..aa28bb9c8a5 100644 --- a/include/xrpl/protocol/AmountConversions.h +++ b/include/xrpl/protocol/AmountConversions.h @@ -184,7 +184,7 @@ getIssue(T const& amt) else if constexpr (std::is_same_v) return xrpIssue(); else if constexpr (std::is_same_v) - return amt.issue(); + return amt.template get(); else { constexpr bool alwaysFalse = !std::is_same_v; diff --git a/include/xrpl/protocol/Issue.h b/include/xrpl/protocol/Issue.h index 0c046378ea0..4d366cf0bde 100644 --- a/include/xrpl/protocol/Issue.h +++ b/include/xrpl/protocol/Issue.h @@ -45,6 +45,12 @@ class Issue AccountID const& getIssuer() const; + void + setIssuer(AccountID const& issuer); + + Currency const& + getCurrency() const; + std::string getText() const; }; diff --git a/include/xrpl/protocol/STAmount.h b/include/xrpl/protocol/STAmount.h index 2f037a1c285..b6716165623 100644 --- a/include/xrpl/protocol/STAmount.h +++ b/include/xrpl/protocol/STAmount.h @@ -190,13 +190,11 @@ class STAmount final : public STBase, public CountedObject constexpr TIss const& get() const; - Issue const& - issue() const; + template + TIss& + get(); // These three are deprecated - Currency const& - getCurrency() const; - AccountID const& getIssuer() const; @@ -247,9 +245,6 @@ class STAmount final : public STBase, public CountedObject void clear(Asset const& asset); - void - setIssuer(AccountID const& uIssuer); - /** Set the Issue for this amount. */ void setIssue(Asset const& asset); @@ -480,16 +475,11 @@ STAmount::get() const return mAsset.get(); } -inline Issue const& -STAmount::issue() const -{ - return get(); -} - -inline Currency const& -STAmount::getCurrency() const +template +TIss& +STAmount::get() { - return mAsset.get().currency; + return mAsset.get(); } inline AccountID const& @@ -563,12 +553,6 @@ STAmount::clear(Asset const& asset) clear(); } -inline void -STAmount::setIssuer(AccountID const& uIssuer) -{ - mAsset.get().account = uIssuer; -} - inline STAmount const& STAmount::value() const noexcept { diff --git a/src/libxrpl/protocol/AMMCore.cpp b/src/libxrpl/protocol/AMMCore.cpp index 7ac27041e76..e6c1b51e23d 100644 --- a/src/libxrpl/protocol/AMMCore.cpp +++ b/src/libxrpl/protocol/AMMCore.cpp @@ -96,7 +96,7 @@ invalidAMMAmount( std::optional> const& pair, bool validZero) { - if (auto const res = invalidAMMAsset(amount.issue(), pair)) + if (auto const res = invalidAMMAsset(amount.get(), pair)) return res; if (amount < beast::zero || (!validZero && amount == beast::zero)) return temBAD_AMOUNT; diff --git a/src/libxrpl/protocol/Issue.cpp b/src/libxrpl/protocol/Issue.cpp index 8aff535fde7..b63b3d45076 100644 --- a/src/libxrpl/protocol/Issue.cpp +++ b/src/libxrpl/protocol/Issue.cpp @@ -36,6 +36,18 @@ Issue::getIssuer() const return account; } +void +Issue::setIssuer(AccountID const& accnt) +{ + account = accnt; +} + +Currency const& +Issue::getCurrency() const +{ + return currency; +} + std::string Issue::getText() const { diff --git a/src/libxrpl/protocol/Rate2.cpp b/src/libxrpl/protocol/Rate2.cpp index 01a3e7deca5..4a794b1b916 100644 --- a/src/libxrpl/protocol/Rate2.cpp +++ b/src/libxrpl/protocol/Rate2.cpp @@ -90,7 +90,7 @@ divide(STAmount const& amount, Rate const& rate) if (rate == parityRate) return amount; - return divide(amount, detail::as_amount(rate), amount.issue()); + return divide(amount, detail::as_amount(rate), amount.get()); } STAmount @@ -101,7 +101,8 @@ divideRound(STAmount const& amount, Rate const& rate, bool roundUp) if (rate == parityRate) return amount; - return divRound(amount, detail::as_amount(rate), amount.issue(), roundUp); + return divRound( + amount, detail::as_amount(rate), amount.get(), roundUp); } STAmount diff --git a/src/test/app/AMMCalc_test.cpp b/src/test/app/AMMCalc_test.cpp index 058cdfd1d2d..d1f5b9dd9f1 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) { std::stringstream str; - str << a.getText() << "/" << to_string(a.issue().currency); + str << a.getText() << "/" << to_string(a.get().currency); return str.str(); } @@ -187,8 +187,9 @@ class AMMCalc_test : public beast::unit_test::suite if (a == b) return amt; if (amt.native()) - return toSTAmount(mulRatio(amt.xrp(), a, b, round), amt.issue()); - return toSTAmount(mulRatio(amt.iou(), a, b, round), amt.issue()); + return toSTAmount( + mulRatio(amt.xrp(), a, b, round), amt.get()); + return toSTAmount(mulRatio(amt.iou(), a, b, round), amt.get()); } void @@ -204,7 +205,7 @@ class AMMCalc_test : public beast::unit_test::suite int limitingStep = vp.size(); STAmount limitStepOut{}; auto trate = [&](auto const& amt) { - auto const currency = to_string(amt.issue().currency); + auto const currency = to_string(amt.template get().currency); return rates.find(currency) != rates.end() ? rates.at(currency) : QUALITY_ONE; }; @@ -269,7 +270,7 @@ class AMMCalc_test : public beast::unit_test::suite int limitingStep = 0; STAmount limitStepIn{}; auto trate = [&](auto const& amt) { - auto const currency = to_string(amt.issue().currency); + auto const currency = to_string(amt.template get().currency); return rates.find(currency) != rates.end() ? rates.at(currency) : QUALITY_ONE; }; diff --git a/src/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index ceddc019504..21120e63244 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -128,11 +128,11 @@ struct AMM_test : public jtx::AMMTest // Make sure asset comparison works. BEAST_EXPECT( - STIssue(sfAsset, STAmount(XRP(2'000)).issue()) == - STIssue(sfAsset, STAmount(XRP(2'000)).issue())); + STIssue(sfAsset, STAmount(XRP(2'000)).get()) == + STIssue(sfAsset, STAmount(XRP(2'000)).get())); BEAST_EXPECT( - STIssue(sfAsset, STAmount(XRP(2'000)).issue()) != - STIssue(sfAsset, STAmount(USD(2'000)).issue())); + STIssue(sfAsset, STAmount(XRP(2'000)).get()) != + STIssue(sfAsset, STAmount(USD(2'000)).get())); } void diff --git a/src/test/app/Check_test.cpp b/src/test/app/Check_test.cpp index 31b45abf43a..fe159ecc6c8 100644 --- a/src/test/app/Check_test.cpp +++ b/src/test/app/Check_test.cpp @@ -2156,8 +2156,8 @@ class Check_test : public beast::unit_test::suite return; BEAST_EXPECT( - offerAmount.issue().account == - checkAmount.issue().account); + offerAmount.get().account == + checkAmount.get().account); BEAST_EXPECT( offerAmount.negative() == checkAmount.negative()); BEAST_EXPECT( diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 2b4245a1ae4..d5e1f711abc 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -2302,19 +2302,21 @@ class OfferBaseUtil_test : public beast::unit_test::suite jtx::Account const& account, jtx::PrettyAmount const& expectBalance) { - auto const sleTrust = - env.le(keylet::line(account.id(), expectBalance.value().issue())); + auto const sleTrust = env.le( + keylet::line(account.id(), expectBalance.value().get())); BEAST_EXPECT(sleTrust); if (sleTrust) { - Issue const issue = expectBalance.value().issue(); + Issue const issue = expectBalance.value().get(); bool const accountLow = account.id() < issue.account; STAmount low{issue}; STAmount high{issue}; - low.setIssuer(accountLow ? account.id() : issue.account); - high.setIssuer(accountLow ? issue.account : account.id()); + low.get().setIssuer( + accountLow ? account.id() : issue.account); + high.get().setIssuer( + accountLow ? issue.account : account.id()); BEAST_EXPECT(sleTrust->getFieldAmount(sfLowLimit) == low); BEAST_EXPECT(sleTrust->getFieldAmount(sfHighLimit) == high); diff --git a/src/test/app/ReducedOffer_test.cpp b/src/test/app/ReducedOffer_test.cpp index a070051e435..16f23038055 100644 --- a/src/test/app/ReducedOffer_test.cpp +++ b/src/test/app/ReducedOffer_test.cpp @@ -198,11 +198,11 @@ class ReducedOffer_test : public beast::unit_test::suite mantissaReduce += 20'000'000ull) { STAmount aliceUSD{ - bobsOffer.out.issue(), + bobsOffer.out.get(), bobsOffer.out.mantissa() - mantissaReduce, bobsOffer.out.exponent()}; STAmount aliceXRP{ - bobsOffer.in.issue(), bobsOffer.in.mantissa() - 1}; + bobsOffer.in.get(), bobsOffer.in.mantissa() - 1}; Amounts alicesOffer{aliceUSD, aliceXRP}; blockedCount += exerciseOfferPair(alicesOffer, bobsOffer); } @@ -356,11 +356,11 @@ class ReducedOffer_test : public beast::unit_test::suite mantissaReduce += 20'000'000ull) { STAmount bobUSD{ - aliceOffer.out.issue(), + aliceOffer.out.get(), aliceOffer.out.mantissa() - mantissaReduce, aliceOffer.out.exponent()}; STAmount bobXRP{ - aliceOffer.in.issue(), aliceOffer.in.mantissa() - 1}; + aliceOffer.in.get(), aliceOffer.in.mantissa() - 1}; Amounts bobsOffer{bobUSD, bobXRP}; blockedCount += exerciseOfferPair(aliceOffer, bobsOffer); @@ -724,7 +724,7 @@ class ReducedOffer_test : public beast::unit_test::suite if (badRate == 0) { STAmount const tweakedTakerGets( - aliceReducedOffer.in.issue(), + aliceReducedOffer.in.get(), aliceReducedOffer.in.mantissa() + 1, aliceReducedOffer.in.exponent(), aliceReducedOffer.in.negative()); @@ -763,7 +763,7 @@ class ReducedOffer_test : public beast::unit_test::suite unsigned int blockedCount = 0; { STAmount increaseGets = USD(0); - STAmount const step(increaseGets.issue(), 1, -8); + STAmount const step(increaseGets.get(), 1, -8); for (unsigned int i = 0; i < loopCount; ++i) { blockedCount += exerciseOfferTrio( diff --git a/src/test/app/Taker_test.cpp b/src/test/app/Taker_test.cpp index 89e44b2b98b..1da87d0cc4f 100644 --- a/src/test/app/Taker_test.cpp +++ b/src/test/app/Taker_test.cpp @@ -182,7 +182,7 @@ class Taker_test : public beast::unit_test::suite { std::string txt = amount.getText(); txt += "/"; - txt += to_string(amount.issue().currency); + txt += to_string(amount.get().currency); return txt; } diff --git a/src/test/app/TheoreticalQuality_test.cpp b/src/test/app/TheoreticalQuality_test.cpp index 917d23377bf..85341340cbb 100644 --- a/src/test/app/TheoreticalQuality_test.cpp +++ b/src/test/app/TheoreticalQuality_test.cpp @@ -250,7 +250,7 @@ class TheoreticalQuality_test : public beast::unit_test::suite auto const sendMaxIssue = [&rcp]() -> std::optional { if (rcp.sendMax) - return rcp.sendMax->issue(); + return rcp.sendMax->get(); return std::nullopt; }(); @@ -260,7 +260,7 @@ class TheoreticalQuality_test : public beast::unit_test::suite sb, rcp.srcAccount, rcp.dstAccount, - rcp.dstAmt.issue(), + rcp.dstAmt.get(), /*limitQuality*/ std::nullopt, sendMaxIssue, rcp.paths, diff --git a/src/test/app/XChain_test.cpp b/src/test/app/XChain_test.cpp index 4f24d17601e..39e3730c45d 100644 --- a/src/test/app/XChain_test.cpp +++ b/src/test/app/XChain_test.cpp @@ -339,8 +339,8 @@ struct BalanceTransfer STAmount const& reward, bool check_payer = true) { - auto reward_cost = - multiply(reward, STAmount(reward_accounts.size()), reward.issue()); + auto reward_cost = multiply( + reward, STAmount(reward_accounts.size()), reward.get()); return check_most_balances(amt, reward) && (!check_payer || payor_.diff() == -(reward_cost + txFees_)); } @@ -1670,7 +1670,7 @@ struct XChain_test : public beast::unit_test::suite, BEAST_EXPECT(!scEnv.claimID(jvb, 1)); // claim id deleted BEAST_EXPECT(transfer.has_happened( - amt, divide(reward, STAmount(3), reward.issue()))); + amt, divide(reward, STAmount(3), reward.get()))); } // 4,4 => should succeed @@ -1695,7 +1695,7 @@ struct XChain_test : public beast::unit_test::suite, return result; }(); STAmount const split_reward_ = - divide(reward, STAmount(signers_.size()), reward.issue()); + divide(reward, STAmount(signers_.size()), reward.get()); mcEnv.tx(create_bridge(mcDoor, jvb)).close(); @@ -1748,7 +1748,7 @@ struct XChain_test : public beast::unit_test::suite, BEAST_EXPECT(!scEnv.claimID(jvb, claimID)); // claim id deleted BEAST_EXPECT(transfer.has_happened( - amt, divide(reward, STAmount(2), reward.issue()))); + amt, divide(reward, STAmount(2), reward.get()))); } // 1,2 => should fail @@ -4455,7 +4455,7 @@ struct XChainSim_test : public beast::unit_test::suite, STAmount amt, std::uint64_t divisor = 1) { - if (amt.issue() != xrpIssue()) + if (amt.get() != xrpIssue()) return; auto it = accounts.find(acct); if (it == accounts.end()) @@ -4469,22 +4469,23 @@ struct XChainSim_test : public beast::unit_test::suite, (divisor == 1 ? amt : divide( amt, - STAmount(amt.issue(), divisor), - amt.issue())); + STAmount(amt.get(), divisor), + amt.get())); } } void spend(jtx::Account const& acct, STAmount amt, std::uint64_t times = 1) { - if (amt.issue() != xrpIssue()) + if (amt.get() != xrpIssue()) return; receive( acct, - times == 1 - ? -amt - : -multiply( - amt, STAmount(amt.issue(), times), amt.issue())); + times == 1 ? -amt + : -multiply( + amt, + STAmount(amt.get(), times), + amt.get())); } void @@ -4712,7 +4713,8 @@ struct XChainSim_test : public beast::unit_test::suite, assert(cr.claim_id - 1 == counters.claim_count); auto r = cr.reward; - auto reward = divide(r, STAmount(num_attestors), r.issue()); + auto reward = + divide(r, STAmount(num_attestors), r.get()); for (auto i : signers) st.receive(bridge_.signers[i].account, reward); @@ -4797,7 +4799,7 @@ struct XChainSim_test : public beast::unit_test::suite, ChainStateTrack& st = srcState(); jtx::Account const& srcdoor = srcDoor(); - if (xfer.amt.issue() != xrpIssue()) + if (xfer.amt.get() != xrpIssue()) { st.env.tx(pay(srcdoor, xfer.from, xfer.amt)); st.spendFee(srcdoor); @@ -4818,7 +4820,7 @@ struct XChainSim_test : public beast::unit_test::suite, distribute_reward(ChainStateTrack& st) { auto r = bridge_.reward; - auto reward = divide(r, STAmount(bridge_.quorum), r.issue()); + auto reward = divide(r, STAmount(bridge_.quorum), r.get()); for (size_t i = 0; i < num_signers; ++i) { diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index 0f4c4ddd3dd..ef3dc370b51 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -40,8 +40,8 @@ countOffers( forEachItem( *env.current(), account, [&](std::shared_ptr const& sle) { if (sle->getType() == ltOFFER && - sle->getFieldAmount(sfTakerPays).issue() == takerPays && - sle->getFieldAmount(sfTakerGets).issue() == takerGets) + sle->getFieldAmount(sfTakerPays).get() == takerPays && + sle->getFieldAmount(sfTakerGets).get() == takerGets) ++count; }); return count; diff --git a/src/test/jtx/amount.h b/src/test/jtx/amount.h index 6f3faebeecb..319f7e6b395 100644 --- a/src/test/jtx/amount.h +++ b/src/test/jtx/amount.h @@ -390,7 +390,8 @@ class MPT } template - requires(sizeof(T) >= sizeof(int) && std::is_arithmetic_v) PrettyAmount + requires(sizeof(T) >= sizeof(int) && std::is_arithmetic_v) + PrettyAmount operator()(T v) const { // VFALCO NOTE Should throw if the @@ -458,7 +459,7 @@ struct AnyAmount { if (!is_any) return; - value.setIssuer(id); + value.get().setIssuer(id); } }; diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index c083b6df35c..2b4e9115fe2 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -42,8 +42,8 @@ static IOUAmount initialTokens(STAmount const& asset1, STAmount const& asset2) { auto const product = number(asset1) * number(asset2); - return (IOUAmount)( - product.mantissa() >= 0 ? root2(product) : root2(-product)); + return (IOUAmount)(product.mantissa() >= 0 ? root2(product) + : root2(-product)); } AMM::AMM( @@ -63,7 +63,7 @@ AMM::AMM( , creatorAccount_(account) , asset1_(asset1) , asset2_(asset2) - , ammID_(keylet::amm(asset1_.issue(), asset2_.issue()).key) + , ammID_(keylet::amm(asset1_.get(), asset2_.get()).key) , initialLPTokens_(initialTokens(asset1, asset2)) , log_(log) , doClose_(close) @@ -74,8 +74,8 @@ AMM::AMM( , fee_(fee) , ammAccount_(create(tfee, flags, seq, ter)) , lptIssue_(ripple::ammLPTIssue( - asset1_.issue().currency, - asset2_.issue().currency, + asset1_.get().currency, + asset2_.get().currency, ammAccount_)) { } @@ -148,7 +148,7 @@ AMM::create( if (!ter || env_.ter() == tesSUCCESS) { if (auto const amm = env_.current()->read( - keylet::amm(asset1_.issue(), asset2_.issue()))) + keylet::amm(asset1_.get(), asset2_.get()))) { return amm->getAccountID(sfAccount); } @@ -184,10 +184,10 @@ AMM::ammRpcInfo( } else if (!ammAccount) { - jv[jss::asset] = - STIssue(sfAsset, asset1_.issue()).getJson(JsonOptions::none); - jv[jss::asset2] = - STIssue(sfAsset2, asset2_.issue()).getJson(JsonOptions::none); + jv[jss::asset] = STIssue(sfAsset, asset1_.get()) + .getJson(JsonOptions::none); + jv[jss::asset2] = STIssue(sfAsset2, asset2_.get()) + .getJson(JsonOptions::none); } if (ammAccount) jv[jss::amm_account] = to_string(*ammAccount); @@ -208,8 +208,8 @@ AMM::balances( Issue const& issue2, std::optional const& account) const { - if (auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) + if (auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get()))) { auto const ammAccountID = amm->getAccountID(sfAccount); auto const [asset1Balance, asset2Balance] = ammPoolHolds( @@ -235,7 +235,7 @@ AMM::expectBalances( std::optional const& account) const { auto const [asset1Balance, asset2Balance, lptAMMBalance] = - balances(asset1.issue(), asset2.issue(), account); + balances(asset1.get(), asset2.get(), account); return asset1 == asset1Balance && asset2 == asset2Balance && lptAMMBalance == STAmount{lpt, lptIssue_}; } @@ -251,8 +251,8 @@ AMM::getLPTokensBalance(std::optional const& account) const FreezeHandling::fhZERO_IF_FROZEN, env_.journal) .iou(); - if (auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) + if (auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get()))) return amm->getFieldAmount(sfLPTokenBalance).iou(); return IOUAmount{0}; } @@ -260,8 +260,8 @@ AMM::getLPTokensBalance(std::optional const& account) const bool AMM::expectLPTokens(AccountID const& account, IOUAmount const& expTokens) const { - if (auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) + if (auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get()))) { auto const lptAMMBalance = ammLPHolds(*env_.current(), *amm, account, env_.journal); @@ -310,8 +310,8 @@ AMM::expectAuctionSlot(std::vector const& authAccounts) const bool AMM::expectTradingFee(std::uint16_t fee) const { - auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue())); + auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get())); return amm && (*amm)[sfTradingFee] == fee; } @@ -319,8 +319,8 @@ bool AMM::ammExists() const { return env_.current()->read(keylet::account(ammAccount_)) != nullptr && - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue())) != - nullptr; + env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get())) != nullptr; } bool @@ -360,7 +360,7 @@ AMM::expectAmmInfo( if (!amountFromJsonNoThrow(lptBalance, jv[jss::lp_token])) return false; // ammRpcInfo returns unordered assets - if (asset1Info.issue() != asset1.issue()) + if (asset1Info.get() != asset1.get()) std::swap(asset1Info, asset2Info); return asset1 == asset1Info && asset2 == asset2Info && lptBalance == STAmount{balance, lptIssue_}; @@ -381,9 +381,9 @@ AMM::setTokens( else { jv[jss::Asset] = - STIssue(sfAsset, asset1_.issue()).getJson(JsonOptions::none); + STIssue(sfAsset, asset1_.get()).getJson(JsonOptions::none); jv[jss::Asset2] = - STIssue(sfAsset, asset2_.issue()).getJson(JsonOptions::none); + STIssue(sfAsset, asset2_.get()).getJson(JsonOptions::none); } } @@ -662,8 +662,8 @@ AMM::vote(VoteArg const& arg) Json::Value AMM::bid(BidArg const& arg) { - if (auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) + if (auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get()))) { assert( !env_.current()->rules().enabled(fixInnerObjTemplate) || @@ -757,8 +757,8 @@ AMM::submit( bool AMM::expectAuctionSlot(auto&& cb) const { - if (auto const amm = - env_.current()->read(keylet::amm(asset1_.issue(), asset2_.issue()))) + if (auto const amm = env_.current()->read( + keylet::amm(asset1_.get(), asset2_.get()))) { assert( !env_.current()->rules().enabled(fixInnerObjTemplate) || diff --git a/src/test/jtx/impl/AMMTest.cpp b/src/test/jtx/impl/AMMTest.cpp index 575e2e1d889..24b3952a5e6 100644 --- a/src/test/jtx/impl/AMMTest.cpp +++ b/src/test/jtx/impl/AMMTest.cpp @@ -63,7 +63,7 @@ fund( for (auto const& amt : amts) { env.trust(amt + amt, account); - env(pay(amt.issue().account, account, amt)); + env(pay(amt.get().account, account, amt)); } } env.close(); @@ -121,10 +121,10 @@ AMMTestBase::testAMM( return defXRP; return a + XRP(1000); } - auto const defIOU = STAmount{a.issue(), 30000}; + auto const defIOU = STAmount{a.get(), 30000}; if (a <= defIOU) return defIOU; - return a + STAmount{a.issue(), 1000}; + return a + STAmount{a.get(), 1000}; }; auto const toFund1 = tofund(asset1); auto const toFund2 = tofund(asset2); diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 6f0f9e3fc73..a7bf4286e63 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -197,7 +197,7 @@ Env::balance(Account const& account, Issue const& issue) const if (!sle) return {STAmount(issue, 0), account.name()}; auto amount = sle->getFieldAmount(sfBalance); - amount.setIssuer(issue.account); + amount.get().setIssuer(issue.account); if (account.id() > issue.account) amount.negate(); return {amount, lookup(issue.account).name()}; diff --git a/src/test/jtx/impl/TestHelpers.cpp b/src/test/jtx/impl/TestHelpers.cpp index b8105b1a631..834ab427219 100644 --- a/src/test/jtx/impl/TestHelpers.cpp +++ b/src/test/jtx/impl/TestHelpers.cpp @@ -67,7 +67,7 @@ stpath_append_one(STPath& st, STPathElement const& pe) bool equal(STAmount const& sa1, STAmount const& sa2) { - return sa1 == sa2 && sa1.issue().account == sa2.issue().account; + return sa1 == sa2 && sa1.get().account == sa2.get().account; } // Issue path element @@ -103,9 +103,9 @@ expectLine( STAmount const& value, bool defaultLimits) { - if (auto const sle = env.le(keylet::line(account, value.issue()))) + if (auto const sle = env.le(keylet::line(account, value.get()))) { - Issue const issue = value.issue(); + Issue const issue = value.get(); bool const accountLow = account < issue.account; bool expectDefaultTrustLine = true; @@ -114,15 +114,15 @@ expectLine( STAmount low{issue}; STAmount high{issue}; - low.setIssuer(accountLow ? account : issue.account); - high.setIssuer(accountLow ? issue.account : account); + low.get().setIssuer(accountLow ? account : issue.account); + high.get().setIssuer(accountLow ? issue.account : account); expectDefaultTrustLine = sle->getFieldAmount(sfLowLimit) == low && sle->getFieldAmount(sfHighLimit) == high; } auto amount = sle->getFieldAmount(sfBalance); - amount.setIssuer(value.issue().account); + amount.get().setIssuer(value.get().account); if (!accountLow) amount.negate(); return amount == value && expectDefaultTrustLine; diff --git a/src/test/jtx/impl/amount.cpp b/src/test/jtx/impl/amount.cpp index 01fa5369592..a9480dbbdef 100644 --- a/src/test/jtx/impl/amount.cpp +++ b/src/test/jtx/impl/amount.cpp @@ -36,12 +36,12 @@ operator<<(std::ostream&& os, if (amount.is_any) { os << amount.value.getText() << "/" << - to_string(amount.value.issue().currency) << + to_string(amount.value.get().currency) << "*"; return os; } os << amount.value.getText() << "/" << - to_string(amount.value.issue().currency) << + to_string(amount.value.get().currency) << "(" << amount.name() << ")"; return os; } @@ -94,8 +94,8 @@ operator<<(std::ostream& os, PrettyAmount const& amount) else { os << amount.value().getText() << "/" - << to_string(amount.value().issue().currency) << "(" << amount.name() - << ")"; + << to_string(amount.value().get().currency) << "(" + << amount.name() << ")"; } return os; } diff --git a/src/test/jtx/impl/balance.cpp b/src/test/jtx/impl/balance.cpp index 42330658eb0..a533e5e7cc2 100644 --- a/src/test/jtx/impl/balance.cpp +++ b/src/test/jtx/impl/balance.cpp @@ -26,7 +26,7 @@ namespace jtx { void balance::operator()(Env& env) const { - if (isXRP(value_.issue())) + if (isXRP(value_.get())) { auto const sle = env.le(account_); if (none_) @@ -40,7 +40,8 @@ balance::operator()(Env& env) const } else { - auto const sle = env.le(keylet::line(account_.id(), value_.issue())); + auto const sle = + env.le(keylet::line(account_.id(), value_.get())); if (none_) { env.test.expect(!sle); @@ -48,8 +49,8 @@ balance::operator()(Env& env) const else if (env.test.expect(sle)) { auto amount = sle->getFieldAmount(sfBalance); - amount.setIssuer(value_.issue().account); - if (account_.id() > value_.issue().account) + amount.get().setIssuer(value_.get().account); + if (account_.id() > value_.get().account) amount.negate(); env.test.expect(amount == value_); } diff --git a/src/test/jtx/impl/xchain_bridge.cpp b/src/test/jtx/impl/xchain_bridge.cpp index 43b0e7c2f96..d4f4838190e 100644 --- a/src/test/jtx/impl/xchain_bridge.cpp +++ b/src/test/jtx/impl/xchain_bridge.cpp @@ -448,25 +448,27 @@ XChainBridgeObjects::XChainBridgeObjects() }()) , quorum(UT_XCHAIN_DEFAULT_QUORUM) , reward(XRP(1)) - , split_reward_quorum( - divide(reward, STAmount(UT_XCHAIN_DEFAULT_QUORUM), reward.issue())) + , split_reward_quorum(divide( + reward, + STAmount(UT_XCHAIN_DEFAULT_QUORUM), + reward.get())) , split_reward_everyone(divide( reward, STAmount(UT_XCHAIN_DEFAULT_NUM_SIGNERS), - reward.issue())) + reward.get())) , tiny_reward(drops(37)) , tiny_reward_split((divide( tiny_reward, STAmount(UT_XCHAIN_DEFAULT_QUORUM), - tiny_reward.issue()))) + tiny_reward.get()))) , tiny_reward_remainder( tiny_reward - multiply( tiny_reward_split, STAmount(UT_XCHAIN_DEFAULT_QUORUM), - tiny_reward.issue())) + tiny_reward.get())) , one_xrp(XRP(1)) - , xrp_dust(divide(one_xrp, STAmount(10000), one_xrp.issue())) + , xrp_dust(divide(one_xrp, STAmount(10000), one_xrp.get())) { } diff --git a/src/test/protocol/STAmount_test.cpp b/src/test/protocol/STAmount_test.cpp index b512c42a643..40b3d29cac5 100644 --- a/src/test/protocol/STAmount_test.cpp +++ b/src/test/protocol/STAmount_test.cpp @@ -53,13 +53,13 @@ class STAmount_test : public beast::unit_test::suite if (mantissa < STAmount::cMinValue) return { - amount.issue(), + amount.get(), mantissa, amount.exponent(), amount.negative()}; return { - amount.issue(), + amount.get(), mantissa, amount.exponent(), amount.negative(), @@ -72,13 +72,13 @@ class STAmount_test : public beast::unit_test::suite if (mantissa > STAmount::cMaxValue) return { - amount.issue(), + amount.get(), mantissa, amount.exponent(), amount.negative()}; return { - amount.issue(), + amount.get(), mantissa, amount.exponent(), amount.negative(), @@ -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.get().currency == res.get().currency); if (res != cmp) { diff --git a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp b/src/xrpld/app/ledger/AcceptedLedgerTx.cpp index e1ad68dff37..ef334d6821c 100644 --- a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp +++ b/src/xrpld/app/ledger/AcceptedLedgerTx.cpp @@ -60,7 +60,7 @@ AcceptedLedgerTx::AcceptedLedgerTx( auto const amount = mTxn->getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the owner balance - if (account != amount.issue().account) + if (account != amount.get().account) { auto const ownerFunds = accountFunds( *ledger, diff --git a/src/xrpld/app/ledger/OrderBookDB.cpp b/src/xrpld/app/ledger/OrderBookDB.cpp index d0eddadbacb..0360cc23da6 100644 --- a/src/xrpld/app/ledger/OrderBookDB.cpp +++ b/src/xrpld/app/ledger/OrderBookDB.cpp @@ -274,8 +274,8 @@ OrderBookDB::processTxn( data->isFieldPresent(sfTakerGets)) { auto listeners = getBookListeners( - {data->getFieldAmount(sfTakerGets).issue(), - data->getFieldAmount(sfTakerPays).issue()}); + {data->getFieldAmount(sfTakerGets).get(), + data->getFieldAmount(sfTakerPays).get()}); if (listeners) listeners->publish(jvObj, havePublished); } diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index 7868807c52a..5e860007901 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -2981,7 +2981,7 @@ NetworkOPsImp::transJson( auto const amount = transaction->getFieldAmount(sfTakerGets); // If the offer create is not self funded then add the owner balance - if (account != amount.issue().account) + if (account != amount.get().account) { auto const ownerFunds = accountFunds( *ledger, @@ -4239,7 +4239,9 @@ NetworkOPsImp::getBookPage( std::min( saTakerPays, multiply( - saTakerGetsFunded, saDirRate, saTakerPays.issue())) + saTakerGetsFunded, + saDirRate, + saTakerPays.get())) .setJson(jvOffer[jss::taker_pays_funded]); } @@ -4390,7 +4392,8 @@ NetworkOPsImp::getBookPage( // going on here? std::min( saTakerPays, - multiply(saTakerGetsFunded, saDirRate, saTakerPays.issue())) + multiply( + saTakerGetsFunded, saDirRate, saTakerPays.get())) .setJson(jvOffer[jss::taker_pays_funded]); } diff --git a/src/xrpld/app/misc/detail/AMMHelpers.cpp b/src/xrpld/app/misc/detail/AMMHelpers.cpp index f10b4c15eb0..d17903566ef 100644 --- a/src/xrpld/app/misc/detail/AMMHelpers.cpp +++ b/src/xrpld/app/misc/detail/AMMHelpers.cpp @@ -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.issue(), t); + return toSTAmount(lptAMMBalance.get(), t); } /* Equation 4 solves equation 3 for b: @@ -79,7 +79,7 @@ ammAssetIn( auto const b = 2 * d / t2 - 1 / f1; auto const c = d * d - f2 * f2; return toSTAmount( - asset1Balance.issue(), asset1Balance * solveQuadraticEq(a, b, c)); + asset1Balance.get(), asset1Balance * solveQuadraticEq(a, b, c)); } /* Equation 7: @@ -97,7 +97,7 @@ lpTokensOut( auto const f1 = getFee(tfee); auto const c = fr * f1 + 2 - f1; auto const t = lptAMMBalance * (c - root2(c * c - 4 * fr)) / 2; - return toSTAmount(lptAMMBalance.issue(), t); + return toSTAmount(lptAMMBalance.get(), t); } /* Equation 8 solves equation 7 for b: @@ -120,7 +120,7 @@ withdrawByTokens( auto const f = getFee(tfee); Number const t1 = lpTokens / lptAMMBalance; auto const b = assetBalance * (t1 * t1 - t1 * (2 - f)) / (t1 * f - 1); - return toSTAmount(assetBalance.issue(), b); + return toSTAmount(assetBalance.get(), b); } Number @@ -176,9 +176,10 @@ adjustAmountsByLPTokens( if (amount2) { Number const fr = lpTokensActual / lpTokens; - auto const amountActual = toSTAmount(amount.issue(), fr * amount); + auto const amountActual = + toSTAmount(amount.get(), fr * amount); auto const amount2Actual = - toSTAmount(amount2->issue(), fr * *amount2); + toSTAmount(amount2->get(), fr * *amount2); if (!ammRoundingEnabled) return std::make_tuple( amountActual < amount ? amountActual : amount, diff --git a/src/xrpld/app/misc/detail/AMMUtils.cpp b/src/xrpld/app/misc/detail/AMMUtils.cpp index efc80cf17b6..f3a1ad3d2e5 100644 --- a/src/xrpld/app/misc/detail/AMMUtils.cpp +++ b/src/xrpld/app/misc/detail/AMMUtils.cpp @@ -191,7 +191,7 @@ ammAccountHolds( auto amount = (*sle)[sfBalance]; if (ammAccountID > issue.account) amount.negate(); - amount.setIssuer(issue.account); + amount.get().setIssuer(issue.account); return amount; } @@ -396,8 +396,8 @@ isOnlyLiquidityProvider( auto const highLimit = sle->getFieldAmount(sfHighLimit); auto const isLPTrustline = lowLimit.getIssuer() == lpAccount || highLimit.getIssuer() == lpAccount; - auto const isLPTokenTrustline = - lowLimit.issue() == ammIssue || highLimit.issue() == ammIssue; + auto const isLPTokenTrustline = lowLimit.get() == ammIssue || + highLimit.get() == ammIssue; // Liquidity Provider trustline if (isLPTrustline) diff --git a/src/xrpld/app/paths/AccountCurrencies.cpp b/src/xrpld/app/paths/AccountCurrencies.cpp index 8646b46939a..0f26224b75d 100644 --- a/src/xrpld/app/paths/AccountCurrencies.cpp +++ b/src/xrpld/app/paths/AccountCurrencies.cpp @@ -48,7 +48,7 @@ accountSourceCurrencies( // Peer extends credit. && ((-saBalance) < rspEntry.getLimitPeer()))) // Credit left. { - currencies.insert(saBalance.getCurrency()); + currencies.insert(saBalance.get().getCurrency()); } } } @@ -77,7 +77,7 @@ accountDestCurrencies( auto& saBalance = rspEntry.getBalance(); if (saBalance < rspEntry.getLimit()) // Can take more - currencies.insert(saBalance.getCurrency()); + currencies.insert(saBalance.get().getCurrency()); } } diff --git a/src/xrpld/app/paths/Credit.cpp b/src/xrpld/app/paths/Credit.cpp index b3870937367..1733cb669c8 100644 --- a/src/xrpld/app/paths/Credit.cpp +++ b/src/xrpld/app/paths/Credit.cpp @@ -39,11 +39,11 @@ creditLimit( { result = sleRippleState->getFieldAmount( account < issuer ? sfLowLimit : sfHighLimit); - result.setIssuer(account); + result.get().setIssuer(account); } assert(result.getIssuer() == account); - assert(result.getCurrency() == currency); + assert(result.get().getCurrency() == currency); return result; } @@ -73,11 +73,11 @@ creditBalance( result = sleRippleState->getFieldAmount(sfBalance); if (account < issuer) result.negate(); - result.setIssuer(account); + result.get().setIssuer(account); } assert(result.getIssuer() == account); - assert(result.getCurrency() == currency); + assert(result.get().getCurrency() == currency); return result; } diff --git a/src/xrpld/app/paths/Flow.cpp b/src/xrpld/app/paths/Flow.cpp index c21d40c33b5..862a10901f9 100644 --- a/src/xrpld/app/paths/Flow.cpp +++ b/src/xrpld/app/paths/Flow.cpp @@ -73,17 +73,17 @@ flow( { Issue const srcIssue = [&] { if (sendMax) - return sendMax->issue(); - if (!isXRP(deliver.issue().currency)) - return Issue(deliver.issue().currency, src); + return sendMax->get(); + if (!isXRP(deliver.get().currency)) + return Issue(deliver.get().currency, src); return xrpIssue(); }(); - Issue const dstIssue = deliver.issue(); + Issue const dstIssue = deliver.get(); std::optional sendMaxIssue; if (sendMax) - sendMaxIssue = sendMax->issue(); + sendMaxIssue = sendMax->get(); AMMContext ammContext(src, false); diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/app/paths/PathRequest.cpp index bb6a104bca2..f813f3c90d3 100644 --- a/src/xrpld/app/paths/PathRequest.cpp +++ b/src/xrpld/app/paths/PathRequest.cpp @@ -313,11 +313,12 @@ PathRequest::parseJson(Json::Value const& jvParams) return PFR_PJ_INVALID; } - convert_all_ = saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true); + convert_all_ = + saDstAmount == STAmount(saDstAmount.get(), 1u, 0, true); - if ((saDstAmount.getCurrency().isZero() && + if ((saDstAmount.get().getCurrency().isZero() && saDstAmount.getIssuer().isNonZero()) || - (saDstAmount.getCurrency() == badCurrency()) || + (saDstAmount.get().getCurrency() == badCurrency()) || (!convert_all_ && saDstAmount <= beast::zero)) { jvStatus = rpcError(rpcDST_AMT_MALFORMED); @@ -335,11 +336,11 @@ PathRequest::parseJson(Json::Value const& jvParams) saSendMax.emplace(); if (!amountFromJsonNoThrow(*saSendMax, jvParams[jss::send_max]) || - (saSendMax->getCurrency().isZero() && + (saSendMax->get().getCurrency().isZero() && saSendMax->getIssuer().isNonZero()) || - (saSendMax->getCurrency() == badCurrency()) || + (saSendMax->get().getCurrency() == badCurrency()) || (*saSendMax <= beast::zero && - *saSendMax != STAmount(saSendMax->issue(), 1u, 0, true))) + *saSendMax != STAmount(saSendMax->get(), 1u, 0, true))) { jvStatus = rpcError(rpcSENDMAX_MALFORMED); return PFR_PJ_INVALID; @@ -396,7 +397,7 @@ PathRequest::parseJson(Json::Value const& jvParams) if (saSendMax) { // If the currencies don't match, ignore the source currency. - if (srcCurrencyID == saSendMax->getCurrency()) + if (srcCurrencyID == saSendMax->get().getCurrency()) { // If neither is the source and they are not equal, then the // source issuer is illegal. @@ -501,7 +502,7 @@ PathRequest::findPaths( auto sourceCurrencies = sciSourceCurrencies; if (sourceCurrencies.empty() && saSendMax) { - sourceCurrencies.insert(saSendMax->issue()); + sourceCurrencies.insert(saSendMax->get()); } if (sourceCurrencies.empty()) { @@ -509,7 +510,7 @@ PathRequest::findPaths( bool const sameAccount = *raSrcAccount == *raDstAccount; for (auto const& c : currencies) { - if (!sameAccount || c != saDstAmount.getCurrency()) + if (!sameAccount || c != saDstAmount.get().getCurrency()) { if (sourceCurrencies.size() >= RPC::Tuning::max_auto_src_cur) return false; @@ -619,7 +620,7 @@ PathRequest::findPaths( if (rc.result() == tesSUCCESS) { Json::Value jvEntry(Json::objectValue); - rc.actualAmountIn.setIssuer(sourceAccount); + rc.actualAmountIn.get().setIssuer(sourceAccount); jvEntry[jss::source_amount] = rc.actualAmountIn.getJson(JsonOptions::none); jvEntry[jss::paths_computed] = ps.getJson(JsonOptions::none); diff --git a/src/xrpld/app/paths/Pathfinder.cpp b/src/xrpld/app/paths/Pathfinder.cpp index a5fe2afe949..b13a914c0ad 100644 --- a/src/xrpld/app/paths/Pathfinder.cpp +++ b/src/xrpld/app/paths/Pathfinder.cpp @@ -154,7 +154,7 @@ pathTypeToString(Pathfinder::PathType const& type) STAmount smallestUsefulAmount(STAmount const& amount, int maxPaths) { - return divide(amount, STAmount(maxPaths + 2), amount.issue()); + return divide(amount, STAmount(maxPaths + 2), amount.get()); } } // namespace @@ -210,7 +210,7 @@ Pathfinder::findPaths( } if (mSrcAccount == mDstAccount && mDstAccount == mEffectiveDst && - mSrcCurrency == mDstAmount.getCurrency()) + mSrcCurrency == mDstAmount.get().getCurrency()) { // No need to send to same account with same currency. JLOG(j_.debug()) << "Tried to send to same issuer"; @@ -219,7 +219,7 @@ Pathfinder::findPaths( } if (mSrcAccount == mEffectiveDst && - mSrcCurrency == mDstAmount.getCurrency()) + mSrcCurrency == mDstAmount.get().getCurrency()) { // Default path might work, but any path would loop return true; @@ -248,7 +248,7 @@ Pathfinder::findPaths( } bool bSrcXrp = isXRP(mSrcCurrency); - bool bDstXrp = isXRP(mDstAmount.getCurrency()); + bool bDstXrp = isXRP(mDstAmount.get().getCurrency()); if (!mLedger->exists(keylet::account(mSrcAccount))) { @@ -305,7 +305,7 @@ Pathfinder::findPaths( JLOG(j_.debug()) << "non-XRP to XRP payment"; paymentType = pt_nonXRP_to_XRP; } - else if (mSrcCurrency == mDstAmount.getCurrency()) + else if (mSrcCurrency == mDstAmount.get().getCurrency()) { // non-XRP -> non-XRP - Same currency JLOG(j_.debug()) << "non-XRP to non-XRP - same currency"; @@ -741,7 +741,7 @@ Pathfinder::getPathsOut( { for (auto const& rspEntry : *lines) { - if (currency != rspEntry.getLimit().getCurrency()) + if (currency != rspEntry.getLimit().get().getCurrency()) { } else if ( @@ -978,7 +978,7 @@ Pathfinder::addLink( bool const bRequireAuth( sleEnd->getFieldU32(sfFlags) & lsfRequireAuth); bool const bIsEndCurrency( - uEndCurrency == mDstAmount.getCurrency()); + uEndCurrency == mDstAmount.get().getCurrency()); bool const bIsNoRippleOut(isNoRippleOut(currentPath)); bool const bDestOnly(addFlags & afAC_LAST); @@ -1012,7 +1012,8 @@ Pathfinder::addLink( continue; } - if ((uEndCurrency == rs.getLimit().getCurrency()) && + if ((uEndCurrency == + rs.getLimit().get().getCurrency()) && !currentPath.hasSeen(acct, uEndCurrency, acct)) { // path is for correct currency and has not been @@ -1031,7 +1032,8 @@ Pathfinder::addLink( else if (bToDestination) { // destination is always worth trying - if (uEndCurrency == mDstAmount.getCurrency()) + if (uEndCurrency == + mDstAmount.get().getCurrency()) { // this is a complete path if (!currentPath.empty()) @@ -1146,7 +1148,8 @@ Pathfinder::addLink( xrpAccount(), book.out.currency, book.out.account) && !issueMatchesOrigin(book.out) && (!bDestOnly || - (book.out.currency == mDstAmount.getCurrency()))) + (book.out.currency == + mDstAmount.get().getCurrency()))) { STPath newPath(currentPath); @@ -1160,7 +1163,7 @@ Pathfinder::addLink( xrpCurrency(), xrpAccount()); - if (mDstAmount.getCurrency().isZero()) + if (mDstAmount.get().getCurrency().isZero()) { // destination is XRP, add account and path is // complete @@ -1204,13 +1207,15 @@ Pathfinder::addLink( if (hasEffectiveDestination && book.out.account == mDstAccount && - book.out.currency == mDstAmount.getCurrency()) + book.out.currency == + mDstAmount.get().getCurrency()) { // We skipped a required issuer } else if ( book.out.account == mEffectiveDst && - book.out.currency == mDstAmount.getCurrency()) + book.out.currency == + mDstAmount.get().getCurrency()) { // with the destination account, this path is // complete JLOG(j_.trace()) diff --git a/src/xrpld/app/paths/RippleCalc.cpp b/src/xrpld/app/paths/RippleCalc.cpp index c7b2e1f01e0..1e66d683e78 100644 --- a/src/xrpld/app/paths/RippleCalc.cpp +++ b/src/xrpld/app/paths/RippleCalc.cpp @@ -84,7 +84,8 @@ RippleCalc::rippleCalculate( auto const sendMax = [&]() -> std::optional { if (saMaxAmountReq >= beast::zero || - saMaxAmountReq.getCurrency() != saDstAmountReq.getCurrency() || + saMaxAmountReq.get().getCurrency() != + saDstAmountReq.get().getCurrency() || saMaxAmountReq.getIssuer() != uSrcAccountID) { return saMaxAmountReq; diff --git a/src/xrpld/app/paths/detail/AmountSpec.h b/src/xrpld/app/paths/detail/AmountSpec.h index 8a1117f9920..db610b62015 100644 --- a/src/xrpld/app/paths/detail/AmountSpec.h +++ b/src/xrpld/app/paths/detail/AmountSpec.h @@ -178,8 +178,8 @@ toAmountSpec(STAmount const& amt) else { result.iou = IOUAmount(sMant, amt.exponent()); - result.issuer = amt.issue().account; - result.currency = amt.issue().currency; + result.issuer = amt.get().account; + result.currency = amt.get().currency; } return result; diff --git a/src/xrpld/app/paths/detail/PathfinderUtils.h b/src/xrpld/app/paths/detail/PathfinderUtils.h index b06dded75bd..bcb6ddaf23e 100644 --- a/src/xrpld/app/paths/detail/PathfinderUtils.h +++ b/src/xrpld/app/paths/detail/PathfinderUtils.h @@ -30,7 +30,8 @@ largestAmount(STAmount const& amt) if (amt.native()) return INITIAL_XRP; - return STAmount(amt.issue(), STAmount::cMaxValue, STAmount::cMaxOffset); + return STAmount( + amt.get(), STAmount::cMaxValue, STAmount::cMaxOffset); } inline STAmount diff --git a/src/xrpld/app/tx/detail/AMMBid.cpp b/src/xrpld/app/tx/detail/AMMBid.cpp index 9de3762d2e3..35d94811f39 100644 --- a/src/xrpld/app/tx/detail/AMMBid.cpp +++ b/src/xrpld/app/tx/detail/AMMBid.cpp @@ -123,7 +123,7 @@ AMMBid::preclaim(PreclaimContext const& ctx) if (bidMin) { - if (bidMin->issue() != lpTokens.issue()) + if (bidMin->get() != lpTokens.get()) { JLOG(ctx.j.debug()) << "AMM Bid: Invalid LPToken."; return temBAD_AMM_TOKENS; @@ -138,7 +138,7 @@ AMMBid::preclaim(PreclaimContext const& ctx) auto const bidMax = ctx.tx[~sfBidMax]; if (bidMax) { - if (bidMax->issue() != lpTokens.issue()) + if (bidMax->get() != lpTokens.get()) { JLOG(ctx.j.debug()) << "AMM Bid: Invalid LPToken."; return temBAD_AMM_TOKENS; @@ -222,7 +222,7 @@ applyBid( else if (auctionSlot.isFieldPresent(sfDiscountedFee)) auctionSlot.makeFieldAbsent(sfDiscountedFee); auctionSlot.setFieldAmount( - sfPrice, toSTAmount(lpTokens.issue(), minPrice)); + sfPrice, toSTAmount(lpTokens.get(), minPrice)); if (ctx_.tx.isFieldPresent(sfAuthAccounts)) auctionSlot.setFieldArray( sfAuthAccounts, ctx_.tx.getFieldArray(sfAuthAccounts)); @@ -230,7 +230,7 @@ applyBid( auctionSlot.makeFieldAbsent(sfAuthAccounts); // Burn the remaining bid amount auto const saBurn = adjustLPTokens( - lptAMMBalance, toSTAmount(lptAMMBalance.issue(), burn), false); + lptAMMBalance, toSTAmount(lptAMMBalance.get(), burn), false); if (saBurn >= lptAMMBalance) { // This error case should never occur. @@ -239,8 +239,8 @@ applyBid( << lptAMMBalance; return tecINTERNAL; } - auto res = - redeemIOU(sb, account_, saBurn, lpTokens.issue(), ctx_.journal); + auto res = redeemIOU( + sb, account_, saBurn, lpTokens.get(), ctx_.journal); if (res != tesSUCCESS) { JLOG(ctx_.journal.debug()) << "AMM Bid: failed to redeem."; @@ -337,7 +337,7 @@ applyBid( sb, account_, auctionSlot[sfAccount], - toSTAmount(lpTokens.issue(), refund), + toSTAmount(lpTokens.get(), refund), ctx_.journal); if (res != tesSUCCESS) { diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 237e1afa240..42fc3f60099 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -50,7 +50,7 @@ AMMCreate::preflight(PreflightContext const& ctx) auto const amount = ctx.tx[sfAmount]; auto const amount2 = ctx.tx[sfAmount2]; - if (amount.issue() == amount2.issue()) + if (amount.get() == amount2.get()) { JLOG(ctx.j.debug()) << "AMM Instance: tokens can not have the same currency/issuer."; @@ -93,32 +93,33 @@ AMMCreate::preclaim(PreclaimContext const& ctx) auto const amount2 = ctx.tx[sfAmount2]; // Check if AMM already exists for the token pair - if (auto const ammKeylet = keylet::amm(amount.issue(), amount2.issue()); + if (auto const ammKeylet = + keylet::amm(amount.get(), amount2.get()); ctx.view.read(ammKeylet)) { JLOG(ctx.j.debug()) << "AMM Instance: ltAMM already exists."; return tecDUPLICATE; } - if (auto const ter = requireAuth(ctx.view, amount.issue(), accountID); + if (auto const ter = requireAuth(ctx.view, amount.get(), accountID); ter != tesSUCCESS) { - JLOG(ctx.j.debug()) - << "AMM Instance: account is not authorized, " << amount.issue(); + JLOG(ctx.j.debug()) << "AMM Instance: account is not authorized, " + << amount.get(); return ter; } - if (auto const ter = requireAuth(ctx.view, amount2.issue(), accountID); + if (auto const ter = requireAuth(ctx.view, amount2.get(), accountID); ter != tesSUCCESS) { - JLOG(ctx.j.debug()) - << "AMM Instance: account is not authorized, " << amount2.issue(); + JLOG(ctx.j.debug()) << "AMM Instance: account is not authorized, " + << amount2.get(); return ter; } // Globally or individually frozen - if (isFrozen(ctx.view, accountID, amount.issue()) || - isFrozen(ctx.view, accountID, amount2.issue())) + if (isFrozen(ctx.view, accountID, amount.get()) || + isFrozen(ctx.view, accountID, amount2.get())) { JLOG(ctx.j.debug()) << "AMM Instance: involves frozen asset."; return tecFROZEN; @@ -135,8 +136,8 @@ AMMCreate::preclaim(PreclaimContext const& ctx) return false; }; - if (noDefaultRipple(ctx.view, amount.issue()) || - noDefaultRipple(ctx.view, amount2.issue())) + if (noDefaultRipple(ctx.view, amount.get()) || + noDefaultRipple(ctx.view, amount2.get())) { JLOG(ctx.j.debug()) << "AMM Instance: DefaultRipple not set"; return terNO_RIPPLE; @@ -154,11 +155,11 @@ AMMCreate::preclaim(PreclaimContext const& ctx) auto insufficientBalance = [&](STAmount const& asset) { if (isXRP(asset)) return xrpBalance < asset; - return accountID != asset.issue().account && + return accountID != asset.get().account && accountHolds( ctx.view, accountID, - asset.issue(), + asset.get(), FreezeHandling::fhZERO_IF_FROZEN, ctx.j) < asset; }; @@ -172,7 +173,7 @@ AMMCreate::preclaim(PreclaimContext const& ctx) auto isLPToken = [&](STAmount const& amount) -> bool { if (auto const sle = - ctx.view.read(keylet::account(amount.issue().account))) + ctx.view.read(keylet::account(amount.get().account))) return sle->isFieldPresent(sfAMMID); return false; }; @@ -196,9 +197,10 @@ AMMCreate::preclaim(PreclaimContext const& ctx) return tesSUCCESS; }; - if (auto const ter = clawbackDisabled(amount.issue()); ter != tesSUCCESS) + if (auto const ter = clawbackDisabled(amount.get()); + ter != tesSUCCESS) return ter; - return clawbackDisabled(amount2.issue()); + return clawbackDisabled(amount2.get()); } static std::pair @@ -211,7 +213,8 @@ applyCreate( auto const amount = ctx_.tx[sfAmount]; auto const amount2 = ctx_.tx[sfAmount2]; - auto const ammKeylet = keylet::amm(amount.issue(), amount2.issue()); + auto const ammKeylet = + keylet::amm(amount.get(), amount2.get()); // Mitigate same account exists possibility auto const ammAccount = [&]() -> Expected { @@ -235,7 +238,9 @@ applyCreate( // LP Token already exists. (should not happen) auto const lptIss = ammLPTIssue( - amount.issue().currency, amount2.issue().currency, *ammAccount); + amount.get().currency, + amount2.get().currency, + *ammAccount); if (sb.read(keylet::line(*ammAccount, lptIss))) { JLOG(j_.error()) << "AMM Instance: LP Token already exists."; @@ -273,7 +278,8 @@ applyCreate( auto ammSle = std::make_shared(ammKeylet); ammSle->setAccountID(sfAccount, *ammAccount); ammSle->setFieldAmount(sfLPTokenBalance, lpTokens); - auto const& [issue1, issue2] = std::minmax(amount.issue(), amount2.issue()); + auto const& [issue1, issue2] = + std::minmax(amount.get(), amount2.get()); ammSle->setFieldIssue(sfAsset, STIssue{sfAsset, issue1}); ammSle->setFieldIssue(sfAsset2, STIssue{sfAsset2, issue2}); // AMM creator gets the auction slot and the voting slot. @@ -316,7 +322,7 @@ applyCreate( if (!isXRP(amount)) { if (SLE::pointer sleRippleState = - sb.peek(keylet::line(*ammAccount, amount.issue())); + sb.peek(keylet::line(*ammAccount, amount.get())); !sleRippleState) return tecINTERNAL; else @@ -356,8 +362,10 @@ applyCreate( !bookExisted) ctx_.app.getOrderBookDB().addOrderBook(book); }; - addOrderBook(amount.issue(), amount2.issue(), getRate(amount2, amount)); - addOrderBook(amount2.issue(), amount.issue(), getRate(amount, amount2)); + addOrderBook( + amount.get(), amount2.get(), getRate(amount2, amount)); + addOrderBook( + amount2.get(), amount.get(), getRate(amount, amount2)); return {res, res == tesSUCCESS}; } diff --git a/src/xrpld/app/tx/detail/AMMDeposit.cpp b/src/xrpld/app/tx/detail/AMMDeposit.cpp index 9bbf5b4a60a..6ef04a0962c 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.cpp +++ b/src/xrpld/app/tx/detail/AMMDeposit.cpp @@ -108,10 +108,11 @@ AMMDeposit::preflight(PreflightContext const& ctx) return res; } - if (amount && amount2 && amount->issue() == amount2->issue()) + if (amount && amount2 && amount->get() == amount2->get()) { - JLOG(ctx.j.debug()) << "AMM Deposit: invalid tokens, same issue." - << amount->issue() << " " << amount2->issue(); + JLOG(ctx.j.debug()) + << "AMM Deposit: invalid tokens, same issue." + << amount->get() << " " << amount2->get(); return temBAD_AMM_TOKENS; } @@ -148,8 +149,8 @@ AMMDeposit::preflight(PreflightContext const& ctx) { if (auto const res = invalidAMMAmount( *ePrice, - std::make_optional( - std::make_pair(amount->issue(), amount->issue())))) + std::make_optional(std::make_pair( + amount->get(), amount->get())))) { JLOG(ctx.j.debug()) << "AMM Deposit: invalid EPrice"; return res; @@ -223,7 +224,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) auto balance = [&](auto const& deposit) -> TER { if (isXRP(deposit)) { - auto const lpIssue = (*ammSle)[sfLPTokenBalance].issue(); + auto const lpIssue = (*ammSle)[sfLPTokenBalance].get(); // Adjust the reserve if LP doesn't have LPToken trustline auto const sle = ctx.view.read( keylet::line(accountID, lpIssue.account, lpIssue.currency)); @@ -233,11 +234,11 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) return tecUNFUNDED_AMM; return tecINSUF_RESERVE_LINE; } - return (accountID == deposit.issue().account || + return (accountID == deposit.template get().account || accountHolds( ctx.view, accountID, - deposit.issue(), + deposit.template get(), FreezeHandling::fhIGNORE_FREEZE, ctx.j) >= deposit) ? TER(tesSUCCESS) @@ -256,17 +257,17 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) // Account is not authorized to hold the assets it's depositing, // or it doesn't even have a trust line for them if (auto const ter = - requireAuth(ctx.view, amount->issue(), accountID)) + requireAuth(ctx.view, amount->get(), accountID)) { // LCOV_EXCL_START JLOG(ctx.j.debug()) << "AMM Deposit: account is not authorized, " - << amount->issue(); + << amount->get(); return ter; // LCOV_EXCL_STOP } // AMM account or currency frozen - if (isFrozen(ctx.view, ammAccountID, amount->issue())) + if (isFrozen(ctx.view, ammAccountID, amount->get())) { JLOG(ctx.j.debug()) << "AMM Deposit: AMM account or currency is frozen, " @@ -274,11 +275,11 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) return tecFROZEN; } // Account frozen - if (isIndividualFrozen(ctx.view, accountID, amount->issue())) + if (isIndividualFrozen(ctx.view, accountID, amount->get())) { JLOG(ctx.j.debug()) << "AMM Deposit: account is frozen, " << to_string(accountID) << " " - << to_string(amount->issue().currency); + << to_string(amount->get().currency); return tecFROZEN; } if (checkBalance) @@ -314,7 +315,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) // Equal deposit lp tokens if (auto const lpTokens = ctx.tx[~sfLPTokenOut]; - lpTokens && lpTokens->issue() != lptAMMBalance.issue()) + lpTokens && lpTokens->get() != lptAMMBalance.get()) { JLOG(ctx.j.debug()) << "AMM Deposit: invalid LPTokens."; return temBAD_AMM_TOKENS; @@ -351,8 +352,8 @@ AMMDeposit::applyGuts(Sandbox& sb) auto const expected = ammHolds( sb, *ammSle, - amount ? amount->issue() : std::optional{}, - amount2 ? amount2->issue() : std::optional{}, + amount ? amount->get() : std::optional{}, + amount2 ? amount2->get() : std::optional{}, FreezeHandling::fhZERO_IF_FROZEN, ctx_.journal); if (!expected) @@ -424,7 +425,7 @@ AMMDeposit::applyGuts(Sandbox& sb) ammAccountID, *amount, *amount2, - lptAMMBalance.issue(), + lptAMMBalance.get(), tfee); // should not happen. // LCOV_EXCL_START @@ -441,7 +442,7 @@ AMMDeposit::applyGuts(Sandbox& sb) // and the voting if (lptAMMBalance == beast::zero) initializeFeeAuctionVote( - sb, ammSle, account_, lptAMMBalance.issue(), tfee); + sb, ammSle, account_, lptAMMBalance.get(), tfee); sb.update(ammSle); } @@ -484,7 +485,7 @@ AMMDeposit::deposit( return temBAD_AMOUNT; if (isXRP(depositAmount)) { - auto const& lpIssue = lpTokensDeposit.issue(); + auto const& lpIssue = lpTokensDeposit.get(); // Adjust the reserve if LP doesn't have LPToken trustline auto const sle = view.read( keylet::line(account_, lpIssue.account, lpIssue.currency)); @@ -492,11 +493,11 @@ AMMDeposit::deposit( return tesSUCCESS; } else if ( - account_ == depositAmount.issue().account || + account_ == depositAmount.template get().account || accountHolds( view, account_, - depositAmount.issue(), + depositAmount.template get(), FreezeHandling::fhIGNORE_FREEZE, ctx_.journal) >= depositAmount) return tesSUCCESS; @@ -613,13 +614,13 @@ AMMDeposit::equalDepositTokens( try { auto const frac = - divide(lpTokensDeposit, lptAMMBalance, lptAMMBalance.issue()); + divide(lpTokensDeposit, lptAMMBalance, lptAMMBalance.get()); return deposit( view, ammAccount, amountBalance, - multiply(amountBalance, frac, amountBalance.issue()), - multiply(amount2Balance, frac, amount2Balance.issue()), + multiply(amountBalance, frac, amountBalance.get()), + multiply(amount2Balance, frac, amount2Balance.get()), lptAMMBalance, lpTokensDeposit, depositMin, @@ -678,7 +679,7 @@ AMMDeposit::equalDepositLimit( std::uint16_t tfee) { auto frac = Number{amount} / amountBalance; - auto tokens = toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac); + auto tokens = toSTAmount(lptAMMBalance.get(), lptAMMBalance * frac); if (tokens == beast::zero) return {tecAMM_FAILED, STAmount{}}; auto const amount2Deposit = amount2Balance * frac; @@ -688,7 +689,7 @@ AMMDeposit::equalDepositLimit( ammAccount, amountBalance, amount, - toSTAmount(amount2Balance.issue(), amount2Deposit), + toSTAmount(amount2Balance.get(), amount2Deposit), lptAMMBalance, tokens, std::nullopt, @@ -696,7 +697,7 @@ AMMDeposit::equalDepositLimit( lpTokensDepositMin, tfee); frac = Number{amount2} / amount2Balance; - tokens = toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac); + tokens = toSTAmount(lptAMMBalance.get(), lptAMMBalance * frac); if (tokens == beast::zero) return {tecAMM_FAILED, STAmount{}}; auto const amountDeposit = amountBalance * frac; @@ -705,7 +706,7 @@ AMMDeposit::equalDepositLimit( view, ammAccount, amountBalance, - toSTAmount(amountBalance.issue(), amountDeposit), + toSTAmount(amountBalance.get(), amountDeposit), amount2, lptAMMBalance, tokens, @@ -868,12 +869,12 @@ AMMDeposit::singleDepositEPrice( auto const b1 = c * c * f2 * f2 + 2 * c - d * d; auto const c1 = 2 * c * f2 * f2 + 1 - 2 * d * f2; auto const amountDeposit = toSTAmount( - amountBalance.issue(), + amountBalance.get(), f1 * amountBalance * solveQuadraticEq(a1, b1, c1)); if (amountDeposit <= beast::zero) return {tecAMM_FAILED, STAmount{}}; auto const tokens = - toSTAmount(lptAMMBalance.issue(), amountDeposit / ePrice); + toSTAmount(lptAMMBalance.get(), amountDeposit / ePrice); return deposit( view, ammAccount, diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.cpp b/src/xrpld/app/tx/detail/AMMWithdraw.cpp index 51b512aba0a..95bd43ef8c8 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.cpp +++ b/src/xrpld/app/tx/detail/AMMWithdraw.cpp @@ -109,10 +109,11 @@ AMMWithdraw::preflight(PreflightContext const& ctx) return res; } - if (amount && amount2 && amount->issue() == amount2->issue()) + if (amount && amount2 && amount->get() == amount2->get()) { - JLOG(ctx.j.debug()) << "AMM Withdraw: invalid tokens, same issue." - << amount->issue() << " " << amount2->issue(); + JLOG(ctx.j.debug()) + << "AMM Withdraw: invalid tokens, same issue." + << amount->get() << " " << amount2->get(); return temBAD_AMM_TOKENS; } @@ -187,8 +188,8 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) auto const expected = ammHolds( ctx.view, *ammSle, - amount ? amount->issue() : std::optional{}, - amount2 ? amount2->issue() : std::optional{}, + amount ? amount->get() : std::optional{}, + amount2 ? amount2->get() : std::optional{}, FreezeHandling::fhIGNORE_FREEZE, ctx.j); if (!expected) @@ -218,15 +219,15 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) return tecAMM_BALANCE; } if (auto const ter = - requireAuth(ctx.view, amount->issue(), accountID)) + requireAuth(ctx.view, amount->get(), accountID)) { JLOG(ctx.j.debug()) << "AMM Withdraw: account is not authorized, " - << amount->issue(); + << amount->get(); return ter; } // AMM account or currency frozen - if (isFrozen(ctx.view, ammAccountID, amount->issue())) + if (isFrozen(ctx.view, ammAccountID, amount->get())) { JLOG(ctx.j.debug()) << "AMM Withdraw: AMM account or currency is frozen, " @@ -234,11 +235,11 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) return tecFROZEN; } // Account frozen - if (isIndividualFrozen(ctx.view, accountID, amount->issue())) + if (isIndividualFrozen(ctx.view, accountID, amount->get())) { JLOG(ctx.j.debug()) << "AMM Withdraw: account is frozen, " << to_string(accountID) << " " - << to_string(amount->issue().currency); + << to_string(amount->get().currency); return tecFROZEN; } } @@ -262,7 +263,8 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) return tecAMM_BALANCE; } - if (lpTokensWithdraw && lpTokensWithdraw->issue() != lpTokens.issue()) + if (lpTokensWithdraw && + lpTokensWithdraw->get() != lpTokens.get()) { JLOG(ctx.j.debug()) << "AMM Withdraw: invalid LPTokens."; return temBAD_AMM_TOKENS; @@ -275,7 +277,7 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) } if (auto const ePrice = ctx.tx[~sfEPrice]; - ePrice && ePrice->issue() != lpTokens.issue()) + ePrice && ePrice->get() != lpTokens.get()) { JLOG(ctx.j.debug()) << "AMM Withdraw: invalid EPrice."; return temBAD_AMM_TOKENS; @@ -315,7 +317,7 @@ AMMWithdraw::applyGuts(Sandbox& sb) if (sb.rules().enabled(fixAMMv1_1)) { if (auto const res = - isOnlyLiquidityProvider(sb, lpTokens.issue(), account_); + isOnlyLiquidityProvider(sb, lpTokens.get(), account_); !res) return {res.error(), false}; else if (res.value()) @@ -340,8 +342,8 @@ AMMWithdraw::applyGuts(Sandbox& sb) auto const expected = ammHolds( sb, *ammSle, - amount ? amount->issue() : std::optional{}, - amount2 ? amount2->issue() : std::optional{}, + amount ? amount->get() : std::optional{}, + amount2 ? amount2->get() : std::optional{}, FreezeHandling::fhZERO_IF_FROZEN, ctx_.journal); if (!expected) @@ -463,7 +465,7 @@ AMMWithdraw::withdraw( auto const expected = ammHolds( view, *ammSle, - amountWithdraw.issue(), + amountWithdraw.get(), std::nullopt, FreezeHandling::fhZERO_IF_FROZEN, j_); @@ -590,7 +592,7 @@ AMMWithdraw::withdraw( view, account_, lpTokensWithdrawActual, - lpTokensWithdrawActual.issue(), + lpTokensWithdrawActual.get(), ctx_.journal); if (res != tesSUCCESS) { @@ -631,9 +633,9 @@ AMMWithdraw::equalWithdrawTokens( auto const frac = divide(lpTokensWithdraw, lptAMMBalance, noIssue()); auto const withdrawAmount = - multiply(amountBalance, frac, amountBalance.issue()); + multiply(amountBalance, frac, amountBalance.get()); auto const withdraw2Amount = - multiply(amount2Balance, frac, amount2Balance.issue()); + multiply(amount2Balance, frac, amount2Balance.get()); // LP is making equal withdrawal by tokens but the requested amount // of LP tokens is likely too small and results in one-sided pool // withdrawal due to round off. Fail so the user withdraws @@ -705,9 +707,9 @@ AMMWithdraw::equalWithdrawLimit( ammAccount, amountBalance, amount, - toSTAmount(amount2.issue(), amount2Withdraw), + toSTAmount(amount2.get(), amount2Withdraw), lptAMMBalance, - toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac), + toSTAmount(lptAMMBalance.get(), lptAMMBalance * frac), tfee); frac = Number{amount2} / amount2Balance; auto const amountWithdraw = amountBalance * frac; @@ -716,10 +718,10 @@ AMMWithdraw::equalWithdrawLimit( view, ammAccount, amountBalance, - toSTAmount(amount.issue(), amountWithdraw), + toSTAmount(amount.get(), amountWithdraw), amount2, lptAMMBalance, - toSTAmount(lptAMMBalance.issue(), lptAMMBalance * frac), + toSTAmount(lptAMMBalance.get(), lptAMMBalance * frac), tfee); } @@ -831,7 +833,8 @@ AMMWithdraw::singleWithdrawEPrice( (lptAMMBalance * f - ae); if (tokens <= 0) return {tecAMM_FAILED, STAmount{}}; - auto const amountWithdraw = toSTAmount(amount.issue(), tokens / ePrice); + auto const amountWithdraw = + toSTAmount(amount.get(), tokens / ePrice); if (amount == beast::zero || amountWithdraw >= amount) return withdraw( view, @@ -840,7 +843,7 @@ AMMWithdraw::singleWithdrawEPrice( amountWithdraw, std::nullopt, lptAMMBalance, - toSTAmount(lptAMMBalance.issue(), tokens), + toSTAmount(lptAMMBalance.get(), tokens), tfee); return {tecAMM_FAILED, STAmount{}}; diff --git a/src/xrpld/app/tx/detail/CashCheck.cpp b/src/xrpld/app/tx/detail/CashCheck.cpp index 8b5ef79b6d4..b8c2c8a2786 100644 --- a/src/xrpld/app/tx/detail/CashCheck.cpp +++ b/src/xrpld/app/tx/detail/CashCheck.cpp @@ -70,7 +70,7 @@ CashCheck::preflight(PreflightContext const& ctx) return temBAD_AMOUNT; } - if (badCurrency() == value.getCurrency()) + if (badCurrency() == value.get().getCurrency()) { JLOG(ctx.j.warn()) << "Malformed transaction: Bad currency."; return temBAD_CURRENCY; @@ -141,8 +141,8 @@ CashCheck::preclaim(PreclaimContext const& ctx) }(ctx.tx)}; STAmount const sendMax = sleCheck->at(sfSendMax); - Currency const currency{value.getCurrency()}; - if (currency != sendMax.getCurrency()) + Currency const currency{value.get().getCurrency()}; + if (currency != sendMax.get().getCurrency()) { JLOG(ctx.j.warn()) << "Check cash does not match check currency."; return temMALFORMED; @@ -341,13 +341,13 @@ CashCheck::doApply() // exceed 200%, we use 1/2 maxValue as our limit. STAmount const flowDeliver{ optDeliverMin ? STAmount( - optDeliverMin->issue(), + optDeliverMin->get(), STAmount::cMaxValue / 2, STAmount::cMaxOffset) : ctx_.tx.getFieldAmount(sfAmount)}; // If a trust line does not exist yet create one. - Issue const& trustLineIssue = flowDeliver.issue(); + Issue const& trustLineIssue = flowDeliver.get(); AccountID const issuer = flowDeliver.getIssuer(); AccountID const truster = issuer == account_ ? srcId : account_; Keylet const trustLineKey = keylet::line(truster, trustLineIssue); @@ -377,9 +377,10 @@ CashCheck::doApply() return tecNO_LINE_INSUF_RESERVE; } - Currency const currency = flowDeliver.getCurrency(); - STAmount initialBalance(flowDeliver.issue()); - initialBalance.setIssuer(noAccount()); + Currency const currency = + flowDeliver.get().getCurrency(); + STAmount initialBalance(flowDeliver.get()); + initialBalance.get().setIssuer(noAccount()); // clang-format off if (TER const ter = trustCreate( diff --git a/src/xrpld/app/tx/detail/Clawback.cpp b/src/xrpld/app/tx/detail/Clawback.cpp index c11dfbd8c11..b4ff55d5642 100644 --- a/src/xrpld/app/tx/detail/Clawback.cpp +++ b/src/xrpld/app/tx/detail/Clawback.cpp @@ -121,8 +121,8 @@ preclaimHelper(PreclaimContext const& ctx) (issuerFlagsIn & lsfNoFreeze)) return tecNO_PERMISSION; - auto const sleRippleState = - ctx.view.read(keylet::line(holder, issuer, clawAmount.getCurrency())); + auto const sleRippleState = ctx.view.read( + keylet::line(holder, issuer, clawAmount.get().getCurrency())); if (!sleRippleState) return tecNO_LINE; @@ -148,7 +148,7 @@ preclaimHelper(PreclaimContext const& ctx) if (accountHolds( ctx.view, holder, - clawAmount.getCurrency(), + clawAmount.get().getCurrency(), issuer, fhIGNORE_FREEZE, ctx.j) <= beast::zero) @@ -213,7 +213,7 @@ applyHelper(ApplyContext& ctx) AccountID const holder = clawAmount.getIssuer(); // cannot be reference // Replace the `issuer` field with issuer's account - clawAmount.setIssuer(issuer); + clawAmount.get().setIssuer(issuer); if (holder == issuer) return tecINTERNAL; @@ -221,7 +221,7 @@ applyHelper(ApplyContext& ctx) STAmount const spendableAmount = accountHolds( ctx.view(), holder, - clawAmount.getCurrency(), + clawAmount.get().getCurrency(), clawAmount.getIssuer(), fhIGNORE_FREEZE, ctx.journal); diff --git a/src/xrpld/app/tx/detail/CreateCheck.cpp b/src/xrpld/app/tx/detail/CreateCheck.cpp index 3a278eed738..add729ac280 100644 --- a/src/xrpld/app/tx/detail/CreateCheck.cpp +++ b/src/xrpld/app/tx/detail/CreateCheck.cpp @@ -60,7 +60,7 @@ CreateCheck::preflight(PreflightContext const& ctx) return temBAD_AMOUNT; } - if (badCurrency() == sendMax.getCurrency()) + if (badCurrency() == sendMax.get().getCurrency()) { JLOG(ctx.j.warn()) << "Malformed transaction: Bad currency."; return temBAD_CURRENCY; @@ -129,8 +129,8 @@ CreateCheck::preclaim(PreclaimContext const& ctx) if (issuerId != srcId) { // Check if the issuer froze the line - auto const sleTrust = ctx.view.read( - keylet::line(srcId, issuerId, sendMax.getCurrency())); + auto const sleTrust = ctx.view.read(keylet::line( + srcId, issuerId, sendMax.get().getCurrency())); if (sleTrust && sleTrust->isFlag( (issuerId > srcId) ? lsfHighFreeze : lsfLowFreeze)) @@ -143,8 +143,8 @@ CreateCheck::preclaim(PreclaimContext const& ctx) if (issuerId != dstId) { // Check if dst froze the line. - auto const sleTrust = ctx.view.read( - keylet::line(issuerId, dstId, sendMax.getCurrency())); + auto const sleTrust = ctx.view.read(keylet::line( + 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 2a5145594a1..2bbc0b04887 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -98,10 +98,10 @@ CreateOffer::preflight(PreflightContext const& ctx) } auto const& uPaysIssuerID = saTakerPays.getIssuer(); - auto const& uPaysCurrency = saTakerPays.getCurrency(); + auto const& uPaysCurrency = saTakerPays.get().getCurrency(); auto const& uGetsIssuerID = saTakerGets.getIssuer(); - auto const& uGetsCurrency = saTakerGets.getCurrency(); + auto const& uGetsCurrency = saTakerGets.get().getCurrency(); if (uPaysCurrency == uGetsCurrency && uPaysIssuerID == uGetsIssuerID) { @@ -134,7 +134,7 @@ CreateOffer::preclaim(PreclaimContext const& ctx) auto saTakerGets = ctx.tx[sfTakerGets]; auto const& uPaysIssuerID = saTakerPays.getIssuer(); - auto const& uPaysCurrency = saTakerPays.getCurrency(); + auto const& uPaysCurrency = saTakerPays.get().getCurrency(); auto const& uGetsIssuerID = saTakerGets.getIssuer(); @@ -704,7 +704,7 @@ CreateOffer::flowCross( sendMax = multiplyRound( takerAmount.in, gatewayXferRate, - takerAmount.in.issue(), + takerAmount.in.get(), true); } } @@ -751,7 +751,7 @@ CreateOffer::flowCross( // Since the transfer rate cannot exceed 200%, we use 1/2 // maxValue for our limit. deliver = STAmount{ - takerAmount.out.issue(), + takerAmount.out.get(), STAmount::cMaxValue / 2, STAmount::cMaxOffset}; } @@ -814,7 +814,7 @@ CreateOffer::flowCross( nonGatewayAmountIn = divideRound( result.actualAmountIn, gatewayXferRate, - takerAmount.in.issue(), + takerAmount.in.get(), true); afterCross.in -= nonGatewayAmountIn; @@ -836,11 +836,14 @@ CreateOffer::flowCross( return divRoundStrict( afterCross.in, rate, - takerAmount.out.issue(), + takerAmount.out.get(), false); return divRound( - afterCross.in, rate, takerAmount.out.issue(), true); + afterCross.in, + rate, + takerAmount.out.get(), + true); }(); } else @@ -853,7 +856,10 @@ CreateOffer::flowCross( if (afterCross.out < beast::zero) afterCross.out.clear(); afterCross.in = mulRound( - afterCross.out, rate, takerAmount.in.issue(), true); + afterCross.out, + rate, + takerAmount.in.get(), + true); } } } @@ -894,7 +900,7 @@ CreateOffer::format_amount(STAmount const& amount) { std::string txt = amount.getText(); txt += "/"; - txt += to_string(amount.issue().currency); + txt += to_string(amount.get().currency); return txt; } @@ -1006,12 +1012,14 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) if (bSell) { // this is a sell, round taker pays - saTakerPays = multiply(saTakerGets, rate, saTakerPays.issue()); + saTakerPays = + multiply(saTakerGets, rate, saTakerPays.get()); } else { // this is a buy, round taker gets - saTakerGets = divide(saTakerPays, rate, saTakerGets.issue()); + saTakerGets = + divide(saTakerPays, rate, saTakerGets.get()); } if (!saTakerGets || !saTakerPays) { @@ -1031,8 +1039,8 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) Amounts place_offer; JLOG(j_.debug()) << "Attempting cross: " - << to_string(takerAmount.in.issue()) << " -> " - << to_string(takerAmount.out.issue()); + << to_string(takerAmount.in.get()) << " -> " + << to_string(takerAmount.out.get()); if (auto stream = j_.trace()) { @@ -1064,8 +1072,8 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) return {result, true}; } - assert(saTakerGets.issue() == place_offer.in.issue()); - assert(saTakerPays.issue() == place_offer.out.issue()); + assert(saTakerGets.get() == place_offer.in.get()); + assert(saTakerPays.get() == place_offer.out.get()); if (takerAmount != place_offer) crossed = true; @@ -1174,10 +1182,11 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) // Update owner count. adjustOwnerCount(sb, sleCreator, 1, viewJ); - JLOG(j_.trace()) << "adding to book: " << to_string(saTakerPays.issue()) - << " : " << to_string(saTakerGets.issue()); + JLOG(j_.trace()) << "adding to book: " + << to_string(saTakerPays.get()) << " : " + << to_string(saTakerGets.get()); - Book const book{saTakerPays.issue(), saTakerGets.issue()}; + Book const book{saTakerPays.get(), saTakerGets.get()}; // Add offer to order book, using the original rate // before any crossing occured. @@ -1185,10 +1194,12 @@ 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) { - sle->setFieldH160(sfTakerPaysCurrency, saTakerPays.issue().currency); - sle->setFieldH160(sfTakerPaysIssuer, saTakerPays.issue().account); - sle->setFieldH160(sfTakerGetsCurrency, saTakerGets.issue().currency); - sle->setFieldH160(sfTakerGetsIssuer, saTakerGets.issue().account); + sle->setFieldH160( + sfTakerPaysCurrency, saTakerPays.get().currency); + sle->setFieldH160(sfTakerPaysIssuer, saTakerPays.get().account); + sle->setFieldH160( + sfTakerGetsCurrency, saTakerGets.get().currency); + sle->setFieldH160(sfTakerGetsIssuer, saTakerGets.get().account); sle->setFieldU64(sfExchangeRate, uRate); }); diff --git a/src/xrpld/app/tx/detail/InvariantCheck.cpp b/src/xrpld/app/tx/detail/InvariantCheck.cpp index 625f8c7b284..92ded862ecb 100644 --- a/src/xrpld/app/tx/detail/InvariantCheck.cpp +++ b/src/xrpld/app/tx/detail/InvariantCheck.cpp @@ -526,8 +526,8 @@ NoXRPTrustLines::visitEntry( // relying on .native() just in case native somehow // were systematically incorrect xrpTrustLine_ = - after->getFieldAmount(sfLowLimit).issue() == xrpIssue() || - after->getFieldAmount(sfHighLimit).issue() == xrpIssue(); + after->getFieldAmount(sfLowLimit).get() == xrpIssue() || + after->getFieldAmount(sfHighLimit).get() == xrpIssue(); } } @@ -922,7 +922,12 @@ ValidClawback::finalize( STAmount const& amount = tx.getFieldAmount(sfAmount); AccountID const& holder = amount.getIssuer(); STAmount const holderBalance = accountHolds( - view, holder, amount.getCurrency(), issuer, fhIGNORE_FREEZE, j); + view, + holder, + amount.get().getCurrency(), + issuer, + fhIGNORE_FREEZE, + j); if (holderBalance.signum() < 0) { diff --git a/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp b/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp index b884a791e78..9f1bebbbc6c 100644 --- a/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp +++ b/src/xrpld/app/tx/detail/NFTokenAcceptOffer.cpp @@ -104,7 +104,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) return tecNFTOKEN_BUY_SELL_MISMATCH; // The two offers being brokered must be for the same asset: - if ((*bo)[sfAmount].issue() != (*so)[sfAmount].issue()) + if ((*bo)[sfAmount].get() != (*so)[sfAmount].get()) return tecNFTOKEN_BUY_SELL_MISMATCH; // The two offers may not form a loop. A broker may not sell the @@ -152,7 +152,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) // cut, if any). if (auto const brokerFee = ctx.tx[~sfNFTokenBrokerFee]) { - if (brokerFee->issue() != (*bo)[sfAmount].issue()) + if (brokerFee->get() != (*bo)[sfAmount].get()) return tecNFTOKEN_BUY_SELL_MISMATCH; if (brokerFee >= (*bo)[sfAmount]) @@ -203,7 +203,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) accountHolds( ctx.view, (*bo)[sfOwner], - needed.getCurrency(), + needed.get().getCurrency(), needed.getIssuer(), fhZERO_IF_FROZEN, ctx.j) < needed) @@ -240,7 +240,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) if (accountHolds( ctx.view, ctx.tx[sfAccount], - needed.getCurrency(), + needed.get().getCurrency(), needed.getIssuer(), fhZERO_IF_FROZEN, ctx.j) < needed) @@ -288,7 +288,7 @@ NFTokenAcceptOffer::preclaim(PreclaimContext const& ctx) auto const issuer = nft::getIssuer(tokenID); // Issuer doesn't need a trust line to accept their own currency. if (issuer != amount.getIssuer() && - !ctx.view.read(keylet::line(issuer, amount.issue()))) + !ctx.view.read(keylet::line(issuer, amount.get()))) return tecNO_LINE; } } diff --git a/src/xrpld/app/tx/detail/NFTokenUtils.cpp b/src/xrpld/app/tx/detail/NFTokenUtils.cpp index 61ff8e200b3..a7503716c13 100644 --- a/src/xrpld/app/tx/detail/NFTokenUtils.cpp +++ b/src/xrpld/app/tx/detail/NFTokenUtils.cpp @@ -876,15 +876,19 @@ tokenOfferCreatePreclaim( if (view.rules().enabled(featureNFTokenMintOffer)) { if (nftIssuer != amount.getIssuer() && - !view.read(keylet::line(nftIssuer, amount.issue()))) + !view.read(keylet::line(nftIssuer, amount.get()))) return tecNO_LINE; } - else if (!view.exists(keylet::line(nftIssuer, amount.issue()))) + else if (!view.exists(keylet::line(nftIssuer, amount.get()))) { return tecNO_LINE; } - if (isFrozen(view, nftIssuer, amount.getCurrency(), amount.getIssuer())) + if (isFrozen( + view, + nftIssuer, + amount.get().getCurrency(), + amount.getIssuer())) return tecFROZEN; } @@ -897,7 +901,11 @@ tokenOfferCreatePreclaim( return tefNFTOKEN_IS_NOT_TRANSFERABLE; } - if (isFrozen(view, acctID, amount.getCurrency(), amount.getIssuer())) + if (isFrozen( + view, + acctID, + amount.get().getCurrency(), + amount.getIssuer())) return tecFROZEN; // If this is an offer to buy the token, the account must have the @@ -918,7 +926,7 @@ tokenOfferCreatePreclaim( accountHolds( view, acctID, - amount.getCurrency(), + amount.get().getCurrency(), amount.getIssuer(), FreezeHandling::fhZERO_IF_FROZEN, j) diff --git a/src/xrpld/app/tx/detail/Offer.h b/src/xrpld/app/tx/detail/Offer.h index a6f707ba561..8d1a6f07e12 100644 --- a/src/xrpld/app/tx/detail/Offer.h +++ b/src/xrpld/app/tx/detail/Offer.h @@ -187,8 +187,8 @@ TOffer::TOffer(SLE::pointer const& entry, Quality quality) auto const tg = m_entry->getFieldAmount(sfTakerGets); m_amounts.in = toAmount(tp); m_amounts.out = toAmount(tg); - this->issIn_ = tp.issue(); - this->issOut_ = tg.issue(); + this->issIn_ = tp.get(); + this->issOut_ = tg.get(); } template <> @@ -300,7 +300,7 @@ template <> inline Issue const& TOffer::issueIn() const { - return m_amounts.in.issue(); + return m_amounts.in.get(); } template @@ -314,7 +314,7 @@ template <> inline Issue const& TOffer::issueOut() const { - return m_amounts.out.issue(); + return m_amounts.out.get(); } template diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index eb803f56ef0..b39f5b6d034 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -84,13 +84,13 @@ preflightHelper(PreflightContext const& ctx) maxSourceAmount = saDstAmount; else maxSourceAmount = STAmount( - Issue{saDstAmount.getCurrency(), account}, + Issue{saDstAmount.get().getCurrency(), account}, saDstAmount.mantissa(), saDstAmount.exponent(), saDstAmount < beast::zero); - auto const& uSrcCurrency = maxSourceAmount.getCurrency(); - auto const& uDstCurrency = saDstAmount.getCurrency(); + auto const& uSrcCurrency = maxSourceAmount.get().getCurrency(); + auto const& uDstCurrency = saDstAmount.get().getCurrency(); // isZero() is XRP. FIX! bool const bXRPDirect = uSrcCurrency.isZero() && uDstCurrency.isZero(); @@ -189,7 +189,7 @@ preflightHelper(PreflightContext const& ctx) << " amount. " << dMin.getFullText(); return temBAD_AMOUNT; } - if (dMin.issue() != saDstAmount.issue()) + if (dMin.get() != saDstAmount.get()) { JLOG(j.trace()) << "Malformed transaction: Dst issue differs " @@ -438,7 +438,7 @@ applyHelper( maxSourceAmount = saDstAmount; else maxSourceAmount = STAmount( - Issue{saDstAmount.getCurrency(), account}, + Issue{saDstAmount.get().getCurrency(), account}, saDstAmount.mantissa(), saDstAmount.exponent(), saDstAmount < beast::zero); diff --git a/src/xrpld/app/tx/detail/SetTrust.cpp b/src/xrpld/app/tx/detail/SetTrust.cpp index 954fc6543f1..d9bf4b50b45 100644 --- a/src/xrpld/app/tx/detail/SetTrust.cpp +++ b/src/xrpld/app/tx/detail/SetTrust.cpp @@ -57,7 +57,7 @@ SetTrust::preflight(PreflightContext const& ctx) return temBAD_LIMIT; } - if (badCurrency() == saLimitAmount.getCurrency()) + if (badCurrency() == saLimitAmount.get().getCurrency()) { JLOG(j.trace()) << "Malformed transaction: specifies XRP as IOU"; return temBAD_CURRENCY; @@ -102,7 +102,7 @@ SetTrust::preclaim(PreclaimContext const& ctx) auto const saLimitAmount = ctx.tx[sfLimitAmount]; - auto const currency = saLimitAmount.getCurrency(); + auto const currency = saLimitAmount.get().getCurrency(); auto const uDstAccountID = saLimitAmount.getIssuer(); if (ctx.view.rules().enabled(fixTrustLinesToSelf)) @@ -174,7 +174,9 @@ SetTrust::preclaim(PreclaimContext const& ctx) ammSle->getFieldAmount(sfLPTokenBalance); lpTokens == beast::zero) return tecAMM_EMPTY; - else if (lpTokens.getCurrency() != saLimitAmount.getCurrency()) + else if ( + lpTokens.get().getCurrency() != + saLimitAmount.get().getCurrency()) return tecNO_PERMISSION; } else @@ -194,7 +196,7 @@ SetTrust::doApply() bool const bQualityIn(ctx_.tx.isFieldPresent(sfQualityIn)); bool const bQualityOut(ctx_.tx.isFieldPresent(sfQualityOut)); - Currency const currency(saLimitAmount.getCurrency()); + Currency const currency(saLimitAmount.get().getCurrency()); AccountID uDstAccountID(saLimitAmount.getIssuer()); // true, iff current is high account. @@ -270,7 +272,7 @@ SetTrust::doApply() } STAmount saLimitAllow = saLimitAmount; - saLimitAllow.setIssuer(account_); + saLimitAllow.get().setIssuer(account_); SLE::pointer sleRippleState = view().peek(keylet::line(account_, uDstAccountID, currency)); diff --git a/src/xrpld/app/tx/detail/Taker.cpp b/src/xrpld/app/tx/detail/Taker.cpp index 9d335de2846..ef1a4e14d14 100644 --- a/src/xrpld/app/tx/detail/Taker.cpp +++ b/src/xrpld/app/tx/detail/Taker.cpp @@ -28,7 +28,7 @@ format_amount(STAmount const& amount) { std::string txt = amount.getText(); txt += "/"; - txt += to_string(amount.issue().currency); + txt += to_string(amount.get().currency); return txt; } @@ -47,8 +47,8 @@ BasicTaker::BasicTaker( , sell_(flags & tfSell) , original_(amount) , remaining_(amount) - , issue_in_(remaining_.in.issue()) - , issue_out_(remaining_.out.issue()) + , issue_in_(remaining_.in.get()) + , issue_out_(remaining_.out.get()) , m_rate_in(rate_in) , m_rate_out(rate_out) , cross_type_(cross_type) @@ -177,14 +177,14 @@ BasicTaker::original_offer() const static STAmount qual_div(STAmount const& amount, Quality const& quality, STAmount const& output) { - auto result = divide(amount, quality.rate(), output.issue()); + auto result = divide(amount, quality.rate(), output.get()); return std::min(result, output); } static STAmount qual_mul(STAmount const& amount, Quality const& quality, STAmount const& output) { - auto result = multiply(amount, quality.rate(), output.issue()); + auto result = multiply(amount, quality.rate(), output.get()); return std::min(result, output); } @@ -559,8 +559,8 @@ Taker::Taker( , direct_crossings_(0) , bridge_crossings_(0) { - assert(issue_in() == offer.in.issue()); - assert(issue_out() == offer.out.issue()); + assert(issue_in() == offer.in.get()); + assert(issue_out() == offer.out.get()); if (auto stream = journal_.debug()) { @@ -692,12 +692,12 @@ Taker::fill(BasicTaker::Flow const& flow, Offer& offer) assert(!isXRP(flow.order.in)); if (result == tesSUCCESS) - result = - redeemIOU(account(), flow.issuers.in, flow.issuers.in.issue()); + result = redeemIOU( + account(), flow.issuers.in, flow.issuers.in.get()); if (result == tesSUCCESS) - result = - issueIOU(offer.owner(), flow.order.in, flow.order.in.issue()); + result = issueIOU( + offer.owner(), flow.order.in, flow.order.in.get()); } else { @@ -714,11 +714,11 @@ Taker::fill(BasicTaker::Flow const& flow, Offer& offer) if (result == tesSUCCESS) result = redeemIOU( - offer.owner(), flow.issuers.out, flow.issuers.out.issue()); + offer.owner(), flow.issuers.out, flow.issuers.out.get()); if (result == tesSUCCESS) - result = - issueIOU(account(), flow.order.out, flow.order.out.issue()); + result = issueIOU( + account(), flow.order.out, flow.order.out.get()); } else { @@ -753,11 +753,11 @@ Taker::fill( { if (result == tesSUCCESS) result = redeemIOU( - account(), flow1.issuers.in, flow1.issuers.in.issue()); + account(), flow1.issuers.in, flow1.issuers.in.get()); if (result == tesSUCCESS) - result = - issueIOU(leg1.owner(), flow1.order.in, flow1.order.in.issue()); + result = issueIOU( + leg1.owner(), flow1.order.in, flow1.order.in.get()); } // leg1 to leg2: bridging over XRP @@ -769,11 +769,13 @@ Taker::fill( { if (result == tesSUCCESS) result = redeemIOU( - leg2.owner(), flow2.issuers.out, flow2.issuers.out.issue()); + leg2.owner(), + flow2.issuers.out, + flow2.issuers.out.get()); if (result == tesSUCCESS) - result = - issueIOU(account(), flow2.order.out, flow2.order.out.issue()); + result = issueIOU( + account(), flow2.order.out, flow2.order.out.get()); } if (result == tesSUCCESS) diff --git a/src/xrpld/app/tx/detail/Taker.h b/src/xrpld/app/tx/detail/Taker.h index 3e64c59b542..392b790f2ab 100644 --- a/src/xrpld/app/tx/detail/Taker.h +++ b/src/xrpld/app/tx/detail/Taker.h @@ -128,14 +128,14 @@ class BasicTaker Rate in_rate(AccountID const& from, AccountID const& to) const { - return effective_rate(m_rate_in, original_.in.issue(), from, to); + return effective_rate(m_rate_in, original_.in.get(), from, to); } // The transfer rate for the output currency between the given accounts Rate out_rate(AccountID const& from, AccountID const& to) const { - return effective_rate(m_rate_out, original_.out.issue(), from, to); + return effective_rate(m_rate_out, original_.out.get(), from, to); } public: diff --git a/src/xrpld/app/tx/detail/XChainBridge.cpp b/src/xrpld/app/tx/detail/XChainBridge.cpp index f5633903567..6620f08103a 100644 --- a/src/xrpld/app/tx/detail/XChainBridge.cpp +++ b/src/xrpld/app/tx/detail/XChainBridge.cpp @@ -679,7 +679,7 @@ finalizeClaimHelper( saveNumberRoundMode _{Number::setround(round_mode)}; STAmount const den{rewardAccounts.size()}; - return divide(rewardPool, den, rewardPool.issue()); + return divide(rewardPool, den, rewardPool.get()); }(); STAmount distributed = rewardPool.zeroed(); for (auto const& rewardAccount : rewardAccounts) @@ -1234,7 +1234,7 @@ attestationPreflight(PreflightContext const& ctx) return temXCHAIN_BAD_PROOF; auto const expectedIssue = bridgeSpec.issue(STXChainBridge::srcChain(att->wasLockingChainSend)); - if (att->sendingAmount.issue() != expectedIssue) + if (att->sendingAmount.template get() != expectedIssue) return temXCHAIN_BAD_PROOF; return preflight2(ctx); @@ -1679,8 +1679,8 @@ XChainClaim::preflight(PreflightContext const& ctx) auto const amount = ctx.tx[sfAmount]; if (amount.signum() <= 0 || - (amount.issue() != bridgeSpec.lockingChainIssue() && - amount.issue() != bridgeSpec.issuingChainIssue())) + (amount.get() != bridgeSpec.lockingChainIssue() && + amount.get() != bridgeSpec.issuingChainIssue())) { return temBAD_AMOUNT; } @@ -1723,12 +1723,12 @@ XChainClaim::preclaim(PreclaimContext const& ctx) if (isLockingChain) { - if (bridgeSpec.lockingChainIssue() != thisChainAmount.issue()) + if (bridgeSpec.lockingChainIssue() != thisChainAmount.get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; } else { - if (bridgeSpec.issuingChainIssue() != thisChainAmount.issue()) + if (bridgeSpec.issuingChainIssue() != thisChainAmount.get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; } } @@ -1919,8 +1919,8 @@ XChainCommit::preflight(PreflightContext const& ctx) if (amount.signum() <= 0 || !isLegalNet(amount)) return temBAD_AMOUNT; - if (amount.issue() != bridgeSpec.lockingChainIssue() && - amount.issue() != bridgeSpec.issuingChainIssue()) + if (amount.get() != bridgeSpec.lockingChainIssue() && + amount.get() != bridgeSpec.issuingChainIssue()) return temBAD_ISSUER; return preflight2(ctx); @@ -1959,12 +1959,12 @@ XChainCommit::preclaim(PreclaimContext const& ctx) if (isLockingChain) { - if (bridgeSpec.lockingChainIssue() != ctx.tx[sfAmount].issue()) + if (bridgeSpec.lockingChainIssue() != ctx.tx[sfAmount].get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; } else { - if (bridgeSpec.issuingChainIssue() != ctx.tx[sfAmount].issue()) + if (bridgeSpec.issuingChainIssue() != ctx.tx[sfAmount].get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; } @@ -2191,7 +2191,7 @@ XChainCreateAccountCommit::preflight(PreflightContext const& ctx) if (reward.signum() < 0 || !reward.native()) return temBAD_AMOUNT; - if (reward.issue() != amount.issue()) + if (reward.get() != amount.get()) return temBAD_AMOUNT; return preflight2(ctx); @@ -2224,7 +2224,7 @@ XChainCreateAccountCommit::preclaim(PreclaimContext const& ctx) if (amount < *minCreateAmount) return tecXCHAIN_INSUFF_CREATE_AMOUNT; - if (minCreateAmount->issue() != amount.issue()) + if (minCreateAmount->get() != amount.get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; AccountID const thisDoor = (*sleBridge)[sfAccount]; @@ -2247,7 +2247,7 @@ XChainCreateAccountCommit::preclaim(PreclaimContext const& ctx) STXChainBridge::ChainType const dstChain = STXChainBridge::otherChain(srcChain); - if (bridgeSpec.issue(srcChain) != ctx.tx[sfAmount].issue()) + if (bridgeSpec.issue(srcChain) != ctx.tx[sfAmount].get()) return tecXCHAIN_BAD_TRANSFER_ISSUE; if (!isXRP(bridgeSpec.issue(dstChain))) diff --git a/src/xrpld/ledger/detail/PaymentSandbox.cpp b/src/xrpld/ledger/detail/PaymentSandbox.cpp index d182d22b56c..b997c6157b5 100644 --- a/src/xrpld/ledger/detail/PaymentSandbox.cpp +++ b/src/xrpld/ledger/detail/PaymentSandbox.cpp @@ -52,7 +52,7 @@ DeferredCredits::credit( assert(sender != receiver); assert(!amount.negative()); - auto const k = makeKey(sender, receiver, amount.getCurrency()); + auto const k = makeKey(sender, receiver, amount.get().getCurrency()); auto i = credits_.find(k); if (i == credits_.end()) { @@ -185,7 +185,7 @@ PaymentSandbox::balanceHook( magnitudes, (B+C)-C may not equal B. */ - auto const currency = amount.getCurrency(); + auto const currency = amount.get().getCurrency(); auto delta = amount.zeroed(); auto lastBal = amount; @@ -206,7 +206,7 @@ PaymentSandbox::balanceHook( // to compute usable balance just slightly above what the ledger // calculates (but always less than the actual balance). auto adjustedAmt = std::min({amount, lastBal - delta, minBal}); - adjustedAmt.setIssuer(amount.getIssuer()); + adjustedAmt.get().setIssuer(amount.getIssuer()); if (isXRP(issuer) && adjustedAmt < beast::zero) // A calculated negative XRP balance is not an error case. Consider a @@ -368,7 +368,7 @@ PaymentSandbox::balanceChanges(ReadView const& view) const } // The following are now set, put them in the map auto delta = newBalance - oldBalance; - auto const cur = newBalance.getCurrency(); + auto const cur = newBalance.get().getCurrency(); result[std::make_tuple(lowID, highID, cur)] = delta; auto r = result.emplace(std::make_tuple(lowID, lowID, cur), delta); if (r.second) diff --git a/src/xrpld/ledger/detail/View.cpp b/src/xrpld/ledger/detail/View.cpp index e1d85d73422..62096e6ecb4 100644 --- a/src/xrpld/ledger/detail/View.cpp +++ b/src/xrpld/ledger/detail/View.cpp @@ -284,7 +284,7 @@ accountHolds( // Put balance in account terms. amount.negate(); } - amount.setIssuer(issuer); + amount.get().setIssuer(issuer); } JLOG(j.trace()) << "accountHolds:" << " account=" << to_string(account) @@ -360,7 +360,7 @@ accountFunds( return accountHolds( view, id, - saDefault.getCurrency(), + saDefault.get().getCurrency(), saDefault.getIssuer(), freezeHandling, j); @@ -901,7 +901,8 @@ trustCreate( sleRippleState->setFieldAmount( bSetHigh ? sfLowLimit : sfHighLimit, STAmount(Issue{ - saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID})); + saBalance.get().getCurrency(), + bSetDst ? uSrcAccountID : uDstAccountID})); if (uQualityIn) sleRippleState->setFieldU32( @@ -1035,7 +1036,7 @@ rippleCredit( beast::Journal j) { AccountID const& issuer = saAmount.getIssuer(); - Currency const& currency = saAmount.getCurrency(); + Currency const& currency = saAmount.get().getCurrency(); // Make sure issuer is involved. assert(!bCheckIssuer || uSenderID == issuer || uReceiverID == issuer); @@ -1137,7 +1138,7 @@ rippleCredit( STAmount const saReceiverLimit(Issue{currency, uReceiverID}); STAmount saBalance{saAmount}; - saBalance.setIssuer(noAccount()); + saBalance.get().setIssuer(noAccount()); JLOG(j.debug()) << "rippleCredit: " "create line: " @@ -1489,7 +1490,7 @@ issueIOU( assert(!isXRP(account) && !isXRP(issue.account)); // Consistency check - assert(issue == amount.issue()); + assert(issue == amount.get()); // Can't send to self! assert(issue.account != account); @@ -1549,7 +1550,7 @@ issueIOU( STAmount const limit(Issue{issue.currency, account}); STAmount final_balance = amount; - final_balance.setIssuer(noAccount()); + final_balance.get().setIssuer(noAccount()); auto const receiverAccount = view.peek(keylet::account(account)); if (!receiverAccount) @@ -1585,7 +1586,7 @@ redeemIOU( assert(!isXRP(account) && !isXRP(issue.account)); // Consistency check - assert(issue == amount.issue()); + assert(issue == amount.get()); // Can't send to self! assert(issue.account != account); diff --git a/src/xrpld/rpc/BookChanges.h b/src/xrpld/rpc/BookChanges.h index 7d7978d3fe2..2a9cc920860 100644 --- a/src/xrpld/rpc/BookChanges.h +++ b/src/xrpld/rpc/BookChanges.h @@ -112,8 +112,8 @@ computeBookChanges(std::shared_ptr const& lpAccepted) STAmount deltaPays = finalFields.getFieldAmount(sfTakerPays) - previousFields.getFieldAmount(sfTakerPays); - std::string g{to_string(deltaGets.issue())}; - std::string p{to_string(deltaPays.issue())}; + std::string g{to_string(deltaGets.get())}; + std::string p{to_string(deltaPays.get())}; bool const noswap = isXRP(deltaGets) ? true : (isXRP(deltaPays) ? false : (g < p)); @@ -186,9 +186,9 @@ computeBookChanges(std::shared_ptr const& lpAccepted) STAmount volB = std::get<1>(entry.second); inner[jss::currency_a] = - (isXRP(volA) ? "XRP_drops" : to_string(volA.issue())); + (isXRP(volA) ? "XRP_drops" : to_string(volA.get())); inner[jss::currency_b] = - (isXRP(volB) ? "XRP_drops" : to_string(volB.issue())); + (isXRP(volB) ? "XRP_drops" : to_string(volB.get())); inner[jss::volume_a] = (isXRP(volA) ? to_string(volA.xrp()) : to_string(volA.iou())); diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index 401f808f56a..6d045dc1600 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -237,7 +237,7 @@ checkPayment( { // If no SendMax, default to Amount with sender as issuer. sendMax = amount; - sendMax.setIssuer(srcAddressID); + sendMax.get().setIssuer(srcAddressID); } if (sendMax.native() && amount.native()) @@ -258,8 +258,8 @@ checkPayment( ledger, app.journal("RippleLineCache")), srcAddressID, *dstAccountID, - sendMax.issue().currency, - sendMax.issue().account, + sendMax.get().currency, + sendMax.get().account, amount, std::nullopt, app); @@ -270,7 +270,10 @@ checkPayment( STPath fullLiquidityPath; STPathSet paths; result = pf.getBestPaths( - 4, fullLiquidityPath, paths, sendMax.issue().account); + 4, + fullLiquidityPath, + paths, + sendMax.get().account); } } diff --git a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp index 6c8fe282674..279b390c01d 100644 --- a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp +++ b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp @@ -74,9 +74,9 @@ doAccountCurrencies(RPC::JsonContext& context) STAmount const& saBalance = rspEntry.getBalance(); if (saBalance < rspEntry.getLimit()) - receive.insert(saBalance.getCurrency()); + receive.insert(saBalance.get().getCurrency()); if ((-saBalance) < rspEntry.getLimitPeer()) - send.insert(saBalance.getCurrency()); + send.insert(saBalance.get().getCurrency()); } send.erase(badCurrency()); diff --git a/src/xrpld/rpc/handlers/AccountLines.cpp b/src/xrpld/rpc/handlers/AccountLines.cpp index 64ca95ebe56..2dfbad995a9 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.issue().currency); + jPeer[jss::currency] = to_string(saBalance.get().currency); 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/GatewayBalances.cpp b/src/xrpld/rpc/handlers/GatewayBalances.cpp index 8fd13d472cc..040db74d7ed 100644 --- a/src/xrpld/rpc/handlers/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/GatewayBalances.cpp @@ -180,7 +180,8 @@ doGatewayBalances(RPC::JsonContext& context) else { // normal negative balance, obligation to customer - auto& bal = sums[rs->getBalance().getCurrency()]; + auto& bal = + sums[rs->getBalance().get().getCurrency()]; if (bal == beast::zero) { // This is needed to set the currency code correctly @@ -199,7 +200,7 @@ doGatewayBalances(RPC::JsonContext& context) // Very large sums of STAmount are approximations // anyway. bal = STAmount( - bal.issue(), + bal.get(), STAmount::cMaxValue, STAmount::cMaxOffset); } @@ -232,7 +233,7 @@ doGatewayBalances(RPC::JsonContext& context) { Json::Value entry; entry[jss::currency] = - to_string(balance.issue().currency); + to_string(balance.get().currency); entry[jss::value] = balance.getText(); balanceArray.append(std::move(entry)); } diff --git a/src/xrpld/rpc/handlers/NoRippleCheck.cpp b/src/xrpld/rpc/handlers/NoRippleCheck.cpp index 94830a4f397..5171511cee7 100644 --- a/src/xrpld/rpc/handlers/NoRippleCheck.cpp +++ b/src/xrpld/rpc/handlers/NoRippleCheck.cpp @@ -178,14 +178,14 @@ doNoRippleCheck(RPC::JsonContext& context) .getIssuer(); STAmount peerLimit = ownedItem->getFieldAmount( bLow ? sfHighLimit : sfLowLimit); - problem += to_string(peerLimit.getCurrency()); + problem += to_string(peerLimit.get().getCurrency()); problem += " line to "; problem += to_string(peerLimit.getIssuer()); problems.append(problem); STAmount limitAmount(ownedItem->getFieldAmount( bLow ? sfLowLimit : sfHighLimit)); - limitAmount.setIssuer(peer); + limitAmount.get().setIssuer(peer); Json::Value& tx = jvTransactions.append(Json::objectValue); tx["TransactionType"] = jss::TrustSet;