Skip to content

Commit

Permalink
Replace STAmount::issue() with STamount::get<Issue>(), STAmount::getC…
Browse files Browse the repository at this point in the history
…urrency() with STAmount::get<Issue>().currency.

Prefer using asset() instead of get<Issue>() unless the latter (i.e. Issue) is explicitly required.
  • Loading branch information
gregtatcam committed Jan 27, 2025
1 parent 33c7a61 commit 556574c
Show file tree
Hide file tree
Showing 42 changed files with 201 additions and 197 deletions.
19 changes: 0 additions & 19 deletions include/xrpl/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ class STAmount final : public STBase, public CountedObject<STAmount>
constexpr TIss const&
get() const;

Issue const&
issue() const;

// These three are deprecated
Currency const&
getCurrency() const;

AccountID const&
getIssuer() const;

Expand Down Expand Up @@ -483,18 +476,6 @@ STAmount::get() const
return mAsset.get<TIss>();
}

inline Issue const&
STAmount::issue() const
{
return get<Issue>();
}

inline Currency const&
STAmount::getCurrency() const
{
return mAsset.get<Issue>().currency;
}

inline AccountID const&
STAmount::getIssuer() const
{
Expand Down
4 changes: 2 additions & 2 deletions src/test/app/AMMCalc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ 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.asset());
return toSTAmount(mulRatio(amt.iou(), a, b, round), amt.asset());
}

void
Expand Down
8 changes: 4 additions & 4 deletions src/test/app/AMM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)).asset()) ==
STIssue(sfAsset, STAmount(XRP(2'000)).asset()));
BEAST_EXPECT(
STIssue(sfAsset, STAmount(XRP(2'000)).issue()) !=
STIssue(sfAsset, STAmount(USD(2'000)).issue()));
STIssue(sfAsset, STAmount(XRP(2'000)).asset()) !=
STIssue(sfAsset, STAmount(USD(2'000)).asset()));
}

void
Expand Down
6 changes: 3 additions & 3 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,12 +2295,12 @@ 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<Issue>()));
BEAST_EXPECT(sleTrust);
if (sleTrust)
{
Issue const issue = expectBalance.value().issue();
Issue const issue = expectBalance.value().get<Issue>();
bool const accountLow = account.id() < issue.account;

STAmount low{issue};
Expand Down
12 changes: 6 additions & 6 deletions src/test/app/ReducedOffer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ class ReducedOffer_test : public beast::unit_test::suite
mantissaReduce += 20'000'000ull)
{
STAmount aliceUSD{
bobsOffer.out.issue(),
bobsOffer.out.asset(),
bobsOffer.out.mantissa() - mantissaReduce,
bobsOffer.out.exponent()};
STAmount aliceXRP{
bobsOffer.in.issue(), bobsOffer.in.mantissa() - 1};
bobsOffer.in.asset(), bobsOffer.in.mantissa() - 1};
Amounts alicesOffer{aliceUSD, aliceXRP};
blockedCount += exerciseOfferPair(alicesOffer, bobsOffer);
}
Expand Down Expand Up @@ -356,11 +356,11 @@ class ReducedOffer_test : public beast::unit_test::suite
mantissaReduce += 20'000'000ull)
{
STAmount bobUSD{
aliceOffer.out.issue(),
aliceOffer.out.asset(),
aliceOffer.out.mantissa() - mantissaReduce,
aliceOffer.out.exponent()};
STAmount bobXRP{
aliceOffer.in.issue(), aliceOffer.in.mantissa() - 1};
aliceOffer.in.asset(), aliceOffer.in.mantissa() - 1};
Amounts bobsOffer{bobUSD, bobXRP};

blockedCount += exerciseOfferPair(aliceOffer, bobsOffer);
Expand Down Expand Up @@ -724,7 +724,7 @@ class ReducedOffer_test : public beast::unit_test::suite
if (badRate == 0)
{
STAmount const tweakedTakerGets(
aliceReducedOffer.in.issue(),
aliceReducedOffer.in.asset(),
aliceReducedOffer.in.mantissa() + 1,
aliceReducedOffer.in.exponent(),
aliceReducedOffer.in.negative());
Expand Down Expand Up @@ -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.asset(), 1, -8);
for (unsigned int i = 0; i < loopCount; ++i)
{
blockedCount += exerciseOfferTrio(
Expand Down
4 changes: 2 additions & 2 deletions src/test/app/TheoreticalQuality_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class TheoreticalQuality_test : public beast::unit_test::suite

auto const sendMaxIssue = [&rcp]() -> std::optional<Issue> {
if (rcp.sendMax)
return rcp.sendMax->issue();
return rcp.sendMax->get<Issue>();
return std::nullopt;
}();

Expand All @@ -260,7 +260,7 @@ class TheoreticalQuality_test : public beast::unit_test::suite
sb,
rcp.srcAccount,
rcp.dstAccount,
rcp.dstAmt.issue(),
rcp.dstAmt.asset(),
/*limitQuality*/ std::nullopt,
sendMaxIssue,
rcp.paths,
Expand Down
24 changes: 12 additions & 12 deletions src/test/app/XChain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ struct BalanceTransfer
bool check_payer = true)
{
auto reward_cost =
multiply(reward, STAmount(reward_accounts.size()), reward.issue());
multiply(reward, STAmount(reward_accounts.size()), reward.asset());
return check_most_balances(amt, reward) &&
(!check_payer || payor_.diff() == -(reward_cost + txFees_));
}
Expand Down Expand Up @@ -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.asset())));
}

// 4,4 => should succeed
Expand All @@ -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.asset());

mcEnv.tx(create_bridge(mcDoor, jvb)).close();

Expand Down Expand Up @@ -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.asset())));
}

// 1,2 => should fail
Expand Down Expand Up @@ -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.asset() != xrpIssue())
return;
auto it = accounts.find(acct);
if (it == accounts.end())
Expand All @@ -4469,22 +4469,22 @@ struct XChainSim_test : public beast::unit_test::suite,
(divisor == 1 ? amt
: divide(
amt,
STAmount(amt.issue(), divisor),
amt.issue()));
STAmount(amt.asset(), divisor),
amt.asset()));
}
}

void
spend(jtx::Account const& acct, STAmount amt, std::uint64_t times = 1)
{
if (amt.issue() != xrpIssue())
if (amt.asset() != xrpIssue())
return;
receive(
acct,
times == 1
? -amt
: -multiply(
amt, STAmount(amt.issue(), times), amt.issue()));
amt, STAmount(amt.asset(), times), amt.asset()));
}

void
Expand Down Expand Up @@ -4712,7 +4712,7 @@ 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.asset());

for (auto i : signers)
st.receive(bridge_.signers[i].account, reward);
Expand Down Expand Up @@ -4797,7 +4797,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.asset() != xrpIssue())
{
st.env.tx(pay(srcdoor, xfer.from, xfer.amt));
st.spendFee(srcdoor);
Expand All @@ -4818,7 +4818,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.asset());

for (size_t i = 0; i < num_signers; ++i)
{
Expand Down
4 changes: 2 additions & 2 deletions src/test/jtx/impl/AMMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ AMMTestBase::testAMM(
return defXRP;
return a + XRP(1000);
}
auto const defIOU = STAmount{a.issue(), 30000};
auto const defIOU = STAmount{a.asset(), 30000};
if (a <= defIOU)
return defIOU;
return a + STAmount{a.issue(), 1000};
return a + STAmount{a.asset(), 1000};
};
auto const toFund1 = tofund(asset1);
auto const toFund2 = tofund(asset2);
Expand Down
4 changes: 2 additions & 2 deletions src/test/jtx/impl/TestHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,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>())))
{
Issue const issue = value.issue();
Issue const issue = value.get<Issue>();
bool const accountLow = account < issue.account;

bool expectDefaultTrustLine = true;
Expand Down
5 changes: 3 additions & 2 deletions src/test/jtx/impl/balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace jtx {
void
balance::operator()(Env& env) const
{
if (isXRP(value_.issue()))
if (isXRP(value_.asset()))
{
auto const sle = env.le(account_);
if (none_)
Expand All @@ -40,7 +40,8 @@ balance::operator()(Env& env) const
}
else if (value_.holds<Issue>())
{
auto const sle = env.le(keylet::line(account_.id(), value_.issue()));
auto const sle =
env.le(keylet::line(account_.id(), value_.get<Issue>()));
if (none_)
{
env.test.expect(!sle);
Expand Down
14 changes: 8 additions & 6 deletions src/test/jtx/impl/xchain_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Issue>()))
, split_reward_everyone(divide(
reward,
STAmount(UT_XCHAIN_DEFAULT_NUM_SIGNERS),
reward.issue()))
reward.get<Issue>()))
, tiny_reward(drops(37))
, tiny_reward_split((divide(
tiny_reward,
STAmount(UT_XCHAIN_DEFAULT_QUORUM),
tiny_reward.issue())))
tiny_reward.get<Issue>())))
, tiny_reward_remainder(
tiny_reward -
multiply(
tiny_reward_split,
STAmount(UT_XCHAIN_DEFAULT_QUORUM),
tiny_reward.issue()))
tiny_reward.get<Issue>()))
, one_xrp(XRP(1))
, xrp_dust(divide(one_xrp, STAmount(10000), one_xrp.issue()))
, xrp_dust(divide(one_xrp, STAmount(10000), one_xrp.get<Issue>()))
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/jtx/mpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ struct MPTCreate
std::optional<std::string> metadata = std::nullopt;
std::optional<std::uint32_t> ownerCount = std::nullopt;
std::optional<std::uint32_t> holderCount = std::nullopt;
// authorize if seated
// if empty vector then authorize all holders
std::optional<std::vector<Account>> authorize = std::nullopt;
// pay only if authorize is seated
// pay if seated and if authorize is seated
// if empty vector then pay to either authorize or all holders
std::optional<std::pair<std::vector<Account>, std::uint64_t>> pay =
std::nullopt;
Expand Down
10 changes: 5 additions & 5 deletions src/test/protocol/STAmount_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class STAmount_test : public beast::unit_test::suite

if (mantissa < STAmount::cMinValue)
return {
amount.issue(),
amount.asset(),
mantissa,
amount.exponent(),
amount.negative()};

return {
amount.issue(),
amount.asset(),
mantissa,
amount.exponent(),
amount.negative(),
Expand All @@ -72,13 +72,13 @@ class STAmount_test : public beast::unit_test::suite

if (mantissa > STAmount::cMaxValue)
return {
amount.issue(),
amount.asset(),
mantissa,
amount.exponent(),
amount.negative()};

return {
amount.issue(),
amount.asset(),
mantissa,
amount.exponent(),
amount.negative(),
Expand All @@ -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<Issue>().currency == res.get<Issue>().currency);

if (res != cmp)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/protocol/STNumber_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct STNumber_test : public beast::unit_test::suite
STNumber const factor{sfNumber, 100};
auto const iouValue = strikePrice.iou();
IOUAmount totalValue{iouValue * factor};
STAmount const totalAmount{totalValue, strikePrice.issue()};
STAmount const totalAmount{totalValue, strikePrice.get<Issue>()};
BEAST_EXPECT(totalAmount == Number{10'000});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/misc/AMMHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ STAmount
ammLPTokens(
STAmount const& asset1,
STAmount const& asset2,
Issue const& lptIssue);
Asset const& lptIssue);

/** Calculate LP Tokens given asset's deposit amount.
* @param asset1Balance current AMM asset1 balance
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/misc/AMMUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ initializeFeeAuctionVote(
ApplyView& view,
std::shared_ptr<SLE>& ammSle,
AccountID const& account,
Issue const& lptIssue,
Asset const& lptIssue,
std::uint16_t tfee);

/** Return true if the Liquidity Provider is the only AMM provider, false
Expand Down
Loading

0 comments on commit 556574c

Please sign in to comment.