mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-26 05:55:51 +00:00
Expand use of Asset::integral()
This commit is contained in:
@@ -174,6 +174,9 @@ public:
|
|||||||
int
|
int
|
||||||
exponent() const noexcept;
|
exponent() const noexcept;
|
||||||
|
|
||||||
|
bool
|
||||||
|
integral() const noexcept;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
native() const noexcept;
|
native() const noexcept;
|
||||||
|
|
||||||
@@ -454,6 +457,12 @@ STAmount::exponent() const noexcept
|
|||||||
return mOffset;
|
return mOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
STAmount::integral() const noexcept
|
||||||
|
{
|
||||||
|
return mAsset.integral();
|
||||||
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
STAmount::native() const noexcept
|
STAmount::native() const noexcept
|
||||||
{
|
{
|
||||||
@@ -735,7 +744,7 @@ roundToAsset(
|
|||||||
{
|
{
|
||||||
NumberRoundModeGuard mg(rounding);
|
NumberRoundModeGuard mg(rounding);
|
||||||
STAmount const ret{asset, value};
|
STAmount const ret{asset, value};
|
||||||
if (ret.asset().native() || !ret.asset().holds<Issue>())
|
if (ret.integral())
|
||||||
return ret;
|
return ret;
|
||||||
// Not that the ctor will round integral types (XRP, MPT) via canonicalize,
|
// Not that the ctor will round integral types (XRP, MPT) via canonicalize,
|
||||||
// so no extra work is needed for those.
|
// so no extra work is needed for those.
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ STAmount::xrp() const
|
|||||||
IOUAmount
|
IOUAmount
|
||||||
STAmount::iou() const
|
STAmount::iou() const
|
||||||
{
|
{
|
||||||
if (native() || !holds<Issue>())
|
if (integral())
|
||||||
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");
|
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");
|
||||||
|
|
||||||
auto mantissa = static_cast<std::int64_t>(mValue);
|
auto mantissa = static_cast<std::int64_t>(mValue);
|
||||||
@@ -1513,7 +1513,7 @@ STAmount
|
|||||||
roundToScale(STAmount value, std::int32_t scale, Number::rounding_mode rounding)
|
roundToScale(STAmount value, std::int32_t scale, Number::rounding_mode rounding)
|
||||||
{
|
{
|
||||||
// Nothing to do for intgral types.
|
// Nothing to do for intgral types.
|
||||||
if (value.asset().native() || !value.asset().holds<Issue>())
|
if (value.integral())
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
// If the value's exponent is greater than or equal to the scale, then
|
// If the value's exponent is greater than or equal to the scale, then
|
||||||
|
|||||||
@@ -193,9 +193,7 @@ class Loan_test : public beast::unit_test::suite
|
|||||||
auto const available = vaultSle->at(sfAssetsAvailable);
|
auto const available = vaultSle->at(sfAssetsAvailable);
|
||||||
env.test.BEAST_EXPECT(
|
env.test.BEAST_EXPECT(
|
||||||
total == available ||
|
total == available ||
|
||||||
(!broker.asset.raw().native() &&
|
(!broker.asset.integral() && available != 0 &&
|
||||||
broker.asset.raw().holds<Issue>() &&
|
|
||||||
available != 0 &&
|
|
||||||
((total - available) / available <
|
((total - available) / available <
|
||||||
Number(1, -6))));
|
Number(1, -6))));
|
||||||
env.test.BEAST_EXPECT(
|
env.test.BEAST_EXPECT(
|
||||||
@@ -1750,7 +1748,7 @@ class Loan_test : public beast::unit_test::suite
|
|||||||
BEAST_EXPECT(
|
BEAST_EXPECT(
|
||||||
paymentComponents.final || diff == beast::zero ||
|
paymentComponents.final || diff == beast::zero ||
|
||||||
(diff > beast::zero &&
|
(diff > beast::zero &&
|
||||||
((broker.asset.raw().integral() &&
|
((broker.asset.integral() &&
|
||||||
(static_cast<Number>(diff) < 3)) ||
|
(static_cast<Number>(diff) < 3)) ||
|
||||||
(totalDue.exponent() - diff.exponent() > 8))));
|
(totalDue.exponent() - diff.exponent() > 8))));
|
||||||
|
|
||||||
|
|||||||
@@ -84,14 +84,14 @@ class Vault_test : public beast::unit_test::suite
|
|||||||
this]() -> std::tuple<PrettyAsset, Account> {
|
this]() -> std::tuple<PrettyAsset, Account> {
|
||||||
auto const vault = env.le(keylet);
|
auto const vault = env.le(keylet);
|
||||||
BEAST_EXPECT(vault != nullptr);
|
BEAST_EXPECT(vault != nullptr);
|
||||||
if (asset.raw().holds<Issue>() && !asset.raw().native())
|
if (!asset.integral())
|
||||||
BEAST_EXPECT(vault->at(sfScale) == 6);
|
BEAST_EXPECT(vault->at(sfScale) == 6);
|
||||||
else
|
else
|
||||||
BEAST_EXPECT(vault->at(sfScale) == 0);
|
BEAST_EXPECT(vault->at(sfScale) == 0);
|
||||||
auto const shares =
|
auto const shares =
|
||||||
env.le(keylet::mptIssuance(vault->at(sfShareMPTID)));
|
env.le(keylet::mptIssuance(vault->at(sfShareMPTID)));
|
||||||
BEAST_EXPECT(shares != nullptr);
|
BEAST_EXPECT(shares != nullptr);
|
||||||
if (asset.raw().holds<Issue>() && !asset.raw().native())
|
if (!asset.integral())
|
||||||
BEAST_EXPECT(shares->at(sfAssetScale) == 6);
|
BEAST_EXPECT(shares->at(sfAssetScale) == 6);
|
||||||
else
|
else
|
||||||
BEAST_EXPECT(shares->at(sfAssetScale) == 0);
|
BEAST_EXPECT(shares->at(sfAssetScale) == 0);
|
||||||
@@ -446,7 +446,7 @@ class Vault_test : public beast::unit_test::suite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!asset.raw().native() && asset.raw().holds<Issue>())
|
if (!asset.integral())
|
||||||
{
|
{
|
||||||
testcase(prefix + " temporary authorization for 3rd party");
|
testcase(prefix + " temporary authorization for 3rd party");
|
||||||
env(trust(erin, asset(1000)));
|
env(trust(erin, asset(1000)));
|
||||||
|
|||||||
@@ -233,6 +233,18 @@ public:
|
|||||||
return {asset_};
|
return {asset_};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
integral() const
|
||||||
|
{
|
||||||
|
return asset_.integral();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
native() const
|
||||||
|
{
|
||||||
|
return asset_.native();
|
||||||
|
}
|
||||||
|
|
||||||
template <ValidIssueType TIss>
|
template <ValidIssueType TIss>
|
||||||
bool
|
bool
|
||||||
holds() const
|
holds() const
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ LoanManage::defaultLoan(
|
|||||||
// Capital and any unclaimed funds amount:
|
// Capital and any unclaimed funds amount:
|
||||||
vaultAssetsAvailableProxy += defaultCovered;
|
vaultAssetsAvailableProxy += defaultCovered;
|
||||||
if (*vaultAssetsAvailableProxy > *vaultAssetsTotalProxy &&
|
if (*vaultAssetsAvailableProxy > *vaultAssetsTotalProxy &&
|
||||||
!vaultAsset.native() && vaultAsset.holds<Issue>())
|
!vaultAsset.integral())
|
||||||
{
|
{
|
||||||
auto const difference =
|
auto const difference =
|
||||||
vaultAssetsAvailableProxy - vaultAssetsTotalProxy;
|
vaultAssetsAvailableProxy - vaultAssetsTotalProxy;
|
||||||
|
|||||||
Reference in New Issue
Block a user