mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Implement Lending Protocol (unsupported) (#5270)
- Spec: XLS-66 - Introduces amendment "LendingProtocol", but leaves it UNSUPPORTED to allow for standalone testing, future development work, and potential bug fixes. - AccountInfo RPC will indicate the type of pseudo-account when appropriate. - Refactors and improves several existing classes and functional areas, including Number, STAmount, STObject, json_value, Asset, directory handling, View helper functions, and unit test helpers.
This commit is contained in:
@@ -279,7 +279,7 @@ STAmount::xrp() const
|
||||
IOUAmount
|
||||
STAmount::iou() const
|
||||
{
|
||||
if (native() || !holds<Issue>())
|
||||
if (integral())
|
||||
Throw<std::logic_error>("Cannot return non-IOU STAmount as IOUAmount");
|
||||
|
||||
auto mantissa = static_cast<std::int64_t>(mValue);
|
||||
@@ -830,7 +830,7 @@ STAmount::isDefault() const
|
||||
void
|
||||
STAmount::canonicalize()
|
||||
{
|
||||
if (native() || mAsset.holds<MPTIssue>())
|
||||
if (integral())
|
||||
{
|
||||
// native and MPT currency amounts should always have an offset of zero
|
||||
// log(2^64,10) ~ 19.2
|
||||
@@ -859,8 +859,10 @@ STAmount::canonicalize()
|
||||
};
|
||||
if (native())
|
||||
set(XRPAmount{num});
|
||||
else
|
||||
else if (mAsset.holds<MPTIssue>())
|
||||
set(MPTAmount{num});
|
||||
else
|
||||
Throw<std::runtime_error>("Unknown integral asset type");
|
||||
mOffset = 0;
|
||||
}
|
||||
else
|
||||
@@ -1461,6 +1463,33 @@ canonicalizeRoundStrict(
|
||||
}
|
||||
}
|
||||
|
||||
STAmount
|
||||
roundToScale(
|
||||
STAmount const& value,
|
||||
std::int32_t scale,
|
||||
Number::rounding_mode rounding)
|
||||
{
|
||||
// Nothing to do for integral types.
|
||||
if (value.integral())
|
||||
return value;
|
||||
|
||||
// If the value's exponent is greater than or equal to the scale, then
|
||||
// rounding will do nothing, and might even lose precision, so just return
|
||||
// the value.
|
||||
if (value.exponent() >= scale)
|
||||
return value;
|
||||
|
||||
STAmount const referenceValue{
|
||||
value.asset(), STAmount::cMinValue, scale, value.negative()};
|
||||
|
||||
NumberRoundModeGuard mg(rounding);
|
||||
// With an IOU, the the result of addition will be truncated to the
|
||||
// precision of the larger value, which in this case is referenceValue. Then
|
||||
// remove the reference value via subtraction, and we're left with the
|
||||
// rounded value.
|
||||
return (value + referenceValue) - referenceValue;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// We need a class that has an interface similar to NumberRoundModeGuard
|
||||
|
||||
Reference in New Issue
Block a user