handle createGuards change and addressed minor pr comment

Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
This commit is contained in:
Pratik Mankawde
2026-06-02 15:22:00 +01:00
parent 4a3fc41202
commit f3afbba77d
4 changed files with 18 additions and 23 deletions

View File

@@ -131,7 +131,6 @@ useRulesGuards(Rules const& rules);
void
createGuards(
Rules const& rules,
std::optional<NumberSO>& stNumberSO,
std::optional<CurrentTransactionRulesGuard>& rulesGuard,
std::optional<NumberMantissaScaleGuard>& mantissaScaleGuard);

View File

@@ -83,7 +83,6 @@ useRulesGuards(Rules const& rules)
void
createGuards(
Rules const& rules,
std::optional<NumberSO>& stNumberSO,
std::optional<CurrentTransactionRulesGuard>& rulesGuard,
std::optional<NumberMantissaScaleGuard>& mantissaScaleGuard)
{
@@ -91,7 +90,6 @@ createGuards(
{
// raii classes for the current ledger rules.
// fixUniversalNumber predates the rulesGuard and should be replaced.
stNumberSO.emplace(rules.enabled(fixUniversalNumber));
rulesGuard.emplace(rules);
}
else

View File

@@ -839,27 +839,25 @@ STAmount::canonicalize()
if (asset_.holds<MPTIssue>() && offset_ > 18)
Throw<std::runtime_error>("MPT amount out of range");
Number const num(isNegative_, value_, offset_, Number::Unchecked{});
auto set = [&](auto const& val) {
auto const value = val.value();
isNegative_ = value < 0;
value_ = isNegative_ ? -value : value;
};
if (native())
{
Number const num(isNegative_, value_, offset_, Number::Unchecked{});
auto set = [&](auto const& val) {
auto const value = val.value();
isNegative_ = value < 0;
value_ = isNegative_ ? -value : value;
};
if (native())
{
set(XRPAmount{num});
}
else if (asset_.holds<MPTIssue>())
{
set(MPTAmount{num});
}
else
{
Throw<std::runtime_error>("Unknown integral asset type");
}
offset_ = 0;
set(XRPAmount{num});
}
else if (asset_.holds<MPTIssue>())
{
set(MPTAmount{num});
}
else
{
Throw<std::runtime_error>("Unknown integral asset type");
}
offset_ = 0;
if (native() && value_ > kMaxNativeN)
{

View File

@@ -71,7 +71,7 @@ withTxnType(Rules const& rules, TxType txnType, F&& f)
//
std::optional<CurrentTransactionRulesGuard> rulesGuard;
std::optional<NumberMantissaScaleGuard> mantissaScaleGuard;
createGuards(rules, std::nullopt, rulesGuard, mantissaScaleGuard);
createGuards(rules, rulesGuard, mantissaScaleGuard);
switch (txnType)
{